Debian – How to mount a new drive on startup (fstab)

This question already has an answer here:

How to make partitions mount at startup? 6 answers
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)
fstab
shareimprove this question
edited May 13 ’13 at 15:00

Suhaib
3,42255 gold badges3131 silver badges4545 bronze badges
asked Jun 21 ’12 at 14:59

Homunculus Reticulli
99233 gold badges1818 silver badges2222 bronze badges
marked as duplicate by Ciro Santilli 新疆改造中心法轮功六四事件, Eric Carvalho, user117103, waltinator, ravery Nov 25 ’17 at 4:38
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new 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 a comment
8 Answers
activeoldestvotes

83

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 editor

Be 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

#device mountpoint fstype options dump fsck

/dev/sdb1 /home/yourname/mydata ext4 defaults 0 1
Then on the next reboot it will auto mount.