1

I am helping a friend setup a bootable Linux image using extlinux. Here is what I have so far, but using qemu-system-x86_64, I am not able to get it to boot this image. The options to qemu-system-x86_64 is just -m 2048 -drive format=raw,file=myapp.img. The qemu-system-x86_64 just says 'Booting from Hard Disk ...'. I am wondering what am I doing wrong. The kernel and initrd boot up just fine in qemu. The bootable image is intended for an old non-UEFI system.

    #!/bin/sh -ex

    APP=myapp
    IMG=${APP}.img
    KERNEL=$1
    INITRD=$2

    MNTPNT=/media/usb
    SIZE=1G

    qemu-img create -f raw  $IMG $SIZE
    sudo dd if=/usr/lib/syslinux/mbr/mbr.bin of=$IMG conv=notrunc bs=440 count=1
    parted -s $IMG mklabel msdos
    parted -s -a none $IMG mkpart primary ext4 0 $SIZE

    lodev=$(losetup -f)
    sudo losetup $lodev $IMG
    sudo partx -a $lodev
    sudo mkfs.ext4 ${lodev}p1

    sudo mount ${lodev}p1 $MNTPNT
    sudo mkdir -p $MNTPNT/boot/extlinux
    sudo cp extlinux.conf $MNTPNT/boot/extlinux/
    sudo cp /usr/lib/syslinux/memdisk $MNTPNT/boot/extlinux/
    sudo cp /usr/lib/syslinux/modules/bios/* $MNTPNT/boot/extlinux/
    sudo cp $KERNEL $MNTPNT/boot/
    sudo cp $INITRD $MNTPNT/boot/
    sudo extlinux --install $MNTPNT/boot/extlinux/
    sudo umount $MNTPNT

    sudo partx -d $lodev
    sudo losetup -d $lodev
0

Adding the following command after creating the Linux partition fixed the issue.

parted -s -a none $IMG set 1 boot on

Copying the bios modules and memdisk wasn't required at all either.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.