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 thinkpad x230i, 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
special devices mounts
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.