QEMU 安装与使用
生活随笔
收集整理的這篇文章主要介紹了
QEMU 安装与使用
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
這里寫自定義目錄標題
- 1. 下載并安裝qemu
- 下載 cloud image 并 在 qumu 中進行運行
- script 一鍵運行
- 使用 libvirt 啟動虛擬機的常用命令
1. 下載并安裝qemu
下載 cloud image 并 在 qumu 中進行運行
script 一鍵運行
#!/usr/bin/env bashsudo apt-get install cloud-image-utils qemu# This is already in qcow2 format. img=ubuntu-18.04-server-cloudimg-amd64.img if [ ! -f "$img" ]; thenwget "https://cloud-images.ubuntu.com/releases/18.04/release/${img}"# sparse resize: does not use any extra space, just allows the resize to happen later on.# https://superuser.com/questions/1022019/how-to-increase-size-of-an-ubuntu-cloud-imageqemu-img resize "$img" +128G fiuser_data=user-data.img # For [ ! -f "$user_data" ] syntax # https://linuxize.com/post/bash-check-if-file-exists/ if [ ! -f "$user_data" ]; then# For the password.# https://stackoverflow.com/questions/29137679/login-credentials-of-ubuntu-cloud-server-image/53373376#53373376# https://serverfault.com/questions/920117/how-do-i-set-a-password-on-an-ubuntu-cloud-image/940686#940686# https://askubuntu.com/questions/507345/how-to-set-a-password-for-ubuntu-cloud-images-ie-not-use-ssh/1094189#1094189# How does "cat << EOF" work in bash?# https://stackoverflow.com/questions/2500436/how-does-cat-eof-work-in-bashcat >user-data <<EOF #cloud-config password: asdfqwer chpasswd: { expire: False } ssh_pwauth: True EOFcloud-localds "$user_data" user-data fiqemu-system-x86_64 \-drive "file=${img},format=qcow2" \-drive "file=${user_data},format=raw" \-device rtl8139,netdev=net0 \-enable-kvm \-m 2G \-netdev user,id=net0 \-serial mon:stdio \-smp 2 \-vga virtio \ ; qemu-system-x86_64 -enable-kvm -hda /tmp/vm00.qcow2 -kernel /var/tmp/vmlinuz-5.7.0-050700-generic -nographic -m 1024 -object memory-backend-uswap,size=1073741824,id=m0,allocator=hugetlb -numa node,memdev=m0 -append 'console=ttyS0 root=/dev/sda1'使用 libvirt 啟動虛擬機的常用命令
定義一個 虛擬機的 配置文件 vm.xml
define a domain
This command outputs the guest’s XML configuration file to standard out (stdout).
EXAMPLE OUTPUT:
# virsh dumpxml guest1-rhel6-64 <domain type='kvm'><name>guest1-rhel6-64</name><uuid>b8d7388a-bbf2-db3a-e962-b97ca6e514bd</uuid><memory>2097152</memory><currentMemory>2097152</currentMemory><vcpu>2</vcpu><os><type arch='x86_64' machine='rhel6.2.0'>hvm</type><boot dev='hd'/></os><features><acpi/><apic/><pae/></features><clock offset='utc'/><on_poweroff>destroy</on_poweroff><on_reboot>restart</on_reboot><on_crash>restart</on_crash><devices><emulator>/usr/libexec/qemu-kvm</emulator><disk type='file' device='disk'><driver name='qemu' type='raw' cache='none' io='threads'/><source file='/home/guest-images/guest1-rhel6-64.img'/><target dev='vda' bus='virtio'/><shareable/<<address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/></disk><interface type='bridge'><mac address='52:54:00:b9:35:a9'/><source bridge='br0'/><model type='virtio'/><address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/></interface><serial type='pty'><target port='0'/></serial><console type='pty'><target type='serial' port='0'/></console><input type='tablet' bus='usb'/><input type='mouse' bus='ps2'/><graphics type='vnc' port='-1' autoport='yes'/><sound model='ich6'><address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/></sound><video><model type='cirrus' vram='9216' heads='1'/><address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/></video><memballoon model='virtio'><address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/></memballoon></devices> </domain>- Here we can find the mac address of the VM (devices->interface->mac)
12 copy file into vm disk image
sudo virt-copy-in -a /tmp/vm00.qcow2 /lib/modules/$(uname -r) /lib/modules/13 copy file out of a vm disk image
virt-copy-out - Copy files and directories out of a virtual machine disk image.more detail
總結
以上是生活随笔為你收集整理的QEMU 安装与使用的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: win7搭建nas存储服务器_普通用户的
- 下一篇: 报错集-------docker中删除镜