====== Replacing/Upgrading a Data Disk ======
In the unlucky event that one of your data disks starts to show [[wp>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. If this is not the case, some of the commands below may need appropriate modifications for your environment.
===== Supported Releases =====
Should work in all Ubuntu releases. Tested from 10.04 (Lucid Lynx) to 13.10 (Saucy Salamander) on Ubuntu 32/64-bit.
===== Required Packages =====
None, as the required tools should already be present.
===== Configuration =====
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:
parted /dev/sdx
If your new disk is 2TB or below, complete the command as follows:
mklabel msdos
mkpart pri 1 -1
quit
If your new disk is larger than 2TB, complete the command as follows:
mklabel gpt
mkpart pri 1 -1
quit
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 2> sync_errors.txt
Review the ''sync_errors.txt'' file (if any) created during the copy to check for any files that may not have copied completely. This is easiest with:
less sync_errors.txt
If you suspect any files may have changed during the copy process it is possible to simply re-run the rsync 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.
===== See Also =====
* [[tech:ubuntu_smart]]
* [[sigma:how_to]]
* [[sigma:contact]]