John's Musings

Yeah, Me Neither

Installing a New Hard Drive in Ubuntu Server for the Home Partition

I recently installed Ubuntu Server 16.04 on a home brew appliance with a 275 GB SSD hard drive. After it was all said and done I realized that wasn't a lot of room for file storage. So I picked up a 2TB drive and moved the servers /home partition to the new drive.

This blog quickly describes how to it in case I destroy my server and need to do it again someday. It's best if you can somehow format the drive for one partition to ext4 first. If not, well we'll cover that too. First of all physically install the device and boot and ssh into your UbuntuServer. Once in type:

sudo blkid

This will give you the UUID of your devices or at least give you their /dev name if it isn't formatted yet. I found out that my hard drives were as follows:

275 GB SSD = /dev/sda

New 2TB drive = /dev/sdb

Now lets make a partition and format:

sudo fdisk /dev/sdb (because that's the new drive, format the wrong one and bye-bye operating system).

Now type in the letter "n" (without the quote marks) and simply follow all the defaults. P for primary partition, 1 for first partition, accept the defaults for the first and last block then when you are done make sure and type "w" to write the changes. Now that you have a partition. let's format it.

sudo mkfs -t ext4 /dev/sdb1

Now after that completes do another blkid Copy the highlighted part after UUID between the quotation marks.

Make a copy of your fstab file that you are about to alter

sudo cp /etc/fstab /etc/fstab.$(date +%Y-%m-%d)

Now do:

sudo nano /etc/fstab

Now add the following to the file

UUID=thatlongnumberyoucopiedbefore /media/home ext4 defaults 0 2

hit CTL + x then yes to save

Now make a directory to mount and then mount your filesystems

sudo mkdir /media/home

sudo mount -a

Now copy your current /home directory to the new drive

sudo rsync -aXS --exclude='/*/.gvfs' /home/. /media/home/.

Once it has copied go back to your fstab file and then remove the /media in front of /media/home

sudo nano /etc/fstab

UUID=thatlongnumberyoucopiedbefore /home ext4 defaults 0 2

Now remount

sudo mount -a

And Bob is yer Uncle. You did it. Your home partition is now on a much, much larger drive.