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.
Read Related Posts
3 Responses to “Add a second drive to your Ubuntu server”
Trackbacks/Pingbacks
-
[...] 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. More here [...]
-
[...] :: ghacks Share and [...]

Set up your new Ubuntu Server as a Samba Server
Auto mounting a Samba share in Linux
Connect to your Samba server from Linux
Install Mantis Bug Tracking tool on your Ubuntu Server
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