This is mainly a notes dump and should be used for reference. This guide assumes:
- Ubuntu 16.04 hypervisor/host with bridge networking
- Knowledge of qemu
- Knowledge of debootstrap
sudo apt-get install debootstrap qemu-utils qemu qemu-user-static flex bison
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 10G
modprobe -av nbd
qemu-nbd -c /dev/nbd0 /srv/chroots/xenial.qcow2
Create partition on ndb0 with cmd 'n' and set the type to linux. Optionally you can also setup a swap partition.
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 xenial /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/ xenial main universe multiverse restricted
deb http://ports.ubuntu.com/ubuntu-ports/ xenial-updates main universe multiverse restricted
deb http://ports.ubuntu.com/ubuntu-ports/ xenial-security main universe multiverse restricted
deb http://ports.ubuntu.com/ubuntu-ports/ xenial-proposed main universe multiverse restricted
deb-src http://ports.ubuntu.com/ubuntu-ports/ xenial main universe multiverse restricted
deb-src http://ports.ubuntu.com/ubuntu-ports/ xenial-updates main universe multiverse restricted
deb-src http://ports.ubuntu.com/ubuntu-ports/ xenial-security main universe multiverse restricted
deb-src http://ports.ubuntu.com/ubuntu-ports/ xenial-proposed main universe multiverse restricted
apt-get update
-
Ubuntu
apt-get install linux-generic linux-headers-generic
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=1024
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
sudo service ssh start
update-rc.d ssh defaults
#PermitRootLogin prohibit-password
PermitRootLogin yes
- add swap to /etc/fstab if desired
- set root password and user if desired
- set networking to static if desired
halt -p
Start VM with 1GB of memory, bridge networking, initrd, and rw / which will fully boot (tap mode not working for arm64)
sudo qemu-system-aarch64 -cpu cortex-a57 -machine type=virt -nographic -smp 1 -m 1024 -kernel vmlinuz-4.4.0-104-generic -initrd initrd.img-4.4.0-104-generic -drive file=xenial.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 user,id=net0,hostfwd=tcp::2222-:22 --append "root=/dev/vda1 rw console=ttyAMA0 --"
on GUEST: dhclient eth0
on HOST: ssh -p 2222 root@localhost
To configure your server to use DHCP for dynamic address assignment, add the dhcp method to the inet address family statement for the appropriate interface in the file /etc/network/interfaces. The example below assumes you are configuring your first Ethernet interface identified as eth0.
auto eth0
iface eth0 inet dhcp