on main help sign in
feat: added disk support
commit727adffb4cf542faf2b10d18dcb2a473a5433c4e authorrobcholz <84130577+robcholz@users.noreply.github.com> dateSat 7 Feb 2026, 23:05 (8 months ago) parent75adb16
8 files changed+129−9
src/bin/vibebox-supervisor.rs+1 src/bin/vibebox.rs+3 src/config.rs+12−1 src/provision.sh+1 src/resize_disk.sh+55 src/tui.rs+4−3 src/vm.rs+52−5 vibebox.toml+1
src/bin/vibebox-supervisor.rs+1
@@ -29,6 +29,7 @@ fn main() -> Result<()> {
2929 let args = vm::VmArg {
3030 cpu_count: config.box_cfg.cpu_count,
3131 ram_bytes: config.box_cfg.ram_mb.saturating_mul(1024 * 1024),
32+ disk_bytes: config.box_cfg.disk_gb.saturating_mul(1024 * 1024 * 1024),
3233 no_default_mounts: false,
3334 mounts: config.box_cfg.mounts.clone(),
3435 };
src/bin/vibebox.rs+3
@@ -63,6 +63,7 @@ fn main() -> Result<()> {
6363 let args = vm::VmArg {
6464 cpu_count: config.box_cfg.cpu_count,
6565 ram_bytes: config.box_cfg.ram_mb.saturating_mul(1024 * 1024),
66+ disk_bytes: config.box_cfg.disk_gb.saturating_mul(1024 * 1024 * 1024),
6667 no_default_mounts: false,
6768 mounts: config.box_cfg.mounts.clone(),
6869 };
@@ -80,6 +81,7 @@ fn main() -> Result<()> {
8081 let vm_args = vm::VmArg {
8182 cpu_count: config.box_cfg.cpu_count,
8283 ram_bytes: config.box_cfg.ram_mb.saturating_mul(1024 * 1024),
84+ disk_bytes: config.box_cfg.disk_gb.saturating_mul(1024 * 1024 * 1024),
8385 no_default_mounts: false,
8486 mounts: config.box_cfg.mounts.clone(),
8587 };
@@ -88,6 +90,7 @@ fn main() -> Result<()> {
8890 let vm_info = VmInfo {
8991 max_memory_mb: vm_args.ram_bytes / (1024 * 1024),
9092 cpu_cores: vm_args.cpu_count,
93+ max_disk_gb: (vm_args.disk_bytes as f32) / 1024.0 / 1024.0 / 1024.0,
9194 system_name: "Debian".to_string(), // TODO: read system name from the VM.
9295 auto_shutdown_ms,
9396 };
src/config.rs+12−1
@@ -13,6 +13,7 @@ pub const CONFIG_PATH_ENV: &str = "VIBEBOX_CONFIG_PATH";
1313const DEFAULT_CPU_COUNT: usize = 2;
1414const DEFAULT_RAM_MB: u64 = 2048;
1515const DEFAULT_AUTO_SHUTDOWN_MS: u64 = 20000;
16+const DEFAULT_DISK_GB: u64 = 5;
1617
1718#[derive(Debug, Clone, Default, Serialize, Deserialize)]
1819pub struct Config {
@@ -25,6 +26,7 @@ pub struct Config {
2526pub struct BoxConfig {
2627 pub cpu_count: usize,
2728 pub ram_mb: u64,
29+ pub disk_gb: u64,
2830 pub mounts: Vec<String>,
2931}
3032
@@ -33,6 +35,7 @@ impl Default for BoxConfig {
3335 Self {
3436 cpu_count: default_cpu_count(),
3537 ram_mb: default_ram_mb(),
38+ disk_gb: default_disk_gb(),
3639 mounts: default_mounts(),
3740 }
3841 }
@@ -67,6 +70,10 @@ fn default_mounts() -> Vec<String> {
6770 Vec::new()
6871}
6972
73+fn default_disk_gb() -> u64 {
74+ DEFAULT_DISK_GB
75+}
76+
7077pub fn config_path(project_root: &Path) -> PathBuf {
7178 project_root.join(CONFIG_FILENAME)
7279}
@@ -102,7 +109,7 @@ pub fn load_config_with_path(project_root: &Path, override_path: Option<&Path>)
102109 tracing::debug!(path = %path.display(), bytes = raw.len(), "loaded vibebox config");
103110 if trimmed.is_empty() {
104111 die(&format!(
105− "config file ({}) is empty. Required fields: [box].cpu_count (integer), [box].ram_mb (integer), [box].mounts (array of strings), [supervisor].auto_shutdown_ms (integer)",
112+ "config file ({}) is empty. Required fields: [box].cpu_count (integer), [box].ram_mb (integer), [box].disk_gb (integer), [box].mounts (array of strings), [supervisor].auto_shutdown_ms (integer)",
106113 path.display()
107114 ));
108115 }
@@ -193,6 +200,7 @@ fn validate_schema(value: &toml::Value) -> Vec<String> {
193200 Some(table) => {
194201 validate_int(table, "cpu_count", "[box].cpu_count (integer)", &mut errors);
195202 validate_int(table, "ram_mb", "[box].ram_mb (integer)", &mut errors);
203+ validate_int(table, "disk_gb", "[box].disk_gb (integer)", &mut errors);
196204 validate_string_array(
197205 table,
198206 "mounts",
@@ -259,6 +267,9 @@ fn validate_or_exit(config: &Config) {
259267 if config.box_cfg.ram_mb == 0 {
260268 die("box.ram_mb must be >= 1");
261269 }
270+ if config.box_cfg.disk_gb == 0 {
271+ die("box.disk_gb must be >= 1");
272+ }
262273 if config.supervisor.auto_shutdown_ms == 0 {
263274 die("supervisor.auto_shutdown_ms must be >= 1");
264275 }
src/provision.sh+1
@@ -14,6 +14,7 @@ apt-get install -y --no-install-recommends \
1414 curl \
1515 git \
1616 ripgrep \
17+ cloud-guest-utils \
1718 openssh-server \
1819 sudo
1920
src/resize_disk.shnew file+55
@@ -0,0 +1,55 @@
1+#!/bin/bash
2+set -euo pipefail
3+
4+ROOT_DEV="$(findmnt / -n -o SOURCE || true)"
5+ROOT_FSTYPE="$(findmnt / -n -o FSTYPE || true)"
6+
7+if [ -z "$ROOT_DEV" ]; then
8+ exit 0
9+fi
10+
11+DISK_DEV=""
12+PART_NUM=""
13+
14+if command -v lsblk >/dev/null 2>&1; then
15+ DISK_DEV="$(lsblk -no pkname "$ROOT_DEV" 2>/dev/null | head -n1 || true)"
16+ PART_NUM="$(lsblk -no PARTNUM "$ROOT_DEV" 2>/dev/null | head -n1 || true)"
17+fi
18+
19+if [ -z "$DISK_DEV" ] || [ -z "$PART_NUM" ]; then
20+ ROOT_BASENAME="$(basename "$ROOT_DEV")"
21+ if echo "$ROOT_BASENAME" | grep -Eq '^nvme.+p[0-9]+$'; then
22+ DISK_DEV="/dev/${ROOT_BASENAME%p[0-9]*}"
23+ PART_NUM="${ROOT_BASENAME##*p}"
24+ elif echo "$ROOT_BASENAME" | grep -Eq '^[a-z]+[0-9]+$'; then
25+ DISK_DEV="/dev/${ROOT_BASENAME%%[0-9]*}"
26+ PART_NUM="${ROOT_BASENAME##*[a-z]}"
27+ fi
28+fi
29+
30+if [ -n "$DISK_DEV" ] && [ -n "$PART_NUM" ]; then
31+ if command -v growpart >/dev/null 2>&1; then
32+ growpart "$DISK_DEV" "$PART_NUM" || true
33+ elif command -v sfdisk >/dev/null 2>&1; then
34+ sfdisk -N "$PART_NUM" --force "$DISK_DEV" <<'EOF' || true
35+,,
36+EOF
37+ fi
38+fi
39+
40+if command -v partprobe >/dev/null 2>&1; then
41+ partprobe "$DISK_DEV" || true
42+fi
43+
44+case "$ROOT_FSTYPE" in
45+ ext4|ext3|ext2)
46+ if command -v resize2fs >/dev/null 2>&1; then
47+ resize2fs "$ROOT_DEV" || true
48+ fi
49+ ;;
50+ xfs)
51+ if command -v xfs_growfs >/dev/null 2>&1; then
52+ xfs_growfs / || true
53+ fi
54+ ;;
55+esac
src/tui.rs+4−3
@@ -41,6 +41,7 @@ const INFO_LINE_COUNT: u16 = 5;
4141pub struct VmInfo {
4242 pub max_memory_mb: u64,
4343 pub cpu_cores: usize,
44+ pub max_disk_gb: f32,
4445 pub system_name: String,
4546 pub auto_shutdown_ms: u64,
4647}
@@ -570,11 +571,11 @@ fn render_header(buffer: &mut Buffer, area: Rect, app: &AppState) {
570571 Span::styled(&app.vm_info.system_name, Style::default().fg(Color::Green)),
571572 ]),
572573 Line::from(vec![
573− Span::raw("CPU / Memory: "),
574+ Span::raw("CPU / Memory / Disk: "),
574575 Span::styled(
575576 format!(
576− "{} cores / {} MB",
577− app.vm_info.cpu_cores, app.vm_info.max_memory_mb
577+ "{} cores / {} MB / {} GB",
578+ app.vm_info.cpu_cores, app.vm_info.max_memory_mb, app.vm_info.max_disk_gb
578579 ),
579580 Style::default().fg(Color::Green),
580581 ),
src/vm.rs+52−5
@@ -74,6 +74,7 @@ impl Drop for StatusFile {
7474}
7575const PROVISION_SCRIPT: &str = include_str!("provision.sh");
7676const PROVISION_SCRIPT_NAME: &str = "provision.sh";
77+const RESIZE_DISK_SCRIPT: &str = include_str!("resize_disk.sh");
7778const DEFAULT_RAW_NAME: &str = "default.raw";
7879const INSTANCE_RAW_NAME: &str = "instance.raw";
7980const BASE_DISK_RAW_NAME: &str = "disk.raw";
@@ -166,6 +167,7 @@ fn expand_tilde_path(value: &str) -> PathBuf {
166167pub struct VmArg {
167168 pub cpu_count: usize,
168169 pub ram_bytes: u64,
170+ pub disk_bytes: u64,
169171 pub no_default_mounts: bool,
170172 pub mounts: Vec<String>,
171173}
@@ -230,7 +232,15 @@ where
230232 std::slice::from_ref(&mise_directory_share),
231233 Some(&status_file),
232234 )?;
233− ensure_instance_disk(&instance_raw, &default_raw, Some(&status_file))?;
235+ let _ = ensure_instance_disk(
236+ &instance_raw,
237+ &default_raw,
238+ args.disk_bytes,
239+ Some(&status_file),
240+ )?;
241+ let base_size = fs::metadata(&default_raw)?.len();
242+ let instance_size = fs::metadata(&instance_raw)?.len();
243+ let needs_resize = instance_size > base_size;
234244 let disk_path = instance_raw;
235245
236246 let mut login_actions = Vec::new();
@@ -263,6 +273,11 @@ where
263273 directory_shares.push(DirectoryShare::from_mount_spec(spec)?);
264274 }
265275
276+ if needs_resize {
277+ let resize_cmd = script_command_from_content("resize_disk", RESIZE_DISK_SCRIPT)?;
278+ login_actions.push(Send(resize_cmd));
279+ }
280+
266281 if let Some(motd_action) = motd_login_action(&directory_shares) {
267282 login_actions.push(motd_action);
268283 }
@@ -559,19 +574,51 @@ fn ensure_default_image(
559574fn ensure_instance_disk(
560575 instance_raw: &Path,
561576 template_raw: &Path,
577+ target_bytes: u64,
562578 status: Option<&StatusFile>,
563−) -> Result<(), Box<dyn std::error::Error>> {
579+) -> Result<bool, Box<dyn std::error::Error>> {
564580 if instance_raw.exists() {
565− return Ok(());
581+ let current_size = fs::metadata(instance_raw)?.len();
582+ if current_size != target_bytes {
583+ let current_gb = current_size as f64 / (1024.0 * 1024.0 * 1024.0);
584+ let target_gb = target_bytes as f64 / (1024.0 * 1024.0 * 1024.0);
585+ tracing::warn!(
586+ current_bytes = current_size,
587+ target_bytes,
588+ "instance disk size does not match config (current {:.2} GB, config {:.2} GB); disk_gb applies only on init. Run `vibebox reset` to recreate or set disk_gb to match; using existing disk.",
589+ current_gb,
590+ target_gb
591+ );
592+ }
593+ return Ok(false);
594+ }
595+
596+ let template_size = fs::metadata(template_raw)?.len();
597+ if target_bytes < template_size {
598+ return Err(format!(
599+ "Requested disk size {} bytes is smaller than base image size {} bytes",
600+ target_bytes, template_size
601+ )
602+ .into());
566603 }
604+ let target_size = target_bytes;
605+ let needs_resize = target_size > template_size;
567606
568607 if let Some(status) = status {
569608 status.update("creating instance disk...");
570609 }
571610 tracing::info!(path = %template_raw.display(), "creating instance disk");
572611 std::fs::create_dir_all(instance_raw.parent().unwrap())?;
573− fs::copy(template_raw, instance_raw)?;
574− Ok(())
612+ if target_size == template_size {
613+ fs::copy(template_raw, instance_raw)?;
614+ return Ok(needs_resize);
615+ }
616+
617+ let mut dst = std::fs::File::create(instance_raw)?;
618+ dst.set_len(target_size)?;
619+ let mut src = std::fs::File::open(template_raw)?;
620+ std::io::copy(&mut src, &mut dst)?;
621+ Ok(needs_resize)
575622}
576623
577624pub struct IoContext {
vibebox.toml+1
@@ -1,6 +1,7 @@
11[box]
22cpu_count = 2
33ram_mb = 2048
4+disk_gb = 5
45mounts = [
56 "~/.codex:~/.codex:read-write",
67 "~/.claude:~/.claude:read-write",