Skip to content

Commit 9aa572e

Browse files
committed
ubuntu-18.04.1-server-arm64.sh working, snapshot all setups that need it
1 parent 5a6032d commit 9aa572e

File tree

4 files changed

+86
-36
lines changed

4 files changed

+86
-36
lines changed

ubuntu-18.04-server-cloudimg-amd64.sh

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,40 +2,54 @@
22

33
set -eux
44

5+
# Parameters.
6+
id=ubuntu-18.04-server-cloudimg-amd64
7+
img="${id}.img"
8+
img_snapshot="${id}.img.snapshot.qcow2"
9+
user_data="${id}-user-data"
10+
user_data_img="${user_data}.img"
11+
512
# Install dependencies.
613
pkgs='cloud-image-utils qemu'
714
if ! dpkg -s $pkgs >/dev/null 2>&1; then
815
sudo apt-get install $pkgs
916
fi
1017

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

17-
# sparse resize: does not use any extra space, just allows the resize to happen later on.
23+
# Create snapshot.
24+
if [ ! -f "$img_snapshot" ]; then
25+
# 1T does a sparse resize: does not use any extra space, just allows the resize to happen later on.
1826
# https://superuser.com/questions/1022019/how-to-increase-size-of-an-ubuntu-cloud-image
19-
qemu-img resize "$img" +128G
27+
qemu-img \
28+
create \
29+
-b "$img" \
30+
-f qcow2 \
31+
"$img_snapshot" \
32+
1T \
33+
;
2034
fi
2135

2236
# Set the password.
2337
# https://serverfault.com/questions/920117/how-do-i-set-a-password-on-an-ubuntu-cloud-image
2438
# https://askubuntu.com/questions/507345/how-to-set-a-password-for-ubuntu-cloud-images-ie-not-use-ssh
25-
user_data=user-data.img
2639
if [ ! -f "$user_data" ]; then
27-
cat >user-data <<EOF
40+
cat >"$user_data" <<EOF
2841
#cloud-config
2942
password: asdfqwer
3043
chpasswd: { expire: False }
3144
ssh_pwauth: True
3245
EOF
33-
cloud-localds "$user_data" user-data
46+
cloud-localds "$user_data_img" "$user_data"
3447
fi
3548

49+
# Run.
3650
qemu-system-x86_64 \
37-
-drive "file=${img},format=qcow2" \
38-
-drive "file=${user_data},format=raw" \
51+
-drive "file=${img_snapshot},format=qcow2" \
52+
-drive "file=${user_data_img},format=raw" \
3953
-device rtl8139,netdev=net0 \
4054
-enable-kvm \
4155
-m 2G \

ubuntu-18.04-server-cloudimg-arm64.sh

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@ set -eux
55
# Parameters.
66
id=ubuntu-18.04-server-cloudimg-arm64
77
img="${id}.img"
8+
img_snapshot="${id}.img.snapshot.qcow2"
89
flash0="${id}-flash0.img"
910
flash1="${id}-flash1.img"
10-
user_data="${id}-user-data.img"
11+
user_data="${id}-user-data"
12+
user_data_img="${user_data}.img"
1113

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

24-
# For the password.
25+
# Create snapshot.
26+
if [ ! -f "$img_snapshot" ]; then
27+
qemu-img \
28+
create \
29+
-b "$img" \
30+
-f qcow2 \
31+
"$img_snapshot" \
32+
1T \
33+
;
34+
fi
35+
36+
# Set the password.
2537
if [ ! -f "$user_data" ]; then
26-
cat >user-data <<EOF
38+
cat >"$user_data" <<EOF
2739
#cloud-config
2840
password: asdfqwer
2941
chpasswd: { expire: False }
3042
ssh_pwauth: True
3143
EOF
32-
cloud-localds "$user_data" user-data
44+
cloud-localds "$user_data_img" "$user_data"
3345
fi
46+
47+
# Firmware.
3448
if [ ! -f "$flash0" ]; then
3549
dd if=/dev/zero of="$flash0" bs=1M count=64
3650
dd if=/usr/share/qemu-efi/QEMU_EFI.fd of="$flash0" conv=notrunc
@@ -41,15 +55,16 @@ fi
4155

4256
# Run.
4357
qemu-system-aarch64 \
58+
-machine virt \
4459
-cpu cortex-a57 \
4560
-device rtl8139,netdev=net0 \
4661
-device virtio-blk-device,drive=hd0 \
47-
-drive "file=${user_data},format=raw" \
48-
-drive "if=none,file=${img},id=hd0" \
62+
-drive "file=${user_data_img},format=raw" \
63+
-drive "if=none,file=${img_snapshot},id=hd0" \
4964
-m 2G \
50-
-machine virt \
5165
-netdev user,id=net0 \
5266
-nographic \
5367
-pflash "$flash0" \
5468
-pflash "$flash1" \
69+
-smp 2 \
5570
;

ubuntu-18.04.1-desktop-amd64.sh

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@ disk_img="${id}.img.qcow2"
1111
disk_img_snapshot="${id}.snapshot.qcow2"
1212
iso="${id}.iso"
1313

14-
# Images.
14+
# Get image.
1515
if [ ! -f "$iso" ]; then
1616
wget "http://releases.ubuntu.com/18.04/${iso}"
1717
fi
18+
19+
# Go through installer manually.
1820
if [ ! -f "$disk_img" ]; then
1921
qemu-img create -f qcow2 "$disk_img" 1T
2022
qemu-system-x86_64 \
@@ -26,16 +28,17 @@ if [ ! -f "$disk_img" ]; then
2628
;
2729
fi
2830

31+
# Snapshot the installation.
2932
if [ ! -f "$disk_img_snapshot" ]; then
3033
qemu-img \
3134
create \
32-
-b \
35+
-b "$disk_img" \
3336
-f qcow2 \
34-
"$disk_img" \
3537
"$disk_img_snapshot" \
3638
;
3739
fi
3840

41+
# Run the installed image.
3942
qemu-system-x86_64 \
4043
-drive file=ubuntu-18.04-desktop-amd64.snapshot.qcow2,format=qcow2 \
4144
-enable-kvm \

ubuntu-18.04.1-server-arm64.sh

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,8 @@
11
#!/usr/bin/env bash
2-
set -eu
32

4-
# TODO not working. Tested on host: Ubuntu 18.10.
5-
# GRUB shows on terminal, but then after language selection,
6-
# it hangs for a while, and then finally says:
7-
#
8-
# > Detect and mount CD-ROM
9-
# >
10-
# > Your installation CD-ROM couldn't be mounted. This probably means
11-
# > that the CD-ROM was not in the drive. If so you can insert it and try
12-
# > again.
13-
# >
14-
# > Retry mounting the CD-ROM?
15-
#
3+
set -eux
4+
5+
# Tested on Ubuntu 18.10.
166
# - https://superuser.com/questions/942657/how-to-test-arm-ubuntu-under-qemu-the-easiest-way
177
# - https://askubuntu.com/questions/797599/how-to-run-ubuntu-16-04-arm-in-qemu
188

@@ -31,6 +21,14 @@ fi
3121
if [ ! -f "$img" ]; then
3222
qemu-img create -f qcow2 "$img" 1T
3323
fi
24+
if [ ! -f "$img_snapshot" ]; then
25+
qemu-img \
26+
create \
27+
-b "$img" \
28+
-f qcow2 \
29+
"$img_snapshot" \
30+
;
31+
fi
3432
if [ ! -f "$flash0" ]; then
3533
dd if=/dev/zero of="$flash0" bs=1M count=64
3634
dd if=/usr/share/qemu-efi/QEMU_EFI.fd of="$flash0" conv=notrunc
@@ -40,16 +38,36 @@ if [ ! -f "$flash1" ]; then
4038
fi
4139

4240
# Run.
43-
# TODO where to put this?
44-
#-drive "file=${img},format=qcow2" \
41+
#
42+
# cdrom must be scsi or else the installation fails midway with:
43+
#
44+
# > Detect and mount CD-ROM
45+
# >
46+
# > Your installation CD-ROM couldn't be mounted. This probably means
47+
# > that the CD-ROM was not in the drive. If so you can insert it and try
48+
# > again.
49+
# >
50+
# > Retry mounting the CD-ROM?
51+
# > Your installation CD-ROM couldn't be mounted.
52+
#
53+
# This is because the drivers for the default virtio are not installed in the ISO,
54+
# because in the past it was not reliable on qemu-system-aarch64.
55+
#
56+
# See also:
57+
# https://bazaar.launchpad.net/~ubuntu-testcase/ubuntu-manual-tests/trunk/view/head:/testcases/image/1688_ARM64_Headless_KVM_Guest
4558
qemu-system-aarch64 \
46-
-cdrom "$iso" \
4759
-cpu cortex-a57 \
4860
-device rtl8139,netdev=net0 \
61+
-device scsi-cd,drive=cdrom \
62+
-device virtio-blk-device,drive=hd0 \
63+
-device virtio-scsi-device \
64+
-drive "file=${iso},id=cdrom,if=none,media=cdrom" \
65+
-drive "if=none,file=${img_snapshot},id=hd0" \
4966
-m 2G \
5067
-machine virt \
5168
-netdev user,id=net0 \
5269
-nographic \
5370
-pflash "$flash0" \
5471
-pflash "$flash1" \
72+
-smp 2 \
5573
;

0 commit comments

Comments
 (0)