Skip to content

Instantly share code, notes, and snippets.

@philipz
Created March 9, 2015 03:17
Show Gist options
  • Save philipz/04a9a165f8ce561f7ddd to your computer and use it in GitHub Desktop.
Save philipz/04a9a165f8ce561f7ddd to your computer and use it in GitHub Desktop.
Debian ARM64 (Aarch64) image for QEMU
QEMU version: 2.2.0
HDD init: qemu-img create -f qcow debian8-arm64.img 10G

Netinstall initrd: http://ftp.ru.debian.org/debian/dists/jessie/main/installer-arm64/20150107/images/netboot/debian-installer/arm64/initrd.gz
Netinstall kernel: wget http://ftp.ru.debian.org/debian/dists/jessie/main/installer-arm64/20150107/images/netboot/debian-installer/arm64/linux

Netinstall start:
 qemu-system-aarch64 -machine virt -cpu cortex-a57 -nographic -smp 1 -m 512 -kernel linux -initrd initrd.gz -append "root=/dev/ram console=ttyAMA0" -global virtio-blk-device.scsi=off -device virtio-scsi-device,id=scsi -drive file=debian8-arm64.img,id=rootimg,cache=unsafe,if=none -device scsi-hd,drive=rootimg -netdev user,id=unet -device virtio-net-device,netdev=unet -net user

Extract kernel and initrd after install:
 sudo modprobe nbd max_part=16
 sudo qemu-nbd -c /dev/nbd0 debian8-arm64.img
 sudo partprobe /dev/nbd0

 mkdir sda2
 sudo mount /dev/nbd0p2 sda2

 cp sda2/boot/vmlinuz vmlinuz-run
 cp sda2/boot/initrd.img initrd-run.img

 sudo umount sda2
 rmdir sda2
 sudo /opt/qemu220/bin/qemu-nbd -d /dev/nbd0

Running:
 qemu-system-aarch64 -machine virt -cpu cortex-a57 -nographic -smp 1 -m 512 -kernel vmlinuz-run -initrd initrd-run.img -append "root=/dev/sda2 console=ttyAMA0" -global virtio-blk-device.scsi=off -device virtio-scsi-device,id=scsi -drive file=debian8-arm64.img,id=rootimg,cache=unsafe,if=none -device scsi-hd,drive=rootimg -netdev user,id=unet -device virtio-net-device,netdev=unet -net user
@ghazanhaider
Copy link

Adding more updates since the GPG keys have expired for debian 8 and below.
During install if busybox (or kernel) fails, run this in the shell (After "Installing the base system" !!)and retry:
echo 'APT::Get::AllowUnauthenticated "true";' > /target/etc/apt/apt.conf.d/99bypass
(This has worked for debians 5-8 armhf or arm64)
(Needless to say very insecure, but if youre booting such an old Debian, you're handling security at other layers)

Most mirrors will not work for older debians.
Instead of picking the mirror country, go to the top and select manual
Use either archive.debian.org or ftp.de.debian.org (directory is /debian-archive/debian/)

qemu-nbd never worked for me on MacOS or Ubuntu 24.04
Alternate steps to mount and copy kernel from the disk image for Linux:

  • qemu convert -O raw debian8-arm64.img debian8-arm64-raw.img
  • losetup -f -P debian8-arm64-raw.img
  • mount /dev/loop0p2 /mnt
    (Explanation: mount is not able to read a qcow2 formatted disk image, we convert it to raw which then takes up the full 10GB space but losetup and mount can mount it.)

The mount and copy kernel part is necessary for all old Debians.
The kernel does not have QEMU SCSI device compiled in so it cant find /dev/sda2 on boot.
The scsi modules come within the initrd image, but the netboot/cdrom provided initrd images all automatically kick off the installer and do not let you boot into your newly installed image. Setting root=/dev/sda2 seems to work for Lenny but did not work for Jessie.
An alternative to this pain is to just compile your own kernel, one that has drivers for virtio/Qemu devices like SCSI. You can then just boot that kernel, set root=/dev/sda2 and not add any initrd.gz, don't have to mount and copy the initrd from within the image before the first boot.

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