Deep Learning On a quest to solve superintelligence

Move from block partition to lvm partition on Ubuntu 17.10

This tutorial shows how to move the Ubuntu filesystem from a regular block partition, to a LVM2 Partition. This may be necessary to do if you are silly like me and forget to select LVM when installing your Ubuntu system. This guide assume that you have a secondary hard-drive/partition with equal or more space than your old block partition. Lets get on with it!

First, log in as root. Ah, and i take no responsibility if you mess things up ūüôā

1. Identify which hard-drive you will use for your LVM Partition. Create a partition. In my case i used /dev/sda and created a partition at /dev/sda2. I used the graphical interface that ships with Ubuntu Mate, but you can also use parted/gparted etc.

2. Create a new LVM parition

 pvcreate /dev/sda2

3. Create a new Logical Group. You can call it whatever. I call mine vg_root.

 vgcreate vg_root /dev/sda2

4. Create a new Logical Volume. The -L argument specifies the volume size. In my case i create a 60 GB volume. As mentioned, it should be larger than your old filesystem

 lvcreate -L 60G -n lv0 vg_root

5. Format the partition with ext4.

 mkfs.ext4 /dev/vg_root/lv0

6. Mount the newly created volume

mkdir /mnt/new_root
mount /dev/vg_root/lv0 /mnt/new_root/

7. Copy old filesystem to the mounted location

cp -ax / /mnt/new_root/
cp -ax /boot /mnt/new_root/

8. Edit /etc/fstab. Comment out the old / mount point and add

/dev/vg_root/lv0 / ext4 errors=remount-ro 0

9. Mount new filesystem

mount -o bind /dev /mnt/new_root/dev
mount -t proc none /mnt/new_root/proc
mount -t sysfs none /mnt/new_root/sys
cd /
chroot .
cd /mnt/new_root/
chroot .

10. Update Grub



11. Reboot

You should now be up and running on your newly create LVM partition

Oh, so you fucked up? If you managed to do the copy procedure correctly, you can still save this. Boot up ubuntu from live-cd

12. Install Boot-Repair

sudo add-apt-repository ppa:yannubuntu/boot-repair
sudo apt-get update
sudo apt-get install -y boot-repair && boot-repair

13. Follow instructions carefully

14. Reboot

Now you should be up and running!

%d bloggers like this: