chroot and serial console to fix ubuntu distro upgrade gone wrong
I had to fix a do-distro-upgrade
from 16.04 to 18.04 due to a severed ssh connection, and no screen running (apparently earlier distro upgrades used screen to prevent this kind of problem)
The machine as a PCengine apu2, so no video. Also, the root file system is sitting on a miniPCI ssd.
Eventually, my laptop and this chroot cheatsheet helped: https://aaronbonner.io/post/21103731114/chroot-into-a-broken-linux-install
Mount the root filesystem device
mount -t ext4 /dev/<device> /mnt/
If there’s a different boot partition or anything else
mount -t ext2 /dev/<device> /mnt/boot
Mount special devices
mount -t proc none /mnt/proc mount -o bind /dev /mnt/dev mount -o bind /sys /mnt/sys
chroot
chroot /mnt /bin/bash source /etc/profile
In order to help troubleshoot in the future, i followed this advice to get a systemd service unit for a constant shell on the serial port, but mine runs for some reason on S0: http://0pointer.de/blog/projects/serial-console.html
systemctl enable serial-getty@ttyS0.service
systemctl start serial-getty@ttyS0.service
It won’t help if systemd does not start, but otherwise it is online really early.