Help! I Cannot Log into My Ubuntu Server!

Tutorials · Published 2019-08-27 · Revised 2026-11-26
Local documentation and editorial review completed; Linux runtime validation is deferred · Joomla source

2,457 Total views across this article’s versions; includes the historical baseline where available.

Can’t boot your Ubuntu server?

Garbled GRUB file got you down?

SSH on the fritz?

Driving you crazy and ready to DELETE AND REINSTALL the O.S.???

Quick and Simple chroot to Server Stuck in Limbo

Wait one. I can’t guarantee a solution, but this strategy has worked for me a few times.

First Things, First

Grab yourself a Linux live USB or LiveCD that can boot the machine and provide a terminal. For an Ubuntu installation, an official Ubuntu live image matching the installed system’s CPU architecture is a straightforward starting point.

You don’t necessarily need the exact same Ubuntu release. However, the recovery environment must support your storage controller, filesystem, and any encryption or volume-management tools your installation requires. Its kernel must also be able to run the installed programs you intend to use inside chroot.

Choose the recovery media with the intended repair in mind. For UEFI bootloader repairs that need access to firmware boot entries, boot the recovery media in UEFI mode. Simply mounting the filesystem and editing configuration files does not carry that same requirement.

See the Linux execution requirements, storage-recovery guidance, and UEFI recovery guidance for the underlying compatibility considerations.

Run the commands from the live environment unless a step explicitly places you inside chroot. Commands that need elevated privileges include sudo; the shell opened inside chroot already runs as root. Run commands individually and stop on unexpected errors. This is a guided procedure, not a script to paste and run from beginning to end.

1. Mount the Installed Root Filesystem

Before we can enter the installed system, we need to mount its root filesystem. Creating a mount point only gives us a directory where that filesystem can be attached.

Identify the partition or logical volume containing your Ubuntu installation, then mount it at the recovery mount point. Check that it contains the expected installation before continuing with the bind mounts and chroot.

The example below assumes a directly mountable root filesystem, with no additional subvolume selection required. An encrypted container or an LVM physical volume is not itself the root filesystem to mount. Those layouts need their storage layers prepared first.

List the devices, filesystem types, labels, UUIDs, and current mounts:

sudo lsblk -f

Use that information to identify the intended installation and record its root-filesystem UUID. Don’t select a partition simply because its number matches an example. If cloned disks have duplicate UUIDs, resolve that ambiguity before using the UUID-based command below.

Create an empty recovery mount point and check whether anything is already mounted there:

sudo mkdir -p /mount/point
findmnt --mountpoint /mount/point --output SOURCE,TARGET,FSTYPE,OPTIONS

If findmnt shows a mount there, stop and identify it before proceeding; don’t stack another mount on top. No matching mount normally produces no output and a nonzero exit status. A missing command or another error needs investigation.

Replace REPLACE_WITH_ROOT_FILESYSTEM_UUID with the confirmed filesystem UUID, then mount it:

sudo mount UUID=REPLACE_WITH_ROOT_FILESYSTEM_UUID /mount/point

If the mount fails, stop here. Don’t continue to the bind mounts or chroot.

Verify the actual mount and inspect the installed system’s identification and filesystem configuration:

findmnt --mountpoint /mount/point --output SOURCE,TARGET,FSTYPE,OPTIONS
sudo cat /mount/point/etc/os-release
sudo cat /mount/point/etc/hostname
sudo cat /mount/point/etc/fstab

Confirm that the mounted source and these files match the installation you intend to repair. The presence of an Ubuntu release file alone doesn’t distinguish two Ubuntu installations. If the expected files are missing or the identity is uncertain, resolve that before continuing.

If /usr is a separate filesystem, mount the verified filesystem at /mount/point/usr before entering chroot, so the installed programs and libraries are available. Other separate filesystems, such as /boot and /boot/efi, must be mounted when the intended repair requires them. Use the installed system’s configuration to identify them.

For command details, see the lsblk, mount, and findmnt manuals.

2. Prepare the Bind Mounts

The installed system needs access to the live environment’s devices and kernel interfaces. Before adding those mounts, inspect the recovery tree:

findmnt --submounts --mountpoint /mount/point --output TARGET,SOURCE,FSTYPE,PROPAGATION

Confirm that this is the root filesystem you mounted in Step 1, with only the additional filesystems you deliberately mounted for this repair. Don’t repeat the bind mounts if they are already present. The installed /dev, /proc, and /sys directories must exist; investigate a missing directory rather than assuming the correct system is mounted.

Keep mount and unmount changes beneath the recovery tree from propagating back to the live environment:

sudo mount --make-rslave /mount/point

Now add the bind mounts, making each new branch a slave mount before proceeding. Run these commands individually and stop on any failure:

sudo mount --rbind /dev /mount/point/dev
sudo mount --make-rslave /mount/point/dev
sudo mount --bind /proc /mount/point/proc
sudo mount --make-slave /mount/point/proc
sudo mount --rbind /sys /mount/point/sys
sudo mount --make-rslave /mount/point/sys

The recursive /dev bind includes /dev/pts; don’t mount it a second time. The recursive /sys bind includes mounted interfaces such as EFI variables when they are available. We aren’t binding the live environment’s entire /run directory into the installed system.

Inspect the tree again with the findmnt command above. The recovery branches should show slave or private, not shared. Record which mounts succeeded. If setup stops partway through, the cleanup step must account for those mounts too. The propagation behavior is described in the mount manual.

3. Configure DNS Only If Needed

Only configure DNS if the repair requires network access and name resolution is not already working inside chroot.

From the live environment, test name lookup there and through the installed system. archive.ubuntu.com is an example; also check the hostname your intended repair actually needs:

getent hosts archive.ubuntu.com
sudo chroot /mount/point /usr/bin/getent hosts archive.ubuntu.com

If the installed system resolves the required names and the intended network operation works, leave its resolver configuration alone and continue to Step 4. A lookup alone doesn’t prove that a package repository or HTTPS connection works. If getent itself cannot run, investigate the chroot environment before treating the failure as a DNS problem.

If the live environment cannot resolve names either, fix its connectivity first. For an offline repair, skip DNS changes entirely.

Preserve the Installed Configuration

Before changing the installed system’s resolver configuration, preserve the original file or symbolic link. If it was absent, record that instead. Any temporary replacement should use a resolver that works from the recovery environment and should be removed when the repair is complete.

Inspect the installed entry without copying onto it:

sudo ls -ld /mount/point/etc/resolv.conf
findmnt --mountpoint /mount/point/etc/resolv.conf

The entry may be a regular file, a symbolic link, or absent. If it is a link, inspect the stored target:

sudo readlink /mount/point/etc/resolv.conf

Missing entries and a readlink call on a regular file have expected nonzero results; other errors need investigation. If findmnt reports a file mount, or the entry is a directory or another unexpected type, stop and resolve that layout before using this example.

Don’t write through the installed link. An absolute link can resolve against the live environment when accessed from outside chroot. Preserve the entry itself, including a dangling link.

Create a private backup directory on the installed filesystem, then copy the contents of the live environment’s working resolver file into it:

sudo mkdir --mode=700 /mount/point/etc/resolv.conf.recovery
sudo cp --dereference --no-target-directory /etc/resolv.conf /mount/point/etc/resolv.conf.recovery/temporary

Run each command separately. If the directory already exists, stop: it may contain a previous recovery backup. If the copy fails, stop before moving the installed configuration. Don’t overwrite an earlier backup or reuse an unfinished recovery session without inspecting it.

Choose one of the following cases:

  • An original file or symbolic link exists: move that entry into the backup directory. Moving the link preserves the link itself, not the file it points to.
sudo mv --no-target-directory /mount/point/etc/resolv.conf /mount/point/etc/resolv.conf.recovery/original
  • The entry was genuinely absent: record that original state instead. A dangling symbolic link belongs to the first case.
sudo touch /mount/point/etc/resolv.conf.recovery/original-was-absent

After the selected command succeeds, put the temporary regular file in place:

sudo ln --no-target-directory /mount/point/etc/resolv.conf.recovery/temporary /mount/point/etc/resolv.conf

This creates a hard link to the temporary regular file. It refuses to replace an existing destination, avoiding a write through an unexpected symbolic link. If it fails, stop and inspect the state; the saved original is still in the backup directory.

Repeat the installed-system lookup test:

sudo chroot /mount/point /usr/bin/getent hosts archive.ubuntu.com

A loopback address such as 127.0.0.53 isn’t automatically wrong here: this plain chroot shares the live environment’s network namespace, so its running DNS stub may be reachable. However, the installed nsswitch.conf, resolver modules, and missing runtime sockets can still affect lookups. If the test fails, investigate those details rather than assuming a file copy fixes every resolver setup. Don’t substitute public DNS servers without considering the network’s requirements. See systemd-resolved and getent.

4. Enter and Leave chroot

Open a shell in the installed system:

sudo chroot /mount/point /bin/bash

You are now root inside chroot. Carry out the intended repair, then leave that shell:

exit

The remaining commands run from the live environment. Exiting chroot does not unmount anything or stop background processes started during the repair. Close those processes and any other shells still using the installed system.

5. Restore Temporary DNS Changes

Restore the original resolver configuration unless changing it was an intentional part of the repair. If you made no temporary DNS change, skip this step. If you deliberately repaired DNS, compare the saved original with the intended final configuration before deciding what to retain.

Move your shell outside the recovery mount point, then inspect the saved state:

cd /
sudo ls -ld /mount/point/etc/resolv.conf
sudo ls -la /mount/point/etc/resolv.conf.recovery
findmnt --mountpoint /mount/point/etc/resolv.conf

Confirm that there is either original or original-was-absent, and that the current entry is the temporary file you installed. You can compare file identities with:

sudo ls -li /mount/point/etc/resolv.conf /mount/point/etc/resolv.conf.recovery/temporary

The two hard links should have the same inode on the same filesystem. If the current entry was replaced, turned into a link or mount, or otherwise changed during repair, stop and inspect it before removing anything.

After confirming the temporary file and saved state, remove only the temporary entry:

sudo rm -- /mount/point/etc/resolv.conf

Then choose the case matching your backup:

  • An original entry was saved: restore it, including its original symbolic-link target if applicable.
sudo mv --no-target-directory /mount/point/etc/resolv.conf.recovery/original /mount/point/etc/resolv.conf
  • The original entry was absent: leave /etc/resolv.conf absent and remove the absence marker.
sudo rm -- /mount/point/etc/resolv.conf.recovery/original-was-absent

Only after the selected restoration succeeds, remove the remaining temporary file and empty backup directory:

sudo rm -- /mount/point/etc/resolv.conf.recovery/temporary
sudo rmdir /mount/point/etc/resolv.conf.recovery

Verify the restored file or link with sudo ls -ld /mount/point/etc/resolv.conf, or confirm the expected absence. A restored link to a runtime file can remain dangling until the installed system boots; preserve its target rather than trying to repair it merely because it is currently dangling.

If setup failed partway through, inspect the backup before cleanup. For example, if the original was moved but the temporary link was never created, restore original directly without running the removal command. Never delete the saved original just to make the backup directory empty. If anything is uncertain, retain the backup and resolve that before rebooting.

6. Unmount the Recovery Filesystems

Move your shell outside the recovery mount point, close anything still using the mounted installation, and inspect the remaining mounts:

cd /
findmnt --submounts --mountpoint /mount/point --output TARGET,SOURCE,FSTYPE,PROPAGATION

Confirm that every listed mount belongs to this recovery session, that temporary DNS changes have been resolved, and that no recovery branch is shared. If a propagation-setting command failed earlier, correct the affected recovery mount before attempting cleanup; don’t change the live environment’s /, /dev, /proc, or /sys mounts.

Unmount the recovery filesystems from the deepest mount points outward, leaving the installed root filesystem until last. For the verified tree established above, umount can handle that order:

sudo umount --recursive /mount/point

If a filesystem is busy, stop and identify what is using it. Don’t treat a failed unmount as successful cleanup. Check open shells, editors, file-manager windows, and repair processes. The recursive command stops when an unmount fails; inspect the remaining tree again after releasing the blocker. Don’t use force or lazy unmount as the routine way around an unexplained failure.

Confirm that the recovery root is no longer mounted:

findmnt --mountpoint /mount/point

No matching mount normally means no output and a nonzero exit status; an unavailable command or other error is not confirmation. If you separately activated encrypted mappings or logical volumes for this session, release only those resources, in their dependency order, after all their filesystems are unmounted. The simple root-mount example does not open those storage layers for you.

Once cleanup is complete, reboot from the live environment and remove the recovery media when prompted:

sudo reboot

See the umount manual for recursive unmounting and busy-filesystem behavior. These instructions describe a recovery workflow; a successful chroot or clean unmount does not establish that the original fault has been repaired. Verify the intended behavior after the installed system boots.