Moving the Root Partition to a New Disk in Ubuntu 18.10 (General GRUB Chicanery)

I had a Ubuntu 18.10 install setup perfectly on a disk shared with a Windows 10 install. I originally setup Windows 10 and then reduced the size of the Windows 10 partition to make room for a Ubuntu 18.10 install.

After the install of Windows 10 and the Ubuntu 18.10 install I had these partitions:

/dev/nvme1n1 -> GPT
/dev/nvme1n1p1 -> Windows Recovery (NTFS)
/dev/nvme1n1p2 -> EFI System Partition (vfat)
/dev/nvme1n1p3 -> Microsoft reserved partition
/dev/nvme1n1p4 -> Windows 10 Install (NTFS)
/dev/nvme1n1p5 -> Ubuntu Install (ext4)

This was a 512GB NVME drive. Windows and Linux each had roughly 256GB of space, not enough for either really. The windows install was mainly for the occasional gaming session and the linux install was my main work environment. To fix this major problem, I purchased a 1 TB PCI NVME drive for the linux install.

Now I had a problem, how do I move my perfect setup without messing it up. Here’s how I did it.

Install the new NVME or hard drive or SSD. Now get started.

First get a Ubuntu live boot CD. If you have a Ubuntu 18.10 USB key or CD you are all set. Boot up into the live environment, not the install option.

Open a terminal.

Type:

sudo blkid

This should provide a list of the block devices on you system

You should see your original disk. Mine was /dev/nvme1* (n1p1, p2, p3, p4, p5, etc.). You should also see your new disk. My new disk was /dev/nvme0.

Make sure you are clear on which disk is new. Use fdisk to create a new partition on the new disk.

fdisk /dev/nvme0

Type ‘n’ to create a new primary partition. The defaults should create a partition that fills the new disk. If you want to delve deeper in the commands for fdisk check out: https://www.tldp.org/HOWTO/Partition/fdisk_partitioning.html

Once you have the partition created type ‘w’ to write it to disk. If you issue the ‘sudo blkid’ command again you should see your new partition. In my case the new partition was ‘/dev/nvme0n1p1’.

Now mount the old partition and the new partition.

To do this type

sudo mkdir /mnt/old
sudo mkdir /mnt/new
sudo mount /dev/nvme1n1p5 /mnt/old
sudo mount /dev/nvme0n1p1 /mnt/new

Now we need to copy the data from the old disk to the new disk. Keep in mind that in my case I had a single partition that kept ‘/’, ‘/boot’, and ‘/home’. If you have separate partitions for those directories then you will need to wither create the same format on your new drive or collapse them onto the single partition during the copy process.

To copy the data do this (preserving permission and owners):

cp -av /mnt/old/.* /mnt/new/

I use the ‘-v’ option so I can check the stream of what is being copied. It may slow down the copy since you are waiting on terminal character buffers in some cases.

Now, you can reboot into the old environment and it is time to update ‘grub’ so your system will boot into the new environment.

Once you are logged into your old environment lets update ‘grub’.

Remember, in my scenario /dev/nvme0 is the new disk, /dev/nvme0n1p1 is the new environment, and /dev/nvme1n1p5 is the old environment.

First let mount the new partition:

sudo mkdir /mnt/new
sudo mount /dev/nvme0n1p1 /mnt/new

Now we need to mount the efi partition that we identified back in the first steps.

sudo mount /dev/nvme1n1p2 /mnt/new/boot/efi

The efi partition will be important later.

Now mount using the ‘-B’ option to bind the following filesystem into the new environment ‘/proc’, ‘/dev’, ‘/dev/pts’, and ‘/sys’.

mount -B /proc /mnt/new/proc
mount -B /dev /mnt/new/dev
mount -B /dev/pts /mnt/new/dev/pts
mount -B /sys /mnt/new/sys

Ok, time for the magic. Chroot into the new environment.

sudo chroot /mnt/new

In the new environment you will run this command to update and install grub on your original volume since you want to keep that grub install.

sudo update-grub
sudo grub-install /dev/nvme1

Remember /dev/nvme1 was my original disk and I did not want to change the grub location.

Now you can reboot into the new environment.

After you validate the update you can delete the old install. I did this by booting into my windows environment and deleting the old install and expanding the window partition back to it’s full 512GB glory.