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 <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1679531
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
This commit is contained in:
Daniel Verkamp 2019-06-26 15:17:46 -07:00 committed by Commit Bot
parent 06944ec625
commit 6a8cd101b2

View file

@ -418,7 +418,8 @@ fn set_argument(cfg: &mut Config, name: &str, value: Option<&str>) -> argument::
syslog::set_proc_name(value.unwrap()); syslog::set_proc_name(value.unwrap());
cfg.syslog_tag = Some(value.unwrap().to_owned()); 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()); let disk_path = PathBuf::from(value.unwrap());
if !disk_path.exists() { if !disk_path.exists() {
return Err(argument::Error::InvalidValue { 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", expected: "this disk path does not exist",
}); });
} }
if name == "root" { if name.ends_with("root") {
if cfg.disks.len() >= 26 { if cfg.disks.len() >= 26 {
return Err(argument::Error::TooManyArguments( return Err(argument::Error::TooManyArguments(
"ran out of letters for to assign to root disk".to_owned(), "ran out of letters for to assign to root disk".to_owned(),
)); ));
} }
cfg.params.push(format!( cfg.params.push(format!(
"root=/dev/vd{} ro", "root=/dev/vd{} {}",
char::from(b'a' + cfg.disks.len() as u8) char::from(b'a' + cfg.disks.len() as u8),
if read_only { "ro" } else { "rw" }
)); ));
} }
cfg.disks.push(DiskOption { cfg.disks.push(DiskOption {
path: disk_path, path: disk_path,
read_only: !name.starts_with("rw"), read_only,
}); });
} }
"pmem-device" | "rw-pmem-device" => { "pmem-device" | "rw-pmem-device" => {
@ -817,6 +819,7 @@ fn run_vm(args: std::env::Args) -> std::result::Result<(), ()> {
"root", "root",
"PATH", "PATH",
"Path to a root disk image. Like `--disk` but adds appropriate kernel command line option."), "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::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("qcow", "PATH", "Path to a qcow2 disk image. (Deprecated; use --disk instead.)"),
Argument::value("rwdisk", "PATH", "Path to a writable disk image."), Argument::value("rwdisk", "PATH", "Path to a writable disk image."),