Fix two disk-setup bugs: byte/gigabyte size mix-up, wrong ownership
1. truncate -s treats a bare number as bytes, not gigabytes - typing "50" at the size prompt (instead of "50G") silently made a 50-byte file, which then failed mkfs.ext4 with "Device size reported to be zero." Added normalize-size: a bare integer answer now gets a "G" suffix appended (matching what the prompts' own defaults imply), anything with an existing suffix passes through unchanged. 2. Every disk-creation step runs through `priv` (sudo/root), so subvolumes and disk images always ended up root-owned - but hermes-vm.service runs as the unprivileged hermes-vm account, which only had read access via the "other" bits. QEMU failed to open system.raw for read-write. Added explicit `chown hermes-vm:hermes-vm` after every creation point (both make-subvol branches, and after each truncate/mkfs) - also self-heals already-existing wrongly-owned disks on a re-run, not just fresh ones. Both confirmed live on hl-fwdesk during tonight's incident. Verified with a unit test of normalize-size and a full sandboxed interactive dry run of `setup` (fake sudo/btrfs/truncate/chown/mkfs.ext4) showing the correct truncate -> chown ordering for both disks. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
1239ea0148
commit
5ea64e88d5
2 files changed
+21
-8
No files matched your search
@@ -806,12 +806,6 @@ in
|
||||
};
|
||||
};
|
||||
|
||||
# =====================================================================
|
||||
# Host GC is now safe: the guest has its own store and shares nothing.
|
||||
# =====================================================================
|
||||
nix.gc.automatic = lib.mkDefault true;
|
||||
nix.gc.options = lib.mkDefault "--delete-older-than 30d";
|
||||
|
||||
environment.systemPackages = [
|
||||
(pkgs.writeShellScriptBin "hermes-vm" ''
|
||||
set -euo pipefail
|
||||
|
||||
+21
-2
@@ -51,6 +51,19 @@ def shquote [s: string] {
|
||||
"'" + ($s | str replace --all "'" "'\\''") + "'"
|
||||
}
|
||||
|
||||
# `truncate -s` treats a bare number as bytes, not gigabytes - the size
|
||||
# prompts' own defaults ("80G", "20G") make gigabytes the obvious intent, so
|
||||
# normalize a bare integer answer to that rather than silently creating a
|
||||
# byte-sized disk. Anything with an existing suffix passes through as-is.
|
||||
def normalize-size [s: string] {
|
||||
try {
|
||||
let n = ($s | into int)
|
||||
$"($n)G"
|
||||
} catch {
|
||||
$s
|
||||
}
|
||||
}
|
||||
|
||||
# Run a command, sudo-prefixed unless already root (set once via
|
||||
# $env.HERMENIX_NEED_SUDO at the top of `main setup`). Fails loudly, like any
|
||||
# other external command, if the command fails.
|
||||
@@ -149,9 +162,11 @@ def "main setup" [
|
||||
priv btrfs subvolume create $path | ignore
|
||||
priv chattr +C $path
|
||||
do -i { priv btrfs property set $path compression none } | complete | ignore
|
||||
priv chown "hermes-vm:hermes-vm" $path
|
||||
ok $"subvolume ($path) \(nodatacow\)"
|
||||
} else {
|
||||
priv mkdir "-p" $path
|
||||
priv chown "hermes-vm:hermes-vm" $path
|
||||
}
|
||||
}
|
||||
make-subvol $"($base)/system" $use_btrfs
|
||||
@@ -164,10 +179,12 @@ def "main setup" [
|
||||
let system_existed = ((priv-out test "-f" $system_img).exit_code == 0)
|
||||
if $system_existed {
|
||||
let sz = ((priv-out du "-h" "--apparent-size" $system_img).stdout | str trim | split column "\t" | get column0.0)
|
||||
priv chown "hermes-vm:hermes-vm" $system_img
|
||||
ok $"system disk exists \(($sz)\)"
|
||||
} else {
|
||||
let syssize = ask "System disk size" "80G"
|
||||
let syssize = (normalize-size (ask "System disk size" "80G"))
|
||||
priv truncate "-s" $syssize $system_img
|
||||
priv chown "hermes-vm:hermes-vm" $system_img
|
||||
if $use_btrfs {
|
||||
let attrs = (priv-out lsattr "-l" $system_img).stdout
|
||||
if ($attrs | str contains "No_COW") {
|
||||
@@ -182,11 +199,13 @@ def "main setup" [
|
||||
|
||||
if (priv-out test "-f" $state_img).exit_code == 0 {
|
||||
let sz = ((priv-out du "-h" "--apparent-size" $state_img).stdout | str trim | split column "\t" | get column0.0)
|
||||
priv chown "hermes-vm:hermes-vm" $state_img
|
||||
ok $"state disk exists \(($sz)\)"
|
||||
} else {
|
||||
let statesize = ask "State disk size" "20G"
|
||||
let statesize = (normalize-size (ask "State disk size" "20G"))
|
||||
priv truncate "-s" $statesize $state_img
|
||||
priv mkfs.ext4 "-q" "-L" hermes-state $state_img
|
||||
priv chown "hermes-vm:hermes-vm" $state_img
|
||||
ok "state disk created and formatted (label: hermes-state)"
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user