Backup OS

#1. Clean Pacman Cache
sudo -i
pacman -Scc

#2. Create a exclude list
cat /root/backup/exclude.txt
/tmp/*
/root/backup/*
/proc
/dev
/sys
/home #If home is mount to another partition you need to exclude home here
/boot/EFI

#3. Create tarball
tar --exclude-form=/root/backup/exclude.txt -czpvf /root/backup/arch-back.tar.gz /

Fix grub

You may ignore this setp if you have a live cd to recover the OS. If you don’t, it would be great to have a second minimal OS installed in your disk. In my case I have a debian intalled in my disk’s /dev/sda5 partition (Arch uses /dev/sda1-4). In this case, if I format /dev/sda2(where arch’s root fs is located). I should be able to boot into debian to recover the tarball I backed up.

However when you boot the PC you may notice that grub is corrupted. This is because it is trying to load modules from /dev/sda2, which has been formated. Fortunately we have another instance of grub installed in /dev/sda5. So we need to tell grub2 to load modules from /dev/sda5.

set prefix=(hd0,gpt5)/boot/grub
set root=(hd0,gpt5)
insmod normal
normal

Then we should be able to see debian’s grub boot menu.

Recovery OS from tarball

mount /dev/sda2 /mnt
mkdir /mnt/home
mount /dev/sda4 /mnt/home
cp arch-back.tar.gz /mnt && cd /mnt
tar xvf arch-back.tar.gz
genfstab -U -p /mnt > /mnt/etc/fstab
arch-chroot /mnt /bin/bash
grub-install --target=i386-pc --recheck /dev/sda
grub-mkconfig -o /boot/grub/grub.cfg

Recovery OS from tarball (EFI Installation)

In a UEFI installed arch, EFI(/dev/sda1) is mount to /boot/EFI, we need to add this folder in exclude list. Other than that, in live cd, we need to resinstall grub

mount /dev/sda2 /mnt
mkdir /mnt/home
mount /dev/sda4 /mnt/home
mkdir /boot/EFI
mount /dev/sda1 /boot/EFi
cp arch-back.tar.gz /mnt && cd /mnt
tar xvf arch-back.tar.gz
genfstab -U -p /mnt > /mnt/etc/fstab
arch-chroot /mnt /bin/bash
grub-mkconfig -o /boot/grub/grub.cfg

Reinstall grub is not nessary if EFI partition is still there