build VM: swap disk, small ZFS cache; salvage interrupted ports steps
A 16 GB VM (18 GB in qemu, 7 GB of it ZFS cache) and the HTPC's other work ran the HTPC out of memory, and its reboot lost 12 hours of the ports step. The VM now gets a swap disk of its own (swap.qcow2, serial gwswap, cache=none: off ZFS, where swap can deadlock, and past the host's page cache), and setup caps the VM's ZFS cache at 2 GB (vm_memory). The VM itself goes down to 12 GB in vm.conf. Tools writes the packages set only when a ports step ends. build now first adds what an interrupted step had finished (salvage_ports): the runtime packages in the stage's packages directory, when the stage belongs to the same series, version and ports commit, each checked to be a whole archive. Build-only dependencies are rebuilt. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
d8bba11344
commit
1addff9484
5 changed files with 313 additions and 15 deletions
25
RELEASE.md
25
RELEASE.md
|
|
@ -153,11 +153,11 @@ machine works with the same `build.sh` and no changes.
|
|||
# ~/.config/gwmirror/vm.conf, sourced by vm.sh
|
||||
GW_VMHOST=htpc # ~/.ssh/config alias of the build host
|
||||
GW_VM_CPUS=24
|
||||
GW_VM_MEM=16G
|
||||
GW_VM_MEM=12G # the HTPC's other work needs most of its memory; see Memory below
|
||||
|
||||
release/vm.sh create 14.3 # on the build host: official image, checksum verified, grown to 100G
|
||||
release/vm.sh start 14.3 # first boot applies freebsd-update patches: an hour or more emulated
|
||||
release/vm.sh setup 14.3 # build.sh setup: host packages, ZFS settings
|
||||
release/vm.sh setup 14.3 # build.sh setup: host packages, ZFS settings, swap
|
||||
release/vm.sh sync 14.3 # this repository (with .git) -> /usr/deps
|
||||
```
|
||||
|
||||
|
|
@ -169,10 +169,18 @@ release/vm.sh sync 14.3 # this repository (with .git) -> /usr/deps
|
|||
copy-on-write disabled (the HTPC's home is btrfs).
|
||||
- **Setup:** `setup` installs git, python3 and rsync from the frozen package
|
||||
set of exactly that FreeBSD release.
|
||||
- **Memory:** the build host backs every page of the VM's memory. On
|
||||
2026-11-20 a 16 GB VM (18 GB in qemu, 7 GB of it ZFS cache) and the
|
||||
HTPC's other work ran it out of memory, and it had to be rebooted. So
|
||||
`setup` caps the VM's ZFS cache at 2 GB, and the VM swaps to a disk of
|
||||
its own (`swap.qcow2`, `GW_VM_SWAP`, default 16G, serial `gwswap`):
|
||||
not on ZFS, where swap can deadlock when memory runs out, and past the
|
||||
host's page cache (`cache=none`). Builds that need more than the VM has
|
||||
(Rust, LLVM) swap inside the VM instead of pressing on the host.
|
||||
- **Restarts:** the VM does not start with the build host. After a reboot,
|
||||
`vm.sh start` it and run `build` again: finished sets are reused. The
|
||||
ports step writes its set only when it ends (below), so a reboot during
|
||||
it loses that run's packages.
|
||||
ports step writes its set only when it ends (below); `build` first adds
|
||||
the packages an interrupted step had finished.
|
||||
|
||||
### Build, sign, collect
|
||||
|
||||
|
|
@ -205,8 +213,13 @@ release/vm.sh pull-out 14.3 26.1 # -> /scratch/mono-opnsense/out/26.1
|
|||
Splitting the list into several steps would rebuild those dependencies in
|
||||
each one. That cost was measured: a second chunk of 20 started by
|
||||
rebuilding the autotools the first chunk had already built. The set is
|
||||
written when the step ends; a reboot of the build host during it loses
|
||||
that run, and the next run starts from the previous set. A port that
|
||||
written when the step ends. A reboot of the build host during it leaves
|
||||
the finished packages only in tools' stage, which the next step clears,
|
||||
so `build` first adds them to the set: the runtime packages tools had
|
||||
copied to the stage's packages directory, if the stage belongs to the
|
||||
same build (series, version and ports commit, kept in
|
||||
`/var/tmp/gwbuild-ports.run`) and each is a whole archive. The
|
||||
build-only dependencies are not kept and get rebuilt. A port that
|
||||
fails is recorded and the step goes on with the others, then fails at the
|
||||
end. Tools stops at the first failure only when its step is given an
|
||||
argument, and `build` gives none.
|
||||
|
|
|
|||
|
|
@ -40,6 +40,7 @@ export GIT_TERMINAL_PROMPT=0 GIT_HTTP_LOW_SPEED_LIMIT=1 GIT_HTTP_LOW_SPEED_TIME=
|
|||
# for ports fetched on this host (make "${FETCH_PATCH}" ...)
|
||||
FETCH_PATCH="FETCH_CMD=sh ${DEPS}/release/fetch-patch.sh"
|
||||
PORTS_LOG=/var/tmp/gwbuild-ports.log
|
||||
PORTS_RUN=/var/tmp/gwbuild-ports.run
|
||||
|
||||
die()
|
||||
{
|
||||
|
|
@ -140,10 +141,11 @@ host_pkg()
|
|||
# for the rest of a run only, and keeps just the listed ports and their runtime
|
||||
# dependencies in the packages set, so splitting the list into several runs rebuilds
|
||||
# those dependencies in each one: days under emulation. The set is written when the
|
||||
# run ends; a reboot of the build host during the run loses it, and the next run
|
||||
# starts again from the previous set. A port that fails is recorded and the run goes
|
||||
# on with the others (tools stops at the first failure only when its step is given an
|
||||
# argument, which is why none is given here); the step fails at the end.
|
||||
# run ends; after a reboot of the build host during the run, salvage_ports adds the
|
||||
# packages it had finished, and the build-only dependencies are rebuilt. A port that
|
||||
# fails is recorded and the run goes on with the others (tools stops at the first
|
||||
# failure only when its step is given an argument, which is why none is given here);
|
||||
# the step fails at the end.
|
||||
#
|
||||
# The ports fetch their distfiles as they build. Tools' distfiles step, which would
|
||||
# fetch them all beforehand for offline rebuilds, is not run: it walks the whole
|
||||
|
|
@ -153,6 +155,9 @@ host_pkg()
|
|||
# never needs.
|
||||
build_ports()
|
||||
{
|
||||
salvage_ports "/usr/obj/usr/tools/config/${SERIES}/aarch64/.pkg/All" \
|
||||
"${SETS}/packages-${VERSION}-aarch64.tar" \
|
||||
"${SERIES} ${VERSION} $(git -C /usr/ports rev-parse HEAD)"
|
||||
# the ports step's chroot builds pkg before anything else
|
||||
step "distfiles of ports-mgmt/pkg"
|
||||
repair_distfiles ports-mgmt/pkg
|
||||
|
|
@ -160,6 +165,39 @@ build_ports()
|
|||
ports_run ports
|
||||
}
|
||||
|
||||
# salvage_ports STAGE SET ID: add to the packages SET what an interrupted ports
|
||||
# step had finished. Tools copies the runtime packages it keeps to its stage's
|
||||
# packages directory (STAGE) as it goes, and makes the set of them when the step
|
||||
# ends; a reboot of the build host before then leaves them only in the stage,
|
||||
# which the next step clears. They are added if the stage belongs to this build:
|
||||
# PORTS_RUN holds the ID (series, version, ports commit) of the last ports step
|
||||
# started. Packages the set has are skipped, and so is one that is not a whole
|
||||
# archive (written when the host went down). The build-only dependencies in the
|
||||
# step's cache are not added (they are not part of the set); the next step
|
||||
# rebuilds the ones it needs.
|
||||
salvage_ports()
|
||||
{
|
||||
if [ -f "${PORTS_RUN}" ] && [ "$(cat "${PORTS_RUN}")" = "${3}" ] && [ -d "${1}" ]; then
|
||||
_have=
|
||||
[ ! -f "${2}" ] || _have=$(tar -tf "${2}")
|
||||
_n=0
|
||||
for _pkg in "${1}"/*.pkg; do
|
||||
[ -f "${_pkg}" ] || continue
|
||||
_entry=./All/$(basename "${_pkg}")
|
||||
printf '%s\n' "${_have}" | grep -qxF "${_entry}" && continue
|
||||
if ! tar -tf "${_pkg}" > /dev/null 2>&1; then
|
||||
echo ">>> not salvaged, incomplete: ${_entry}"
|
||||
continue
|
||||
fi
|
||||
if [ -f "${2}" ]; then _op=-rf; else _op=-cf; fi
|
||||
tar -C "${1}/.." ${_op} "${2}" "${_entry}"
|
||||
_n=$((_n + 1))
|
||||
done
|
||||
[ "${_n}" -eq 0 ] || step "salvaged ${_n} packages of an interrupted ports step"
|
||||
fi
|
||||
echo "${3}" > "${PORTS_RUN}"
|
||||
}
|
||||
|
||||
# ports_run TARGET [ARG...]: a tools ports step, its output also in PORTS_LOG. The
|
||||
# ports whose distfiles failed to fetch are repaired, and the step runs once more;
|
||||
# it skips the packages it has already built.
|
||||
|
|
@ -298,9 +336,34 @@ setup()
|
|||
zfs set compression=zstd "${_pool}"
|
||||
zpool set autotrim=on "${_pool}"
|
||||
zpool list
|
||||
vm_memory
|
||||
step "host ready: $(freebsd-version -u), $(sysctl -n hw.ncpu) CPUs, $(($(sysctl -n hw.physmem) / 1073741824)) GB"
|
||||
}
|
||||
|
||||
# vm_memory: in the build VM (it has the disk with serial gwswap that vmhost.sh
|
||||
# attaches), swap on that disk and a ZFS cache of at most 2 GB. The build host backs
|
||||
# every page of the VM's memory, and a cache grown into all of it leaves the host
|
||||
# short; swap on ZFS itself can deadlock when memory runs out. Elsewhere, nothing.
|
||||
vm_memory()
|
||||
{
|
||||
for _d in $(sysctl -n kern.disks); do
|
||||
[ "$(diskinfo -s "/dev/${_d}" 2> /dev/null)" = gwswap ] || continue
|
||||
if [ ! -e /dev/gpt/gwswap ]; then
|
||||
gpart create -s gpt "${_d}"
|
||||
gpart add -t freebsd-swap -l gwswap "${_d}"
|
||||
fi
|
||||
grep -q '^/dev/gpt/gwswap[[:space:]]' /etc/fstab ||
|
||||
printf '/dev/gpt/gwswap\tnone\tswap\tsw\t0\t0\n' >> /etc/fstab
|
||||
swapctl -l | grep -q '^/dev/gpt/gwswap[[:space:]]' || swapon /dev/gpt/gwswap
|
||||
# (sysrc refuses dotted names; the last setting in loader.conf counts)
|
||||
grep -qx 'vfs.zfs.arc_max="2147483648"' /boot/loader.conf ||
|
||||
echo 'vfs.zfs.arc_max="2147483648"' >> /boot/loader.conf
|
||||
sysctl vfs.zfs.arc_max=2147483648
|
||||
swapctl -lh
|
||||
return 0
|
||||
done
|
||||
}
|
||||
|
||||
build()
|
||||
{
|
||||
args "$@"
|
||||
|
|
|
|||
|
|
@ -702,5 +702,219 @@ esac""")
|
|||
self.assertFalse(self.in_set(self.LISTING, "", port="cat/unknown"))
|
||||
|
||||
|
||||
def build_function(name, subst=()):
|
||||
"""The text of one function of build.sh (to run it alone), paths substituted."""
|
||||
func = subprocess.run(["sed", "-n", f"/^{name}()/,/^}}/p", BUILD],
|
||||
capture_output=True, text=True, check=True).stdout
|
||||
assert func.startswith(f"{name}()"), name
|
||||
for a, b in subst:
|
||||
func = func.replace(a, b)
|
||||
return func
|
||||
|
||||
|
||||
class SalvagePortsTest(unittest.TestCase):
|
||||
"""build.sh's salvage_ports: an interrupted ports step's packages into the set."""
|
||||
|
||||
ID = "26.1 26.1.11 0123abcd"
|
||||
|
||||
def setUp(self):
|
||||
self.tmp = tempfile.mkdtemp(prefix="gw-salvage-")
|
||||
self.addCleanup(shutil.rmtree, self.tmp)
|
||||
self.stage = os.path.join(self.tmp, "stage", ".pkg", "All")
|
||||
os.makedirs(self.stage)
|
||||
self.set = os.path.join(self.tmp, "packages-26.1.11-aarch64.tar")
|
||||
self.run_file = os.path.join(self.tmp, "ports.run")
|
||||
self.func = build_function("salvage_ports")
|
||||
# the set as tools makes it, holding one package the stage also has
|
||||
setdir = os.path.join(self.tmp, "setdir")
|
||||
os.makedirs(os.path.join(setdir, "All"))
|
||||
open(os.path.join(setdir, ".abi_hint"), "w").close()
|
||||
self.make_pkg(os.path.join(setdir, "All"), "old-1.0.pkg")
|
||||
self.make_pkg(self.stage, "old-1.0.pkg")
|
||||
subprocess.run(["tar", "-C", setdir, "-cf", self.set, "./.abi_hint", "./All/old-1.0.pkg"], check=True)
|
||||
|
||||
def make_pkg(self, d, name, content=b"x" * 5000):
|
||||
src = os.path.join(self.tmp, "content")
|
||||
with open(src, "wb") as f:
|
||||
f.write(os.urandom(2000) + content)
|
||||
path = os.path.join(d, name)
|
||||
subprocess.run(["tar", "-czf", path, "-C", self.tmp, "content"], check=True)
|
||||
return path
|
||||
|
||||
def salvage(self, id_=ID, stage=None, set_=None):
|
||||
r = subprocess.run(["sh", "-c", 'step() { echo ">>> $*"; }\n' + self.func + '\nsalvage_ports "$@"',
|
||||
"sh", stage or self.stage, set_ or self.set, id_],
|
||||
env={"PATH": "/usr/bin:/bin", "PORTS_RUN": self.run_file},
|
||||
capture_output=True, text=True)
|
||||
self.assertEqual(r.returncode, 0, r.stderr)
|
||||
return r.stdout
|
||||
|
||||
def entries(self, set_=None):
|
||||
return subprocess.run(["tar", "-tf", set_ or self.set], capture_output=True, text=True,
|
||||
check=True).stdout.split("\n")[:-1]
|
||||
|
||||
def started(self, id_=ID):
|
||||
with open(self.run_file, "w") as f:
|
||||
f.write(id_ + "\n")
|
||||
|
||||
def test_first_step_adds_nothing_records_the_build(self):
|
||||
self.make_pkg(self.stage, "new-2.0.pkg")
|
||||
self.salvage()
|
||||
self.assertEqual(self.entries(), ["./.abi_hint", "./All/old-1.0.pkg"])
|
||||
with open(self.run_file) as f:
|
||||
self.assertEqual(f.read(), self.ID + "\n")
|
||||
|
||||
def test_stage_of_another_build_is_ignored(self):
|
||||
self.started("26.1 26.1.10 0123abcd")
|
||||
self.make_pkg(self.stage, "new-2.0.pkg")
|
||||
self.salvage()
|
||||
self.assertEqual(self.entries(), ["./.abi_hint", "./All/old-1.0.pkg"])
|
||||
with open(self.run_file) as f:
|
||||
self.assertEqual(f.read(), self.ID + "\n")
|
||||
|
||||
def test_adds_the_finished_packages(self):
|
||||
self.started()
|
||||
a = self.make_pkg(self.stage, "new-2.0.pkg")
|
||||
self.make_pkg(self.stage, "py313-foo-1.2_1.pkg")
|
||||
out = self.salvage()
|
||||
self.assertIn("salvaged 2 packages", out)
|
||||
self.assertEqual(sorted(self.entries()), ["./.abi_hint", "./All/new-2.0.pkg", "./All/old-1.0.pkg",
|
||||
"./All/py313-foo-1.2_1.pkg"])
|
||||
x = os.path.join(self.tmp, "x")
|
||||
os.makedirs(x)
|
||||
subprocess.run(["tar", "-C", x, "-xf", self.set], check=True)
|
||||
with open(a, "rb") as f1, open(os.path.join(x, "All", "new-2.0.pkg"), "rb") as f2:
|
||||
self.assertEqual(f1.read(), f2.read())
|
||||
|
||||
def test_twice_adds_nothing_more(self):
|
||||
self.started()
|
||||
self.make_pkg(self.stage, "new-2.0.pkg")
|
||||
self.salvage()
|
||||
before = self.entries()
|
||||
self.assertNotIn("salvaged", self.salvage())
|
||||
self.assertEqual(self.entries(), before)
|
||||
|
||||
def test_incomplete_package_is_skipped(self):
|
||||
self.started()
|
||||
p = self.make_pkg(self.stage, "cut-1.0.pkg")
|
||||
with open(p, "rb") as f:
|
||||
data = f.read()
|
||||
with open(p, "wb") as f:
|
||||
f.write(data[:len(data) // 2])
|
||||
open(os.path.join(self.stage, "empty-1.0.pkg"), "w").close()
|
||||
self.make_pkg(self.stage, "whole-1.0.pkg")
|
||||
out = self.salvage()
|
||||
self.assertIn("incomplete: ./All/cut-1.0.pkg", out)
|
||||
self.assertIn("incomplete: ./All/empty-1.0.pkg", out)
|
||||
self.assertIn("salvaged 1 packages", out)
|
||||
self.assertNotIn("./All/cut-1.0.pkg", self.entries())
|
||||
self.assertIn("./All/whole-1.0.pkg", self.entries())
|
||||
|
||||
def test_without_a_set_makes_one(self):
|
||||
self.started()
|
||||
os.unlink(self.set)
|
||||
self.make_pkg(self.stage, "new-2.0.pkg")
|
||||
self.salvage()
|
||||
self.assertEqual(sorted(self.entries()), ["./All/new-2.0.pkg", "./All/old-1.0.pkg"])
|
||||
|
||||
def test_without_a_stage_or_packages(self):
|
||||
self.started()
|
||||
self.salvage(stage=os.path.join(self.tmp, "nonexistent"))
|
||||
shutil.rmtree(self.stage)
|
||||
os.makedirs(self.stage)
|
||||
self.salvage()
|
||||
self.assertEqual(self.entries(), ["./.abi_hint", "./All/old-1.0.pkg"])
|
||||
|
||||
def test_awkward_names(self):
|
||||
# names are not options to tar, and match whole set entries only
|
||||
self.started()
|
||||
for name in ("-rf.pkg", "a b-1.0.pkg", "old-1.0.pkg.pkg", "ld-1.0.pkg"):
|
||||
self.make_pkg(self.stage, name)
|
||||
self.salvage()
|
||||
self.assertEqual(sorted(self.entries()),
|
||||
sorted(["./.abi_hint", "./All/old-1.0.pkg", "./All/-rf.pkg", "./All/a b-1.0.pkg",
|
||||
"./All/old-1.0.pkg.pkg", "./All/ld-1.0.pkg"]))
|
||||
|
||||
|
||||
class VmMemoryTest(unittest.TestCase):
|
||||
"""build.sh's vm_memory: swap on the VM's swap disk, a small ZFS cache."""
|
||||
|
||||
def setUp(self):
|
||||
self.tmp = tempfile.mkdtemp(prefix="gw-vmmem-")
|
||||
self.addCleanup(shutil.rmtree, self.tmp)
|
||||
self.fx = Fixture(self.tmp)
|
||||
self.fstab = os.path.join(self.tmp, "fstab")
|
||||
with open(self.fstab, "w") as f:
|
||||
f.write("/dev/gpt/rootfs\t/\tufs\trw\t1\t1\n")
|
||||
self.gpt = os.path.join(self.tmp, "gpt")
|
||||
os.makedirs(self.gpt)
|
||||
self.swaps = os.path.join(self.tmp, "swaps")
|
||||
open(self.swaps, "w").close()
|
||||
self.loader = os.path.join(self.tmp, "loader.conf")
|
||||
with open(self.loader, "w") as f:
|
||||
f.write('zfs_load="YES"\n')
|
||||
self.func = build_function("vm_memory", [("/etc/fstab", self.fstab), ("/dev/gpt/", self.gpt + "/"),
|
||||
("/boot/loader.conf", self.loader)])
|
||||
fakes = {
|
||||
"sysctl": 'case "$*" in "-n kern.disks") echo "${FAKE_DISKS}";; esac',
|
||||
"diskinfo": 'eval "echo \\${FAKE_IDENT_${2#/dev/}:-}"',
|
||||
"gpart": f'[ "$1" = add ] && touch "{self.gpt}/gwswap"; exit 0',
|
||||
"swapctl": f'echo "Device 1K-blocks Used"; cat "{self.swaps}"',
|
||||
"swapon": f'echo "$1 16777216 0" >> "{self.swaps}"',
|
||||
}
|
||||
for name, body in fakes.items():
|
||||
self.fx.make_fake(name, body)
|
||||
|
||||
def vm_memory(self, disks, **idents):
|
||||
env = {"PATH": f"{self.fx.bin}:/usr/bin:/bin", "FAKE_LOG": self.fx.log, "FAKE_DISKS": disks}
|
||||
env.update({f"FAKE_IDENT_{k}": v for k, v in idents.items()})
|
||||
r = subprocess.run(["sh", "-c", self.func + "\nvm_memory"], env=env, capture_output=True, text=True)
|
||||
self.assertEqual(r.returncode, 0, r.stderr)
|
||||
calls = self.fx.calls()
|
||||
os.unlink(self.fx.log)
|
||||
return [c for c in calls if not c.startswith(("diskinfo", "swapctl", "sysctl -n"))]
|
||||
|
||||
def fstab_lines(self):
|
||||
with open(self.fstab) as f:
|
||||
return f.read().splitlines()
|
||||
|
||||
def loader_lines(self):
|
||||
with open(self.loader) as f:
|
||||
return f.read().splitlines()
|
||||
|
||||
def test_not_in_the_vm(self):
|
||||
self.assertEqual(self.vm_memory("vtbd0 vtbd1", vtbd0="BHYVE-1234", vtbd1=""), [])
|
||||
self.assertEqual(self.vm_memory(""), [])
|
||||
self.assertEqual(len(self.fstab_lines()), 1)
|
||||
self.assertEqual(self.loader_lines(), ['zfs_load="YES"'])
|
||||
|
||||
def test_sets_up_swap_and_cache(self):
|
||||
# the swap disk need not be the last one (it came up as vtbd0 in the VM)
|
||||
calls = self.vm_memory("vtbd0 vtbd1 vtbd2", vtbd0="", vtbd2="gwswap")
|
||||
self.assertEqual(calls, ["gpart create -s gpt vtbd2", "gpart add -t freebsd-swap -l gwswap vtbd2",
|
||||
f"swapon {self.gpt}/gwswap", "sysctl vfs.zfs.arc_max=2147483648"])
|
||||
self.assertEqual(self.fstab_lines()[1], f"{self.gpt}/gwswap\tnone\tswap\tsw\t0\t0")
|
||||
self.assertEqual(self.loader_lines(), ['zfs_load="YES"', 'vfs.zfs.arc_max="2147483648"'])
|
||||
|
||||
def test_overrides_an_earlier_cache_setting(self):
|
||||
with open(self.loader, "a") as f:
|
||||
f.write('vfs.zfs.arc_max="8G"\n')
|
||||
self.vm_memory("vtbd0", vtbd0="gwswap")
|
||||
self.assertEqual(self.loader_lines()[-1], 'vfs.zfs.arc_max="2147483648"')
|
||||
|
||||
def test_again_changes_nothing_on_the_disk(self):
|
||||
self.vm_memory("vtbd0 vtbd2", vtbd2="gwswap")
|
||||
calls = self.vm_memory("vtbd0 vtbd2", vtbd2="gwswap")
|
||||
self.assertEqual(calls, ["sysctl vfs.zfs.arc_max=2147483648"])
|
||||
self.assertEqual(len(self.fstab_lines()), 2)
|
||||
self.assertEqual(len(self.loader_lines()), 2)
|
||||
|
||||
def test_after_a_reboot_swap_is_turned_on_again(self):
|
||||
self.vm_memory("vtbd2", vtbd2="gwswap")
|
||||
open(self.swaps, "w").close()
|
||||
self.assertIn(f"swapon {self.gpt}/gwswap", self.vm_memory("vtbd2", vtbd2="gwswap"))
|
||||
self.assertEqual(len(self.fstab_lines()), 2)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
|
|
|||
|
|
@ -12,7 +12,8 @@
|
|||
# image on the build host, grow it, make the seed
|
||||
# vm.sh start | stop | status OSREL
|
||||
# vm.sh ssh OSREL [COMMAND...]
|
||||
# vm.sh setup OSREL install the build host packages (build.sh setup)
|
||||
# vm.sh setup OSREL install the build host packages, swap on the swap
|
||||
# disk, a small ZFS cache (build.sh setup)
|
||||
# vm.sh sync OSREL copy this repository (with .git) to /usr/deps in the VM
|
||||
# vm.sh run OSREL BUILD-ARGS... run release/build.sh BUILD-ARGS in the VM, detached;
|
||||
# output goes to /root/gwbuild.log
|
||||
|
|
@ -27,7 +28,7 @@
|
|||
#
|
||||
# Settings come from the environment or from $GW_KEYDIR/vm.conf (sourced): GW_VMHOST,
|
||||
# GW_VMROOT (the VM directory on the build host; vmhost.sh's default ~/gwbuild-vm),
|
||||
# GW_VM_CPUS (8), GW_VM_MEM (16G), GW_VM_DISK (100G), GW_OUT (default
|
||||
# GW_VM_CPUS (8), GW_VM_MEM (16G), GW_VM_DISK (100G), GW_VM_SWAP (16G), GW_OUT (default
|
||||
# /scratch/mono-opnsense/out), GW_KEYDIR (default ~/.config/gwmirror, holding repo.key,
|
||||
# repo.pub and the VM's ssh key).
|
||||
#
|
||||
|
|
@ -91,7 +92,7 @@ vmhost()
|
|||
{
|
||||
safe_words "$@"
|
||||
_env=
|
||||
for _v in GW_VMROOT GW_VM_CPUS GW_VM_MEM GW_VM_DISK; do
|
||||
for _v in GW_VMROOT GW_VM_CPUS GW_VM_MEM GW_VM_DISK GW_VM_SWAP; do
|
||||
eval "_val=\${${_v}:-}"
|
||||
[ -z "${_val}" ] || { safe_words "${_val}"; _env="${_env} ${_v}=${_val}"; }
|
||||
done
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@
|
|||
# vmhost.sh status | destroy OSREL
|
||||
#
|
||||
# Environment: GW_VMROOT (default ~/gwbuild-vm), GW_VM_CPUS (8), GW_VM_MEM (16G),
|
||||
# GW_VM_DISK (100G).
|
||||
# GW_VM_DISK (100G), GW_VM_SWAP (16G, the VM's swap disk).
|
||||
#
|
||||
# Copyright 2026 Karst Tech
|
||||
# SPDX-License-Identifier: BSD-2-Clause
|
||||
|
|
@ -26,6 +26,7 @@ VMROOT=${GW_VMROOT:-${HOME}/gwbuild-vm}
|
|||
CPUS=${GW_VM_CPUS:-8}
|
||||
MEM=${GW_VM_MEM:-16G}
|
||||
DISKSIZE=${GW_VM_DISK:-100G}
|
||||
SWAPSIZE=${GW_VM_SWAP:-16G}
|
||||
IMAGE=localhost/gwbuild-qemu:1
|
||||
|
||||
die()
|
||||
|
|
@ -40,7 +41,7 @@ OSREL=${2}
|
|||
shift 2
|
||||
echo "${OSREL}" | grep -Eqx '1[4-9]\.[0-9]' || die "bad FreeBSD release '${OSREL}'"
|
||||
echo "${CPUS}" | grep -Eqx '[1-9][0-9]{0,2}' || die "bad GW_VM_CPUS '${CPUS}'"
|
||||
for v in "${MEM}" "${DISKSIZE}"; do
|
||||
for v in "${MEM}" "${DISKSIZE}" "${SWAPSIZE}"; do
|
||||
echo "${v}" | grep -Eqx '[1-9][0-9]*[MG]' || die "bad size '${v}'"
|
||||
done
|
||||
|
||||
|
|
@ -153,10 +154,14 @@ start()
|
|||
running && die "already running"
|
||||
[ -f "${VMDIR}/disk.qcow2" ] || die "no ${VMDIR}/disk.qcow2 (vm.sh create ${OSREL})"
|
||||
build_image
|
||||
[ -f "${VMDIR}/swap.qcow2" ] || in_image qemu-img create -q -f qcow2 /vm/swap.qcow2 "${SWAPSIZE}"
|
||||
podman rm -f "${NAME}" > /dev/null 2>&1 || true
|
||||
# neoverse-n1: ARMv8.2 with LSE atomics, without the costly emulation of SVE
|
||||
# and pointer authentication. The ssh port is on the host's loopback only. The
|
||||
# NIC has no option ROM (iPXE network boot; not in the image, not needed).
|
||||
# The swap disk (serial gwswap, which build.sh setup looks for) keeps swap off
|
||||
# ZFS, where it can deadlock when memory runs out, and bypasses the host's
|
||||
# page cache: the VM swaps when memory is short on the host too.
|
||||
podman run -d --name "${NAME}" --network host -v "${VMDIR}:/vm:z" "${IMAGE}" \
|
||||
qemu-system-aarch64 -name "${NAME}" -machine virt,gic-version=3 -cpu neoverse-n1 \
|
||||
-accel tcg,thread=multi -smp "${CPUS}" -m "${MEM}" \
|
||||
|
|
@ -164,6 +169,8 @@ start()
|
|||
-drive if=pflash,format=raw,file=/vm/efivars.fd \
|
||||
-drive file=/vm/disk.qcow2,if=virtio,format=qcow2,discard=unmap \
|
||||
-drive file=/vm/seed.iso,if=virtio,format=raw,readonly=on \
|
||||
-drive file=/vm/swap.qcow2,if=none,id=swap,format=qcow2,cache=none,discard=unmap \
|
||||
-device virtio-blk-pci,drive=swap,serial=gwswap \
|
||||
-netdev "user,id=n0,hostfwd=tcp:127.0.0.1:${PORT}-:22" -device virtio-net-pci,netdev=n0,romfile= \
|
||||
-display none -serial file:/vm/console.log > /dev/null
|
||||
# qemu's own errors (bad options, missing firmware) end it at once
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue