Cloning Debian system in extra partition before update

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 / /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
chroot /mnt/destino/
vim /etc/fstab

Now inside fstab I’m going to replace:

/dev/sda4 /               ext4    errors=remount-ro 0       1

with:

/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:

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/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.

Anuncios

Etiquetas: , , ,

Responder

Introduce tus datos o haz clic en un icono para iniciar sesión:

Logo de WordPress.com

Estás comentando usando tu cuenta de WordPress.com. Cerrar sesión / Cambiar )

Imagen de Twitter

Estás comentando usando tu cuenta de Twitter. Cerrar sesión / Cambiar )

Foto de Facebook

Estás comentando usando tu cuenta de Facebook. Cerrar sesión / Cambiar )

Google+ photo

Estás comentando usando tu cuenta de Google+. Cerrar sesión / Cambiar )

Conectando a %s


A %d blogueros les gusta esto: