Moving Ubuntu from SSD to NVMe (mostly online) with LVM
This is mostly notes to my future self however it may also help someone else.
So to set the scene, I run most of my self-hosted services on a single server at home. Previously this was an Intel NUC6CAYH with the OS on a 2.5" SSD. Almost a year ago I picked up a Lenovo P330 Tiny to replace this NUC. It came with a 500GB NVMe. Anyway, when it arrived, I moved the SSD over and my system was moved. I now wanted to utilse the 2.5" slot for other purposes and that brings me to wanting to move the OS from the SSD to the NVMe drive.
I could have used pvmove
but I wasn't 100% confident, as like it's name suggests moves the data. I didn't know what this would look like had things failed.
TL;DR
Note: My SSD was /dev/sda
and the new NVMe is /dev/nvme0n1
- Created 3 partitions to match /dev/sda: 512MB, 1024MB and the rest for LVM
$ sudo cfdisk /dev/nvme0n1
2. Created PV from 3rd partition
$ pvcreate /dev/nvme0n1p3
3. Added the NVMe to vg0
$ vgextend vg0 /dev/nvme0n1p3
4. List the devices (I forget what this looked like)
$ lvs -a -o name,copy_percent,devices
5. This is the good bit, here we mirror vg0/system also onto our nvme PV. The command will hang until complete, but I found Ctrl-C seems safe
$ lvconvert -m1 --type mirror --mirrorlog mirrored --alloc anywhere vg0/system /dev/nvme0n1p3
6. Monitor that the copy has completed
$ lvs -a -o name,copy_percent,devices
7. Once happy, I then split off the /old/ PV: /dev/sda3 to an LV called system_old.
$ lvconvert --splitmirrors 1 --name system_old vg0/system /dev/sda3
That was roughly it, as I said this is more of a memory jog if I need to handle it again in the future. There were some missing commands to fully remove /dev/sda3
from the pv but I can't remember what they were.
The other bit was moving /boot/
and /boot/efi
which was little more than dd
ing the old partitions to the new ones. Some how I didn't need to mess around with efibootmgr
the machine just booted. One thing I would do next time is create a larger /boot/
next time, 512mb can be a struggle with more than one kernel.