[转]qemu安装虚拟机
Posted yi-mu-xi
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[转]qemu安装虚拟机相关的知识,希望对你有一定的参考价值。
转自
https://wiki.ubuntu.com/ARM64/QEMU
https://gist.github.com/george-hawkins/16ee37063213f348a17717a7007d2c79
https://morningd.github.io/2018/01/08/how-to-run-aarch64-ubuntu-server-cloudimg-on-x86-64/
https://www.cnblogs.com/jinanxiaolaohu/p/11003388.html
AArch64上qemu起虚拟机的过程
1.编译安装aarch64的qemu
这里用的是spdk-3.0.0 qemu
Mkdir build && cd build
../configure --target-list=aarch64-softmmu --enable-debug
make && make install
Mkdir build && cd build
../configure --target-list=aarch64-softmmu --enable-debug
make && make install
2.安装qemu-efi
sudo apt-install qemu-efi
生成的文件在 /usr/share/qemu-efi/QEMU_EFI.fd
wget https://releases.linaro.org/components/kernel/uefi-linaro/latest/release/qemu64/QEMU_EFI.fd 这个 估计有问题,用上面的!
wget https://releases.linaro.org/components/kernel/uefi-linaro/latest/release/qemu64/QEMU_EFI.fd 这个 估计有问题,用上面的!
3. flash0.img为UEFI固件,flash1为UEFI vars
dd if=/dev/zero of=flash0.img bs=1M count=64
dd if=/usr/share/qemu-efi/QEMU_EFI.fd of=flash0.img conv=notrunc
dd if=/dev/zero of=flash1.img bs=1M count=64
dd if=/dev/zero of=flash0.img bs=1M count=64
dd if=/usr/share/qemu-efi/QEMU_EFI.fd of=flash0.img conv=notrunc
dd if=/dev/zero of=flash1.img bs=1M count=64
来自 <https://wiki.ubuntu.com/ARM64/QEMU>
4. 下载的image地址 https://cloud-images.ubuntu.com/releases/bionic/release/
5.改密码方法:
5.1.写文件cloud.txt
#cloud-config
password: root
chpasswd: { expire: False }
ssh_pwauth: True
5.2.生成cloud.img
cloud-localds cloud.img cloud.txt
5.1.写文件cloud.txt
#cloud-config
password: root
chpasswd: { expire: False }
ssh_pwauth: True
5.2.生成cloud.img
cloud-localds cloud.img cloud.txt
5.3.修改qemu参数:
在boot的driver后面 加上
-drive if=none,id=cloud,file=cloud.img
-device virtio-blk-device,drive=cloud
-drive if=none,id=cloud,file=cloud.img
-device virtio-blk-device,drive=cloud
5.4.问题
起qemu后可能起不来,进入shell了,按顺序输入 fs0: ls cd EFI/BOOT ls
会有BOOTAA64.EFI的文件, 输入该文件 即可
登录 ubuntu:root
解决:【要重新dd两个 flash0.img 和 flash1.img ,改密码后会被污染?? 】
起qemu后可能起不来,进入shell了,按顺序输入 fs0: ls cd EFI/BOOT ls
会有BOOTAA64.EFI的文件, 输入该文件 即可
登录 ubuntu:root
解决:【要重新dd两个 flash0.img 和 flash1.img ,改密码后会被污染?? 】
#!/bin/bash taskset -c 2,3 ../qemu-spdk300/build/aarch64-softmmu/qemu-system-aarch64 -m 1G -smp 2 -machine virt,accel=kvm,gic-version=host -nographic -cpu host -pflash flash0.img -pflash flash1.img -drive if=none,file=bionic-server-cloudimg-arm64.img,id=hd0 -device virtio-blk-device,drive=hd0 -drive if=none,id=cloud,file=cloud.img -device virtio-blk-device,drive=cloud -serial stdio -nodefaults -no-acpi -no-user-config -display none -netdev user,id=user0,hostfwd=tcp::3333-:22 -device virtio-net-pci,netdev=user0 |
6.qemu模拟OCSSD
6.1
touch myocssd0-datafile myocssd0-metadatafile
sudo fallocate -l 384G myocssd0-datafile
touch myocssd0-datafile myocssd0-metadatafile
sudo fallocate -l 384G myocssd0-datafile
#!/bin/bash ./qemu/build/aarch64-softmmu/qemu-system-aarch64 -machine virt,accel=kvm,gic-version=host,usb=off -cpu host -m 8192 #要分配足够大,不然设置hugepage后会out-of-memory -pflash flash0.img -pflash flash1.img -nographic -drive if=none,file=ubuntu-16.04-server-cloudimg-arm64-uefi1.img,id=hd0 -device virtio-blk-device,drive=hd0 -drive format=raw,file=myocssd0-datafile,if=none,id=myocssd0 -device nvme,drive=myocssd0,serial=deadbeef,lver=2,lba_index=3,lnum_ch=1,lnum_lun=8,lnum_pln=4,lpgs_per_blk=1536,lsecs_per_pg=4,lblks_per_pln=512,lmetadata=myocssd0-metadatafile -monitor unix:qemu-monitor-socket,server,nowait |
6.2 登陆虚拟机后:
修改 /etc/default/grub 加上 iommu.passthrough=1 hugepagesz=2M hugepages=2048
sudo update-grub 重启 之后
修改 /etc/default/grub 加上 iommu.passthrough=1 hugepagesz=2M hugepages=2048
sudo update-grub 重启 之后
6.3下载编译spdk
sudo ./scripts/setup.sh
输出 0000:00:02.0 (1d1d 1f1f): nvme -> uio_pci_generic
sudo ./examples/nvme/identify/identify
输出:
输出:
Starting SPDK v19.07-pre / DPDK 19.02.0 initialization...
[ DPDK EAL parameters: identify --no-shconf -c 0x1 -n 1 -m 0 --log-level=lib.eal:6 --log-level=lib.cryptodev:5 --log-level=user1:6 --base-virtaddr=0x200000000000 --match-allocations --file-prefix=spdk_pid9915 ]
=====================================================
NVMe Controller at 0000:00:02.0 [1d1d:1f1f]
=====================================================
Controller Capabilities/Features
================================
Vendor ID: 1d1d
Subsystem Vendor ID: 1af4
Serial Number: deadbeef
Model Number: QEMU NVMe Ctrl
·······
Namespace OCSSD Geometry
=======================
OC version: maj:2 min:0
LBA format:
Group bits: 0
PU bits: 3
Chunk bits: 9
Logical block bits: 15
Media and Controller Capabilities:
Namespace supports Vector Chunk Copy: Supported
Namespace supports multiple resets a free chunk: Not Supported
Wear-level Index Delta Threshold: 0
Groups (channels): 1
PUs (LUNs) per group: 8
Chunks per LUN: 512
Logical blks per chunk: 24576
MIN write size: 4
OPT write size: 16
Cache min write size: 16
Max open chunks: 0
Max open chunks per PU: 0
OCSSD Chunk Info Glance
·············
·············
6.4 执行 sudo ./test/ftl/bdevperf.sh 0000:00:02.0
【生成的config是:test/ftl/config/ftl.conf
[Ftl]
TransportID "trtype:PCIe traddr:0000:00:02.0" nvme0 0-3 00000000-0000-0000-0000-000000000000
】
【生成的config是:test/ftl/config/ftl.conf
[Ftl]
TransportID "trtype:PCIe traddr:0000:00:02.0" nvme0 0-3 00000000-0000-0000-0000-000000000000
】
sudo ./test/bdev/bdevperf/bdevperf -c test/ftl/config/ftl.conf -q 1 -w randwrite -t 1 -o 69632
7.其他
-monitor unix:qemu-monitor-socket,server,nowait
启动之后在另一个shell的同一个目录下中: socat - unix-connect:qemu-monitor-socket
info可以看到信息
启动之后在另一个shell的同一个目录下中: socat - unix-connect:qemu-monitor-socket
info可以看到信息
以上是关于[转]qemu安装虚拟机的主要内容,如果未能解决你的问题,请参考以下文章