如何在 Fedora 18 上為使用者模式 Linux 建立 rootfs?

如何在 Fedora 18 上為使用者模式 Linux 建立 rootfs?

我想建立一個與 UML 核心一起使用的 rootfs,並且能夠使用網路。我正在使用febootstrap包:bash, coreutils, net-tools, iputils。使用後,febootstrap-supermin-helper我得到了我的rootfs,但當嘗試使用 UML 啟動它時,我收到以下錯誤:

[    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

我想知道哪些軟體包是必需的,rootfs以及除此之外是否還有其他方法febootstrap

答案1

也許你可以嘗試 PROot (http://proot.me)作為 UML 的替代方案。兩者都基於 ptrace(2),儘管 PRoot 不需要任何設定即可從訪客系統獲取互聯網訪問權限:

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

其中「./fedora-18-x86_64/」是從下載的 rootfs 的內容http://download.openvz.org/template/precreated/

答案2

建構根

defconfigqemu_x86_64_defconfig幾乎可以工作,除了我必須添加::sysinit:/sbin/mdev -sinittab.我認為這是因為 Buildroot 依賴CONFIG_DEVTMPFS_MOUNT創建/dev.

根檔案系統:

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

然後在內核原始碼上:

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

現在您已進入虛擬機,您可以使用以下命令離開:

poweroff

檔案系統是持久的,試試看:

date >f

並重新啟動。

TODO 讓網路正常運作。目前eth0=只是一個虛擬值,以防止 Buildroot 的 init 停止等待網路設備。

您也可以單步調試內核,如下所示:https://stackoverflow.com/questions/4943857/linux-kernel-live-debugging-how-its-done-and-what-tools-are-used/44669413#44669413

TODO 我不知道如何處理核心模組,因為它們必須針對 UML 而不是 x86 進行編譯。第一個問題是insmod會失敗,因為 UML 沒有SMP影響vermagic,如果你強制 vermagic ,就會發生奇怪的事情,例如printk不印任何東西。有關的:https://stackoverflow.com/questions/2488625/user-mode-linux-installing-a-module-error

如果您願意,也可以使用 QEMU 檢查該映像:

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

在 Ubuntu 14.04、核心 3.13.0 主機上測試。

相關內容