Qemu
Qemu can be started with:
* qemu-kvm
: old versions of qemu, with KVM support
* qemu
: old version of qemu
* qemu-system-i386
: recent version, i386 mode
* qemu-system-x86_64
: recen version, AMD64 mode
Monitor
change floppy0 disk2.img
change ide1-cd0 win311.iso
eject ide1-cd0
sendkey ctrl-alt-f2 sendkey esc
Disk file
Create a disk file
Unless you use ISO files or dd
-created raw files, you may want to use qemu-img
.
For instance:
* mkfs.msdos -C blank.ima 1440
Some examples:
* qemu-img create base.raw 2G
* qemu-img create -f qcow2 extra.qcow2 -b base.raw -F qcow2
The format can be forced with -f [fmt]
(default is raw
):
* recent formats: raw
, qcow2
* legacy and third-party formats: vmdk
, vdi
, vhd
, vhdx
, qcow1
, qed
Snapshot mode: create a new disk with a base image:
* -b base.img
: the base image will be the main disk, but changes will be written tio the new one
* -F qcow2
: backing image format is qcow2
Convert a disk file
Converting an image can be done with qemu-img convert
:
* qemu-img convert input_file output_file
* qemu-img convert input_file1 input_file2... output_file
: for special multi-files input formats
* qemu-img convert -c [...]
: add compression (on conversion, not on usage: you may want to re-apply it once in a while)
The format can be selected with:
* -f [fmt]
: input format
* -O [fmt]
: output format
Note that the format is always raw
unless specified.
You may choose between:
* recent formats: raw
, qcow2
* legacy and third-party formats: vmdk
, vdi
, vhd
, vhdx
, qcow1
, qed
Access the disk file (raw mode) from the Host
You need to setup the loopback device to access such a file.
It can be easier if you setup your fstab
for it.
Your system must configure the loopback device with partitions support (i.e., rc.local
):
* modprobe -r loop
* modprobe loop max_part=8
Operations:
* losetup file.raw /dev/loop0
* mount /dev/loop0p1 /mnt/loop/loop1
* work in the mounted fs
* umount /mnt/loop/loop1
* losetup -d /dev/loop0
Access the disk file (raw mode) from the Host, easy way
To use a partition, we need to know where it is located in the image.
Check with fdisk, which will give you the start sector and the size of a sector.
offset=`echo p | fdisk "$f" | grep --after=1 Device | tail -n1 \
| sed 's:^[^ ]* *\** *\([0-9]*\).*:\1:g'`
sector=`echo p |fdisk "$f" |grep "Sector size " |cut -f2- -d/ |cut -f2 -d " "`
expr offset \* sector
Note: or you can use mount-loop.sh --offset DISK
Mount
Note: or you can use mount-loop.sh DISK
MTools
We suppose the offset is 1048576, i.e., usual 512 size sector and 2048 start.
mcopy -i win98se.img@@1048576 ::FILE1 ::FILE2 ./
Use a disk file
- to add: -snapshot # discard writes (beware of ctrl+a, S : write back!)
no snapshot with blockdev...
set -- "$@" -drive file="$disk2",index=1,media=disk,format=raw
HDD="-hda $NAME.img" HDD="-blockdev driver=raw,node-name=disk,file.driver=file,file.filename=$NAME.img"
Floppy
-drive file=/path/to/floppy.img,index=0,if=floppy,format=raw
-blockdev driver=file,node-name=f0,filename=/path/to/floppy.img -device floppy,drive=f0
Cdrom
Old (still compatible) version:
* -cdrom cd.iso
-hdb fat:rw:/tmp/fat # ??
Graphics adapter
You can choose your graphics adapter via the -vga
switch:
* -vga qxl
: QXL virtio via spice (recent)
* -vga virtio
: normal virtio
* -vga vmware
: VMWare SVGA-II compatible
* -vga std
: XP+
* -vga cirrus
: old card, 256 colours
Note that regarding performances, the graphics adapter is one thing, the display is another. Even an old DOS game can be unbearably slow if you use software rendering to process its graphics output.
-display sdl
: more or less required if you do any graphical thing
Sound
SOUND="-soundhw all" # old versions SOUND="-audiodev pipewire,id=qemu"
snd= pa, pipewire, alsa, sdl...
set -- "$@" -machine pcspk-audiodev="$snd" set -- "$@" -audiodev "$snd",id="$snd" set -- "$@" -device adlib,audiodev="$snd" -device sb16,audiodev="$snd"
Network
NET="-net none"
Miscallenaous options
-machine accel=kvm,XXX
RAM="-m 64m"
-boot order=dac -k fr-be -usb -usbdevice tablet -serial stdio -name "$NAME"
Script
#!/bin/sh
NAME=`basename "$PWD"`
DISK1="$NAME".hdc
DISK2="$NAME".hdd
CDROM="$NAME".iso
FLOPPY="$NAME".fdd
[ "$SND" = "" ] && SND=pipewire
[ "$RAM" = "" ] && RAM=64m
set --
set -- "$@" -machine accel=kvm
set -- "$@" -machine pcspk-audiodev="$SND"
set -- "$@" -audiodev "$SND",id="$SND"
set -- "$@" -device adlib,audiodev="$SND" -device sb16,audiodev="$SND"
set -- "$@" -boot order=dac
set -- "$@" -m $RAM
set -- "$@" -name "$NAME"
set -- "$@" -display sdl
if [ -e "$FLOPPY" ]; then
set -- "$@" -drive file="$FLOPPY",index=0,if=floppy,format=raw
fi
if [ -e "$DISK1" ]; then
set -- "$@" -drive file="$DISK1",index=1,media=disk,format=raw
fi
if [ -e "$DISK2" ]; then
set -- "$@" -drive file="$DISK2",index=2,media=disk,format=raw
fi
if [ -e "$CDROM" ]; then
set -- "$@" -drive file="$CDROM",index=3,media=cdrom,format=raw
fi
echo qemu-system-i386 "$@"
qemu-system-i386 "$@"