Aarch64 use qemu installed on a virtual machine architecture [reprint] X86_64 platform

Aarch64 use qemu installed on a virtual machine architecture platform X86_64

Some time ago to explore the following installation arm architecture on the x86 platform (including aarch64 and armhf) virtual machine, middle encountered many problems. The lessons learned down hope to help you.

 

 


1. Install qemu-system-aarch64

If the host is only installed qemu-kvm, you can only run on X86 architecture of the virtual machine host, and the ability to use kvm accelerate, does not bring the arm instructions translated into X86 instruction execution. All also need to install qemu-system-aarch64, which provides support for running virtual machines on aarch64 architecture x86 architecture. 
Can be installed by downloading and compiling the source code:

wget https://download.qemu.org/qemu-2.11.0.tar.xz tar xvJf qemu-2.11.0.tar.xz cd qemu-2.11.0 ./configure –-target-list=aarch64-softmmu make sudo make install

During the installation of the report may be missing some dependencies, after I installed the following packages depend on the success of the installation during the installation process.

sudo yum install zlib-devel 
sudo yum install glib2-devel 
sudo yum install pixman-devel

 

After successful installation qemu-system-aarch64 installed to the / usr / local / bin / directory.

2.UEFI firmware download

Previous boot process can be simplified to BIOS firmware -> bootstrap -> operating system, but since there are many problems in the conventional BIOS startup mode, as bios runs in 16-bit mode, a small address space, run slow, so now X86, ARM architecture and other architectures change uses an improved  UEFI  boot mode (of course, there will be considered compatible with the traditional BIOS boot mode), the system startup process in this case as shown below. 
UEFI mode at system startup process 
The figure startup process in detail I'm not sure, we can see further information on the wiki, there should be noted, is dedicated UEFI firmware UEFI start in the beginning of execution. Therefore, we want to guide the installation CD (supports UEFI mode) further installation aarch64 architecture system, first download the corresponding UEFI firmware architecture (here aarch64) of. 
QEMU_EFI.fd (Download: http://releases.linaro.org/components/kernel/uefi-linaro/16.02/release/qemu64/ )

3. OS Download

I used here is arm64 architecture ubuntu 16.04 server version: Ubuntu-16.04.3-Server-arm64.iso

4. Create a virtual hard disk

Using qemu-img instructions may create an empty virtual hard disk, easy to install later time will install the system on the virtual hard disk.

qemu-img create ubuntu16.04-arm64.img 16G
  • 1

If there is no such command, you can install networking.

5. Virtual Machine Installation

Execute the following command:

qemu-system-aarch64 -m 2048 -cpu cortex-a57 -smp 2 -M virt -bios QEMU_EFI.fd -nographic -drive if=none,file=ubuntu-16.04.3-server-arm64.iso,id=cdrom,media=cdrom -device virtio-scsi-device -device scsi-cd,drive=cdrom -drive if=none,file=ubuntu16.04-arm64.img,id=hd0 -device virtio-blk-device,drive=hd0

 

Ensure QEMU_EFI.fd, ubuntu-16.04.3-server- arm64.iso, ubuntu16.04-arm64.img file in the current under the present, or need to modify the file path into the corresponding implementation of the above command. In the above parameters, specify the installation CD Here -drive if=none,file=ubuntu-16.04.3-server-arm64.iso,id=cdrom,media=cdrom -device virtio-scsi-device -device scsi-cd,drive=cdromI found a different way on some websites and try, but after entering the installation CD-ROM interface will be reported the following error map, and finally found the above specified correctly complete the installation. 
Write pictures described here

Here are some screenshots of the installation process. 
Write pictures described here

Write pictures described here

Write pictures described here

Write pictures described here

6. The virtual machine starts

After the installation is complete, the following is the virtual machine. Under normal circumstances, the installation is complete will automatically restart, and then found to enter the following interface. Suddenly panic, and a problem. Problems arise during the installation process we do not easily give up, be sure to rational analysis and solve problems. 
Write pictures described here

The above is entered into the UEFI interactive shell inside, why did not execute grub and boot into ubuntu system blanket? Description UEFI firmware is not found ESP partition (EFI system partition, the installation process will be seen to create a partition ESP) ESP is not found or the EFI partition in the file, because the system needs to boot the EFI file. In the implementation of the shell exitinto the UEFI management interface, and to manually select the EFI boot file system, as shown below.

Write pictures described here

Write pictures described here

Write pictures described here

Finally entered into the system ...... 
Write pictures described here

qemu-system-aarch64 -m 2048 -cpu cortex-a57 -smp 2 -M virt -bios QEMU_EFI.fd -nographic -drive if=none,file=ubuntu16.04-arm64.img,id=hd0 -device virtio-blk-device,drive=hd0

6. Use virt-manager start a virtual machine

Front to take advantage of the successful launch of the virtual machine commands you, but for me this is more entry-level players want to use the virt-manager tool with an intuitive interface to manage virtual machine (VM switch, add remove network interface is also very convenient) , then I made some attempts to find a feasible method. 
The first is to install virt-manager tool.

sudo yum install virt-manager

 

安装完成后启动virt-manager,如下图。在选择Architecture为aarch64后,出现了图中所示的warning,表示找不到aarch64架构的UEFI固件,并且在安装方式上自动选择了Import existing disk image。一想也是,系统最开始执行的就是UEFI固件,而我们并没有指定UEFI固件的路径。

Write pictures described here

这种情况下需要提供系统镜像外,还要提供vmlinuz内核文件和initrd文件。 
Write pictures described here

这里给出了安装UEFI固件的步骤,网页打开较慢,我这里给出步骤的截图。

Write pictures described here

安装完成后,从下面的图中可以看到,warning消失了,并且只需要导入硬盘镜像文件,说明UEFI固件已经起作用了。只要UEFI固件能够执行到硬盘ESP分区上的EFI文件,那就能够成功启动系统了。 
Write pictures described here

Write pictures described here

指定镜像文件后启动系统,出现了下面错误 
Write pictures described here

通过查阅资料,发现这是由于libvirt库的版本导致的,将libvirt版本升级到3.10.0。在libvirt官网上最新稳定版本是3.10.0,但通过yum直接安装还没有这个最新版本。我直接找到了一个可用源。在/etc/yum.repos.d目录下建一个virt.repo文件,将下面代码复制到文件中。

[virt]
name=CentOS-$releasever - virt
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra
baseurl=http://mirrors.nwsuaf.edu.cn/centos/$releasever/virt/$basearch/libvirt-latest/ ailovermethod=priority enabled=1 gpgcheck=0 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

 

运行sudo yum update libvirt完成更新! 
更新完成后再次启动虚拟机,本以为会没有问题了额,结果卡在了下面的界面中

Write pictures described here

个人觉得是新安装的UEFI固件的问题,在网上也没有找到可用的解决方法。如果有读者能够找到上面问题的解决方法,也可以留言告知我。

最终不得不采用内核启动的方式。将前面的系统镜像/boot目录挂载到本地,然后提取其中的vmlinuz和initrd文件。

首先用fdisk查看系统镜像的分区和偏移,下图是我的系统镜像的信息。 
Write pictures described here

可以看到,我的/boot在/所在的第二个分区中,执行下面命令将/所在分区挂载到本地的/mnt目录下(注意偏移量的修改),并将两个文件拷贝出来。命令如下

sudo mount -o loop,ro,offset=$((1050624*512)) xxx.img /mnt
sudo cp /mnt/boot/vmlinuz .
sudo cp /mnt/boot/initrd .

And then introduced into the process and the specified virtual machine image vmlinuz, initrd file, the kernel parameter is specified as root=/dev/sda2, or in a custom configuration stage, as shown in FIG. 
Write pictures described here

Start the system again, successfully entered into the system ......

Write pictures described here

If you find that the use of the kernel startup mode still does not start, and stop the interface shown in the following figure, indicating that the problem is or firmware of the UEFI, I ran into this problem. You can use the front of QEMU_EFI.fd file, use the following command on UEFI firmware installed to replace

dd if=QEMU_EFI.fd of=/usr/share/edk2.git/aarch64/QEMU_EFI-pflash.raw conv=notrunc

Write pictures described here

7. Reference Links

https://wiki.linaro.org/LEG/UEFIforQEMU 
https://kennedy-han.github.io/2015/06/16/QEMU-debian-ARMv8.html 
https://en.opensuse.org/openSUSE:AArch64 
https://gmplib.org/~tege/qemu.html 
https://marcin.juszkiewicz.com.pl/2015/04/17/running-vms-on-fedoraaarch64/ 
https://bugzilla.redhat.com/show_bug.cgi?id=1449837 
https://marcin.juszkiewicz.com.pl/2015/04/17/running-vms-on-fedoraaarch64/

Guess you like

Origin www.cnblogs.com/jinanxiaolaohu/p/11003388.html