Booting LXC into single user mode

ahwang

New Member
Feb 19, 2024
5
0
1
Trying to figure out how to boot an LXC (Ubuntu 22.04) into single user mode. I accidentally renamed bin not realizing I was in / instead of /root. Now all the commands don't run properly. Was hoping to boot into single user mode and rename bin back but can't for the life of me figure out how to do that.
 
You can use the pct enter VMID command, to edit the file system of the container from the host.
 
Last edited:
That's pretty cool. However, it didn't work when something catastrophic like renaming /bin to something else such that the system no longer had a /bin. I get the following error trying to do a pct enter...

root@pve4:~# pct enter 101
lxc-attach: 101: ../src/lxc/attach.c: lxc_attach_run_shell: 1869 No such file or directory - Failed to execute shell

Just trying to figure out how one would recover from something like this other than rebuild of the LXC from backups.
 
Maybe try pct mount 101 to mount the root filesystem of the container and do the rename operation from the host? I'm not sure where it mounts the root filesystem but it should give you a way to do file operations without the container actually running (and keeping files open).
 
  • Like
Reactions: david_tao
Nice. That actually worked perfectly for this situation. The pct mount actually tells you where it mounted to. Was able to cd to the mounted root filesystem and do whatever repairs I needed.

root@pve4:~# pct mount 101
mounted CT 101 in '/var/lib/lxc/101/rootfs'

In case anyone needs this for the future, when done, just run "pct unmount 101" to unmount the filesystem.

Just wondering if the repair required you run some commands while in the "broken" system, is there a way? I'm thinking for example, if you mess up your bootloader in linux, traditionally, you'd boot off a rescue disk, mount the partitions, chroot in, then run whatever commands you need at that point for the repair (ie. grub-install, update-grub, etc...). Is there an equivalent of doing this in proxmox?