Skip to content

Commit 2e001a4

Browse files
paulzholbradfitz
authored andcommitted
env/freebsd-amd64: add FreeBSD 10.4, 11.2 images, update build script
Use freebsd-update when preparing the downloaded -RELEASE image to get errata and security updates made since the release. Switch kern.timecounter.hardware from ACPI-safe to TSC on GCE https://lists.freebsd.org/pipermail/freebsd-cloud/2017-January/000080.html Drop vtnet hw.vtnet.csum_disable=1 workaround, should be fixed in all supported versions. https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=207446 Update the expect script to switch the console to serial, this makes it possible to match prompts via a regexp (11.2 has 'root@freebsd:~ #', while the older images are 'root@:~ #'). Otherwise qemu with -display curses emits ansi escape codes which make a mess of everything. This requires the sgabios smbios extension installed on the host preparing the images. https://code.google.com/archive/p/sgabios/ https://packages.ubuntu.com/xenial/sgabios SeaBIOS 1.11.0 and up should have a compatible rom builtin, but it's not even available in Ubuntu 18.04. qemu/seabios@d6728f3 Additionaly drop the -smp 2 directive for qemu, until MTTCG is enabled on amd64 targets. Updates golang/go#25289 Change-Id: If33c2b35b4221f27d719938bcfc013efe3549305 Reviewed-on: https://go-review.googlesource.com/135475 Reviewed-by: Brad Fitzpatrick <[email protected]>
1 parent 23ca772 commit 2e001a4

File tree

4 files changed

+75
-22
lines changed

4 files changed

+75
-22
lines changed

env/freebsd-amd64/README

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
make.bash creates a Google Compute Engine VM image to run the Go
22
FreeBSD builder, booting up to run the buildlet.
33

4-
make.bash should be run on a Linux box with qemu.
4+
make.bash should be run on a Linux box with qemu and a few additional packages.
5+
on ubuntu 16.04 / debian 9 install:
6+
apt-get install qemu-system-x86 sgabios expect genisoimage
57

68
After it completes, it creates a file freebsd-amd64-gce101.tar.gz
79

env/freebsd-amd64/loader.conf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ loader_logo="none"
44
hw.memtest.tests="0"
55
console="comconsole,vidconsole"
66
hw.vtnet.csum_disable=1
7-
hw.vtnet.mq_disable=1
8-
kern.timecounter.hardware=ACPI-safe
7+
machdep.disable_tsc_calibration=1
8+
kern.timecounter.invariant_tsc=1
99
aesni_load="YES"
1010
nvme_load="YES"

env/freebsd-amd64/make.bash

Lines changed: 69 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
# SSH is enabled, and a user gopher, password gopher, is created.
1010

1111
# Only tested on Ubuntu 16.04.
12-
# Requires packages: qemu expect genisoimage
12+
# Requires packages: qemu expect sgabios genisoimage
1313

1414
set -e
1515

@@ -33,6 +33,11 @@ case $1 in
3333
readonly VERSION_TRAILER=
3434
readonly SHA256=1d710ba643bf6a8ce5bff5a9d69b1657ccff83dd1f2df711d9b4e02f9aab7d06
3535
;;
36+
10.4)
37+
readonly VERSION=10.4
38+
readonly VERSION_TRAILER=
39+
readonly SHA256=8d1ff92e74a70f1ec039a465467f19abd7892331403ef1d4952d271adddab625
40+
;;
3641
11.0)
3742
readonly VERSION=11.0
3843
readonly VERSION_TRAILER=
@@ -43,9 +48,14 @@ case $1 in
4348
readonly VERSION_TRAILER=
4449
readonly SHA256=233c6b269a29c1ce38bb4eb861251d1c74643846c1de937b8e31cc0316632bc0
4550
;;
51+
11.2)
52+
readonly VERSION=11.2
53+
readonly VERSION_TRAILER=
54+
readonly SHA256=d8638aecbb13bdc891e17187f3932fe477f5655846bdaad8fecd60614de9312c
55+
;;
4656
*)
4757
echo "Usage: $0 <version>"
48-
echo " version - FreeBSD version to build. Valid choices: 9.3 10.3 11.0 11.1"
58+
echo " version - FreeBSD version to build. Valid choices: 9.3 10.3 10.4 11.0 11.1 11.2"
4959
exit 1
5060
esac
5161

@@ -65,6 +75,7 @@ cp FreeBSD-${VERSION:?}-RELEASE-amd64${VERSION_TRAILER}.raw disk.raw
6575
mkdir -p iso/boot iso/etc iso/usr/local/etc/rc.d
6676
cp loader.conf iso/boot
6777
cp rc.conf iso/etc
78+
cp sysctl.conf iso/etc
6879
cp buildlet iso/usr/local/etc/rc.d
6980

7081
cat >iso/install.sh <<'EOF'
@@ -76,6 +87,7 @@ cp /mnt/usr/local/etc/rc.d/buildlet /usr/local/etc/rc.d/buildlet
7687
chmod +x /usr/local/etc/rc.d/buildlet
7788
cp /mnt/boot/loader.conf /boot/loader.conf
7889
cp /mnt/etc/rc.conf /etc/rc.conf
90+
cat /mnt/etc/sysctl.conf >> /etc/sysctl.conf
7991
adduser -f - <<ADDUSEREOF
8092
gopher::::::Gopher Gopherson::/bin/sh:gopher
8193
ADDUSEREOF
@@ -89,32 +101,69 @@ genisoimage -r -o config.iso iso/
89101
# TODO(wathiede): remove sleep
90102
sleep 2
91103

92-
# TODO(wathiede): set serial output so we can track boot on GCE.
93-
expect <<EOF
94-
set timeout 600
95-
spawn qemu-system-x86_64 -display curses -smp 2 -m 1G -drive if=virtio,file=disk.raw,cache=none -cdrom config.iso -net nic,model=virtio -net user
104+
expect <<'EOF'
105+
set prompt "root@.*:~ #[ ]"
106+
set timeout -1
96107
97-
# Speed-up boot by going in to single user mode.
98-
expect "Welcome to FreeBSD"
108+
spawn qemu-system-x86_64 -nographic -option-rom sgabios.bin -m 1G -drive if=virtio,file=disk.raw,format=raw,cache=none -cdrom config.iso -net nic,model=virtio -net user
109+
set qemu_pid $spawn_id
110+
111+
# boot with serial console enabled
112+
expect -ex "Welcome to FreeBSD"
99113
sleep 2
100-
send "\n"
114+
expect -ex "ape to loader prompt"
115+
send "3\n"
116+
expect -ex "Type '?' for a list of commands, 'help' for more detailed help."
117+
send "set console=\"comconsole\"\n"
118+
sleep 1
119+
send "boot\n"
120+
121+
# wait for login prompt
122+
set timeout 120
123+
expect {
124+
"\nlogin: " {
125+
send "root\n"
126+
sleep 1
127+
}
128+
timeout { exit 2 }
129+
}
101130
102-
expect "login:"
131+
expect -re $prompt
103132
sleep 1
104-
send "root\n"
133+
send "mount_cd9660 /dev/cd0 /mnt\nsh /mnt/install.sh\n"
105134
106-
expect "root@:~ # "
135+
expect -re $prompt
107136
sleep 1
108-
send "dhclient vtnet0\n"
109137
110-
expect "root@:~ # "
138+
# generate SSH keys
139+
send "service sshd keygen\n"
140+
expect -re "Generating .+ host key."
111141
sleep 1
112-
send "mount_cd9660 /dev/cd0 /mnt\nsh /mnt/install.sh\n"
113142
114-
expect "root@:~ # "
143+
expect -re $prompt
115144
sleep 1
116-
send "pkg install bash curl git\n"
145+
set timeout -1
146+
# download updates
147+
send "env PAGER=cat freebsd-update fetch --not-running-from-cron\n"
148+
expect {
149+
"The following files will be updated as part of updating to" {
150+
sleep 2
151+
expect -re $prompt
152+
send "freebsd-update install\n"
153+
expect "Installing updates... done."
154+
sleep 1
155+
send "\n"
156+
}
157+
158+
"No updates needed to update system to" {
159+
sleep 1
160+
send "\n"
161+
}
162+
}
117163
164+
expect -re $prompt
165+
sleep 1
166+
send "pkg install bash curl git\n"
118167
expect "Do you want to fetch and install it now"
119168
sleep 1
120169
send "y\n"
@@ -123,11 +172,12 @@ expect "Proceed with this action"
123172
sleep 1
124173
send "y\n"
125174
126-
expect "root@:~ # "
175+
expect -re $prompt
127176
sleep 1
128177
send "poweroff\n"
129178
expect "All buffers synced."
130-
sleep 5
179+
180+
wait -i $qemu_pid
131181
EOF
132182

133183
# Create Compute Engine disk image.

env/freebsd-amd64/sysctl.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
kern.timecounter.hardware=TSC-low

0 commit comments

Comments
 (0)