1

I am building a custom Alpine image based on isolinux. Basically, I am squashing rootfs, and mounting it as overlayfs.

Bootloader does its job fine, kernel loads, but I am stuck at initramfs. Let say I have the following:

#!/bin/sh
export PATH=/sbin:/usr/sbin:/bin:/usr/bin
/bin/busybox --install -s

rescue_shell() {
    echo "Something went wrong. Dropping you to a shell."
    #/bin/busybox --install -s
    /bin/sh || exec /bin/busybox sh
}
mount -t sysfs sysfs /sys
mount -t proc  proc /proc
mkdir  -p /dev/pts

mount -t devtmpfs -o exec,nosuid,mode=0755,size=2M devtmpfs /dev 2>/dev/null \
        || mount -t tmpfs -o exec,nosuid,mode=0755,size=2M tmpfs /dev

[ -c /dev/ptmx ] || mknod -m 666 /dev/ptmx c 5 2
[ -d /dev/pts ] || mkdir -m 755 /dev/pts
mount -t devpts -o gid=5,mode=0620,noexec,nosuid devpts /dev/pts
# shared memory area (later system will need it)
[ -d /dev/shm ] || mkdir /dev/shm
mount -t tmpfs -o nodev,nosuid,noexec shm /dev/shm

/bin/sh
# other code left for simplicity

So once I enters /bin/sh, I don't have any modules loaded, especially I am meaning for block devices, /dev/sda, /dev/sr0, which I need to mount and then extract squashed image, and mount overlay.

Listing /proc/partitions gives me only ram[0-15] devices, which make sense since after boot it's loaded into RAM.

So, my question would be, is there any way that devices gets probed based on available hardware? I have tried with mdev as well, but still can not get my block devices. Proper mdev.conf is there, and tests are performed in VirtualBox. Thank you.

1 Answer 1

1

You could try your luck with modalias as exposed through the sysfs interface.

See for example https://patchwork.openembedded.org/patch/148854/ which suggests:

echo "/sbin/mdev" > /proc/sys/kernel/hotplug
mdev -s
find /sys/ -name modalias -print0 | xargs -0 sort -u -z | xargs -0 modprobe -abq

Note that I haven't tested this myself. Also this doesn't seem to be using BusyBox modprobe, which probably does not support -ab. Still, it might be worth checking out what your /sys looks like in early initramfs.

More links regarding modalias:

2
  • Brilliant great find! Wasted at least 2 days with debug. One thing I had to do, was to recompile BusyBox from source, and set ` MODPROBE_SMALL [=n]` , so I can get more feature-able modprobe. :) Thanks again! Commented Sep 6, 2019 at 18:31
  • 1
    Thanks, I didn't know there was a MODPROBE_SMALL setting in busybox. So sometimes enabling everything (=y) disables stuff. Why is it so hard to build a feature-complete busybox ...oh well. :-) Commented Sep 6, 2019 at 19:22

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.