I have problems with creating initramfs for ISO live cd. I don't know whats wrong with
I'm running ISO in Hyper-V. And there is a code of
init
script in initramfs, you can see below the screenshots about trying to boot kernel and initramfs, the first screenshot is booting in VM with UEFI, the second screenshot - VM with legacy firmware (BIOS):


init
script:
#!/busybox
# Mount essential filesystems
mount -t proc none /proc
mount -t sysfs none /sys
mount -t tmpfs none /tmp
mount -t devtmpfs none /dev
mknod /dev/console c 5 1
mknod /dev/tty1 c 4 1
mknod /dev/tty2 c 4 2
mknod /dev/tty3 c 4 3
mknod /dev/tty4 c 4 4
mount -t devpts none /dev/pts
# Search for the root filesystem
for dev in /dev/sr* /dev/sd* /dev/loop* /dev/mmcblk*; do
echo "Checking $dev..."
if mount -o ro "$dev" /mnt 2>/dev/null; then
if [ -f /mnt/sysroot.squashfs ]; then
echo "Found root filesystem on $dev"
break
fi
umount /mnt
else
echo "Failed to mount $dev"
fi
done
# Check if the root filesystem was found
if [ ! -f /mnt/sysroot.squashfs ]; then
echo "Live CD root not found. Dropping to shell..."
exec sh
fi
# Mount the root filesystem
echo "Mounting root filesystem..."
mount -t squashfs /mnt/sysroot.squashfs /sysroot
mount --bind /dev /sysroot/dev
mount --bind /dev/pts /sysroot/dev/pts
mount --bind /proc /sysroot/proc
mount --bind /sys /sysroot/sys
mount --bind /tmp /sysroot/tmp
mknod /sysroot/dev/console c 5 1
mknod /sysroot/dev/tty1 c 4 1
mknod /sysroot/dev/tty2 c 4 2
mknod /sysroot/dev/tty3 c 4 3
mknod /sysroot/dev/tty4 c 4 4
# Switch root and start the real init process
exec switch_root /sysroot /sbin/init
sh
sysroot.squashfs
is a rootfs of live cd to load.
The structure of initramfs:
vadim@GoldenVadim:~/Initramfs$ l
busybox* dev/ init* proc/ sys/ sysroot/ tmp/
Can you help me with init
script (initramfs/initrd)?
Thank you
Asked by GoldenVadim
(11 rep)
Jan 25, 2025, 12:17 PM