00:03

Formatting USB hard drives for Ubuntu (Gutsy Gibbon)

Recently my home Network Attached Storage (NAS) started acting flaky, so I wanted to back up my data. I picked up a 750 gigabyte Seagate Free Agent Pro drive. Here’s how I fixed a couple annoyances:

1. The drive is formatted with ntfs.

That’s great for Windows computers, but I preferred to format into a native Linux filesystem like ext3 or ext2. Rather than typing commands like mk2efs myself, I installed a wonderful utility called gparted. GParted lets you format and partition hard drives. Type the following:

sudo apt-get install gparted
sudo gparted

GParted is pretty intuitive. If you’ve just plugged your drive into the computer, unmount the drive by selecting the external drive (under GParted->Devices) and then doing Partition->Unmount. Then make sure the correct drive is selected (under GParted->Devices again). Once the right device is selected, click on the partition you want to format and select Partition->Format to . I recommend “ext3″ because it’s a very stable file system. Finally, click “Apply” on the menu bar and just wait 3-4 minutes. GParted will do all the formatting for you.

2. Give the partition a label

It’s nice if you plug in an external hard drive and you see something more descriptive than “disk” or “usbdisk”. If you formatted the drive as ext3 in step 1, you can use e2label (from the e2fsprogs set of utilities) to give your drive a persistent name. Each time you plug in that drive, you’ll see the same label for that drive. Attach the USB drive to the computer and use the “mount” command to identify the partition to add a label to. Normally you’ll see something like “/media/disk” mapping to a device like “/dev/sdX” where X is a letter like a, b, or c. Suppose the disk partition that you want to label is /dev/sdf1 and you want to call the hard drive “M1″. Here’s how to do it:

mount
sudo apt-get install e2fsprogs
sudo e2label /dev/sdf1
sudo e2label /dev/sdf1 “M1″
sudo e2label /dev/sdf1

The command “sudo e2label /dev/sdf1″ will query /dev/sdf1 to see what label it has. If there is no label, you will get back a blank line. The above command makes the label be “M1″. The final command reads the label back. If everything worked correctly, the final command should return the word “M1″. I’d stick with a short and simple label (under 16 characters, and nothing fancy schmancy like punctuation/spaces).

3. The Seagate Free Agent Pro drive can spin down under Linux when you don’t want it to.

There’s a setting in the hard drive that you can easily modify with the “sdparm” program. Install sdparm with “sudo apt-get install sdparm”. Then imagine that your device is /dev/sdX (again, X will normally be a letter like ‘b’ or ‘c’). Here’s what I typed to see the setting and modify it:

mount
sdparm -al /dev/sdX
sudo sdparm --clear STANDBY -6 /dev/sdX
sdparm -al /dev/sdX


You should see a line that looks like “STANDBY 1 [cha: y, def: 1, sav: 1] Standby timer active” change to “STANDBY 0 [cha: n, def: 1, sav: 0] Standby timer active“. If the drive has already spun down, you can unplug it, reboot everything, and plug it back in. Or the handy command “sudo sdparm --command=start /dev/sdX” might also wake it up.

The “-6″ is a fallback for some older types of drives and I think it’s pretty safe to include on sdparm commands.

0 comments: