Thursday, 6 June 2024

gentoo existing backup/reinstall your system quickly

 There is a good tool for Linux that simplifies the archiving process:

"Mkstage4 - Stage 4 Tarballs Made Easy"

This blog post was made for me. I understand the risks, so keep them in mind while reading the following. Partitioning can cause data loss, so make sure you have backups of everything. It's best to work on a new and empty machine without dual-boot or any data that hasn't been backed up.

Using it is simple:

$ sudo mkstage4 -l -e "/home/*"  -C zst -s genci

After this step finishes, you'll get a "genci.tar.zst".

Here's a copy-paste from the help:
-l: excludes lost+found directory.
-e: an additional excludes directory (one dir one -e, do not use it with *).
-s: makes tarball of current system.
-C: specify tar compression (default: bz2, available: lz4 xz bz2 zst gz).

The last parameter is the archive name without extension. You can safely use the home folder because it will be excluded. I prefer zst because it is super fast, although not the most efficient compressor.

Now we have an archive of the system without the home folder.

Boot a new machine (I also prefer gentoo livecd, because it set up wifi/net easily, and has GUI partition editor) or the same one:

Create the required partitions and mount the root to /mnt/gentoo.

$ mkdir -p /mnt/gentoo/boot

Mount boot EFI partition (a partition with fat32, about 0.5Gib or 1Gib) into /mnt/gentoo/boot

cp genci.tar.zst /mnt/gentoo
tar xvpf genci.tar.zst

mount --types proc /proc /mnt/gentoo/proc
mount --rbind /sys /mnt/gentoo/sys
mount --rbind /dev /mnt/gentoo/dev
mount --bind /run /mnt/gentoo/run
mount --make-rslave /mnt/gentoo/sys
mount --make-rslave /mnt/gentoo/dev
mount --make-rslave /mnt/gentoo/run

chroot /mnt/gentoo
grub-install --efi-directory=/boot
grub-mkconfig -o /boot/grub/grub.cfgblkid
! Update your UDID in vim /etc/fstab...
exit
umount /mnt/gentoo
sync
reboot

Now you are done. But without the home folder, there may be issues. You can copy the entire home folder if you want, or you can add a new user.

ref.:
https://www.tutorials.chymera.eu/blog/2014/05/18/mkstage4-stage4-tarballs-made-easy

No comments:

Post a Comment