Tuesday, June 3, 2008

Formatting a hard drive in linux

I got 2 hard drives for my system. Seagate 7200.10 Barracudas, 250gb each. The first one was formatted and the partitions were created (ext3 file system) during the ubuntu install. However, I couldn't figure out how to format the second one.

After a bit of searching, I found a couple of ways to do it. The first is to use fdisk and mkfs: http://www.ehow.com/how_1000631_hard-drive-linux.html

The second is to use gparted. I chose to use gparted because it has a gui. I first selected the drive I wanted (/dev/sdb) and created a disklabel (I used the "msdos" table type). I then created a primary partition (ext3 filesystem) by choosing Partition -> New from the menus.

After hitting "Apply", the partition was created in a few seconds. Pretty easy.

Next I edited /etc/fstab to get the drive to automatically mount on startup. I added the following line to my fstab file:

UUID=41a557bc-3f4f-4cc9-8edf-c32672529897 /stuff ext3 relatime,errors=remount-ro 0 1

where the relatime,errors=remount-ro options are the same as my main drive.

I chose to mount by UUID instead of device name in case I wind up swapping the drives around. In order for the mount by UUID to work, I first had to add a symbolic link in /dev/disk/by-uuid/ for the partition I just created.

I found the UUID of the partition using the vol_id command:

sudo vol_id /dev/sdb1

I then created the symbolic link in /dev/disk/by-uuid/ using the ln command:

sudo ln -s ../../sdb1 41a557bc-3f4f-4cc9-8edf-c32672529897

where sdb1 is the partition I just created and 41a557bc-3f4f-4cc9-8edf-c32672529897 is the UUID returned by vol_id

No comments: