6

I want to create a rootfs to be used with an UML kernel and be able to use the internet. I was using febootstrap with packages: bash, coreutils, net-tools, iputils. After using febootstrap-supermin-helper I got my rootfs but when trying to boot it with UML I get these errors:

[    4.340000] systemd[1]: systemd-logind.service holdoff time over, scheduling restart.
[    4.340000] systemd[1]: dbus.service start request repeated too quickly, refusing to start.
[    4.340000] systemd-logind[638]: Failed to get system D-Bus connection: Did not receive a reply. Possible causes include: the remote application did not send a reply, the message bus security policy blocked the reply, the reply timeout expired, or the network connection was broken.
[    4.340000] systemd-logind[638]: Failed to fully start up daemon: Connection refused

I am wondering which packages are necessary for rootfs and if there is any other way besides febootstrap.

erch
  • 4,890
  • 17
  • 49
  • 81

2 Answers2

0

Buildroot

The qemu_x86_64_defconfig defconfig almost worked, except that I had to add ::sysinit:/sbin/mdev -s to the inittab. I think this is because Buildroot relies on CONFIG_DEVTMPFS_MOUNT to create /dev.

Rootfs:

git clone git://git.buildroot.net/buildroot
cd buildroot
git checkout 2017.02
make qemu_x86_64_defconfig

# Custom inittab.
echo 'BR2_ROOTFS_OVERLAY="rootfs_overlay"' >>.config
make olddefconfig
mkdir -p rootfs_overlay/etc
printf '
::sysinit:/bin/mount -t proc proc /proc
::sysinit:/bin/mount -o remount,rw /
::sysinit:/bin/mkdir -p /dev/pts
::sysinit:/bin/mkdir -p /dev/shm
::sysinit:/bin/mount -a
::sysinit:/sbin/mdev -s
::sysinit:/bin/hostname -F /etc/hostname
::sysinit:/etc/init.d/rcS
console::respawn:/sbin/getty -n -L console 0 vt100
::ctrlaltdel:/sbin/reboot
::shutdown:/etc/init.d/rcK
::shutdown:/sbin/swapoff -a
::shutdown:/bin/umount -a -r
' > rootfs_overlay/etc/inittab

# Build image.
make BR2_JLEVEL=$(($(nproc)-2))
cp output/images/rootfs.ext2 /path/to/linux

Then on kernel source:

cd /path/to/linux
git checkout v4.9
make mrproper
make defconfig ARCH=um
make ARCH=um
./linux eth0=tuntap,,,192.168.0.254

Now you are inside the VM, and you can leave with:

poweroff

The filesystem is persistent, try it out with:

date >f

and reboot.

TODO get network working. The current eth0= is just a dummy to prevent Buildroot's init from stalling waiting for the network device.

You can also step debug the kernel as shown at: https://stackoverflow.com/questions/4943857/linux-kernel-live-debugging-how-its-done-and-what-tools-are-used/44669413#44669413

TODO I don't know how to deal with kernel modules, since they must be compiled against the UML, not x86. The first problem is that insmod will fail because UML does not have SMP which affects vermagic, and if you force vermagic, weird things happen like printk does not print anything. Related: https://stackoverflow.com/questions/2488625/user-mode-linux-installing-a-module-error

You can also inspect that image with QEMU if you prefer:

qemu-system-x86_64 -M pc -kernel output/images/bzImage -drive file=output/images/rootfs.ext2,if=virtio,format=raw -append root=/dev/vda -net nic,model=virtio -net user

Tested in Ubuntu 14.04, kernel 3.13.0 host.

0

Maybe you could try PRoot (http://proot.me) as an alternative to UML. Both are based on ptrace(2), although PRoot does not require any setup to get internet access from the guest system:

host$ proot -R ./fedora-18-x86_64/ bash
guest$ wget http://google.fr
...

where "./fedora-18-x86_64/" is the content of a rootfs downloaded from http://download.openvz.org/template/precreated/