Skip to content

Instantly share code, notes, and snippets.

@Sam0230
Last active June 8, 2024 06:46
Show Gist options
  • Save Sam0230/57673468b3b9f5050c7f051227f0920a to your computer and use it in GitHub Desktop.
Save Sam0230/57673468b3b9f5050c7f051227f0920a to your computer and use it in GitHub Desktop.
Installing Arch Linux ARM in a UTM virtual machine

Installing Arch Linux ARM in a UTM virtual machine

Steps:

  1. Create a new virtual machine.
  2. Go to System tab, change architecture to `ARM64 (aarch64)' and increase memory as needed.
  3. Download Alpine Linux LiveCD:
mirror=https://dl-cdn.alpinelinux.org/alpine
curl -o alpine-virt-latest-aarch64.iso "$mirror/latest-stable/releases/aarch64/$(curl "$mirror/latest-stable/releases/aarch64/latest-releases.yaml" | /usr/bin/grep -E 'file: alpine-virt-[0-9\.]+-aarch64\.iso' | head -n 1 | sed 's/ //g' | sed 's/\t//g' | sed 's/^file://')"
  1. Go to Drives tab, New Drive, set size to 20GiB or larger, then Inport Drive, choose the file you just downloaded.
  2. Go to Display tab, change Type to Console Only to enable pasting.
  3. Save the settings.
  4. Start the VM.
  5. Login as root.
  6. setup-alpine

Leave all fileds empty (including password) until selecting a mirror. You might want to use a mirror, and then select `none' for ssh server and everything left.

  1. Paste these commands:
alpineMirror=ALPIN_MIRROR
archlinuxARMMirror=ARCH_ARM_MIRROR
hostname=YOUR_HOSTNAME
username=YOUR_USER_NAME

echo "$alpineMirror"'/edge/main
'"$alpineMirror"'/edge/community' >/etc/apk/repositories
apk add arch-install-scripts pacman-makepkg gptfdisk btrfs-progs
mkdir /etc/pacman.d
cat >/etc/pacman.conf <<END
[options]
HoldPkg = pacman glibc
SigLevel = Required DatabaseOptional
Architecture = aarch64
Color
CheckSpace
ParallelDownloads = 8
LocalFileSigLevel = Optional
[core]
Include = /etc/pacman.d/mirrorlist
[extra]
Include = /etc/pacman.d/mirrorlist
[community]
Include = /etc/pacman.d/mirrorlist
[alarm]
Include = /etc/pacman.d/mirrorlist
[aur]
Include = /etc/pacman.d/mirrorlist
END
echo 'Server = '"$archlinuxARMMirror"'/$arch/$repo' >/etc/pacman.d/mirrorlist
mkdir /tmp/pacmaninit
cd /tmp/pacmaninit
pacman -Sydd pacman-mirrorlist archlinuxarm-keyring --noconfirm
rm /var/cache/pacman/pkg/*.sig
tar -xf /var/cache/pacman/pkg/pacman-mirrorlist-*.pkg.tar.*
tar -xf /var/cache/pacman/pkg/archlinuxarm-keyring-*.pkg.tar.*
cat etc/pacman.d/mirrorlist >>/etc/pacman.d/mirrorlist
mkdir /usr/share/pacman/keyrings
cp usr/share/pacman/keyrings/archlinuxarm.gpg /usr/share/pacman/keyrings/
echo '02922214DE8981D14DC2ACABBC704E86B823CD25:4:' >>/usr/share/pacman/keyrings/archlinuxarm-trusted
echo '9D22B7BB678DC056B1F7723CB55C5315DCD9EE1A:4:' >>/usr/share/pacman/keyrings/archlinuxarm-trusted
echo '69DD6C8FD314223E14362848BF7EEF7A9C6B5765:4:' >>/usr/share/pacman/keyrings/archlinuxarm-trusted
touch /usr/share/pacman/keyrings/archlinuxarm-revoked
pacman-key --init
pacman-key --populate archlinuxarm
pacman -Sdd archlinuxarm-keyring --noconfirm --overwrite '*'
pacman-key --init
pacman-key --populate archlinuxarm
echo -e 'n\n\n\n+1G\nef00\np\nn\n\n\n\n8300\nw\ny\n' | gdisk /dev/vda
mkfs.vfat /dev/vda1
mkfs.btrfs /dev/vda2
mount -t btrfs /dev/vda2 /mnt
mkdir -p /mnt/boot/efi
mount -t vfat /dev/vda1 /mnt/boot/efi
pacstrap /mnt base linux linux-firmware grub btrfs-progs sudo dhcpcd busybox
if [ ! -e /mnt/boot/Image ]; then
	ln -s Image /mnt/boot/vmlinuz-linux
fi
genfstab -U /mnt >> /mnt/etc/fstab
cat >/mnt/.__init <<END
grub-install --removable
grub-mkconfig -o /boot/grub/grub.cfg
echo "\$hostname" >> /etc/hostname
echo -e "127.0.0.1\tlocalhost" >> /etc/hosts
echo -e "::1\t\t\tlocalhost" >> /etc/hosts
echo -e "127.0.0.1\t\$hostname" >> /etc/hosts
chmod +w /etc/sudoers
echo 'Defaults env_reset' >>/etc/sudoers
sed -i 's|# Defaults secure_path="|Defaults secure_path="/usr/local/sbin:/usr/local/bin:/usr/bin"\n# Defaults secure_path="|' /etc/sudoers
sed -i 's/# \%sudo\tALL/\%sudo\tALL/' /etc/sudoers
chmod -w /etc/sudoers
sed -i 's/proc:x:26:/proc:x:26:\nsudo:x:27:'"\$username"'/' /etc/group
useradd "\$username" -m -U
passwd -d "\$username"
systemctl enable dhcpcd
systemctl set-default multi-user.target
END
export username hostname
arch-chroot /mnt bash /.__init
rm /mnt/.__init
  1. chroot /mnt /bin/passwd "$username" to change your passwd.
  2. poweroff
  3. Open VM settings panel, switch to Display tab, change display type back to full graphics and chang scaling algorithm to nearst neighbor.
  4. Go to Drivers and remove Alpine Linux LiveCD.
  5. Save config, power on and install a graphic user interface.
@SpaceJLS
Copy link

SpaceJLS commented Jan 7, 2022

Hi, i can't connect to network, can you help me ?

@mrRob0text-zz
Copy link

how can you create vm without image? how did you skip this process??? like really, first step from you own instructions!

@emory
Copy link

emory commented May 20, 2023

Download Alpine Linux LiveCD:
mirror=https://dl-cdn.alpinelinux.org/alpine
curl -o alpine-virt-latest-aarch64.iso "$mirror/latest-stable/releases/aarch64/$(curl "$mirror/latest-stable/releases/aarch64/latest-releases.yaml" | /usr/bin/grep -E 'file: alpine-virt-[0-9\.]+-aarch64\.iso' | head -n 1 | sed 's/ //g' | sed 's/\t//g' | sed 's/^file://')"

that image?

@peggy-48
Copy link

This is Alpine Linux. Not Arch Linux actually. So please replace the title because it doesn't talk about Arch Linux (yeah i could do that with Debian too 😒)

@mdupuy
Copy link

mdupuy commented Jan 20, 2024

This is Alpine Linux. Not Arch Linux actually. So please replace the title because it doesn't talk about Arch Linux (yeah i could do that with Debian too 😒)

Evidently, you aren't familiar with Arch Linux. Since there is no Aarch64 boot iso for Arch Linux, these instructions get you started with a bootable Alpine Linux image, essentially as a rescue disk, but from there you configure pacman and use pacstrap to install the Arch "base" and "linux" parts of Arch to the virtual disk, you are literally installing Arch. Once you eject the Alpine rescue image and boot from the disk image, you're running Arch. Please delete your confusing and misguided comment.

@peggy-48
Copy link

Not exactly because it stays Alpine, Arch has AL-ARM which is a port of it who has a boot iso for aarch64. So please rectify the use of alpine.

@mrcook
Copy link

mrcook commented Feb 3, 2024

Hi, I'm stuck at points 8 and 9.

I've downloaded the Alpine Standard ISO, set up a new VM in UTM (actually Emulation for x86 image) and booted. It runs its startup.nsh and then places me at a Shell> prompt.

I'm not able to find any files/folders on any of the FS0 or BLK* mounts except the efi/boot directory, so no setup-alpine script. There's also no su command available, so I don't know how to login as root.

Any hints would be much appreciated.

@adocampo
Copy link

I've used archboot, and it installs pretty straight forward. But when I'm in plasma, I couldn't see the fonts properly. To fix it, I had to change the M1 resolution to 1800x1169 and inside plasma, change it as well to 1920x1080.

@peggy-48
Copy link

peggy-48 commented Jun 8, 2024

👎 Really a bad option. Guys if you want Arch Linux on ARM go install the true ALARM from the website. This is a fake Arch (a disguised Alpine actually.).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment