Translation(s) : English - Italiano - Русский - Українська
QEMU
QEMU is a fast processor emulator using dynamic translation to achieve good emulation speed. It is a free open-source alternative to VMware.
As QEMU requires no host kernel patches to run, it is very safe and easy to use.
Оперування
QEMU має два режими оперування:
- Full system emulation. In this mode, QEMU emulates a full system (for example a PC), including a processor and various peripherals. It can be used to launch different Operating Systems without rebooting the PC or to debug system code.
User mode emulation (Linux host only). In this mode, QEMU can launch Linux processes compiled for one CPU on another CPU. For example, it can be used to launch Wine or to ease cross-compilation and cross-debugging.
Furthermore, there are two options for running QEMU:
Встановлення
Емулятор QEMU запакований у qemu
$ sudo apt install qemu qemu-utils qemu-system-x86 qemu-system-gui
Використання
Налаштування стабільної системи
Розробник Debian Aurelien Jarno підтримує список готових до використання образів QEMU для стабільної Debian на http://people.debian.org/~aurel32/qemu (але станом на 22.07.2020, не оновлюється з 2015 року).
Налаштування тестової/нестабільної системи
QEMU is especially handy to set up an emulated testing/unstable system when working on the Debian installer itself or on the boot system, or when trying some experimental features without impact on the productive system. A sid system can be set up with the following steps:
Create the hard disk image with:
$ qemu-img create debian.img 2G
If you're installing a desktop environment, you'll need more than 2G. https://www.debian.org/releases/stable/amd64/apds02.en.html
or with the qcow2 disk image format if you want to use QEMU's own "Copy On Write" image format:
$ qemu-img create -f qcow2 debian.qcow 2G
Download a current boot image, e.g. the businesscard image at http://cdimage.debian.org/cdimage/daily-builds/daily/arch-latest/amd64/iso-cd/
$ wget https://cdimage.debian.org/cdimage/daily-builds/daily/arch-latest/amd64/iso-cd/debian-testing-amd64-netinst.iso
Boot the image with:
$ qemu-system-x86_64 -hda debian.img -cdrom debian-testing-amd64-netinst.iso -boot d -m 512
- If you have KVM, you can use it by including the option -enable-kvm.
- When the usual debian boot screen appears, boot into "expert" mode.
- Install the system as usual; to set up a sid system choose "unstable" when being asked by the installer.
After the installation is done, the system can be booted with:
$ qemu-system-x86_64 -hda debian.img -m 512
Резервне копіювання образа диска
The disk image "debian.img" is a sparse file. After installing a Debian base system, it fits on a CD-ROM even without compression:
$ tar c --sparse -f backup.tar debian.img
This creates a tar file of about 320M (supposed that the image contains a 1.9GB ext3 root filesystem and a 250MB swap partition). After unpacking with tar xf, the sparse file is restored and can be booted immediately.
Better still, convert from a sparse file into the qemu's own "Copy On Write" image. This conversion will save the same space and still be runnable:
$ qemu-img convert -c debian.img -O qcow debian_recompressed.img
If the guest system's image is still larger than reasonable, then open up the Guest system and run "dd if=/dev/zero of=/tmp/junk ; sync ; rm /tmp/junk". That will push out deleted file scraps, recompression should work then.
Мережа
Гості у внутрішній мережі NAT
За замовчуванням, QEMU виконує параметри -nic і -user для додавання одного мережевого адаптера гостьовій системі і забезпечує зовнішній доступ до Інтернету через NAT. Основна система і гостьова система не бачать одне одного.
Основна і гостьова система в одній мережі
Щоб створити міст між основною і гостьовою системами робіть наступне (випробувано на DebianSqueeze). Зверніть увагу, що всі ці зміни потрібно зробити в основній системі.
Встановити bridge-utils.
Змінити /etc/network/interfaces:
Remove the 'auto' line and change the 'method' of your physical, wired network adapters from 'auto' to 'manual':
#auto eth0 iface eth0 inet manual
Додайте строфу для мосту:
auto br0 iface br0 inet dhcp pre-up ip tuntap add dev tap0 mode tap user <імʼя_користувача> pre-up ip link set tap0 up bridge_ports all tap0 bridge_stp off bridge_maxwait 0 bridge_fd 0 post-down ip link set tap0 down post-down ip tuntap del dev tap0 mode tap
Пояснення: ця строфа автоматично завантажує міст і налаштовує його за допомогою DHCP. Створюється пристрій tap, що належить <ім'я_користувача>, і піднімається; зверніть увагу, що <ім'я користувача> - це ім'я користувача в основній системі. У рядку 'bridge_ports' значення 'all' додає всі фізичні інтерфейси до мосту; віртуальні інтерфейси повинні бути перераховані явно. Три інші директиви моста прискорюють активацію моста. Дивіться bridge-utils-interfaces(5) - зауважте, що сторінка man застерігає від додавання бездротових адаптерів до моста (див. також BridgeNetworkConnections).
Запуск QEMU:
$ qemu-system-x86_64 -hda imagefile.img -net nic -net tap,ifname=tap0,script=no,downscript=no
ifname=tap0 - назва tap тут відповідає назві вказаній у строфі мосту вище.
script=no,downscript=no вимикає скрипти /etc/qemu-ifup та /etc/qemu-ifdown, оскільки вони не потрібні.
The guest virtual network adapters will be configured by the /etc/network/interfaces file in the guest file system. DHCP will work so this is simplest way to go.
To run additional guests, duplicate the lines in the bridge stanza for tap1, tap2 as needed and change the ifname argument in the command line. If you run more guests from the same image file, udev will rename the interface to avoid duplication (e.g. eth0 => eth1), so add extra interface stanzas in the guest interfaces file to configure these.
Мережа QEMU через VDE
Virtual Distributed Ethernet (VDE) provides is a virtual switch that can connect multiple virtual machines together, both local and remote. With VDE it is possible to create a virtual network of QEMU machines running on one or more real computers.
Install vde2 and uml-utilities (for tunctl).
- Add users which will be running VM's to the vde2-net group.
Add to /etc/network/interfaces:
auto mytap iface mytap inet static address 10.0.3.1 netmask 255.255.255.0 vde2-switch -t mytapIf automatic configuration of guest network interfaces is desired, install a DHCP server such as dnsmasq as well. Configure it to assign addresses only on the TAP interface (e.g. 'mytap' in the above example). If you use dhcpd, make sure mytap is added to /etc/default/dhcp3-server and the INTERFACES directive. anm
Either reboot or run the following:
# modprobe tun # ifup mytap # /etc/init.d/dnsmasq restart #if used $ newgrp vde2-net #run as user starting Qemu VM's
Finally, start the VM:
$ qemu-system-x86_64 -net nic -net vde,sock=/var/run/vde2/mytap.ctl debianimage.img
If running more than one VM, you need to provide a unique MAC address:
$ qemu-system-x86_64 -net nic,macaddr=52:54:00:12:01:00 -net vde,sock=/var/run/vde2/mytap.ctl debianimage.img
(in DebianLenny, vdeqemu was needed for running qemu with VDE, but recent versions of qemu has vde enabled already.) If copying a MAC address from an existing interface, make it unique by altering any of the last 6 digits at the end. The first 6 designate the card manufacturer and so should not be made up. If running kvm instead of QEMU, the command name is 'vdekvm'.
QEMU VM's networked under VDE are not automatically NATed as they are under QEMU's default User Mode networking. For guest external network access you must enable NAT/Masquerading via iptables. An iptables rules-building program such as shorewall makes this easier. You may also use NAT/Masquerade script from tldp
More info on VDE:
Інше
Монтування образів QEMU
Ніколи не монтуйте образ QEMU під час використання QEMU, інакше ви можете пошкодити файлову систему(и) всередині.
raw
Linux and other Unix-like hosts can mount images created with the raw format type using a loopback device. From a root login (or using sudo), mount a loopback with an offset of 32,256:
# mount -o loop,offset=32256 /path/to/image.img /mnt/mountpoint
For example, to copy some files across to a FreeDOS hard drive image:
# mkdir -p /mnt/freedos # mount -o loopback,offset=32256 freedos-c.img /mnt/freedos # cp oldgames /mnt/freedos # umount /mnt/freedos
Note: if you have an image without partitions you should omit the ,offset=32256 part. This is for instance the case if you want to mount linux-0.2.img (which can be found at the QEMU web site at the time of writing).
qcow2
You will need a 2.6.26 kernel or newer, so Lenny will do. Load the ndb module:
# modprobe nbd max_part=8
If you leave off the max_part attribute, partitions are not supported and you’ll be able to access the disk, but not have device nodes for any of the partitions.
Assuming your qcow2 image filename is imagename.qcow, run:
# kvm-nbd --connect=/dev/nbd0 imagename.qcow
Now you can check the partition table with:
# fdisk -l /dev/nbd0
and mount, e.g., the first partition on /mnt with:
# mount /dev/nbd0p1 /mnt
Див. також
Засоби повʼязані з QEMU:
qemubuilder - creates Debian packages sandboxed with QEMU
- QEMU frontends:
qemulator (since Wheezy superseded by virtualbricks)
Альтернативні або схожі засоби:
Засоби для системної віртуалізації
Зовнішні посилання
http://qemu-buch.de/cgi-bin/moin.cgi/FrequentlyAskedQuestions - ЧАП по QEMU (visited 04/2012)
- Other Guides
Networking KVM (applies to QEMU) (visited 04/2012) Note: the command 'qemu-system-x86_64' in this guide on Debian Etch is 'kvm'
інформація повʼязана з Debian
інформація від виробника
інша інформація
CategoryEmdebian | CategorySoftware | CategoryVirtualization | CategorySystemAdministration
