move root partition (existing installation) to btrfs

    • move root partition (existing installation) to btrfs

      Disclaimer: Do it on your own risk. I only tried this in a virtual machine.

      Hi there.
      I'm trying to figure out how to move an existing installation to btrfs to use apt-btrfs-snapshot.
      apt-btrfs-snapshot creates a snapshot every time you run apt to install something. This also works if you install software through GUI.
      After moving to btrfs you can also create snapshots manually before you try out something.

      All commands in the guid have to be called from a linux live system.
      In my case I used kubuntu 17.04. sda is the existing OMV3 installation on ext4.
      I used the command btrfs-convert despite warnings you get all over the place.
      In production you might copy files around to a second drive and create a fresh brtfs partition.

      So far I succeeded inside a virtual machine. My question is.. did I miss something?

      Here comes the guide:

      Shell-Script

      1. # convert fs to btrfs
      2. btrfs-convert /dev/sda2
      3. # mount new filesysteme
      4. mount /dev/sda2 /mnt/
      5. # snap / into @
      6. btrfs sub snap /mnt/ /mnt/@
      7. # create subvolume @home. move files from home to @home
      8. btrfs sub create /mnt/@home
      9. mv -av /mnt/home/* /mnt/@home/
      10. # show your uuid
      11. btrfs fi sh
      12. # add changes in /etc/fstab
      13. nano /mnt/\@/etc/fstab
      14. ## change uuid of boot drive to the new UUID
      15. ## change fstype of boot drive from ext4 to btrfs
      16. ## remove all option of boot drive
      17. ## add option subvol=@ of boot drive
      18. ## change dump and pass to 0 and 0
      19. ## copy the line of boot drive to a new line
      20. ## change subvol=@ to subvol=@home in new line
      21. ## change mountpoint / to /home in new line
      22. # repair grub
      23. umount /mnt
      24. mount -o subvol=@ /dev/sda2 /mnt/
      25. mount /dev/sda1 /boot/efi/ # skip this if efi is not used
      26. mount --bind /dev/ /mnt/dev/
      27. mount --bind /proc/ /mnt/proc/
      28. mount --bind /sys/ /mnt/sys/
      29. chroot /mnt/
      30. grub-install /dev/sda
      31. grub-mkconfig -o /boot/grub/grub.cfg
      32. # setup complete. restart without linux live system
      Display All

      The post was edited 1 time, last by mehlbox: slight changes in code ().

    • I now successfully applied this to a debian machine. It worked out pretty well. I damaged my system on purpose and did a rollback without the need of live linux.

      Get apt-btrfs-snapshot like mentioned in my post before

      Source Code

      1. # install apt-btrfs-snapshot
      2. wget https://ftp.fau.de/ubuntu/pool/universe/a/apt-btrfs-snapshot/apt-btrfs-snapshot_3.5.1_all.deb
      3. dpkg -i apt-btrfs-snapshot_3.5.1_all.deb
      4. rm apt-btrfs-snapshot_3.5.1_all.deb

      Backup and rollbacks:
      Backup is being performed live.

      Source Code

      1. # initiate backup manually
      2. apt-btrfs-snapshot snapshot
      3. # show taken snapshots
      4. apt-btrfs-snapshot list
      5. # initiate rollback
      6. apt-btrfs-snapshot set-default <snapshot-name>
      7. # you need to restart after rollback
      Backups can be done by cron on a regular base. This works instantly. Takes not even a second.
      Without configuration Backups are done every time apt is installing something.



      you might clean up your old root after conversion since it is not used anymore.

      Source Code

      1. # clean up old root
      2. mount /dev/sda2 /mnt
      3. cd /mnt
      4. rm bin
      5. rm dev
      6. rm etc
      7. rm usr
      8. and so on....
      9. btrfs sub del /mnt/ext2_saved # no rollback to ext4 possible after this operation
      10. btrfs balance start / # no rollback to ext4 possible after this operation



      There are still question marks left...
      • Does anyone know what's wrong about btrfs-convert? There is a warning on the wiki page. So far it worked out for me.
      • apt-btrfs-snapshot_xxx.deb is written for ubuntu. I guess I'm not the only one to use a ubuntu package in debian. Just worth to mention.

      The post was edited 2 times, last by mehlbox ().

    • I used this years ago. I can't remember what was wrong with ext4 conversion but never had issue, anyhow you can still move the data somewhere else and do a native format of you want.
      chat support at #openmediavault@freenode IRC | Spanish & English | GMT+10
      telegram.me/openmediavault broadcast channel
      openmediavault discord server

      The post was edited 1 time, last by subzero79 ().

    • Concerning btrfs-convert I found on the mailing list:

      Lakshmipathi.G wrote:

      AFAIK, there are quite number of people converted their EXT4 to BTRFS .IMO, btrfs-convert is fairly stable, especially if you have only GB's of data
      and

      Adam Borowski wrote:

      It has been recently (btrfs-progs 4.6) rewritten nearly from scratch. Thiswas a year ago and from the lack of complaints recently it sounds like anymajor bugs should be ironed out -- assuming you're using a version of -progsnew enough.

      This has been discussed just recently (22 Jun 2017)... maybe there is more to come from others...