Saturday, August 13, 2011

Adding an extra hard disk to Ubuntu

So I just bought myself a 2TB Western Digital Caviar Green hard disk. It’s been 6 - 7 years since my last hard disk upgrade. I did upgrade my PC a while back but I opted to reuse certain components to minimise cost. My dual 160GB SATA hard disks worked well at the time so I didn’t see a need to replace them. They still work well now, in fact.

Be that as it may 6 - 7 years is a long time so I start to worry about when these two might decide to die out on me. A bigger consideration is the increasingly larger media files that I’m accumulating in my hard disks. I have 2 hard disks precisely so I can keep data on one and the system on another. This way it’s not too big a deal if Ubuntu fails on me for whatever reason and I need to clean install. But that also means I’m limiting myself to using only 160GB for media storage. Nowadays, that’s peanuts.

So, with explanations out of the way. Let’s get to the meaty parts.

A simple benchmark

Disk Utility benchmark
Before I make use of this hard disk, I’ll use Ubuntu’s disk utility to benchmark this hard disk. Once I start using it I won’t be so eager to clear it out just for a benchmark so I’ll get this out of the way first. This will also help give me a rough idea what kind of performance I can expect.

An average read rate of ~95MB/s would be almost double what my current hard disks can do. I’ve no idea about the write rate though since I’ve never benchmarked the old drives (~50MB/s). The write test in Disk Utility needs the hard disk to be devoid of partitions. I’d hardly empty out my hard disk just for that.

Formatting the disk

This’ll be taking over as my new data hard disk from now on, so I’ll be formatting it to ext4. As much as I like btrfs it’s still much too early to trust it with all my data. Having a 2TB drive to store all my data means I’m free to possibly explore using btrfs for /. Since I’ll have 2 160GB hard disks that also creates the possibility of trying out a multiple device setup. But that’s for another post.

Formatting is a bit convoluted. You’ll need to install and use Gparted to create the partitions. Alternatively, the Ubuntu LiveCD comes with it already so reboot to the LiveCD and create the partition(s) from there. For some reason creating partitions using fdisk, or Disk Utility isn’t aligned to the new Advanced Format sectors.

Once your desired partitions have been created, use Disk Utility to format them. Partitions formatted with Gparted seem to require root to mount whereas Disk Utility formatted partitions allow the user to mount them by double clicking the volume. I chalk it down as one of those things in need of spit and polish.

Automounting the volume on startup

As for making the new volume auto-mount during Ubuntu startup, it takes a bit of messing around with /etc/fstab. The good news is it’s nothing too complicated.

First, is to find out the new volume’s UUID. The community documentation provides a more detailed explanation.

~$ sudo blkid
/dev/sda1: LABEL="yuuna" UUID="28fefd55-af36-4ccf-ae6c-f0d2fab71a88" SEC_TYPE="ext2" TYPE="ext3"
/dev/sdb1: UUID="3e2aba9b-e4ef-4c39-b7c1-b73694cf9989" TYPE="ext4"
/dev/sdc1: LABEL="yune" UUID="c4d02b47-d137-41b1-951d-bdfde0f41234" TYPE="ext4"

Above is the output I get with the blkid command. Yours will be different, of course. My new hard disk is formatted to a single volume. I set the label to “yune”.

~$ sudo vim /etc/fstab

I used vim to do the editing but you could easily make use of gedit, nano, or any other text editor for the job. Once you have it open just add the following line to /etc/fstab:

UUID=c4d02b47-d137-41b1-951d-bdfde0f41234 /media/yune ext4 defaults 0 2

Remember to change the UUID and /media/yune accordingly. The volume should auto-mount on subsequent reboots. If you're interested there's more info on /etc/fstab here.