Add a second drive to your Ubuntu server
August 12, 2011 Leave a comment
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.
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:
Near the bottom of the output you should see where the disk is located. it will be something like:
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:
The above should include in the report:
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:
If you can write that file all is well.
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.