Adding a New Hard Drive to an Ubuntu Virtual Machine

How to setup a new hard drive in Ubuntu

Since Ubuntu just has to be different to be difficult unlike other flavours of Linux, here is a mini how to on configuring a new hard drive. Keep in mind this all can be done over ssh. GUI are probably available but this is the good old way.

I’m assuming you already have the drive added to the vm, you just need to know how to configure it because it’s not the same as my other post.

I’ve copied everything and edited it a bit, from here.  I tried it the first time with Server Version 8.04.

Once it’s up, login and type:

df -h

Paste that output somewhere as it may be useful later.

Then again the following command:

ls /dev/sd*

It should report back with a list of partitions on the disks both the original and the new.

We need to establish which is the new one, it’ll probably be sdb but you’ll know because it will be the one NOT mentioned in the output of df -h.

Once we know which one the new is, we can partition/format it. Again, in the command window, we need to run the following:

fdisk newdisklocation (eg. fdisk /dev/sdb)
type p and press enter, it will list the partitions (if any) on the disk.
Once your happy its definitely the new disk as opposed to the old, press n and enter.
Press p for primary partition.
Press 1 for the partition number.

Use the default values for the cylinders so it uses the whole disk.

Once its complete press w and enter to write the changes to the disk and exit from FDISK back to the command line.

On the command line, we use the following command to format the disk:

mkfs.ext3 newhddpartitionname (eg. mkfs.ext3 /dev/sdb1)

note the 1 is the number of the partition created.

Once this is done, we’re good to mount the drive to a location on the system.

Linux as I’m sure you’ll be aware doesn’t use drive letters like windows, and instead each ‘directory’ could be a different drive, partition, or even machine and you’d be unlikely to know unless you looked.

So, we need to decide where to put this disk, and I think from memory Zimbra likes to install itself into /opt.

Its up to you at this point whether we make /opt the entire new disk, or whether we make /opt/zimbra and set the new disk to just hold zimbra.

Either way, you use the following command to mount the new drive

mount /dev/sdb1 /opt


mkdir /opt/zimbra
mount /dev/sdb1 /opt/zimbra

This assumes /dev/sdb1 is the name of the partition.

If this works, re-run df -h and you should see a new entry as the new drive.

Bear in mind though, this will only work for this current boot up, we’ll need to add it to fstab (or via a little script) to mount this on boot up.

fstab commands:
/dev/sdb1 /opt/zimbra ext3 defaults,errors=remount-ro 0 0

Its important to test it before rebooting just to be sure its not mashed up fstab (and prevents booting!).

So, mount it as we did, and then type:

cd /
umount /opt/zimbra
Confirm this with df -h to make sure its not there anymore.
mount -a

Confirm its now in df -h

It's only fair to share...
Share on Facebook
Tweet about this on Twitter
Share on LinkedIn

Leave a Reply