go-debos / fakemachine

fake a machine
Apache License 2.0
34 stars 37 forks source link

Busybox expects full modules.dep dependencies, not just direct dependencies #148

Closed davidmhewitt closed 1 year ago

davidmhewitt commented 1 year ago

busybox modprobe only loads modules listed in a single modules.dep line before attempting to load a module, it doesn't recurse indirect dependencies of kernel modules.

See: https://github.com/mirror/busybox/blob/1dd2685dcc735496d7adde87ac60b9434ed4a04c/modutils/modprobe.c#L46-L49

Therefore, currently, trying to boot an Ubuntu kernel results in the following:

[    1.446410] Run /init as init process
modprobe: module virtio_pci not found in modules.dep
modprobe: module virtio_console not found in modules.dep
[    1.493994] 9pnet: Installing 9P2000 support
[    1.503597] fscache: Unknown symbol netfs_stats_show (err -2)
[    1.519624] fscache: Unknown symbol netfs_stats_show (err -2)
modprobe: can't load module fscache (/lib/modules/5.15.0-73-generic/kernel/fs/fscache/fscache.ko): unknown symbol in module, or unknown parameter
mount: mounting usr on /usr failed: No such device

The module dependency tree is as follows: 9p -> fscache -> netfs.

The modules.dep file generated by fakemachine is as such (9p only depending on fscache and 9pnet):

/lib/modules/5.15.0-73-generic/kernel/fs/netfs/netfs.ko: 
/lib/modules/5.15.0-73-generic/kernel/net/9p/9pnet_virtio.ko: /lib/modules/5.15.0-73-generic/kernel/net/9p/9pnet.ko
/lib/modules/5.15.0-73-generic/kernel/net/9p/9pnet.ko: 
/lib/modules/5.15.0-73-generic/kernel/fs/9p/9p.ko: /lib/modules/5.15.0-73-generic/kernel/fs/fscache/fscache.ko /lib/modules/5.15.0-73-generic/kernel/net/9p/9pnet.ko
/lib/modules/5.15.0-73-generic/kernel/fs/fscache/fscache.ko: /lib/modules/5.15.0-73-generic/kernel/fs/netfs/netfs.ko

Therefore, when busybox modprobe tries to load 9p, it doesn't load netfs first, despite it being an indirect dependency.

In fact, the modules.dep file for this kernel from Ubuntu has the following (we can see netfs specified as a dependency of 9p directly):

kernel/fs/9p/9p.ko: kernel/net/9p/9pnet.ko kernel/fs/fscache/fscache.ko kernel/fs/netfs/netfs.ko

The modules.dep file should be generated such that it includes all dependencies for each module (including indirect dependencies).

PR incoming.

evelikov commented 1 year ago

@davidmhewitt out of curiosity, does the busybox depmod produce meaningful modules.dep file?