How to test your live USB without rebooting your computer on Linux
Problem:
You want to create a live USB stick e.g. gparted, Ubuntu etc and you quickly want to test it without rebooting your computer.
Solution
You can use qemu, a system emulator, to do that.
First, install qemu. On Ubuntu:
sudo apt -y install qemu-system-x86
Now find out what the block your USB stick is called (e.g. /dev/sdb
). You can use lsblk
to do this:
sudo lsblk
this will output, for example
[...]
sda 8:0 0 447,1G 0 disk
├─sda1 8:1 0 549M 0 part
├─sda2 8:2 0 121,2G 0 part
├─sda3 8:3 0 1K 0 part
└─sda5 8:5 0 325,4G 0 part /
sdb 8:16 1 29,3G 0 disk
└─sdb1 8:17 1 268M 0 part
/dev/sda
is usually your own hard drive (in my case, a 500 GB
drive - 447.1G
listed). In my case, I use a 32 GByte USB stick for the live USB, which is /dev/sdb (29.3 GB).
Note: You want to use the drive block device (e.g. /dev/sdb
), not the partition block device (e.g. /dev/sdb1
)
Now you can run qemu
like this:
sudo qemu-system-x86_64 -hda /dev/sdb -m 1024
Remember to replace /dev/sdb
by your USB stick block device (which we identified before using lsblk
).
-m 1024
tells qemu to use 1024 Megabytes = 1 Gigabyte of RAM. You might need to increase this depending on what you are trying to boot.
Note that this approach will try to boot using BIOS and won’t try to boot UEFI-only drives like the ones created by tuxboot
. In order to use UEFI with qemu you first need to install OVMF (which is a UEFI emulator that can be used for qemu
):
sudo apt -y install ovmf
then run qemu
like this:
sudo qemu-system-x86_64 -bios /usr/share/ovmf/OVMF.fd -hda /dev/sdb -m 1024
Remember to replace /dev/sdb
by your USB stick block device (which we identified before using lsblk
).
Since qemu
is an emulator, it will be slower than booting your computer from the stick - but you can keep your computer running while you are testing your live USB stick.