Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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)
share|improve this question
    
there's a disks utility in 12.04 ... have a look you may find one in your version. It allows you to edit mount option on a partition there's one for startup –  Merlin Jun 21 '12 at 15:51
add comment

7 Answers

up vote 9 down vote accepted

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

then type o press enter # creates a new table

then type n press enter # creates a new partition

then type p press enter # makes a primary partition.

then type 1 press enter # creates it as the 1st partition

finally type w #this will right 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 o fstab

You need to add it to /etc/fstab use your favourite text editor

Be careful with this file as it can quite easily cause you system to not boot.

Add a line for the drive, the format would look like this.

This assumes the partition is formated as ext3

#device        mountpoint             fstype    options  dump   fsck

/dev/sdb1    /home/yourname/mydata    ext3    defaults    0    1

Then on the next reboot it will auto mount.

this web page has a lot of useful info on fstab

share|improve this answer
1  
+1 for pointing out the danger with editing fstab (thats why I thought I'd come in here and ask first). As it happens, my new drive is not partitioned, I formatted the entire drive using file type ext4, and the device name (obtained using Disk Utility GUI app) is /dev/sdb. Following from the syntax you gave, the new entry should be /dev/sdb /mydata ext4 defaults 0 1. I want the drive to be mapped to /mydata (from the root). Is that the correct syntax to use? –  Homunculus Reticulli Jun 21 '12 at 15:48
    
No it should be /dev/sdb1 if it is the only partition on the disk. you can check with "sudo fdisk -l" this will show you the disk /dev/sdb and then its partitions so /dev/sdb1 will be your ext4, and the mount point would be "/mydata" which would mean it was a folder that already exists on the root of the drive called mydata. FYI use the existing folders /mnt/mydata or possibly/var/mydata its what they're for. –  Shutupsquare Jun 21 '12 at 16:12
    
Yikes!. Thanks for the feedback. I have added the output of running sudo fdisk -l on my machine. Please advice how to proceed. MTIA. –  Homunculus Reticulli Jun 21 '12 at 16:20
    
I'll add it to my answer –  Shutupsquare Jun 21 '12 at 16:25
    
Steve: Have you noticed that fdisk reports Disk /dev/sdb doesn't contain a valid partition table in the output - should I be worried?. I remember reading somewhere that some apps may expect me to have created a partition on the disk and if they attempt to write to the disk - I'll lose the data on that disk. True?. If so, I will start from scratch again (instructions please ...). I can afford to lose the data at this stage but definitely not later on. –  Homunculus Reticulli Jun 21 '12 at 16:34
show 2 more comments

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.

gksudo gedit /etc/fstab

Add this line to the end:

/dev/sdaX /media/mydata ext4 defaults 0 0

Note: Make sure to replace the X with the right value for you situation.

Or you can use Storage Device Manager. If you don't have it installed then

share|improve this answer
add comment

You could do it via /etc/fstab.

For example, if you add

/dev/hda2   /myfiles    ext2    defaults    0    0

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.

share|improve this answer
add comment

If you are using FAT32 or NTFS file system using the following:

For NTFS:

/dev/sda3 /media/entertainment ntfs-3g rw,auto,user,fmask=0111,dmask=0000,noatime,nodriatime 0 0 /dev/sda4 /media/other ntfs-3g rw,auto,user,fmask=0111,dmask=0000,noatime,nodriatime 0 0

noatime and nodriatime are some optimization. If you want you can remove them.

For FAT32 replace ntfs-3g with vfat.

share|improve this answer
add comment

The fstab file lets the system know which drives to mount (or how to mount them, at least).

sudo edit /etc/fstab

then add a line like this one:

/dev/sdb1      /mydata   ext4   defaults   0   0

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 the mount 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 type auto which determines the filesystem for you at launch)
  • The other values (defaults 0 0) are OK like I show them.

If you want to learn more, you can read man fstab.

share|improve this answer
add comment

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) or sudo 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":

enter image description here

PySDM assistant settings for automounting EXT4 partition: enter image description here

PySDM assistant for automounting NTFS partition: enter image description here

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.

share|improve this answer
add comment

You can edit fstab to do it. You can follow this tutorial with pics:

http://www.computerandyou.net/2011/05/how-to-mount-a-windows-partition-on-linux-automatically-on-each-start-up/

share|improve this answer
    
There are no pics there. –  Elfy Jun 21 '12 at 16:35
    
There are lots of example though.. –  abhishek Jun 23 '12 at 11:10
    
There's one example - better to give people help.ubuntu.com/community/Fstab than some random blog page which might or might not be there in future –  Elfy Jun 23 '12 at 11:14
    
Welcome to Ask Ubuntu! Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference. –  Peachy May 31 '13 at 16:43
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.