@@ -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 {