How to recover your Linux system with LiveUSB and chroot

2024-05-24

Bad days happen and sometimes you need to recover your system without re-installation. The issue may be caused by unsuccessful upgrades or other failures.

1. Prepare Ubuntu/Kubuntu LiveUSB stick

2. Boot your LiveUSB, open up terminal and run these commands:

sudo -i
mkdir /mnt/server
fdisk -l # find out the correct partition with your Linux, in this example it is /dev/sda7
mount /dev/sda7 /mnt/server
mount -t proc /proc /mnt/server/proc
mount -o bind /sys /mnt/server/sys
mount -o bind /dev /mnt/server/dev
mount -o bind /etc/resolv.conf /mnt/server/etc/resolv.conf
mount -o bind /dev/pts /mnt/server/dev/pts

# enter chroot
chroot /mnt/server

# do what you want in chroot, for example finish failed upgrade
apt update; apt install --fix-missing && apt dist-upgrade && apt clean

sync
exit # exit chroot

umount /mnt/server/dev/pts
umount /mnt/server/etc/resolv.conf
umount /mnt/server/dev
umount /mnt/server/sys
umount /mnt/server/proc
umount /mnt/server
rm -r /mnt/server
exit

Reboot you computer, unplug Linux LiveUSB stick and enjoy working Linux OS.