-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharch-create-vm
executable file
·53 lines (43 loc) · 2.08 KB
/
arch-create-vm
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
#!/usr/bin/bash
set -euox pipefail
# TODO Build and use my own minimal faster arch builder VM image
# https://gitlab.archlinux.org/archlinux/arch-boxes
if [ ! -f Arch-Linux-x86_64-basic.qcow2 ]; then
curl -fSL# https://geo.mirror.pkgbuild.com/images/latest/Arch-Linux-x86_64-basic.qcow2 \
-o Arch-Linux-x86_64-basic.qcow2
fi
rm -f Arch-Linux-x86_64-basic_OVERLAY.qcow2 && \
qemu-img create -o backing_file=Arch-Linux-x86_64-basic.qcow2,backing_fmt=qcow2 \
-f qcow2 Arch-Linux-x86_64-basic_OVERLAY.qcow2
mkdir -p "$(dirname $1)"
rm -f $1 && truncate -s 10G $1
qemu-system-x86_64 \
-no-user-config \
-display gtk,zoom-to-fit=on \
-enable-kvm -cpu host -m 2047 -smp 2 \
-nic user,model=virtio,hostfwd=tcp::2222-:22,ipv6=off \
-drive file=$1,format=raw,index=0 \
-drive file=Arch-Linux-x86_64-basic_OVERLAY.qcow2,index=1,if=none,id=disk2 \
-device virtio-blk-pci,drive=disk2,bootindex=1 &
# -cdrom ~/Downloads/archlinux-2020.12.01-x86_64.iso
# https://www.qemu.org/docs/master/system/bootindex.html
# NB: It's pointless to await port 2222 (e.g. à la https://stackoverflow.com/a/70985361/421602),
# because QEMU is immediately forwarding it already anyway - even if the VM isn't actually listening, yet.
# 60s because of https://gitlab.archlinux.org/archlinux/arch-boxes/-/issues/153
# see https://github.com/vorburger/vorburger.ch-Notes/blob/develop/linux/systemd-analyze.md
sleep 60
vm-ssh() {
sshpass -p arch ssh -p 2222 -o PubkeyAuthentication=no -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null arch@localhost "$*"
}
vm-scp() {
sshpass -p arch scp -P 2222 -o PubkeyAuthentication=no -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null "$@"
}
vm-ssh 'bash -c "mkdir -p .ssh/ && chmod 700 .ssh/"'
vm-scp "$HOME/.ssh/authorized_keys" arch@localhost:.ssh/
vm-ssh 'sudo bash -c "mkdir -p /root/.ssh/ && chmod 700 /root/.ssh/ && cp /home/arch/.ssh/authorized_keys /root/.ssh/"'
vm-scp arch-install* arch@localhost:
vm-ssh sudo bash ./arch-install-sda-mnt
vm-ssh sudo umount -R /mnt
vm-ssh sudo shutdown now || true
sleep 3
../run-gtk-bios $1