Recently I picked up a new 4 TB SSD on sale at the Amazon Prime day sale to replace an aging RAID5 array in my media server. Over the last couple days I made the exchange and thought I should save an outline of the steps for posterity.
Connect the new drive through your preferred method, I chose USB.
Log into the server with SSH.
Identify the new drive with:
sudo parted -l | grep Error
Alternatively you can use the following command and make a visual match with the listed drives:
lsblk
Choose the partition standard for the drive with the following command:
sudo parted /dev/<drive> mklabel gpt
The drive name will be something like sda1, be careful as this is not consistent between boots and could possibly change if you restart during the process. You can read more about the GPT file system here .
Now create the partition with:
sudo parted -a opt /dev/<drive> mkpart primary ext4 0% 100%
As you might imagine the preceding command also created the filesystem in addition to creating a primary partition that takes up 100% of the drive. I currently use the ext4 filesystem for when I install Ubuntu on bare-metal, you can read about ext4 here .
Now we want to mount the new partition, you can do that with:
sudo mkdir -p /mnt/<folder name>
sudo mount -o defaults /dev/<partition> /mnt/<folder name>
Now that the drive is mounted the home directory, or wherever you have mounted the old drive, can be copied with:
sudo cp -rp /home/* <mounted drive>
The drawback to the previous command is that there is no progress provided. In order to have a progress indicator the rsync utility can be used. However, progress can still be monitored using the df tool:
df -hBM -x tmpfs -x devtmpfs
Once the transfer is complete unmount the old drive with the lazy option and comment out (or delete) it’s fstab entry. At this point you can power down and remove the old drive and install the replacement.
Once powered back on follow the prior steps to temporarily mount the drive and now to make the mount permanent requires a change to the fstab file I usually add the mount using the UUID, although there are a few different ways to accomplish the mount:
blkid | grep <UUID>
You can always check mount points using:
findmnt
Editing the fstab can be done with the editor of your choice with root, I use vim:
sudo vim /etc/fstab
Your entry in /etc/fstab should end up looking something like the following:
UUID=<your UUID> /home ext4 defaults 0 0
Congratulations you’ve now replaced your old disk or array with a shiny new one!
Sources and References
- https://devconnected.com/how-to-mount-and-unmount-drives-on-linux/
- https://www.howtogeek.com/442101/how-to-move-your-linux-home-directory-to-another-hard-drive/
- https://www.digitalocean.com/community/tutorials/how-to-partition-and-format-storage-devices-in-linux
- https://www.computerhope.com/unix/udf.htm