This is an old revision of the document!


Replacing/Upgrading a Data Disk

In the unlucky event that one of your data disks starts to show S.M.A.R.T. errors warning of its decline, or you are just running out of storage space, this article describes how to provision a new disk and migrate the data to replace the old one.

This guide assumes your old disk has a single partition, is formatted with the EXT4 file-system and is mounted at /srv during boot.

Should work in all Ubuntu releases. Tested from 10.04 (Lucid Lynx) to 13.10 (Saucy Salamander) on Ubuntu 32/64-bit.

None, as the required tools should already be present.

Firstly, shut the machine down and attach your new disk to the SATA/SAS/SCSI bus and give it some power. Once connected, restart the machine, log on and become root:

sudo -s

Create a list of the disks connected to the machine:

sudo lshw -C disk

The output will be similar to below:

*-disk
       description: ATA Disk
       product: IC25N040ATCS04-0
       vendor: Hitachi
       physical id: 0
       bus info: ide@0.0
       logical name: /dev/sdb
       version: CA4OA71A
       serial: CSH405DCLSHK6B
       size: 37GB
       capacity: 37GB

Locate your new disk (by make/model) and make a note of its logical name.

For the rest of this guide we'll use /dev/sdx but you should substitute your device name.

Now create a partition on the new disk using:

fdisk /dev/sdx

The fdisk menu will appear. Use the commands in the following order to complete the task:

  1. “n” to create a new parition
  2. “p” for a primary partition
  3. “1” for the first partition
  4. “w” to write the partition table back to the disk and exit

Now format the new partition using:

mkfs -t ext4 /dev/sdx1

Mount the newly formatted parition at /mnt so that we can copy the data to it:

mount /dev/sdx1 /mnt

Copy the data from the old disk to the new one using (omit the v from the options if you don't wish to see detailed output as the copy proceeds):

rsync -aAXv /srv /mnt
If you suspect any files may have changed during the copy process it is possible to simply re-run the above command to update them. However, it is best to stop any processes that modify files on your data disk during the data transfer.

Now we must update /etc/fstab to mount the new disk to /srv during boot. Ubuntu now uses UUIDs to mount disks during boot. To locate these, run:

blkid

Locate the /dev/sdx1 line in the output, similar to the following:

/dev/sdx1: UUID="24e13b29-9c40-4cab-96aa-31777017b031" TYPE="ext4"

Make a note (or better still, copy to the clipboard) the UUID of the new disk and then edit the fstab:

nano /etc/fstab

Locate the line that contains /srv and update the UUID entry in it, so that it looks similar to the following:

UUID=24e13b29-9c40-4cab-96aa-31777017b031 /srv ext4 defaults 0 2

Save the file and exit.

You are now ready to shut the machine down, remove the failing/old disk and ensure the new one is securely mounted in its permanent position. When you restart the machine the new disk should automatically mount as /srv and contain all the data from the old one.