This is mainly a notes dump and should be used for reference. This guide assumes:
- Ubuntu 14.04 (or Debian 8) hypervisor/host with bridge networking
- Knowledge of qemu
- Knowledge of debootstrap
Limitations of the qemu-system-aarch64 emulator on x86 include only being able to emulate one CPU and no KVM support.
sudo apt-get install debootstrap qemu-utils qemu
sudo apt-get build-dep qemu
git clone git://git.qemu.org/qemu.git qemu.git
cd qemu.git
./configure --target-list=aarch64-softmmu --enable-fdt --enable-vhost-net --enable-kvm
make -j4
sudo make install
/usr/local/bin/qemu-system-aarch64
qemu-img create -f qcow2 /srv/chroots/trusty.qcow2 60G
modprobe -av nbd
qemu-nbd -c /dev/nbd0 /srv/chroots/trusty.qcow2
fdisk /dev/nbd0
mkfs.ext4 /dev/nbd0p1
mount -t ext4 /dev/nbd0p1 /mnt
debootstrap --arch=arm64 --keyring=/usr/share/keyrings/ubuntu-archive-keyring.gpg --verbose --foreign trusty /mnt/
cp /usr/bin/qemu-aarch64-static /mnt/usr/bin/
chroot /mnt/ /bin/bash
/debootstrap/debootstrap --second-stage
deb http://ports.ubuntu.com/ubuntu-ports/ trusty main universe multiverse restricted
deb http://ports.ubuntu.com/ubuntu-ports/ trusty-updates main universe multiverse restricted
deb http://ports.ubuntu.com/ubuntu-ports/ trusty-security main universe multiverse restricted
deb http://ports.ubuntu.com/ubuntu-ports/ trusty-proposed main universe multiverse restricted
deb-src http://ports.ubuntu.com/ubuntu-ports/ trusty main universe multiverse restricted
deb-src http://ports.ubuntu.com/ubuntu-ports/ trusty-updates main universe multiverse restricted
deb-src http://ports.ubuntu.com/ubuntu-ports/ trusty-security main universe multiverse restricted
deb-src http://ports.ubuntu.com/ubuntu-ports/ trusty-proposed main universe multiverse restricted
qemu-img create -f qcow2 /srv/chroots/jessie.qcow2 60G
modprobe -av nbd
qemu-nbd -c /dev/nbd0 /srv/chroots/jessie.qcow2
mkfs.ext4 /dev/nbd0p1
mount -t ext4 /dev/nbd0p1 /mnt
apt-get install debian-archive-keyring
apt-key add /usr/share/keyrings/debian-archive-keyring.gpg
mkdir -p /mnt/usr/bin
cp /usr/bin/qemu-aarch64-static /mnt/usr/bin/
debootstrap --arch=arm64 --keyring /usr/share/keyrings/debian-archive-keyring.gpg --exclude=debfoster jessie /mnt/ http://ftp.debian.org/debian
chroot /mnt/ /bin/bash
deb http://ftp.debian.org/debian/ jessie main contrib non-free
deb http://ftp.debian.org/debian/ jessie-updates main contrib non-free
deb-src http://ftp.debian.org/debian/ jessie main contrib non-free
deb-src http://ftp.debian.org/debian/ jessie-updates main contrib non-free
apt-get update
-
Ubuntu
apt-get install linux-generic linux-headers-generic
-
Debian
apt-get install linux-image-arm64 linux-headers-arm64
cp /mnt/boot/vmlinux* /srv/chroots/
cp /mnt/boot/initrd* /srv/chroots/
umount /mnt
Start up the VM in ro mode first without an initrd so we can get to a rescue shell to finish configuration
/usr/local/bin/qemu-system-aarch64 -cpu cortex-a57 -machine type=virt -nographic -smp 1 -m 8192 -kernel /srv/chroots/vmlinuz-3.13.0-34-generic -drive file=/srv/chroots/trusty.qcow2,if=none,id=blk -device virtio-blk-device,drive=blk -device virtio-net-device,netdev=net0,mac=00:00:00:00:00:00 -netdev tap,id=net0 --append "root=/dev/vda1 ro console=ttyAMA0 --"
The boot will halt with an error about not being about to mount filesystems, choose continue to drop to a rescue shell and
remount / as rw
mount -o remount,rw /
hostname NEWHOSTNAME
dhclient eth0
dd if=/dev/zero of=/swapfile bs=1M count=4096
chmod 600 /swapfile
mkswap /swapfile
swapon /swapfile
-
Ubuntu
apt-get install ssh openssh-server perl netcat netcat6 bind9utils dnsutils libio-socket-ssl-perl libnet-ssleay-perl ldap-utils libtime-modules-perl lsb sysv-rc-conf dkms linux-headers-generic make bzip2 git curl build-essential
-
Debian
apt-get install ssh openssh-server perl netcat netcat6 bind9utils dnsutils libio-socket-ssl-perl libnet-ssleay-perl ldap-utils libtime-modules-perl lsb sysv-rc-conf dkms linux-headers-arm64 make bzip2 git curl build-essential
sudo service ssh start
update-rc.d ssh defaults
- add swap to /etc/fstab if desired
- set root password and user if desired
- set networking to static if desired
halt -p
/usr/local/bin/qemu-system-aarch64 -cpu cortex-a57 -machine type=virt -nographic -smp 1 -m 8192 -kernel /srv/chroots/vmlinuz-3.13.0-34-generic -initrd /srv/chroots/initrd.img-3.13.0-34-generic -drive file=/srv/chroots/trusty.qcow2,if=none,id=blk -device virtio-blk-device,drive=blk -device virtio-net-device,netdev=net0,mac=00:00:00:00:00:00 -netdev tap,id=net0 --append "root=/dev/vda1 rw console=ttyAMA0 --"