This article is not exactly a tutorial, it’s the sharing of an experience that might help others. Follow this guide at your own risk. Document yourselves before doing anything. „Don’t write code you don’t understand” (Toth Arpad).
After using LVM for a long time, and performing all sorts of experiments with logical volumes on my laptop, to have flexibility and to be able to keep moving and reinstalling all sorts of Linux distros, I’ve decided to go for it and listen to the Open Source community and give BTRFS a run for it’s money.
At first I didn’t understand what it is and how it works so like a fool, I kept making LVM partitions but used BTRFS as a filesystem on them, basically using it like ext4.
I kept at it, mostly because I was too lazy to document myself, until Alex saw what I did and knocked some sense into me.
I’ve began to study rigorously and read (at least part of) the documentation. That was a moment of revelation. WOOOOO’ what can BTRFS do!!
Like I said earlier this is not a tutorial on how to use BTRFS, I’m just encouraging you to give it a spin. The story „it’s not yet stable” is just something that the developers say. From reading and asking developers about it both result in: „It’s not declared stable”. Though companies are using it on their production systems. I say: make your own opinion of how stable it is.
After I’ve played with it here and there, I’ve decided to give up LVM completely. Here came the challenge: How do I do this?
My system was a mixture of LVM, BTRFS and Ext4. I had something like:
- MBR Partition table
- 4 primary partitions -allusingLVM (in the following order):
- 100 GB
- the rest
- 80 GB
- 4 GB (swap)
- I had 4 logical volumes:
- root 1 (btrfs)
- root 2 (ext4)
- root 3 (ext4)
- home (ext4)
I can’t even remember which volume was on which physical partition.
OK, how do I migrate? In short, I had 3 options:
- Reinstall everything and start from scratch (this would mean to waste lots of time in reconfiguring my system the way I like it)
- Create a new BTRFS partition and copy everything over (using cp) (then fight with the hashes to make them work)
- Add another device to the filesystem, remove the old one, and let BTRFS move the data
Obviously I’ve opted for the third option.
I’ve began by cleaning up: removed root 2 and root 3, made sure that all the data aren’t on the first partition (100 GB) anymore and that it is free to be used.
sudo lvremove VolGroup00/lvolroot3 sudo lvremove VolGroup00/lvolroot2 sudo pvmove /dev/sda1 sudo vgreduce VolGroup00 /dev/sda1 sudo pvremove /dev/sda1
I used the KDE Partition Manager to format it as an empty partition.
After I’ve cleaned up and got my system running with only Kubuntu 15.04 with backports, and a single root partition, I’ve started the migration.
I’ve added the partition as a new device to the BTRFS filesystem on root 1, and removed the old one.
sudo mount /dev/VolGroup00/lvolroot /mnt/ cd /mnt/ sudo btrfs device add /dev/sda1 @
Kubuntu named my subvolume @. I got to the following arrangement:
$ sudo btrfs filesystem show Label: none uuid: 4fec1419-052f-40bc-b390-41cadab82e0b Total devices 2 FS bytes used 11.69GiB devid 2 size 100.01GiB used 0.00GiB path /dev/sda1 devid 3 size 50.00GiB used 14.06B path /dev/mapper/VolGroup00-lvolroot
I removed the LVM using device.
sudo btrfs device delete /dev/mapper/VolGroup00-lvolroot @
After a waiting period during which my Hard Disk cranked like hell, I’ve reached this arrangement:
$ sudo btrfs filesystem show Label: none uuid: 4fec1419-052f-40bc-b390-41cadab82e0b Total devices 2 FS bytes used 11.69GiB devid 2 size 100.01GiB used 14.06GiB path /dev/sda1 devid 3 size 50.00GiB used 0.00B path /dev/mapper/VolGroup00-lvolroot
This is where the fun began: make GRUB work. I’ve edited my fstab (commented the root LVM partition) and updated grub.cfg, hoping it’s enough:
$ cat /etc/fstab # #/dev/mapper/VolGroup00-lvolroot / btrfs defaults,subvol=@ 0 1 /dev/sda1 / btrfs defaults,subvol=@ 0 1 /dev/mapper/VolGroup00-lvolhome /home ext4 defaults 0 2 # swap was on /dev/sda2 during installation UUID=8f87084f-c265-4efd-b3af-10f597ea1126 none swap sw 0 0
Rebooting my laptop:
Error: unknown filesystem. grub rescue>
After some searching online and many failed experiments, I’ve reached this solution: In grub rescue> To test each partition and find the one I needed, I ran:
grub rescue> ls msdos4 msdos3 msdos2 msdos1 VolGroup00-lvolroot VolGroup00-lvolhome grub rescue> ls grub rescue> ls (hd0, msdos4) unknown filesystem grub rescue> ls (hd0, msdos3) unknown filesystem grub rescue> ls (hd0, msdos2) unknown filesystem grub rescue> ls (hd0, msdos1) @ grub rescue> set boot=(hd0,msdos1) grub rescue> set prefix=(hd0,msdos1)/@/boot/grub grub rescue> insmod normal grub rescue> normal
And my system started. Yeeeeey!!!
I’ve also ran the following to fix my grub permanently:
sudo grub-update sudo grub-install /dev/sda
And it’s done. It works!
Next I’ll migrate /home and finish eliminating LVM.