Note: This is an update for my Cloning Debian system in extra partition before update article so that it takes my efi boot support into account. It also works in a systemd system. The explanation is: Linux has the mount tree by default not shared. systemd changes this default setting while booting up. If you don’t do it this way you will have double mount when using –bind.
My system among others has a home partition, a main Debian system and an extra Debian system. My extra Debian system is for saving current Debian Unstable just before updates or upgrades. That’s what I’m going to describe here.
So my current partition is sda4. The Debian clone partition is /dev/sda6.
The overall process is:
- Copy system data
- Change fstab to reflect new partition as root partition
- Update grub
I do not install grub from Debian clone partition because I’m updating the current system and not the clone one.
In order to copy system data I need to mount the current system in a special directory so that only the sda4 partition is seen and not all of the partitions mounted in it (we do not want to copy /home).
mkdir /mnt/origen mount -o bind --make-private / /mnt/origen
We also need to mount the destination partition
mkdir /mnt/destino mount -t ext4 /dev/sda6 /mnt/destino
Now we are going to do a live copy. I’m not stopping any services because I personally do not use any of them. If this was a production server you would need to run the commands twice making sure the last time you run it you stop all the services you want to preserve previously.
rsync -aHK --delete --delete-during /mnt/origen/ /mnt/destino/
This is the most efficient way of copying the files because if the files are the same ones they are not copied… although I think Rsync in local copies does not help too much because usually all the destination file has to be read to decide to overwrite it or not. But I’m not quite sure. Anyway… let’s continue.
Now we are going to edit fstab and reinstall grub
mount -o bind /dev /mnt/destino/dev mount -o bind /proc /mnt/destino/proc mount -o bind /sys /mnt/destino/sys mount -o bind /boot/efi /mnt/destino/boot/efi chroot /mnt/destino/ vim /etc/fstab
Now inside fstab I’m going to replace:
/dev/sda4 / ext4 errors=remount-ro 0 1
/dev/sda6 / ext4 errors=remount-ro 0 1
and save the file. You might probably want to use LABELs or UUIDs instead of me.
Once we have saved it we are going to update grub:
Now we just need to exit from chroot and umount all the partitions and folders.
exit umount /mnt/destino/proc umount /mnt/destino/boot/efi umount /mnt/destino/sys umount /mnt/destino/dev umount /mnt/destino umount /mnt/origen
So that’s it! If you boot your system with Super Grub2 Disk or another tool you will be able to load your grub.cfg and boot this SDA6 system without too much effort.
Now I’m ready to upgrade or update my Debian Unstable system in sda4 without fear for loosing my daily functionality because it has been cloned in sda6.
Waiting for btrfs to be stable in Debian so that I can use snapshots :).