Last active
November 28, 2020 03:14
-
-
Save trodemaster/12d8024b5a4ab0bfcdb31ee11feec23d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # install prerequsits as needed | |
| sudo apt update | |
| sudo apt install -y cloud-utils qemu-utils | |
| # lets put the stuff here | |
| mkdir ~/ubuntu2004cloudimg | |
| cd ~/ubuntu2004cloudimg | |
| # download the ubuntu cloud image | |
| if ! [[ -f focal-server-cloudimg-arm64.img ]]; then | |
| wget https://cloud-images.ubuntu.com/focal/20201123/focal-server-cloudimg-arm64.img | |
| fi | |
| # mount the cloud image to extract kernel and such | |
| sudo modprobe nbd max_part=1 | |
| sudo qemu-nbd --connect=/dev/nbd0 focal-server-cloudimg-arm64.img | |
| sudo mkdir -p /mnt/nbd | |
| sleep 8 | |
| sudo mount /dev/nbd0p1 /mnt/nbd/ -o noatime | |
| if [[ -d /mnt/nbd/boot ]]; then | |
| ls /mnt/nbd/boot | |
| else | |
| echo "mount failed.." | |
| exit 1 | |
| fi | |
| # extract the needed files | |
| sudo cat /mnt/nbd/boot/vmlinuz-5.4.0-54-generic | gzip -d > vmlinuz-5.4.0-54-generic | |
| sudo cp /mnt/nbd/boot/initrd.img-5.4.0-54-generic initrd.img-5.4.0-54-generic | |
| sudo chown $USER:$USER ./* | |
| # hack in a root password of ubuntu | |
| SHADOW=$(sudo cat /mnt/nbd/etc/shadow | grep -v root) | |
| echo 'root:$6$/14.3JvFwhEHViIT$1N37V7rNApmlieA5FE1F1zCfucy6vg0RCr6.qVrJHxtC8Ek4e0JH1HAdvLkAMxrFpa8x.Vb0IfP9OoIEWKwFf/:18589:0:99999:7:::' | sudo tee /mnt/nbd/etc/shadow | |
| echo "$SHADOW" | sudo tee -a /mnt/nbd/etc/shadow | |
| sync | |
| # unmount the cloud image | |
| sudo qemu-nbd -d /dev/nbd0 | |
| # convert the cloud image to raw format | |
| qemu-img convert -f qcow2 -O raw focal-server-cloudimg-arm64.img focal-server-cloudimg-arm64.raw | |
| # make an archive of the needed bits | |
| tar -czvf focal-server-cloudimg-arm64.tgz *generic focal-server-cloudimg-arm64.raw | |
| echo "scp the archive focal-server-cloudimg-arm64.tgz to your m1 mac for use" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment