Check if an ISO or USB Drive is Bootable using QEMU
Qemu is a generic and open source machine emulator and virtualizer. This article will show you how to check and test if an ISO or USB Drive is bootable using Qemu in the Linux operating system. In my opinion this is a cool way to confirm whether or not image files (ISO) and USB drives/devices should be expected to be bootable during boot of a normal x86/x64 desktop/laptop/server.
With a Bootable drive, you can not only install distro applications, you can also use the disk to test the desktop experience of Ubuntu without needing to meddle with your computer’s configuration or even help in fixing any configuration issues.
Run operating systems for any machine, on any supported architecture
Run programs for another Linux/BSD target, on any supported architecture
Run KVM and Xen virtual machines with near native performance
Install Qemu if you have not already:
pacman -S qemu
apt-get install qemu
dnf install @virtualization
emerge --ask app-emulation/qemu
yum install qemu-kvm
zypper install qemu
You can also download Qemu directly from their website for various platforms.
The following packages were installed on my machine after
apt install qemu.
ipxe-qemu-256k-compat-efi-roms/focal,focal,now 1.0.0+git-20150424.a25a16d-0ubuntu4 all [installed] ipxe-qemu/focal-updates,focal-updates,now 1.0.0+git-20190109.133f4c4-0ubuntu3.2 all [installed] libvirt-daemon-driver-qemu/focal-updates,now 6.0.0-0ubuntu8.11 amd64 [installed] qemu-block-extra/focal-updates,focal-security,now 1:4.2-3ubuntu6.17 amd64 [installed] qemu-kvm/focal-updates,focal-security,now 1:4.2-3ubuntu6.17 amd64 [installed] qemu-system-common/focal-updates,focal-security,now 1:4.2-3ubuntu6.17 amd64 [installed] qemu-system-data/focal-updates,focal-updates,focal-security,focal-security,now 1:4.2-3ubuntu6.17 all [installed] qemu-system-gui/focal-updates,focal-security,now 1:4.2-3ubuntu6.17 amd64 [installed] qemu-system-x86/focal-updates,focal-security,now 1:4.2-3ubuntu6.17 amd64 [installed] qemu-utils/focal-updates,focal-security,now 1:4.2-3ubuntu6.17 amd64 [installed] qemu/focal-updates,focal-security,now 1:4.2-3ubuntu6.17 amd64 [installed]
Check if an image file (ISO, etc) is bootable
The -m parameter controls how much memory in MB is to be allocated.
sudo qemu-system-x86_64 -boot d -cdrom "image.iso" -m 512
Check if your real cdrom is bootable
It is also possible to use your regular cdrom device too. If the device is
/dev/cdrom you can boot a cd in the device like that:
sudo qemu-system-x86_64 -boot d -cdrom /dev/cdrom -m 512
Check if a USB drive is bootable
This first method will be using the block device path (/dev/sdx):
sudo qemu-system-x86_64 -hda /dev/sdx
Get the host bus and host address identifiers from your USB drive:
lsusb # Output from lsusb command Bus 002 Device 005: ID 090c:1000 Silicon Motion, Inc. - Taiwan (formerly Feiya Technology Corp.) Flash Drive Bus 002 Device 004: ID 05e3:0616 Genesys Logic, Inc. hub Bus 002 Device 003: ID 0bda:0411 Realtek Semiconductor Corp. 4-Port USB 3.0 Hub Bus 002 Device 002: ID 0bc2:ab28 Seagate RSS LLC BUP BK Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
The thumb drive I’m targeting is the Silicon Motion at bus 002, device 005.
sudo qemu-system-x86_64 -m 512 -enable-kvm -usb -device usb-host,hostbus=2,hostaddr=005
Check if a USB drive is bootable and install to disk image
If you want to install a distribution to a harddisk image file, you need to create harddisk image file first.
Create the raw disk image file to install onto:
qemu-img create mydisk.img 15G sudo qemu-system-x86_64 -boot d -cdrom image.iso -m 512 -hda mydisk.img
Check if an ISO image is bootable plus control CPU-related resources
sudo qemu-system-x86_64 -boot d -drive format=raw,file=$HOME/mydisk.img \ -enable-kvm -bios /usr/share/qemu/OVMF.fd -cpu host -smp cpus=8,cores=4,\ threads=2,sockets=1 -m 1024 -cdrom image.iso
November 26, 2021 2:10 pm @ 14:10
I will check this out, I have a USB drive that I am not sure if the files on it were modified and don’t know if it still works.
February 16, 2022 11:05 pm @ 23:05
Sounds like you have bigger problems ;)