Skip to content

Instantly share code, notes, and snippets.

@mungler
Last active September 16, 2022 10:40
Show Gist options
  • Star 12 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save mungler/c7f67bbb27ddbac01d30a1727c0346b5 to your computer and use it in GitHub Desktop.
Save mungler/c7f67bbb27ddbac01d30a1727c0346b5 to your computer and use it in GitHub Desktop.
firstly, build vftool (via make or xcode, whatever)
cd build
mkdir vm
# grab needed things:
curl -o - https://cloud-images.ubuntu.com/releases/focal/release/unpacked/ubuntu-20.04-server-cloudimg-arm64-vmlinuz-generic | gunzip > vm/vmlinuz
curl -o vm/initrd https://cloud-images.ubuntu.com/releases/focal/release/unpacked/ubuntu-20.04-server-cloudimg-arm64-initrd-generic
curl -o - https://cloud-images.ubuntu.com/releases/focal/release/ubuntu-20.04-server-cloudimg-arm64.tar.gz | tar zxvC vm
# grow disk
dd if=/dev/zero of=vm/focal-server-cloudimg-arm64.img seek=20000000 obs=1024 count=0
# boot VM to ramdisk
./vftool -k vm/vmlinuz -i vm/initrd -d vm/focal-server-cloudimg-arm64.img -m 6144 -a "console=hvc0"
# connect via screen - boots to initramfs
# paste the following:
mkdir /mnt
mount /dev/vda /mnt
chroot /mnt
touch /etc/cloud/cloud-init.disabled
echo 'root:root' | chpasswd
ssh-keygen -f /etc/ssh/ssh_host_rsa_key -N '' -t rsa
ssh-keygen -f /etc/ssh/ssh_host_dsa_key -N '' -t dsa
ssh-keygen -f /etc/ssh/ssh_host_ed25519_key -N '' -t ed25519
cat <<EOF > /etc/netplan/01-dhcp.yaml
network:
renderer: networkd
ethernets:
enp0s1:
dhcp4: true
version: 2
EOF
# and now add the host's ssh key:
mkdir /root/.ssh
cat <<EOF > /root/.ssh/authorized_keys
< paste id_rsa.pub contents, followed by ‘EOF’ >
EOF
# and bail out
exit
umount /dev/vda
# and ctrl-c the vftool session to kill the VM
# and now boot properly:
./vftool -k vm/vmlinuz -i vm/initrd -d vm/focal-server-cloudimg-arm64.img -m 6144 -a "console=hvc0 root=/dev/vda"
# attach screen again
# login with root/root
# fix filesystem size
resize2fs /dev/vda
# ready for use!
# find guest IP
ip address | grep 192
# from outside, you can ssh directly as root to that IP
firstly, build vftool (via make or xcode, whatever)
cd build
mkdir vm
# grab needed things:
curl -o vm/vmlinuz https://cloud-images.ubuntu.com/releases/focal/release/unpacked/ubuntu-20.04-server-cloudimg-amd64-vmlinuz-generic
curl -o vm/initrd https://cloud-images.ubuntu.com/releases/focal/release/unpacked/ubuntu-20.04-server-cloudimg-amd64-initrd-generic
curl -o - https://cloud-images.ubuntu.com/releases/focal/release/ubuntu-20.04-server-cloudimg-amd64.tar.gz | tar zxvC vm
# grow disk
dd if=/dev/zero of=vm/focal-server-cloudimg-amd64.img seek=20000000 obs=1024 count=0
# boot VM to ramdisk
./vftool -k vm/vmlinuz -i vm/initrd -d vm/focal-server-cloudimg-amd64.img -m 6144 -a "console=hvc0"
# connect via screen - boots to initramfs
# paste the following:
mkdir /mnt
mount /dev/vda /mnt
chroot /mnt
touch /etc/cloud/cloud-init.disabled
echo 'root:root' | chpasswd
ssh-keygen -f /etc/ssh/ssh_host_rsa_key -N '' -t rsa
ssh-keygen -f /etc/ssh/ssh_host_dsa_key -N '' -t dsa
ssh-keygen -f /etc/ssh/ssh_host_ed25519_key -N '' -t ed25519
cat <<EOF > /etc/netplan/01-dhcp.yaml
network:
renderer: networkd
ethernets:
enp0s1:
dhcp4: true
version: 2
EOF
# and now add the host's ssh key:
mkdir /root/.ssh
cat <<EOF > /root/.ssh/authorized_keys
< paste id_rsa.pub contents, followed by ‘EOF’ >
EOF
# and bail out
exit
umount /dev/vda
# and ctrl-c the vftool session to kill the VM
# and now boot properly:
./vftool -k vm/vmlinuz -i vm/initrd -d vm/focal-server-cloudimg-amd64.img -m 6144 -a "console=hvc0 root=/dev/vda"
# attach screen again
# login with root/root
# fix filesystem size
resize2fs /dev/vda
# ready for use!
# find guest IP
ip address | grep 192
# from outside, you can ssh directly as root to that IP
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment