{"id":98,"date":"2025-02-05T12:26:28","date_gmt":"2025-02-05T12:26:28","guid":{"rendered":"https:\/\/haco.club\/?p=98"},"modified":"2025-02-17T12:38:49","modified_gmt":"2025-02-17T12:38:49","slug":"how-to-launch-arm-aarch64-vm-with-qemu-from-scratch","status":"publish","type":"post","link":"https:\/\/haco.club\/?p=98","title":{"rendered":"How to launch ARM aarch64 VM with QEMU from scratch"},"content":{"rendered":"\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p><a href=\"https:\/\/futurewei-cloud.github.io\/ARM-Datacenter\/qemu\/how-to-launch-aarch64-vm\">https:\/\/futurewei-cloud.github.io\/ARM-Datacenter\/qemu\/how-to-launch-aarch64-vm<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/ww2.coastal.edu\/mmurphy2\/oer\/qemu\/aarch64\">https:\/\/ww2.coastal.edu\/mmurphy2\/oer\/qemu\/aarch64<\/a><\/p>\n<\/blockquote>\n\n\n\n<p>The below instructions will allow for bringing up an ARM VM from scratch.<\/p>\n\n\n\n<p>To launch an aarch64 VM we first need to install a few dependencies, including QEMU and the qemu-efi-aarch64 package, which includes the efi firmware.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>apt-get install qemu-system-arm\napt-get install qemu-efi-aarch64\napt-get install qemu-utils<\/code><\/pre>\n\n\n\n<p>Create the flash images with the correct sizes.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>dd if=\/dev\/zero of=flash1.img bs=1M count=64\ndd if=\/dev\/zero of=flash0.img bs=1M count=64\ndd if=\/usr\/share\/qemu-efi-aarch64\/QEMU_EFI.fd of=flash0.img conv=notrunc<\/code><\/pre>\n\n\n\n<p>Create a dedicated directory (folder) on your host system to contain this virtual machine.<\/p>\n\n\n\n<p>Download the latest&nbsp;<a href=\"https:\/\/www.alpinelinux.org\/downloads\/\">Alpine Linux<\/a>&nbsp;\u201cVirtual\u201d ISO file for the aarch64 architecture.<\/p>\n\n\n\n<p>Create the disk image by running the following command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>qemu-img create -f qcow2 alpine.qcow2 40G<\/code><\/pre>\n\n\n\n<p>Start QEMU with the installer.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>qemu-system-aarch64 -nographic -machine virt,gic-version=max -m 2048 -cpu max -smp 4 \\\n-netdev user,id=vnet,hostfwd=:127.0.0.1:2222-:22 -device virtio-net-pci,netdev=vnet \\\n-drive file=alpine.qcow2,if=none,id=drive0,cache=writeback -device virtio-blk,drive=drive0,bootindex=0 \\\n-drive file=alpine-virt-3.21.2-aarch64.iso,if=none,id=drive1,cache=writeback -device virtio-blk,drive=drive1,bootindex=1 \\\n-drive file=flash0.img,format=raw,if=pflash -drive file=flash1.img,format=raw,if=pflash <\/code><\/pre>\n\n\n\n<p>Setup the system with the command: setup-alpine<\/p>\n\n\n\n<p>Once the install is finished you can exit QEMU with&nbsp;ctrl+a\uff0cx<\/p>\n\n\n\n<p>Then restart QEMU without the installer image with the following command.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>qemu-system-aarch64 -nographic -machine virt,gic-version=max -m 2048 -cpu max -smp 4 \\\n-netdev user,id=vnet,hostfwd=:127.0.0.1:2222-:22 -device virtio-net-pci,netdev=vnet \\\n-drive file=alpine.qcow2,if=none,id=drive0,cache=writeback -device virtio-blk,drive=drive0,bootindex=0 \\\n-drive file=flash0.img,format=raw,if=pflash -drive file=flash1.img,format=raw,if=pflash <\/code><\/pre>\n\n\n\n<p>Starting the virtual machine by hand with the full command line each time would be cumbersome and error-prone. Consequently, I recommend creating a script that contains the QEMU command. The following example is a Bourne shell script for Linux or macOS.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><em>#!\/bin\/sh<\/em>\n<em>#<\/em>\n<em># Alpine Linux on AArch64<\/em>\n<em>#<\/em>\n\nqemu-system-aarch64 -nographic -machine virt,gic-version=max -m 2048 -cpu max -smp 4 \\\n-netdev user,id=vnet,hostfwd=:127.0.0.1:2222-:22 -device virtio-net-pci,netdev=vnet \\\n-drive file=alpine.qcow2,if=none,id=drive0,cache=writeback -device virtio-blk,drive=drive0,bootindex=0 \\\n-drive file=flash0.img,format=raw,if=pflash -drive file=flash1.img,format=raw,if=pflash \n\necho \"QEMU has finished. Press Enter to continue.\"\nread throwaway<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>https:\/\/futurewei-cloud.github.io\/ARM-Datacenter\/qemu\/how-to-launch-aarch64-vm https:\/\/ww2.coastal.edu\/mmurphy2\/oer\/qemu\/aarch64 The below instructions will allow for bringing up [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[13,11],"class_list":["post-98","post","type-post","status-publish","format-standard","hentry","category-tutotial","tag-aarch64","tag-qemu"],"_links":{"self":[{"href":"https:\/\/haco.club\/index.php?rest_route=\/wp\/v2\/posts\/98","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/haco.club\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/haco.club\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/haco.club\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/haco.club\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=98"}],"version-history":[{"count":3,"href":"https:\/\/haco.club\/index.php?rest_route=\/wp\/v2\/posts\/98\/revisions"}],"predecessor-version":[{"id":102,"href":"https:\/\/haco.club\/index.php?rest_route=\/wp\/v2\/posts\/98\/revisions\/102"}],"wp:attachment":[{"href":"https:\/\/haco.club\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=98"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/haco.club\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=98"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/haco.club\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=98"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}