Skip to content

Commit 4101b26

Browse files
committed
vume:base property to track full snapshot name
1 parent ad2791f commit 4101b26

File tree

3 files changed

+14
-23
lines changed

3 files changed

+14
-23
lines changed

README.md

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -151,20 +151,18 @@ vume <command> --help
151151

152152
## Customizing the rootfs
153153

154-
You can create a custom base image from a running VM. The active rootfs version is tracked
155-
via the `vume:latest` ZFS user property on `vume/rootfs`, so you can create new versions without
156-
affecting existing VMs.
154+
You can create a custom base image from a running VM. The active rootfs snapshot is tracked
155+
via the `vume:base` ZFS user property on the pool, which stores the full snapshot path.
157156

158157
```bash
159158
# 1. Customize a running VM, e.g.
160159
sudo vume exec <vm-id> "apt install -y python3 nginx"
161160

162-
# 2. Snapshot the customized VM and create a new rootfs version
161+
# 2. Snapshot the customized VM
163162
sudo zfs snapshot vume/<vm-id>@<version>
164-
sudo zfs send vume/<vm-id>@<version> | sudo zfs receive vume/rootfs@<version>
165163

166-
# 3. Point to the new version
167-
sudo zfs set vume:latest=<version> vume/rootfs
164+
# 3. Point to the new snapshot
165+
sudo zfs set vume:base=vume/<vm-id>@<version> vume
168166
```
169167

170-
All future VMs will clone from the new version. Existing VMs are unaffected.
168+
All future VMs will clone from the new snapshot. Existing VMs are unaffected.

src/vm.rs

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -161,26 +161,19 @@ impl VM {
161161
fn resolve_rootfs_snapshot() -> Result<String> {
162162
let pool = &get().zfs_pool;
163163
let output = Command::new("zfs")
164-
.args([
165-
"get",
166-
"-H",
167-
"-o",
168-
"value",
169-
"vume:latest",
170-
&format!("{}/rootfs", pool),
171-
])
164+
.args(["get", "-H", "-o", "value", "vume:base", pool])
172165
.output()
173166
.context("Failed to run zfs get")?;
174167

175168
if !output.status.success() {
176169
bail!("zfs get failed");
177170
}
178171

179-
let version = String::from_utf8_lossy(&output.stdout).trim().to_string();
180-
if version.is_empty() || version == "-" {
181-
bail!("vume:latest property not set on {}/rootfs", pool);
172+
let snapshot = String::from_utf8_lossy(&output.stdout).trim().to_string();
173+
if snapshot.is_empty() || snapshot == "-" {
174+
bail!("vume:base property not set on {}", pool);
182175
}
183-
Ok(format!("{}/rootfs@{}", pool, version))
176+
Ok(snapshot)
184177
}
185178

186179
/// Remove a VM's filesystem, ZFS dataset, and state record.

vume.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
1818

1919
POOL_DEVICE=""
2020
ROOTFS_PATH=""
21-
ROOTFS_SIZE="2G"
22-
ZVOL_SIZE="2G"
21+
ROOTFS_SIZE="10G"
22+
ZVOL_SIZE="10G"
2323
SSH_KEY=""
2424
POOL_NAME=""
2525

@@ -163,7 +163,7 @@ cmd_setup() {
163163
else
164164
echo ":: creating snapshot '${POOL_NAME}/rootfs@base'"
165165
zfs snapshot "${POOL_NAME}/rootfs@base"
166-
zfs set vume:latest=base "${POOL_NAME}/rootfs"
166+
zfs set vume:base=${POOL_NAME}/rootfs@base "${POOL_NAME}"
167167
fi
168168

169169
echo ""

0 commit comments

Comments
 (0)