Baeldung - Linux

Learn about Linux in practice

 

Linux Emergency Recovery With init=/bin/bash
2025-06-10 19:40 UTC by Francesco Galgani

1. Overview

A Linux system can become unbootable due to misconfigurations, broken packages, or accidental deletions. While a live distro on USB or CD/DVD is typically the recommended recovery support, physical access or compatible media isn’t always available. In these situations, booting directly into a shell with the command init=/bin/bash provides just enough access to fix critical problems, assuming the bootloader and kernel still work.

In this tutorial, we’ll learn how to apply this technique to a modern, encrypted Linux installation with LVM+LUKS. We’ll use Linux Mint 22 for our tests, but the information applies to any Debian/Ubuntu-based system.

2. How and Why to Use init=/bin/bash

In most modern Linux distributions, systemd is the first user-space process during the boot process. It runs with Process ID (PID) 1 and is responsible for launching and managing all other processes in the system:

$ ps -p 1
PID TTY          TIME CMD
  1 ?        00:00:03 systemd

In the GRUB menu, let’s press e to edit the commands before booting. Adding init=/bin/bash to the kernel parameters skips the usual startup and launches a Bash shell with PID 1. Optionally, we can remove quiet and splash. Then, let’s press F10 to boot. If the disk uses LUKS and LVM, the unlock prompt appears automatically.

This video shows the full process, with an arrow to highlight where to pay attention:

The system is now in an emergency recovery state with root privileges, and /bin/bash has the PID 1:

# ps -p 1
PID TTY          TIME CMD
  1 ?        00:00:00 bash

This allows us to bypass broken service managers, login daemons, and most boot-time scripts. We can use this approach as a last resort when misconfigurations or errors prevent a normal boot.

3. Resetting the root Password

We can use the init=/bin/bash emergency shell to reset passwords.

First, we need to remount the file system as read/write because it’s read-only by default:

# mount | grep " / "
/dev/mapper/vgmint-root on / type ext4 (ro,relatime)
# mount -o remount,rw /
[...] EXT4-fs (dm-1): re-mounted [...] r/w. Quota mode: none.
# mount | grep " / "
/dev/mapper/vgmint-root on / type ext4 (rw,relatime,errors=remount-ro)

Then, we can change the password for the root or any other user:

# passwd root
[...]
passwd: password updated successfully

Standard commands like poweroff, reboot, or shutdown don’t seem to work because the standard init system isn’t running:

# reboot
System has not been booted with systemd as init system (PID 1). Can't operate.

Usually, the -f flag solves the problem:

# reboot -f

In rare cases, this isn’t sufficient, so we need a different approach. First, we have to flush any pending disk writes by running sync, and then write b to the file /proc/sysrq-trigger:

# sync
# echo b > /proc/sysrq-trigger

This method only makes sense in an emergency environment, as it forces an immediate reboot without first unmounting file systems or stopping services properly. In a production environment, this can result in data loss or corruption.

4. Recovering a Broken Linux Installation

Here we’ll try to identify and resolve some issues preventing our Linux machine from booting.

4.1. Fix Disk Errors Preventing Booting

Unexpected power outages can leave a Linux system inoperable upon reboot. This includes virtual private servers, where abrupt reboots during cloud provider maintenance can leave guest operating systems with corrupted file systems.

The video below shows a similar failure. We corrupted the file system on purpose and disabled every automatic repair to see what would happen if fsck couldn’t fix the damage on its own. This is a rare but real situation:

In this scenario, using only init=/bin/bash isn’t ideal because the kernel will still attempt to mount the corrupted root file system. However, adding break=premount gives us the BusyBox’s emergency shell without mounting any file system. It runs entirely from the initramfs in RAM:

Linux kernel break premount parameter to avoid mounting disks

BusyBox offers a variety of essential recovery commands, such as fsck, cryptsetup, and lvm. However, the list of commands in the man page is incomplete.

In BusyBox, let’s manually mount LVM and fix any errors in the file system. Of course, we must be careful to adapt these example commands to our configuration:

(initramfs) cryptsetup open --type luks /dev/sda3 cryptroot
Enter passphrase for /dev/sda3: 
 
(initramfs) lvm vgchange -ay
  2 logical volume(s) in volume group "vgmint" now active
 
(initramfs) fsck.ext4 -f /dev/mapper/vgmint-root
e2fsck 1.47.0 (5-Feb-2023)
/dev/mapper/vgmint-root: recovering journal
Clearing orphaned inode 264824 (uid=0, gid=0, mode=0100600, size=2)
Clearing orphaned inode 264849 (uid=0, gid=0, mode=0100644, size=1131)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
Free blocks count wrong (3456692, counted=3456674).
Fix<y>? yes
Free inodes count wrong (901506, counted=901501).
Fix<y>? yes
/dev/mapper/vgmint-root: ***** FILE SYSTEM WAS MODIFIED *****
/dev/mapper/vgmint-root: 469379/1370880 files (0.1% non-contiguous), 2022750/5479424 blocks
 
(initramfs) reboot -f

This way, Linux reboots smoothly without disk errors.

Alternatively, instead of rebooting, we can type exit to quit BusyBox and start /bin/bash to perform additional recovery operations.

4.2. Internet Connection to Reinstall Broken Packages

If essential packages are missing or damaged, the system can’t finish a normal boot. In this example, Linux fails to boot because /sbin/init is missing:

Linux doesnt boot because init is missingIf we can boot with init=/bin/bash, then we can try to restore some critical packages.

Here is an example of how to manually set up an Internet connection to use the package manager. However, let’s keep in mind to adapt the commands to our network configuration:

# Remount root filesystem as read-write
# mount -o remount,rw /
# Show network interfaces
# ip link show
enp0s3: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN [...]
# Bring up the network interface
# ip link set enp0s3 up
[...] enp0s3 NIC Link is Up 1000 Mbps Full Duplex, Flow Control: RX
# Request an IP address via DHCP (error may appear, safe to ignore)
# dhclient enp0s3
# Check assigned IP address
# ip -brief addr show enp0s3
enp0s3  UP  10.0.2.15/24 fe80::a00:27ff:fe95:27fd/64
# Confirm network interface configuration
# ifconfig
enp0s3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 10.0.2.15  netmask 255.255.255.0  broadcast 10.0.2.255
        [...]
# Mount proc filesystem
# mount -t proc none /proc
# Mount sysfs
# mount --rbind /sys /sys
# Mount devfs
# mount --rbind /dev /dev
# Add default route (may already exist)
# ip route add default via 10.0.2.2 dev enp0s3
# Show current routing table
# ip route
default via 10.0.2.2 dev enp0s3
10.0.2.0/24 dev enp0s3 proto kernel scope link src 10.0.2.15
# Set DNS resolver manually
# echo "nameserver 1.1.1.1" > /etc/resolv.conf
# Test internet connectivity
# ping -c 1 baeldung.com
PING baeldung.com (172.66.40.248) 56(84) bytes of data.
64 bytes from 172.66.40.248: icmp_seq=1 ttl=255 time=52.8 ms
--- baeldung.com ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms

We’re now ready to reinstall some essential packages:

  • systemd + systemd-sysv: provide /sbin/init and start every other service
  • libc6: the GNU C runtime; almost every binary on the disk links to it
  • libpam-modules + libpam-modules-bin: vital for login, su, sudo, and graphical display managers
  • initramfs-tools: builds the initramfs image that the bootloader hands to the kernel
  • linux-image-generic: meta-package for the current kernel image and headers

Let’s try to reinstall them:

# dpkg --configure -a
# apt update
# apt install --reinstall systemd systemd-sysv libc6 \
    libpam-modules libpam-modules-bin initramfs-tools linux-image-generic \
    libpam0g libpam-runtime
# update-initramfs -c -k all
# dpkg --configure -a

We can install as many other packages as we want.

At this stage, we can manually edit configuration files such as /etc/fstab, /etc/crypttab, and /etc/shadow. We can also remove problematic drivers or modules and perform other administrative tasks to fix a system that won’t boot up.

Finally, let’s run reboot -f to make Linux reboot smoothly.

5. Conclusion

In this article, we examined how to use the init=/bin/bash kernel parameter and the break=premount fallback to access a minimalist root shell on systems that wouldn’t otherwise boot.

This root environment enables us to unlock LUKS volumes, activate LVM, remount the root file system for reading and writing, reset forgotten passwords, and repair corrupted file systems using fsck. We can also reinstall core packages after setting up the network manually and carry out various configuration fixes.

Mastering these low-level recovery techniques can transform seemingly catastrophic “won’t boot” situations into solvable problems. However, it’s always important to maintain an up-to-date backup for disaster recovery purposes.

The post Linux Emergency Recovery With init=/bin/bash first appeared on Baeldung on Linux.


 

Content mobilized by FeedBlitz RSS Services, the premium FeedBurner alternative.