aboutsummaryrefslogtreecommitdiff
path: root/vm/arch-armv7.sh
blob: 41b3a1a9019a41738f618a20da2ecab04e4a5eaf (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
: ${VM_CACHE:?} ${VM_DATA:?} ${VM_TMP:?}

arch_url=http://os.archlinuxarm.org/os/ArchLinuxARM-armv7-latest.tar.gz

arch_path=$VM_CACHE/$(basename -- "$arch_url")
kernel_path=$VM_CACHE/zImage
initrd_path=$VM_CACHE/initramfs-linux.img

image_path=$VM_DATA/image


if [ ! -f $arch_path ]; then
    curl -L -o $arch_path $arch_url
fi

if [ ! -f $kernel_path ]; then
    bsdtar -x -f $arch_path -C $(dirname $kernel_path) \
        --strip-components=2 ./boot/$(basename $kernel_path)
fi

if [ ! -f $initrd_path ]; then
    bsdtar -x -f $arch_path -C $(dirname $initrd_path) \
        --strip-components=2 ./boot/$(basename $initrd_path)
fi

if [ ! -f $image_path ]; then
    truncate -s 2G $image_path
    mkfs.ext4 -q $image_path
    mkdir -p $VM_TMP/mnt
    doas mount -o loop $image_path $VM_TMP/mnt
    doas bsdtar -xpf $arch_path -C $VM_TMP/mnt
    doas umount $VM_TMP/mnt
    rmdir $VM_TMP/mnt
fi

exec qemu-system-arm \
    -machine virt \
    -cpu cortex-a15 \
    -m 2G \
    -kernel $kernel_path \
    -initrd $initrd_path \
    -append "root=/dev/sda rw" \
    -drive if=none,file=$image_path,format=raw,id=drive0 \
    -netdev user,id=netdev0 \
    -device virtio-scsi-pci,id=scsi \
    -device virtio-blk-pci,drive=drive0 \
    -device virtio-net-pci,netdev=netdev0 \
    -nographic \
    "$@"