I have recently installed a new hard drive to my Ubuntu 10.0.4 box. I used System -> Administration -> Disk Utils to format the disk (ext4 file type) - but did not create a partition (is this advisable?).
I have manually mounted the drive as /mydata.
I want to have the machine automatically mount the device on startup/reboot. How may I do this?
[[Update]]
This is the output from running sudo fdisk -l
on my system:
Disk /dev/sda: 500.1 GB, 500107862016 bytes
255 heads, 63 sectors/track, 60801 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000858bf
Device Boot Start End Blocks Id System
/dev/sda1 * 1 59334 476595200 83 Linux
/dev/sda2 59334 60802 11789313 5 Extended
/dev/sda5 59334 60802 11789312 82 Linux swap / Solaris
Disk /dev/sdb: 500.1 GB, 500107862016 bytes
255 heads, 63 sectors/track, 60801 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Disk /dev/sdb doesn't contain a valid partition table
Disk /dev/sdc: 16.0 GB, 16026435072 bytes
254 heads, 63 sectors/track, 1956 cylinders
Units = cylinders of 16002 * 512 = 8193024 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Device Boot Start End Blocks Id System
/dev/sdc1 1 1955 15641929 c W95 FAT32 (LBA)
First of all your
/dev/sdb
isn't partitioned. I am assuming this is the disk you want to mount.WARNING: THIS WILL DESTROY ANY DATA ON YOUR TARGET DISK
Run
sudo fdisk /dev/sdb
Press O and press Enter (creates a new table)
Press N and press Enter (creates a new partition)
Press P and press Enter (makes a primary partition)
Then press 1 and press Enter (creates it as the 1st partition)
Finally, press W (this will write any changes to disk)
Okay now you have a partition, now you need a filesystem.
Run
sudo mkfs.ext4 /dev/sdb1
Now you can add it to fstab
You need to add it to
/etc/fstab
use your favourite text editorBe careful with this file as it can quite easily cause your system not to boot.
Add a line for the drive, the format would look like this.
This assumes the partition is formatted as ext4 as per mkfs above
Then on the next reboot it will auto mount.
This web page has a lot of useful info on fstab
The GUI solution for me is gnome-disks
Then with the configuration button you can "edit mount options", feel free to give the destination of your mount point and it will be saved into the /etc/fstab automatically
Note: the
nofail
option that causes the system not to hang if this mount point is not available, could be useful in case of potential unreachable filesystem on boot such as USB, NFS, etc.To set the drive to mount automatically each time you boot the computer
You’ll need to edit /etc/fstab:
Just press Ctrl+Alt+T on your keyboard to open Terminal. When it opens, run the command below.
Add this line to the end:
Note: Make sure to replace the X with the right value for your situation.
Or you can use Storage Device Manager, from the software centre.
The fstab file lets the system know which drives to mount (or how to mount them, at least).
then add a line like this one:
Of course, replace the values to suit your actual locations:
/dev/sdb1
should be the device and partition for the disk you want to mount./mydata
is the place where you want to mount it.ext4
is the type of filesystem it's using. If you're not sure, issue themount
command without arguments when the drive is mounted (even if you mounted it manually), it will tell you the filesystem type. (in 12.04 you may simply typeauto
which determines the filesystem for you at launch)defaults 0 0
) are OK like I show them.If you want to learn more, you can read
man fstab
.You could do it via /etc/fstab.
For example, if you add
It means that the device/partition located at /dev/hda2 will be mounted to /myfiles using the file system ext2, with default mount options and no dumping and no error-checking enabled.
If you are using FAT32 or NTFS file system using the following:
For NTFS:
noatime
andnodiratime
are some optimizations. If you want you can remove them.For FAT32 replace
ntfs-3g
withvfat
.fstab will help you for sure.
For those lazy and cautious ones who want to use a simple and self-explanatory GUI there is a tool called Storage Device Manager (pysdm). The tutorial here will do basically the same as other answers in this thread suggest to do, but the tool will accomplish it with a couple of clicks and no need to enter configurations manually into fstab config file.
sudo apt-get install pysdm
(Ubuntu) orsudo yum install pysdm
(Fedora)Nothing should go wrong, but just in case, backup the fstab conf:
sudo cp /etc/fstab /etc/fstab.old
Now run the Storage Device Manager and select your preferred partition, click "Assistant":
PySDM assistant settings for automounting EXT4 partition:
PySDM assistant for automounting NTFS partition:
Reboot and see that your drive gets automatically mounted now.
You can learn more about assistant settings from this article, as it explains the process in details and my answer is based on it.
UPDATE:
pysdm
has been removed from the Ubuntu archives (AskUbuntu page),sudo apt-get install pysdm
does not work anymore.If you do not want to partition or cannot afford to, you can use udisks to mount or unmount devices or disks. The UUID method is the most stable one as other ID methods can change if you rename your label for example.
It will in fact do the same as you would do by clicking the device on nautilus.
Just add it as a "startup application" to preform at login.
To unmount, (if you need to):
Will do the same as clicking the unmount arrow in nautilus.
One disadvantage over the
fstab
method is the device will be mounted in/media/disk_label
with no option to choose another mount-point.One advantage is you do not need root access to mount or unmount the drive.
More info over different methods of auto-mounting : AutomaticallyMountPartitions