Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,33 @@ are taken from its section here.

## [Unreleased]

### Changed
- Quitting DockZ (menu bar Quit, ⌘Q, the Dock, or logout) now shows a "Shutting down
DockZ…" window listing the Docker engine and Linux machines being stopped, with a check
as each one finishes, instead of seeming frozen for the seconds a clean VM shutdown takes.

- Monitor's disk card shows space used against the disk limit (orange from 80%, red from
95%) instead of against the filesystem size, with how much space is free on the Mac.
Settings shows the Mac's free space too.

### Fixed
- The disk limit is now enforced when it is lowered. Before, the VM disk only ever grew, so
a disk created at 64 GB kept using up to 64 GB after the limit was set to 16 GB. Apply &
Restart now stops Docker, shrinks the disk offline to the new limit and starts Docker
again. A safety copy is kept until the shrink succeeds. If the data does not fit, the
disk is left as it is and the message says which limit would fit. `DockZ shrink-disk`
does the same from the terminal while DockZ is closed.
- `docker run` (without `-d`), `docker exec` and other attached commands lost any output
printed more than half a second after they started: `sh -c 'echo start; sleep 3; echo
end'` showed only "start". The VM's socket relay closed the stream half a second after
the docker CLI finished sending input. Existing VMs get the fix at their next start: DockZ
now brings the VM's own DockZ service files up to date with the app on every boot (boot
files excluded), so later fixes to them reach existing disks too.
- Opening DockZ while its menu bar icon is hidden (a crowded menu bar or the notch) did
nothing, so the app looked frozen. Opening it again from Finder, Spotlight or Launchpad
now always shows the dashboard (restoring it if minimised), and a launch you start
yourself opens it too; only Launch at Login still starts quietly in the menu bar.

## [0.2.2] - 2026-10-07

### Added
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ Settings):

| File / dir | Purpose |
| -------------- | -------------------------------------------------------------- |
| `disk.img` | VM disk (sparse; grows up to the configured disk limit) |
| `disk.img` | VM disk (sparse; sized to the disk limit — lowering the limit shrinks it on Apply & Restart, or with `DockZ shrink-disk` while DockZ is closed) |
| `docker.sock` | Host-side Docker socket (bridged to the guest over vsock) |
| `console.log` | Guest serial console — first stop for boot debugging |
| `host.log` | Host-side VM lifecycle log (state changes, stop/poweroff path) |
Expand Down
2 changes: 1 addition & 1 deletion README.vi.md
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ Settings):

| Tệp / thư mục | Mục đích |
| -------------- | -------------------------------------------------------------- |
| `disk.img` | Ổ đĩa VM (sparse; tăng dần tới giới hạn dung lượng đĩa đã cấu hình) |
| `disk.img` | Ổ đĩa VM (sparse; đúng bằng giới hạn dung lượng — hạ giới hạn thì Apply & Restart sẽ thu nhỏ đĩa, hoặc chạy `DockZ shrink-disk` khi DockZ đang tắt) |
| `docker.sock` | Docker socket phía host (bắc cầu tới guest qua vsock) |
| `console.log` | Serial console của guest — nơi đầu tiên cần xem khi debug quá trình boot |
| `host.log` | Log vòng đời VM phía host (đổi trạng thái, đường stop/poweroff) |
Expand Down
16 changes: 12 additions & 4 deletions guest/rootfs/etc/init.d/dockz-agent
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,32 @@ depend() {
use net docker
}

# socat ends a connection 0.5 s (its default -t) after either side half-closes.
# The docker CLI half-closes its side of a hijacked stream right after
# attaching (`docker run` without -i), so output arriving later was dropped:
# `sh -c 'echo start; sleep 3; echo end'` printed only "start". Keep the other
# direction open until it ends by itself. 2147483 s (~24 days) is the largest
# value whose milliseconds still fit a 32-bit int in socat's poll timeout.
RELAY_OPTS="-t 2147483"

start() {
ebegin "Starting dockz vsock agents"
modprobe virtio_vsock 2>/dev/null || true
start-stop-daemon --start --background --make-pidfile \
--pidfile /run/dockz-proxy.pid \
--exec /usr/bin/socat -- \
--exec /usr/bin/socat -- $RELAY_OPTS \
VSOCK-LISTEN:2375,reuseaddr,fork UNIX-CONNECT:/var/run/docker.sock
start-stop-daemon --start --background --make-pidfile \
--pidfile /run/dockz-ip.pid \
--exec /usr/bin/socat -- \
--exec /usr/bin/socat -- $RELAY_OPTS \
VSOCK-LISTEN:2376,reuseaddr,fork EXEC:/usr/local/bin/dockz-print-ip
start-stop-daemon --start --background --make-pidfile \
--pidfile /run/dockz-power.pid \
--exec /usr/bin/socat -- \
--exec /usr/bin/socat -- $RELAY_OPTS \
VSOCK-LISTEN:2377,reuseaddr,fork EXEC:/usr/local/bin/dockz-poweroff
start-stop-daemon --start --background --make-pidfile \
--pidfile /run/dockz-shell.pid \
--exec /usr/bin/socat -- \
--exec /usr/bin/socat -- $RELAY_OPTS \
VSOCK-LISTEN:2378,reuseaddr,fork EXEC:'/bin/sh -i',stderr
eend $?
}
Expand Down
90 changes: 90 additions & 0 deletions guest/shrink-disk-inside-vm.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#!/bin/sh
# Runs INSIDE the Alpine netboot builder VM, driven over the serial console by
# DiskShrinker (sources/dockz/disk-shrinker.swift). Shrinks an existing DockZ
# disk (GPT: vda1 ESP, vda2 ext4 root — the last partition) so the host can
# truncate the image to TARGET_SECTORS. ext4 can only be shrunk unmounted,
# which is why this runs here and not in the guest itself.
#
# Env: TARGET_SECTORS — new disk size in 512-byte sectors
# HEADROOM_BYTES — free space the shrunk filesystem must still have
#
# Markers for the host (one line each):
# DOCKZ-SHRINK-STEP:<label>
# DOCKZ-SHRINK-TOOSMALL:<minimum filesystem bytes>
# DOCKZ-SHRINK-FAIL:<reason>
# DOCKZ-SHRINK-DONE
# The host keeps an APFS clone of the image and restores it on anything but
# DONE, so a failure at any point leaves the original disk untouched.
set -u

TARGET_SECTORS="${TARGET_SECTORS:?TARGET_SECTORS must be set}"
HEADROOM_BYTES="${HEADROOM_BYTES:?HEADROOM_BYTES must be set}"

fail() { echo "DOCKZ-SHRINK-FAIL:$1"; sync; poweroff; exit 1; }
step() { echo "DOCKZ-SHRINK-STEP:$1"; }

step "installing filesystem tools"
apk add e2fsprogs e2fsprogs-extra sfdisk >/dev/null || fail "could not install e2fsprogs/sfdisk (no network?)"
modprobe ext4 2>/dev/null || true
mdev -s 2>/dev/null || true

[ -b /dev/vda2 ] || fail "the disk has no root partition (vda2)"
DISK_SECTORS=$(cat /sys/block/vda/size)
P2_START=$(cat /sys/block/vda/vda2/start)
[ "$TARGET_SECTORS" -lt "$DISK_SECTORS" ] || fail "target is not smaller than the disk"

# Root ends 1 MiB-aligned, before the 33 sectors of the GPT backup (header +
# 32 sectors of entries) at the very end of the new disk.
P2_SECTORS=$(( (TARGET_SECTORS - 34 - P2_START) / 2048 * 2048 ))
[ "$P2_SECTORS" -gt 0 ] || fail "target is smaller than the boot partition"

step "checking the filesystem"
e2fsck -f -y /dev/vda2
[ $? -lt 4 ] || fail "e2fsck found errors it could not fix"

BLOCK_SIZE=$(dumpe2fs -h /dev/vda2 2>/dev/null | sed -n 's/^Block size: *//p')
MIN_BLOCKS=$(resize2fs -P /dev/vda2 2>/dev/null | sed -n 's/.*: *//p' | tail -n1)
[ -n "$BLOCK_SIZE" ] && [ -n "$MIN_BLOCKS" ] || fail "could not read the filesystem size"
MIN_BYTES=$(( MIN_BLOCKS * BLOCK_SIZE ))
if [ $(( MIN_BYTES + HEADROOM_BYTES )) -gt $(( P2_SECTORS * 512 )) ]; then
echo "DOCKZ-SHRINK-TOOSMALL:$MIN_BYTES"
sync; poweroff; exit 1
fi

step "shrinking the filesystem"
resize2fs /dev/vda2 "${P2_SECTORS}s" || fail "resize2fs could not shrink the filesystem"

# A GPT names its own end (last usable LBA, backup location), so it must be
# rewritten for the smaller disk. Build it with sfdisk on a sparse file of the
# new size (same label id, partitions, UUIDs and names; root shortened), then
# copy its primary (sectors 0-33) and backup (last 33 sectors) onto the disk at
# the places they will occupy once the host truncates the image.
step "rewriting the partition table"
sfdisk --dump /dev/vda > /tmp/table.old || fail "could not read the partition table"
grep -v -e '^device:' -e '^last-lba:' /tmp/table.old \
| sed 's#^/dev/vda[0-9]* *: *##' \
| awk -v start="$P2_START" -v size="$P2_SECTORS" '
/^start=/ && $0 ~ ("^start= *" start ",") { sub(/size= *[0-9]+/, "size=" size) }
{ print }' > /tmp/table.new
grep -q "size=$P2_SECTORS," /tmp/table.new || fail "could not prepare the new partition table"
rm -f /tmp/gpt.img
truncate -s $(( TARGET_SECTORS * 512 )) /tmp/gpt.img
sfdisk --no-reread --no-tell-kernel /tmp/gpt.img < /tmp/table.new >/dev/null \
|| fail "sfdisk rejected the new partition table"
dd if=/tmp/gpt.img of=/dev/vda bs=512 count=34 conv=notrunc 2>/dev/null \
|| fail "could not write the primary partition table"
dd if=/tmp/gpt.img of=/dev/vda bs=512 skip=$(( TARGET_SECTORS - 33 )) \
seek=$(( TARGET_SECTORS - 33 )) count=33 conv=notrunc 2>/dev/null \
|| fail "could not write the backup partition table"
sync

step "verifying"
# Full output goes to the console (builder/shrink.log): a failure here must
# leave the evidence behind, not just the verdict.
e2fsck -f -n /dev/vda2 > /tmp/verify.log 2>&1
rc=$?
tail -n 60 /tmp/verify.log
[ "$rc" -eq 0 ] || fail "the shrunk filesystem did not check clean (e2fsck exit $rc)"
echo "DOCKZ-SHRINK-DONE"
sync
poweroff
Loading
Loading