Skip to content

Commit

Permalink
ubuntu-18.04.1-server-arm64.sh working, snapshot all setups that need it
Browse files Browse the repository at this point in the history
  • Loading branch information
cirosantilli committed Jan 15, 2019
1 parent 5a6032d commit 9aa572e
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 36 deletions.
32 changes: 23 additions & 9 deletions ubuntu-18.04-server-cloudimg-amd64.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,54 @@

set -eux

# Parameters.
id=ubuntu-18.04-server-cloudimg-amd64
img="${id}.img"
img_snapshot="${id}.img.snapshot.qcow2"
user_data="${id}-user-data"
user_data_img="${user_data}.img"

# Install dependencies.
pkgs='cloud-image-utils qemu'
if ! dpkg -s $pkgs >/dev/null 2>&1; then
sudo apt-get install $pkgs
fi

# Get the image.
# This is already in qcow2 format.
img=ubuntu-18.04-server-cloudimg-amd64.img
if [ ! -f "$img" ]; then
wget "https://cloud-images.ubuntu.com/releases/18.04/release/${img}"
fi

# sparse resize: does not use any extra space, just allows the resize to happen later on.
# Create snapshot.
if [ ! -f "$img_snapshot" ]; then
# 1T does a sparse resize: does not use any extra space, just allows the resize to happen later on.
# https://superuser.com/questions/1022019/how-to-increase-size-of-an-ubuntu-cloud-image
qemu-img resize "$img" +128G
qemu-img \
create \
-b "$img" \
-f qcow2 \
"$img_snapshot" \
1T \
;
fi

# Set the password.
# https://serverfault.com/questions/920117/how-do-i-set-a-password-on-an-ubuntu-cloud-image
# https://askubuntu.com/questions/507345/how-to-set-a-password-for-ubuntu-cloud-images-ie-not-use-ssh
user_data=user-data.img
if [ ! -f "$user_data" ]; then
cat >user-data <<EOF
cat >"$user_data" <<EOF
#cloud-config
password: asdfqwer
chpasswd: { expire: False }
ssh_pwauth: True
EOF
cloud-localds "$user_data" user-data
cloud-localds "$user_data_img" "$user_data"
fi

# Run.
qemu-system-x86_64 \
-drive "file=${img},format=qcow2" \
-drive "file=${user_data},format=raw" \
-drive "file=${img_snapshot},format=qcow2" \
-drive "file=${user_data_img},format=raw" \
-device rtl8139,netdev=net0 \
-enable-kvm \
-m 2G \
Expand Down
31 changes: 23 additions & 8 deletions ubuntu-18.04-server-cloudimg-arm64.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ set -eux
# Parameters.
id=ubuntu-18.04-server-cloudimg-arm64
img="${id}.img"
img_snapshot="${id}.img.snapshot.qcow2"
flash0="${id}-flash0.img"
flash1="${id}-flash1.img"
user_data="${id}-user-data.img"
user_data="${id}-user-data"
user_data_img="${user_data}.img"

# Install dependencies.
pkgs='cloud-image-utils qemu-system-arm qemu-efi'
Expand All @@ -18,19 +20,31 @@ fi
# Get the image.
if [ ! -f "$img" ]; then
wget "https://cloud-images.ubuntu.com/releases/18.04/release/${img}"
qemu-img resize "$img" +128G
fi

# For the password.
# Create snapshot.
if [ ! -f "$img_snapshot" ]; then
qemu-img \
create \
-b "$img" \
-f qcow2 \
"$img_snapshot" \
1T \
;
fi

# Set the password.
if [ ! -f "$user_data" ]; then
cat >user-data <<EOF
cat >"$user_data" <<EOF
#cloud-config
password: asdfqwer
chpasswd: { expire: False }
ssh_pwauth: True
EOF
cloud-localds "$user_data" user-data
cloud-localds "$user_data_img" "$user_data"
fi

# Firmware.
if [ ! -f "$flash0" ]; then
dd if=/dev/zero of="$flash0" bs=1M count=64
dd if=/usr/share/qemu-efi/QEMU_EFI.fd of="$flash0" conv=notrunc
Expand All @@ -41,15 +55,16 @@ fi

# Run.
qemu-system-aarch64 \
-machine virt \
-cpu cortex-a57 \
-device rtl8139,netdev=net0 \
-device virtio-blk-device,drive=hd0 \
-drive "file=${user_data},format=raw" \
-drive "if=none,file=${img},id=hd0" \
-drive "file=${user_data_img},format=raw" \
-drive "if=none,file=${img_snapshot},id=hd0" \
-m 2G \
-machine virt \
-netdev user,id=net0 \
-nographic \
-pflash "$flash0" \
-pflash "$flash1" \
-smp 2 \
;
9 changes: 6 additions & 3 deletions ubuntu-18.04.1-desktop-amd64.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ disk_img="${id}.img.qcow2"
disk_img_snapshot="${id}.snapshot.qcow2"
iso="${id}.iso"

# Images.
# Get image.
if [ ! -f "$iso" ]; then
wget "http://releases.ubuntu.com/18.04/${iso}"
fi

# Go through installer manually.
if [ ! -f "$disk_img" ]; then
qemu-img create -f qcow2 "$disk_img" 1T
qemu-system-x86_64 \
Expand All @@ -26,16 +28,17 @@ if [ ! -f "$disk_img" ]; then
;
fi

# Snapshot the installation.
if [ ! -f "$disk_img_snapshot" ]; then
qemu-img \
create \
-b \
-b "$disk_img" \
-f qcow2 \
"$disk_img" \
"$disk_img_snapshot" \
;
fi

# Run the installed image.
qemu-system-x86_64 \
-drive file=ubuntu-18.04-desktop-amd64.snapshot.qcow2,format=qcow2 \
-enable-kvm \
Expand Down
50 changes: 34 additions & 16 deletions ubuntu-18.04.1-server-arm64.sh
Original file line number Diff line number Diff line change
@@ -1,18 +1,8 @@
#!/usr/bin/env bash
set -eu

# TODO not working. Tested on host: Ubuntu 18.10.
# GRUB shows on terminal, but then after language selection,
# it hangs for a while, and then finally says:
#
# > Detect and mount CD-ROM
# >
# > Your installation CD-ROM couldn't be mounted. This probably means
# > that the CD-ROM was not in the drive. If so you can insert it and try
# > again.
# >
# > Retry mounting the CD-ROM?
#
set -eux

# Tested on Ubuntu 18.10.
# - https://superuser.com/questions/942657/how-to-test-arm-ubuntu-under-qemu-the-easiest-way
# - https://askubuntu.com/questions/797599/how-to-run-ubuntu-16-04-arm-in-qemu

Expand All @@ -31,6 +21,14 @@ fi
if [ ! -f "$img" ]; then
qemu-img create -f qcow2 "$img" 1T
fi
if [ ! -f "$img_snapshot" ]; then
qemu-img \
create \
-b "$img" \
-f qcow2 \
"$img_snapshot" \
;
fi
if [ ! -f "$flash0" ]; then
dd if=/dev/zero of="$flash0" bs=1M count=64
dd if=/usr/share/qemu-efi/QEMU_EFI.fd of="$flash0" conv=notrunc
Expand All @@ -40,16 +38,36 @@ if [ ! -f "$flash1" ]; then
fi

# Run.
# TODO where to put this?
#-drive "file=${img},format=qcow2" \
#
# cdrom must be scsi or else the installation fails midway with:
#
# > Detect and mount CD-ROM
# >
# > Your installation CD-ROM couldn't be mounted. This probably means
# > that the CD-ROM was not in the drive. If so you can insert it and try
# > again.
# >
# > Retry mounting the CD-ROM?
# > Your installation CD-ROM couldn't be mounted.
#
# This is because the drivers for the default virtio are not installed in the ISO,
# because in the past it was not reliable on qemu-system-aarch64.
#
# See also:
# https://bazaar.launchpad.net/~ubuntu-testcase/ubuntu-manual-tests/trunk/view/head:/testcases/image/1688_ARM64_Headless_KVM_Guest
qemu-system-aarch64 \
-cdrom "$iso" \
-cpu cortex-a57 \
-device rtl8139,netdev=net0 \
-device scsi-cd,drive=cdrom \
-device virtio-blk-device,drive=hd0 \
-device virtio-scsi-device \
-drive "file=${iso},id=cdrom,if=none,media=cdrom" \
-drive "if=none,file=${img_snapshot},id=hd0" \
-m 2G \
-machine virt \
-netdev user,id=net0 \
-nographic \
-pflash "$flash0" \
-pflash "$flash1" \
-smp 2 \
;

0 comments on commit 9aa572e

Please sign in to comment.