qemu boot iso
sudo apt install qemu-utils qemu-efi qemu-system-x86
qemu-img create debian.img 2G
qemu-img create -f qcow2 debian.qcow 2G
qemu-system-x86_64 -hda debian.img -cdrom debian-testing-amd64-netinst.iso -boot d -m 512
kvm -cdrom ~/mnt/aps/iso/Windows7SuperNanoLite64.iso -hda win7.img -m 1G -boot d
TIPS:
By default only 128 MiB of memory is assigned to the machine. The amount of memory can be
adjusted with the-m
switch, for example-m 512M
or-m 2G
.
-boot menu=on
,-boot order=x
When running QEMU in headless mode, it starts a local VNC server on port 5900 per default.
if you need to replace floppies or CDs as part of the installation process, you can use the
QEMU machine monitor (press Ctrl+Alt+2
in the virtual machine's window) to remove and attach
storage devices to a virtual machine. Type info block
to see the block devices, and use the
change
command to swap out a device. PressCtrl+Alt+1
to go back to the virtual machine.
qemu-system-x86_64 -machine help
qemu-system-x86_64 -machine q35,help
qemu-system-x86_64 -device help
qemu-system-x86_64 -device qxl,help
qemu-system-x86_64 -audiodev help
qemu-system-x86_64 -hda debian.img -m 512
qemu-system-x86_64 -cdrom EaseUS.Partition.Master.17.0.WinPE.iso -m 1G
mount -o loop,offset=32256 /path/to/image.img /mnt/mountpoint
Image format |
Argument to qemu-img |
---|---|
QCOW2 (KVM, Xen) |
|
QED (KVM) |
|
raw |
|
VDI (VirtualBox) |
|
VHD (Hyper-V) |
|
VMDK (VMware) |
|
raw image > qcow2 image
fileqemu-img convert -f raw -O qcow2 image.img image.qcow2
vmdk image file > raw image file
qemu-img convert -f vmdk -O raw image.vmdk image.img
qemu-img convert -f vmdk -O qcow2 image.vmdk image.qcow2
VBoxManage clonehd ~/VirtualBox\ VMs/image.vdi image.img --format raw
qemu-img info win7.img
image: win7.img
file format: raw
virtual size: 10 GiB (10737418240 bytes)
disk size: 891 MiB
run qemu with kvm
qemu-system-x86_64 -accel kvm
kvm win7.img -m 1G
qemu-system-x86_64 -machine accel=kvm:tcg
emulated virtual fat
qemu-system-x86_64 linux.img -hdb fat:/my_directory
qemu-system-x86_64 linux.img -fda fat:floppy:/my_directory
qemu-system-x86_64 linux.img -fda fat:floppy:rw:/my_directory
modprobe vfio-pci
https://www.qemu.org/docs/master/system/images.html
specify disk
-drive file=my.img,index=0,media=disk,format=raw
-drive format=raw,media=cdrom,readonly=on,file=debian-8.2.0-amd64-DVD-1.iso
-hda,hdb,hdc,hdd file
Use file as hard disk 0, 1, 2 or 3 image
you cannot use -hdc and -cdrom at the same time
-blockdev driver=file,node-name=disk_file,filename=disk.img
-blockdev driver=raw,node-name=disk,file=disk_file
-blockdev driver=raw,node-name=disk,file.driver=file,file.filename=disk.img
-blockdev driver=qcow2,node-name=hda,file=my_file,overlap-check=none,cache-size=16777216
-blockdev driver=qcow2,node-name=disk,file.driver=http,file.filename=http://example.com/image.qcow2
Instead of -cdrom you can use:
qemu-system-x86_64 -drive file=file,index=2,media=cdrom
Instead of -hda, -hdb, -hdc, -hdd, you can use:
qemu-system-x86_64 -drive file=file,index=0,media=disk
qemu-system-x86_64 -drive file=file,index=1,media=disk
qemu-system-x86_64 -drive file=file,index=2,media=disk
qemu-system-x86_64 -drive file=file,index=3,media=disk
Instead of -fda, -fdb, you can use:
qemu-system-x86_64 -drive file=file,index=0,if=floppy
qemu-system-x86_64 -drive file=file,index=1,if=floppy
By default, interface is "ide" and index is automatically incremented
qemu-system-x86_64 -drive file=a -drive file=b"
direct linux boot / kernel testing
qemu-system-x86_64 -kernel bzImage -hda rootdisk.img -append "root=/dev/sda"
qemu-system-x86_64 -kernel vmlinuz-6.1.41-gentoo -initrd initrd.img-6.1.0-11-amd64 -m 1G -hda kernel-hd -append "root=/dev/sda verbose"
Use -kernel
to provide the Linux kernel image and -append
to
give the kernel command line arguments. The -initrd
option can be
used to provide an INITRD image.
qemu-system-x86_64 -kernel bzImage -hda rootdisk.img-append "root=/dev/hda console=ttyS0" -nographic
Use Ctrl-a c to switch between the serial console and the monitor
create rootfs
dd if=/dev/zero of=kernel-hd bs=1M count=100
mkfs.ext4 kernel-hd
sudo mount kernel-hd /mnt
archlinux rootfs
sudo pacstrap /mnt base ##you can just go with coreutils
for alpine linux root
https://dl-cdn.alpinelinux.org/alpine/latest-stable/main/x86_64/apk-tools-static-2.14.0-r2.apk
tar xf
apk-tools-static-2.14.0-r2.apk
tar: Ignoring unknown extended header keyword 'APK-TOOLS.checksum.SHA1'
https://dl-cdn.alpinelinux.org/alpine/MIRRORS.txt
http://dl-cdn.alpinelinux.org/alpine
./sbin/apk.static -X/latest-stable/main -U --allow-untrusted -p /mnt --initdb add alpine-base
## mouse controls
- Ctrl-Alt-f
Toggle full screen
- Ctrl-Alt-+
Enlarge the screen
- Ctrl-Alt--
Shrink the screen
- Ctrl-Alt-u
Restore the screen’s un-scaled dimensions
- Ctrl-Alt-n
Switch to virtual console ‘n’. Standard console mappings are:
- 1
Target system display
- 2
Monitor
- 3
Serial port
- Ctrl-Alt
Toggle mouse and keyboard grab.
Ctrl+Alt+g
.
In the virtual consoles, you can use Ctrl-Up, Ctrl-Down, Ctrl-PageUp and Ctrl-PageDown to move in the back log.
Alt-Shift (instead of Ctrl-Alt)
and if you use -ctrl-grab
then the modifier is the right Ctrl key
(instead of Ctrl-Alt):
qemu-img resize --shrink win7.img 4G
kvm -soundhw all
-soundhw ac97
convert raw img to qcow2
qemu-img convert -p -f raw -O qcow2 win7.img win7.qcow2
https://en.wikibooks.org/wiki/QEMU/Images
To use additional images in QEMU, specify them on the command line with options -hda, -hdb, -hdc, -hdd.
NB: QEMU doesn't support both -hdc and -cdrom at the same time, as they both represent the first device on the second IDE channel.
Copying an image to a physical device
qemu-img convert -O raw diskimage.qcow2 diskimage.raw
dd if=diskimage.raw of=/dev/sdX
qemu-img convert -O raw diskimage.qcow2 /dev/sdX
virtio windows drivers
https://github.com/virtio-win/virtio-win-pkg-scripts/blob/master/README.md
https://en.wikibooks.org/wiki/QEMU/Devices/Virtio
or Win 7 use version 0.1.173-4. Some singular drivers from newer virtio builds may be used on Win 7 but you will have to install them manually via device manager.
Networking
The default user-mode networking allows the guest to access the host OS at the IP address 10.0.2.2
qemu-system-i386 -m 256 -hda disk.img -netdev user,id=network0 -device e1000,netdev=network0,mac=52:54:00:12:34:56 &
tap networking
-device virtio-net,netdev=network0 -netdev tap,id=network0,ifname=tap0,script=no,downscript=no
-device virtio-net,netdev=network0 -netdev tap,id=network0,ifname=tap0,script=no,downscript=no,vhost=on
host only networking
# ip addr add 172.20.0.1/16 dev br0 # ip link set br0 up # dnsmasq --interface=br0 --bind-interfaces --dhcp-range=172.20.0.2,172.20.255.254
Audio
qemu-system-x86_64 -audiodev help
create backend
-audiodev pa,id=snd0
intel hd audio
qemu-system-x86_64 -device help | grep hda
-device ich9-intel-hda
-device hda-output,audiodev=snd0
ac 97
-device AC97,audiodev=snd0
https://en.wikibooks.org/wiki/QEMU/Devices/Audio
Grapics
qemu-system-x86_64 -h | grep vga
-vga [std|cirrus|vmware|qxl|xenfb|tcx|cg3|virtio|none]
std
With -vga std
you can get a resolution of up to 2560 x 1600 pixels without requiring guest
drivers. This is default
cirrus
The cirrus graphical adapter was the default before 2.2. It should not be used on modern systems.
vmware
Although it is a bit buggy, it performs better than std and cirrus. I
qxl
QXL is a paravirtual graphics driver with 2D support. To use it, pass the -vga qxl
option and
install drivers in the guest. You may want to use #SPICE for improved graphical performance
when using QXL.
On Linux guests, the qxl
and bochs_drm
kernel modules must be loaded in order to gain a decent performance.
Default VGA memory size for QXL devices is 16M which is sufficient to drive resolutions approximately up to QHD (2560x1440). To enable higher resolutions, increase vga_memmb.
virtio
virtio-vga
/virtio-gpu
is a paravirtual 3D graphics driver based on virgl. Currently a work
in progress, supporting only very recent (>= 4.4) Linux guests with mesa (>=11.2) compiled
with the option gallium-drivers=virgl
.
To enable 3D acceleration on the guest system select this vga with -device virtio-vga-gl
and enable the opengl context in the display device with -display sdl,gl=on
or -display gtk,gl=on
for the sdl and gtk display output respectively. Successful
configuration can be confirmed looking at the kernel log in the guest:
# dmesg | grep drm [drm] pci: virtio-vga detected [drm] virgl 3d acceleration enabled
none
This is like a PC that has no VGA card at all. You would not even be able to access it with the -vnc
option. Also, this is different from the -nographic
option which lets QEMU emulate a VGA card, but disables the SDL display.
SPICE
The SPICE project aims to provide a complete open source solution for remote access to virtual machines in a seamless way.
nano qemu-headless.sh
#!/bin/sh
WINIMG=/path/to/win10.iso
VIRTIMG=/path/to/virtio-drivers.iso
VMLOC=/path/to/vm/location
qemu-system-x86_64 \
-enable-kvm \
-m 8G \
-machine q35,accel=kvm \
-smp cores=2,threads=4 \
-cpu host \
-smbios type=2 \
-vga qxl \
-drive driver=raw,file=${VMLOC}/win10.img,if=virtio \
-cdrom ${WINIMG} \
-drive file=${VIRTIMG},index=3,media=cdrom \
-rtc base=localtime,clock=host \
-usb -device usb-kbd -device usb-tablet \
-device e1000-82545em,netdev=net0,mac=12:34:56:78:90 \
-netdev user,id=net0
-nographic \
-vnc :0 \
-k en-us
Enabling IOMMU (Intel VT-d/AMD-Vi) support
qemu-system-x86_64 -enable-kvm -machine q35 -device intel-iommu -cpu host ..
While adding the kernel parameter intel_iommu=on
is still needed for
remapping IO (e.g. PCI passthrough with vfio-pci), -device intel-iommu
should not be set
if PCI passthrough is required.
Booting in UEFI mode
The default firmware used by QEMU is SeaBIOS
/usr/share/qemu/
sudo apt install ovmf
https://packages.debian.org/bookworm/all/ovmf/filelist
ls /usr/share/ovmf/
.rw-r--r-- 2.1M root 6 Mar 02:21 OVMF.fd
ls /usr/share/OVMF/
archlinux ovmf location
https://archlinux.org/packages/extra/any/edk2-ovmf/
-drive if=pflash,format=raw,file=/copy/of/OVMF.fd
-drive if=pflash,format=raw,readonly=on,file=/usr/share/ovmf/x64/OVMF_CODE.fd \ -drive if=pflash,format=raw,file=/copy/of/OVMF_VARS.fd
SecureBoot
If secure boot is wanted, replace /usr/share/OVMF/OVMF_CODE.fd
with
/usr/share/OVMF/
/OVMF_CODE.secboot.fd
.
direct disk access
VBoxManage internalcommands createrawvmdk -filename /path/to/file.vmdk -rawdisk /dev/hda
dd if=/dev/zero of=/path/to/mbr count=2048
losetup --show -f /path/to/mbr
echo "0 2048 linear /dev/loop0 0 2048 `blockdev --getsz /dev/hdaN` linear /dev/hdaN 0" | dmsetup create qemu
dd if=/dev/hda count=1 of=/path/to/mbr # loop=`losetup --show -f /path/to/mbr` # start=`blockdev --report /dev/hdaN | tail -1 | awk '{print $5}'` # size=`blockdev --getsz /dev/hdaN` # disksize=`blockdev --getsz /dev/hda` # echo "0 1 linear $loop 0 1 $((start-1)) zero $start $size linear /dev/hdaN 0 $((start+size)) $((disksize-start-size)) zero" | dmsetup create qemu
Mouse integration
To prevent the mouse from being grabbed when clicking on the guest operating system's window
qemu-system-x86_64 -hda disk_image -m 512 -usb -device usb-tablet
if not working -vga qxl
For Windows 8 (or later) guests it is better to disable "Turn on fast startup (recommended)" from the Power Options of the Control Panel as explained in the following forum page, as it causes the guest to hang during every other boot.
Comments
Post a Comment