dracut
dracut copied to clipboard
document how to install dracut in a chroot
I'd like to create a bootable VM image with dracut using chroot. Cannot find any documentation except this which doesn't work for me.
After the VM is booted, dracut takes a long time to timeout and then in the debut shell I can see that folder /dev/disk
does not exist.
How to install dracut inside a chroot?
Installation via live-boot in chroot
Since our live system kernel version is probably different from our chrooted one, we need to explicitly specify the version and in order to prevent using current mount info, we need to use fstab mode
mount /dev/mapper/your-root /mnt/temp
mount /dev/sda1 /mnt/temp/boot
chroot /mnt/temp
mount -t devtmpfs devtmpfs /dev
mount -t devpts devpts /dev/pts
mount -t proc proc /proc
mount -t tmpfs tmpfs /run
mount -t sysfs sysfs /sys
dracut --kver 5.15.0-40-generic --fstab
Installation inside chroot of our target root
Chroot and target root should have matching base system version, otherwise library version conflicts can cause errors
We need to copy crypttab to chroot to make encrypted devices work
We also need to specify version and location of kernel modules to use in our target root
And to prevent using current mount info, use fstab and include the one in our target root
The following assumes our chroot is in temp/
and dracut
already installed:
chroot temp/
mount -t devtmpfs devtmpfs /dev
mount -t devpts devpts /dev/pts
mount -t proc proc /proc
mount -t tmpfs tmpfs /run
mount -t sysfs sysfs /sys
mount /dev/sda1 /boot
mkdir fs_root
mount -o r /dev/mapper/your-root fs_root
cp fs_root/etc/crypttab /etc/crypttab
dracut --kver 5.15.0-40-generic -k fs_root/lib/modules/5.15.0-40-generic/ --fstab --add-fstab fs_root/etc/fstab
Is it bootable in a VM?
Yes, tested with Ubuntu 22.04 in Virtualbox. If you intend to make the image portable to run also in different VMs, you should disable Host-Only mode, which minimizes size by removing anything not required on the host you build. Just add the -N
option to dracut