1

I'm trying to boot an OS (linux kernel) using the debian kernel so i needed to use an initramfs (as everything is builded as modules). But after booting into the initramfs, it doesn't seems to populate /sys/blocks as:

# mdev -s

"failed" to populate dev with devices (/dev/sd[a-z][0-9]).

Then how should i populate "/sys" correctly? i'm booting the system with qemu and using an raw image as "hd".

Notes:
* this isn't debian (or any other distro for that matter), and my initramfs is created from scratch
* i'm using mdev
* the /init script looks like this:

mount -n -t proc none /proc
mount -n -t sysfs none /sys
mkdir /.root
mdev -s
mount -n -t $rootfstype $device /.root
umount /proc
umount /sys
exec switch_root /.root $init $@

EDIT: My problem is not populating dev, that could be done by hand if necessary, just looking at "/sys" and using "mknod". The problem is "/sys" lacking devices "/sys/block/sd[a-z][0-9]".

dmesg: https://bin.privacytools.io/?d50e11eea81d8158#1ga51UE+NI6nX49SbkdjGitXOyZpalWUu2I3BuEMx+o=
(As i copied it from the qemu curses, i may have missed something)

  • By mounting sysfs? – 炸鱼薯条德里克 Aug 17 at 0:56
  • isn't mount -n -t sysfs none /sys exactly for that? – MayAccer Aug 17 at 0:57
  • Most of your question seems to be about /sys, but you say ""failed" to populate dev with devices". Which do you really care about, /sys or /dev? – Joseph Sible Aug 17 at 1:06
  • 1
    in order to populate "/dev" with devices "/sys" must have them first, so i care about the devices appearing inside "/sys/block" (which is empty) – MayAccer Aug 17 at 1:08
1

To use mdev, you'll need to have CONFIG_UEVENT_HELPER=y in your kernel configuration, and one command before your mdev -s:

echo /sbin/mdev > /proc/sys/kernel/hotplug
mdev -s

Source: Gentoo wiki

The default Debian 10 kernel does not have CONFIG_UEVENT_HELPER set, so mdev is not going to be usable with it. Instead, it has CONFIG_DEVTMPFS=y so you could do this instead:

mount -n -t proc none /proc
mount -n -t sysfs none /sys
mount -n -t devtmpfs none /dev
mkdir /.root
# this would be a great place to run "fsck -C0 $device" if required by $rootfstype
mount -n -t $rootfstype $device /.root
umount /proc
umount /sys
umount /dev
exec switch_root /.root $init $@

... and after the switch to the real root filesystem is complete, you can again mount the devtmpfs filesystem:

mount -n -t devtmpfs none /dev
  • mdev -s would work even without this flag to the kernel, it just shouldn't work as a hotplug. anyway this will not solve the problem, the devices will not appear inside "/dev" as they doesn't exist at "/sys" (devtmpfs as the first thing that i were using before trying mdev (as i had the intention of using it as hotplug)) – MayAccer Aug 17 at 8:44
  • It might be that your initramfs script runs mdev -s when the kernel is still busy probing hardware, and has not detected the disks yet. Probing the PCI(e) bus, loading the storage controller driver, activating the controller and probing for disks can take several hundreds of milliseconds (that's ages in computer timescales), and once you're past mdev -s in your script, you won't get any further devices unless you have hotplug enabled. In modern multi-core computers, several things tend to happen in parallel. When writing startup scripts, you must deal with it. – telcoM Aug 17 at 9:02
  • I have added a call to a shell inside /init, if that were the case shouldn't i see them appearing there at some moment? – MayAccer Aug 17 at 9:10
  • Have all the modules required to support your root disk been loaded? If not, something required by the module autoloading mechanism might be missing. The output of the dmesg command might provide more clues. – telcoM Aug 17 at 14:43
  • no module loaded automatically, but doing it manually didn't made appear the devices. (I loaded: scsi_mod, ata_generic, ata_piix) – MayAccer Aug 17 at 17:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.