summaryrefslogtreecommitdiff
path: root/md/writeup/qemu_arm64.md
blob: 79f88194b287b12b7dd67bd58c243e082a60e392 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
title:Qemu ARM64
keywords:arm64,linux,kernel,initrd

# Qemu ARM64

How to run QEMU with various ARM64 images.
Not covering full blown support of each distribution. Goal is just to get to Linux shell
and no more further at this stage. 

## Run Ubuntu Image

```bash
wget -c https://cdimage.ubuntu.com/releases/22.04/release/ubuntu-22.04.3-live-server-arm64.iso
```


## Run Debian Image

```bash
wget -c http://http.us.debian.org/debian/dists/bookworm/main/installer-arm64/current/images/netboot/debian-installer/arm64/initrd.gz
wget -c http://http.us.debian.org/debian/dists/bookworm/main/installer-arm64/current/images/netboot/debian-installer/arm64/linux
```

Prepare qemu empty hdd image

```bash
qemu-img create -f qcow2 hda.qcow2 5G
```

Boot image and follow installation steps. That will install Debian ARM64 distribution

```bash
qemu-system-aarch64 -M virt -m 1024 -cpu cortex-a53 \
  -kernel linux \
  -initrd initrd.gz \
  -drive if=none,file=hda.qcow2,format=qcow2,id=hd \
  -device virtio-blk-pci,drive=hd \
  -netdev user,id=mynet \
  -device virtio-net-pci,netdev=mynet \
  -nographic -no-reboot
```

get guestfs-tools to make below commands work [https://libguestfs.org/](https://libguestfs.org/)

find vmlinuz and initrd names in /boot directory

```
virt-ls -a hda.qcow2 /boot
virt-copy-out -a hda.qcow2 /boot/vmlinuz-6.1.0-12-arm64 /boot/initrd.img-6.1.0-12-arm64 .
```

Boot qemu with installed debian arm64 image

```
qemu-system-aarch64 -M virt -m 1024 -cpu cortex-a53 \
  -kernel vmlinuz-6.1.0-12-arm64 \
  -initrd initrd.img-6.1.0-12-arm64 \
  -append 'root=/dev/vda2' \
  -drive if=none,file=hda.qcow2,format=qcow2,id=hd \
  -device virtio-blk-pci,drive=hd \
  -netdev user,id=mynet \
  -device virtio-net-pci,netdev=mynet \
  -nographic
```



## Run virt 

Qemu contains configuration to run physicaly non existant ARM64 board called virt that suppose to be run with virtual machines and contains generic configuration.

Basic examples how to boot into the busy box shell is. Build busy boxwith mount,ash,exec and echo.
Create init script that will set the pathes and create some dev,proc and sys mount points and switch
to busybox shell. 

```bash
#!/sh
/busybox echo "Boom" > /dev/kmsg
export PATH=/sbin:/usr/sbin:/bin:/usr/bin:/
/busybox mount -t proc none /proc
/busybox mount -t sysfs none /sys
/buysbox mount -t devtmpfs -o nosuid,mode=0755 udev /dev
/busybox mount /dev/pts
/busybox mount -t devpts -o noexec,nosuid,gid=5,mode=0620 devpts /dev/pts || true
exec /busybox sh
```

Create initrd files with init file and busybox utilities

```bash
find . | cpio -o -c -R root:root | gzip -9 > ../initrd-arm64.img
```

Boot into the just created initrd

```bash
qemu-system-aarch64 \
    -machine virt -m 1024M -cpu cortex-a53  \
    -kernel bootfs-arm64/Image.gz \
    -initrd initrd-out.gz \
    -append "root=/dev/ram0  console=ttyAMA0 debug " \
    -nographic
```




## Under ArchLinux

Install all qemu packages with 

```bash
pacman -S qemu-full
```





## Links
1. [/writeup/qemu_usage.md](/writeup/qemu_usage.md)  
2. [https://www.qemu.org/docs/master/system/target-arm.html](https://www.qemu.org/docs/master/system/target-arm.html)  
3. [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/)  
4. [https://wiki.debian.org/Arm64Qemu](https://wiki.debian.org/Arm64Qemu)  
5. [https://gist.github.com/oznu/ac9efae7c24fd1f37f1d933254587aa4](https://gist.github.com/oznu/ac9efae7c24fd1f37f1d933254587aa4)  
6. [https://medium.com/@kiky.tokamuro/creating-initramfs-5cca9b524b5a](https://medium.com/@kiky.tokamuro/creating-initramfs-5cca9b524b5a)  
7. [https://translatedcode.wordpress.com/2017/07/24/installing-debian-on-qemus-64-bit-arm-virt-board/](https://translatedcode.wordpress.com/2017/07/24/installing-debian-on-qemus-64-bit-arm-virt-board/)  
8. [https://archlinuxarm.org/platforms/armv8/generic](https://archlinuxarm.org/platforms/armv8/generic)  
9. [https://github.com/niw/TinyLinux](https://github.com/niw/TinyLinux)  
10. [https://cs4118.github.io/dev-guides/debian-kernel-compilation.html](https://cs4118.github.io/dev-guides/debian-kernel-compilation.html)  
11. [https://developer.ibm.com/articles/l-initrd/](https://developer.ibm.com/articles/l-initrd/)  
12. [https://wiki.archlinux.org/title/mkinitcpio](https://wiki.archlinux.org/title/mkinitcpio)  
13. https://www.ibm.com/docs/en/zos/2.4.0?topic=codes-exit-status-usrsbininit
14. https://access.redhat.com/solutions/24029  
15. [http://phwl.org/2022/qemu-aarch64-debian/](http://phwl.org/2022/qemu-aarch64-debian/)
16. [http://git.main.lv/cgit.cgi/os201.git/tree/create_installroot](http://git.main.lv/cgit.cgi/os201.git/tree/create_installroot)