[tip:tools/kvm] kvm tools: Use '-d' to boot a directory as a rootfs

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Commit-ID:  b20c8eb770ea2e63f29b38aa8f3cf77d0ccfd79a
Gitweb:     http://git.kernel.org/tip/b20c8eb770ea2e63f29b38aa8f3cf77d0ccfd79a
Author:     Sasha Levin <levinsasha928@xxxxxxxxx>
AuthorDate: Fri, 5 Aug 2011 16:43:13 +0300
Committer:  Pekka Enberg <penberg@xxxxxxxxxx>
CommitDate: Sun, 7 Aug 2011 21:00:18 +0300

kvm tools: Use '-d' to boot a directory as a rootfs

Pointing to a directory when specifying an image ('-d') will attempt to boot
the directory as if it was a root device using virtio-9p.

Tested-by: Asias He <asias.hejun@xxxxxxxxx>
Signed-off-by: Sasha Levin <levinsasha928@xxxxxxxxx>
Signed-off-by: Pekka Enberg <penberg@xxxxxxxxxx>
---
 tools/kvm/builtin-run.c |   18 +++++++++++++++++-
 1 files changed, 17 insertions(+), 1 deletions(-)

diff --git a/tools/kvm/builtin-run.c b/tools/kvm/builtin-run.c
index 2e04265..67ab43e 100644
--- a/tools/kvm/builtin-run.c
+++ b/tools/kvm/builtin-run.c
@@ -81,6 +81,7 @@ static bool readonly_image[MAX_DISK_IMAGES];
 static bool vnc;
 static bool sdl;
 static bool balloon;
+static bool using_rootfs;
 extern bool ioport_debug;
 extern int  active_console;
 extern int  debug_iodelay;
@@ -98,6 +99,18 @@ static const char * const run_usage[] = {
 static int img_name_parser(const struct option *opt, const char *arg, int unset)
 {
 	char *sep;
+	struct stat st;
+
+	if (stat(arg, &st) == 0 &&
+	    S_ISDIR(st.st_mode)) {
+		char tmp[PATH_MAX];
+
+		if (realpath(arg, tmp) == 0 ||
+		    virtio_9p__init(kvm, tmp, "/dev/root") < 0)
+			die("Unable to initialize virtio 9p");
+		using_rootfs = 1;
+		return 0;
+	}
 
 	if (image_count >= MAX_DISK_IMAGES)
 		die("Currently only 4 images are supported");
@@ -615,7 +628,7 @@ int kvm_cmd_run(int argc, const char **argv, const char *prefix)
 		strlcat(real_cmdline, kernel_cmdline, sizeof(real_cmdline));
 
 	hi = NULL;
-	if (!image_filename[0]) {
+	if (!using_rootfs && !image_filename[0]) {
 		hi = host_image(real_cmdline, sizeof(real_cmdline));
 		if (hi) {
 			image_filename[0] = hi;
@@ -627,6 +640,9 @@ int kvm_cmd_run(int argc, const char **argv, const char *prefix)
 	if (!strstr(real_cmdline, "root="))
 		strlcat(real_cmdline, " root=/dev/vda rw ", sizeof(real_cmdline));
 
+	if (using_rootfs)
+		strcat(real_cmdline, " root=/dev/root rootflags=rw,trans=virtio,version=9p2000.u rootfstype=9p");
+
 	if (image_count) {
 		kvm->nr_disks = image_count;
 		kvm->disks    = disk_image__open_all(image_filename, readonly_image, image_count);
--
To unsubscribe from this list: send the line "unsubscribe linux-tip-commits" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Stable Commits]     [Linux Stable Kernel]     [Linux Kernel]     [Linux USB Devel]     [Linux Video &Media]     [Linux Audio Users]     [Yosemite News]     [Linux SCSI]

  Powered by Linux