From 6a8cd101b2e81e0478fb0fe6659759bad470e213 Mon Sep 17 00:00:00 2001 From: Daniel Verkamp Date: Wed, 26 Jun 2019 15:17:46 -0700 Subject: main: add --rwroot option to run This allows specifying a read-write rootfs (rather than read-only as with --root), including the automatic kernel command line additions normally added by --root. BUG=None TEST=Boot crosvm with --rwroot and write to root filesystem Change-Id: I6a3dc9176bffdefe664139cb33bf3e65a751dbf2 Signed-off-by: Daniel Verkamp Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1679531 Reviewed-by: Zach Reizner Tested-by: kokoro --- src/main.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index 64001a4..ee02b57 100644 --- a/src/main.rs +++ b/src/main.rs @@ -418,7 +418,8 @@ fn set_argument(cfg: &mut Config, name: &str, value: Option<&str>) -> argument:: syslog::set_proc_name(value.unwrap()); cfg.syslog_tag = Some(value.unwrap().to_owned()); } - "root" | "disk" | "rwdisk" | "qcow" | "rwqcow" => { + "root" | "rwroot" | "disk" | "rwdisk" | "qcow" | "rwqcow" => { + let read_only = !name.starts_with("rw"); let disk_path = PathBuf::from(value.unwrap()); if !disk_path.exists() { return Err(argument::Error::InvalidValue { @@ -426,20 +427,21 @@ fn set_argument(cfg: &mut Config, name: &str, value: Option<&str>) -> argument:: expected: "this disk path does not exist", }); } - if name == "root" { + if name.ends_with("root") { if cfg.disks.len() >= 26 { return Err(argument::Error::TooManyArguments( "ran out of letters for to assign to root disk".to_owned(), )); } cfg.params.push(format!( - "root=/dev/vd{} ro", - char::from(b'a' + cfg.disks.len() as u8) + "root=/dev/vd{} {}", + char::from(b'a' + cfg.disks.len() as u8), + if read_only { "ro" } else { "rw" } )); } cfg.disks.push(DiskOption { path: disk_path, - read_only: !name.starts_with("rw"), + read_only, }); } "pmem-device" | "rw-pmem-device" => { @@ -817,6 +819,7 @@ fn run_vm(args: std::env::Args) -> std::result::Result<(), ()> { "root", "PATH", "Path to a root disk image. Like `--disk` but adds appropriate kernel command line option."), + Argument::value("rwroot", "PATH", "Path to a writable root disk image."), Argument::short_value('d', "disk", "PATH", "Path to a disk image."), Argument::value("qcow", "PATH", "Path to a qcow2 disk image. (Deprecated; use --disk instead.)"), Argument::value("rwdisk", "PATH", "Path to a writable disk image."), -- cgit 1.4.1