blocks icon indicating copy to clipboard operation
blocks copied to clipboard

[GUIDE] Converting root -> LVM on Ubuntu 20.04 Setup

Open ossie-git opened this issue 5 years ago • 4 comments

This project hasn't been updated in years but I was able to get it working on Ubuntu 20.04. Here is what I did to get it working on a Ubuntu 20.04 host using an Ubuntu 20.04 Live CD to actually run blocks. I ran it successfully both in a VM environment (I did this to test before actually running it on my real environment) and on my desktop machine

Steps

On Your Host

perform the following steps:

make s

  • ure that filesystems are accessed via UUIDs in /etc/fstab (this is the default)
  • then run: $ sudo apt install lvm2
  • make sure that lvm.mod exists under your /boot partition
  • reboot into your LiveCD

In Your LiveCD

I was able to get this up and running on an Ubuntu 20.04 LiveCD by doing the following:

# sudo -i
## copy over an /etc/apt/sources.list and overwrite your current /etc/apt/sources.list using it. For example, you can use this: https://gist.github.com/ishad0w/788555191c7037e249a439542c53e170
# apt update
# apt install python3.8 python3-pip git libparted-dev libaugeas0 pkg-config libpython3.8-dev gcc cryptsetup lvm2 liblzo2-dev nilfs-tools reiserfsprogs xfsprogs e2fsprogs vim
# git clone https://github.com/g2p/blocks
# cd blocks
# pip3 install -r requirements.txt

You now have to make a small modification to main.py so you don't run into this issue: https://github.com/g2p/blocks/issues/8

vim /home/ubuntu/blocks/src/blocks/blocks/__main__.py

search for:

exit_stack.callback(lambda: quiet_call(cmd))

add this line BEFORE IT:

time.sleep(5)

now you can simply point it to your partition and reboot once it is done:

# blocks to-lvm /dev/vda3
The filesystem (ext4) leaves enough room, no need to shrink it
Copying 4194304 bytes from pos 0 to pos 134872039424... ok
Preparing LVM metadata... ok
If the next stage is interrupted, it can be reverted with:
    dd if=/dev/vda3 of=/dev/vda3 bs=4194304 count=1 skip=32156 conv=notrunc
Installing LVM metadata... ok
LVM conversion successful!
Volume group name: vg.vda3
Logical volume name: vda3
Filesystem uuid: 96c8179b-a4af-478d-ba6a-99908128f18e

now reboot your system and you should be good to go. I successfully ran this in both a VM (to test it out first) + my desktop installation

ossie-git avatar Dec 10 '20 02:12 ossie-git

This is excellent, thank you !

I'll just add 2 minor points:

  1. copy an existing source file is because some packages (libaugeas0, nilfs-tools) belong to the universe repo, it's enough to edit /etc/apt/source.list to add it.

  2. when migrating a luks encrypted partition, the software will try to use the partition name as a LVM volume name and will assert out (I think that's the dashes in the LUKS ID LVM is not liking) , so it's necessary to specify a volume name explicitly:

blocks to-lvm -vg=newlvmvol /dev/mapper/luks-872b653c-5194-.....

gpatel-fr avatar Apr 10 '21 16:04 gpatel-fr

Great manual, thanks! Maybe the https://github.com/g2p/maintboot tool will work without massive rework too? The blocks needs especially when we need to convert root filesystem without ability to boot from other partition or iso (it is a common situation on VPS provided by popular hosters), so we can't do this without maintboot :-(

MurzNN avatar Aug 17 '21 15:08 MurzNN

Also I see that @viccie30 forked both project with fresh commit with preparing to package in debian, so maybe he have some test results...

MurzNN avatar Aug 17 '21 15:08 MurzNN

I did not convert my root partition, but I can confirm that converting a regular partition to LVM still works without problems under Ubuntu 20.04 with the steps outlined by @ossie-git

KenADev avatar Jan 17 '22 19:01 KenADev