[Discuss] Running things from initramfs

Dale R. Worley worley at alum.mit.edu
Wed Mar 17 22:33:17 EDT 2021


Thanks to everyone for ideas!  Out of cussedness, I dug enough to figure
out how to get at the disk partitions from the initramfs environment.
The details of the procedure depend on your initramfs environment and
disk configuration, but the pattern is simple enough that having seen an
example, you can probably make it work on lots of systems.

I'm sure there are better ways of getting "single user" mode working,
but this method is very quick for the things it works for.

Dale

----------

Reboot the host.  Once the boot menu shows, type down-arrow to stop the 
boot countdown timer and then up-arrow to return to the boot menu entry 
that normally boots.

Type "e" to edit the boot commands for the menu entry.  This puts you 
into a simple editor.  Go down to the command starting "linux16", 
"lunuxuefi", or similar.  Go to its end and add a parameter 
"rdinit=/bin/bash".

Type control-x to cause the edited boot commands to be executed.  After 
a few seconds, you will get a shell prompt "#".  The system is running 
from the initramfs with a very impoverished set of utilities.  If the 
builders of the initramfs have been smart, the partition-repair utility 
for the root partition's filesystem (e.g. xfs_repair, fsck.ext4) is present.

Add /usr/sbin to the path for convenience:

# PATH=$PATH:/usr/sbin

Set up the internal utility filesystems:

# mount -t devtmpfs devtmpfs /dev
# mount -t proc proc /proc
# mount -t sysfs sysfs /sys

Further steps are to install kernel modules needed for disk access. 
There seems to be no reliable way to determine the modules that are 
needed.  I have done "lsmod" on a running system, examined the listed 
modules (with non-zero use counts), and guessed from their names which 
ones are relevant.  There seems to be no downside to loading unneeded 
modules, so exploration should work OK.

Install the kernel modules for the disk's hardware attachment.  I have used:

# modprobe ata_piix
# modprobe libata
# modprobe megaraid_sas

Install the SCSI disk driver:

# modprobe sd_mod

At this point, you should be able to see the disk devices:

# ls /dev/sda*
/dev/sda  /dev/sda1  /dev/sda2

If the root partition is an LVM partition, set up LVM:

# lvm vgchange -ay
# lvm vgscan --mknodes
# ls /dev/mapper
control  ol_oracle7-root  ol_oracle7-swap

If you need to mount the partition, load the modules for the filesystem 
type:

# modprobe xfs
# modprobe ext4

You can now do management operations like:

# xfs_repair /dev/sda1
# mkdir /mnt ; mount /dev/mapper/ol_oracle7-root /mnt

To exit the initramfs environment, use "shutdown".  In my experience, 
this "shutdown" accepts the normal shutdown options but always reboots:

# ./shutdown now


More information about the Discuss mailing list