Add a second drive to your Ubuntu server
You have your Ubuntu Server up and running (with the help of "Installing Ubuntu Server 9.04") but you're afraid you'll run out of room on your drive. To solve this problem you have installed a new hard drive, but because this is a GUI-less server you do not have access to the user-friendly GUI tools that make this job easy. So you're going to have to install this drive with the help of the command line.
GASP!
Never fear, it's not that hard. Just a few commands and you'll be up and running with your new hard drive installed on your server. This article will assume the physical drive is already installed on your machine.
I am going to make a couple of assumptions here, for the sake of simplicity for this article. The first assumption is that the new drive will be mounted to the directory /data. The next assumption is that you want this directory to be both readable and writable by all users on the system. Another assumption is that you will want the drive to be formatted with the ext3 file system with just one partition. Finally I will assume you want this drive to be automatically mounted upon boot of the system.
With that out of the way, let's get down to business.
Once you boot the machine with the new drive log into the console and issue the command:
dmesg
Near the bottom of the output you should see where the disk is located. it will be something like:
/dev/sdb
So let's assume it is on /dev/sdb.
If you can't figure it out where the drive is located  with dmesg issue the command:
sudo fdisk -l
The above command will report something like:
/dev/sda1 * 1 18709 150280011 83 Linux
/dev/sda2 18710 19457 6008310 5 Extended
/dev/sda5 18710 19457 6008278+ 82 Linux swap / Solaris
But will include a listing for your new drive. If you only see listings for /dev/sda* then your new drive has not been recognized and there is a problem with the physical installation.
Once you know where your drive is located (again we'll use /dev/sdb for our example) it's time to create a new directory where this drive will be mounted. We are mounting our drive to the directory /data so we'll create this directory with the following command:
sudo mkdir /data
Now let's make it available to all users:
sudo chmod -R 777 /data
With a place to mount the drive, it's time to format the new drive. The formatting will be done with the command:
sudo mkfs.ext3 /dev/sdb
When this is complete you are ready to mount the drive. Before you edit fstab entry (so the drive will be automatically mounted) make sure it can be successfully mounted with the command:
sudo mount /dev/sdb /data
If this is successful let's create an entry in /etc/fstab. open that file with the command
sudo nano /etc/fstab
Now add the following entry at the end of that file:
/dev/sdb /data ext3 defaults 0 0
Once you save that file, mount the drive (without having to reboot) with the command:
sudo mount -a
To make sure the drive mounted successfully issue the command:
df
The above should include in the report:
/dev/sdb  /data
If that's the case, success! You can run one file test by trying to write a file to the new drive with the command:
touch /data/test
If you can write that file all is well.
Final thoughts
Yes it is a bit more complicated than adding a new drive when you have GUI tools available, but it's not anything that can't be accomplished by the average user. If you are not afraid of the command line, you can add a second drive in Ubuntu with ease.
Advertisement
Wrote up how to do this on an Ubuntu VM here: http://www.zachpfeffer.com/single-post/Add-a-disk-to-an-Ubuntu-VirtualBox-VM
Perfect. Thanks for the assistance.
Thanks mate, I was getting really confused about how this was meant to be done. I was at the point of all sorts of shenanigans just to use gparted.
Much appreciation for your guide, very precise, very simple to follow. Installed and configured the second drive the first time. No hiccups, no drama.
Slow is Smooth, Smooth is Fast..!!!!
Thank You for this guide, I am a new on ubuntu server and your guide was very easy to follow and works very fine, I am now into how to share this folder/volume/partition (/data) over a network using samba … thanks again.
I want to add another physical storage (1TB) to /home which. Currently the /home is 1TB and I want to add another 1TB.
Is it possible to do your procedure except that creating /data, mount the new formatted disk to /home?
If you want to mount to /home, you should add a line at /etc/fstab something likje:
/dev/sdb /home/data ext4 defaults 0 0
for
/dev/sdb /home/user_name/data ext4 defaults 0 0
Isn’t it necessary to create a partition first before formatting with mkfs?
One thing that is not clear from this tutorial is why use /dev/sda, instead of creating one partition. My intent is to use the whole drive but is there any advantage or disadvantages over one vs the other one?
Jack, thanks for this tutorial! As mentioned above, it helped me fast in my first server set up. I would really take Rupert’s note about UUID into consideration, whether to incorporate it into the tutorial itself. I guess it might save couple of server admins in the future.:)
Rupert’s comment is absolutely right. i had exact same problem trying to figure out why my Ubuntu 10 system wont continue to load, instead it just gives me message “Disk drive for /home is not ready yet or not present. Continue to wait; or press S to skip or M for manual recovery.” I ended up doing manual recovery. since linux is a new ground for me, its been a while before i figure out with the help of this page and of course Rupert.
My system drive ended up /sdb instead of /sda before. so what i after doing a fdisk -l, is to edit fstab and modify the drive letters. then replaced the entries and used UUID.
with lots of thanks to you guys. hope my experience will help others as well.
Cheers!!!
You rock! This is by far the best instructions that I have come across so far. You really do make Linux easy for us.
Thanks
Out of the few tutorials I read and after spending many hours toying with parted and fdisk, your guide is the one that has helped me to sucessfully add, format and mount another drive to my Ubuntu Server 9.10 installation. Very simple to follow, requires NO prior knowledge or Linux experience (I just started 2-3 days ago).
Will be adding this site to my favs. Thanks!!!
I would STRONGLY advise against using /dev/sdb to automount the drive in /etc/fstab. It is MUCH safer to use UUID= to mount the drive (you can determine UUID using blkid in the Terminal). The reason being Ubuntu sometimes changes the drive order, particularly if you boot up with a USB drive attached, so what is normally /dev/sdb might randomly become /dev/sdc. This can cause some severe problems if you have any file processing scripts running when your machine boots up (as I have). I used to use /dev/sdb until my rsync script completely overwrote my backup drive after a reboot when /dev/sdc and /dev/sdb swapped places…
If you use the UUID number instead of /dev/sdb, this is much safe, since the UUID is a unique number assigned to each individual hard drive and it doesn’t change.
Using UUID is now the recommended way to mount a drive using fstab.
More information here:
https://help.ubuntu.com/community/UsingUUID
i have headache due to mounting using /dev/sd*
wasting hours trouble shouting and end up the safest way to mount is by using UUID
Note: /dev/sd* might change everytime you restart