last update: 22-8-11
User mode
qemu linux.img
System mode
qemu-i386 -L / /bin/ls
apt-get install qemu qemu-utils
qemu
qemu-img
建立 image
qemu-img create -f qcow2 hda.img 10G
Default cluster_size: 65536
啟動
qemu -hda c.img -cdrom linux.iso -boot d -m 128 -localtime -vnc,password -monitor stdio
-monitor stdio 在 cmd mode 下見到 monitor
-boot [a|b|c|d]
a|b: floppy
c: 硬硬 (default)
d: CD-ROM
-localtime
預設上是使用 UTC 時間
(qemu) change vnc password Password: ******** (qemu)
(qemu) info vnc
Server: address: 0.0.0.0:5900 auth: vnc Client: none (qemu) info vnc Server: address: 0.0.0.0:5900 auth: vnc Client: address: 192.168.123.21:1478 x509_dname: none username: none
QEMU Monitor
- info
- change
Ctrl-Alt-n
- 1 Target system display
- 2 Monitor
- 3 Serial port
Ctrl-a c
Switch between console and monitor
info
screendump filename
commit device|all -- commit changes to the disk images (if -snapshot is used) or backing files
change device filename
savevm filename
loadvm filename
stop
cont
sendkey
system_reset
quit
網路
-nics n
-n script
/etc/qemu-ifup
-user-net
default
-dummy-net
VMwave To qemu
qemu-img convert -f vmdk ./sata-d0.vmdk debian6.master.qcow2
Default 的 output fmt 是 raw !!!
如果要設定 Format 的話, 就要加上 -O output_fmt
強烈建議用 qcow2, 因為它支援
- backing_file
- encryption
- cluster_size
- preallocation
- compression
- snapshots
查看 Image 資訊
qemu-img info debian6.master.qcow2
image: debian6.master.qcow2 file format: raw virtual size: 2.0G (2147483648 bytes) disk size: 971M
snapshot
snapshot [-l | -a snapshot | -c snapshot | -d snapshot ] filename
list (-l)
# qemu-img snapshot -l centos6.3.qcow2
Snapshot list:
ID TAG VM SIZE DATE VM CLOCK
3 1345047956 0 2012-08-16 00:25:56 00:00:00.000
apply (-a)
# qemu-img snapshot -a 1345047956 centos6.3.qcow2
create(-c)
# qemu-img snapshot -c 12345 centos6.3.qcow2
Snapshot list:
ID TAG VM SIZE DATE VM CLOCK
3 1345047956 0 2012-08-16 00:25:56 00:00:00.000
4 12345 0 2012-08-20 22:02:18 00:00:00.000
delete(-d)
# qemu-img snapshot -d 12345 centos6.3.qcow2
Snapshot list: ID TAG VM SIZE DATE VM CLOCK 3 1345047956 0 2012-08-16 00:25:56 00:00:00.000
qemu-img
mv disk.qcow2 base_disk.qcow2
qemu-img create -c -b base_disk.qcow2 delta_disk.qcow2
ln -s delta_disk.qcow2 disk.qcow2
# formats "qcow2" and "qed"
rebase [-p] [-u] -b backing_file [-F backing_fmt] filename
Safe mode (default)
# merged into filename before actually changing the backing file.
# expensive operation, comparable to converting an image.
Unsafe mode
# without any checks on the file contents.
# fix an image whose backing file has already been moved/renamed.
# Commit the changes recorded in filename in its base image.
commit filename
virtio-rng
paravirtualized device that is exposed as a hardware RNG device to the guest.
* Linux kernel contains the guest driver
-device virtio-rng-pci
* default backend is to use the host's /dev/random
-object rng-random,filename=/dev/hwrng,id=rng0 \ -device virtio-rng-pci,rng=rng0
cat /sys/devices/virtual/misc/hw_random/rng_available virtio
cat /sys/devices/virtual/misc/hw_random/rng_current virtio
cat /dev/hwrng
rngd -r /dev/hwrng