• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to auto-mount a drive on boot in Linux
#1
How to auto-mount a drive on boot in Linux

Due to my qualification in breaking things, especially in Linux i've decided to house all of my information for both Windows and Linux on a separate partition. This means the next time i brake my Linux install, (which i will), then all of my data is easily transferable.


Introduction

There's a file called /etc/fstab in your Linux system, fstab is a configuration file that contains information of all the partitions and storage devices in your computer. The file is located under /etc, so the full path to this file is /etc/fstab. /etc/fstab is just a plain text file, so you can open and edit it with any text editor.

By default Linux doesn't auto mount drives, (at least not in Ubuntu), to auto mount a selected drive or partition on boot, you need to edit that file.


Steps

1) Open the terminal
2) sudo nano /etc/fstab

The default file will look like this:
[spoiler][code=other]# /etc/fstab: static file system information.
#
# Use 'blkid -o value -s UUID' to print the universally unique identifier
# for a device; this may be used with UUID= as a more robust way to name
# devices that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point> <type> <options> <dump> <pass>
proc /proc proc nodev,noexec,nosuid 0 0
# / was on /dev/sda3 during installation
UUID=296662e8-9cba-4767-9858-880ca546b8e0 / ext4 errors=remount-ro 0 1
# swap was on /dev/sda4 during installation
UUID=2f02062d-7d02-4cab-9340-fbbe3a0c9108 none swap sw 0 0[/code][/spoiler]


3) Add the following (to the bottom of the file):
This is to auto mount the second partition of your hard drive, in my case formatted in NTFS. (Yours will be different depending on your circumstances!)

[code=other]#Auto mount the Shared partition, (sda2), File format: NTFS
/dev/sda2 /media/Shared ntfs-3g defaults,uid=1000,user,locale=en_GB.UTF-8 0 0[/code]


Explanation

The /etc/fstab file takes the following configuration:

<file system> <mount point> <type> <options> <dump> <pass>

The columns are as follows:

1. The device name or other means of locating the partition or data source.
2. The mount point, where the data is to be attached to the filesystem.
3. The filesystem type, or the algorithm used to interpret the filesystem.
4. Options, including if the filesystem should be mounted at boot. (kudzu is an option specific to Red Hat and Fedora Core.)
5. dump-freq adjusts the archiving schedule for the partition (used by dump).
6. pass-num Controls the order in which fsck checks the device/partition for errors at boot time. The root device should be 1. Other partitions should be either 2 (to check after root) or 0 (to disable checking for that partition altogether).


Also

After experimenting with this you may get a problem when deleting files, saying that they can only be deleted permanently and not moved to the wastebasket. Also opening text files was throwing errors, saying they're executables. Here's a fix!

Replace the above configuration with this:

[code=other]/dev/sda2 /media/Shared ntfs-3g defaults,uid=1000,user,locale=en_GB.UTF-8 0 0[/code]

You can find your id by running the "id" command from a terminal.
The reason for the message is that the folder is mounted and owned by root. In linux, non-linux file systems such as fat and NTFS have their permissions set at the time of mounting and can't be changed. To get the behaviour you desire you have to make yourself the owner of the mount point at the time of mounting.

If you do this, the first time you delete a file or folder a trash bin called .Trash-1000 will be created and deletions will go there until you empty it. (in the .Trash-1000/files folder, to be precise).


My set up

As i operate a dual boot machine, my partitions are set up as the following:

/dev/sda1 = Windows XP (NTFS)
/dev/sda2 = /media/Shared (Shared) (NTFS)
/dev/sda3 = / Ubuntu 10.04 (ext4)
/dev/sda4 = linux-swap


:tux
  Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Automatically start the eth0 network interface on boot - Linux Cent OS 6.5 Mark 0 5,155 07-07-2014, 11:05 PM
Last Post: Mark
  How to disable Auto Login in OpenSuse 12.1 Mark 0 10,398 08-01-2012, 05:46 PM
Last Post: Mark
  Deleting and recreating disks, shares, mount points and RAIDs with FreeNAS 7 / 7.2 Mark 0 8,734 17-09-2011, 05:13 PM
Last Post: Mark

Forum Jump: