kvm tools: Modify 'kvm run' to use virt fs
PATCH 1/2 kvm tools: Modify 'kvm run' to use virt fs
'kvm run' will now create a 'default' profile and boot into it.
Currently we boot into rw rootfs of the host, which is risky. Instead, we can boot in a 'safe' enviroment with networking.
Signed-off-by Sasha Levin <[email protected]>
--- tools/kvm/builtin-run.c | 13 ++++++++++--- tools/kvm/builtin-setup.c | 13 ++++++++++--- tools/kvm/include/kvm/builtin-setup.h | 1 + 3 files changed, 21 insertions(+), 6 deletions(-)
tools/kvm/builtin-run.c +10 -3
@@ -1,5 +1,6 @@#include "kvm/builtin-run.h" +#include "kvm/builtin-setup.h" #include "kvm/virtio-balloon.h" #include "kvm/virtio-console.h" #include "kvm/parse-options.h"
@@ -747,10 +748,16 @@ int kvm_cmd_run(int argc, const char **argv, const char *prefix)strlcat (real_cmdline, kernel_cmdline,sizeof (real_cmdline));if (!using_rootfs && !image_filename[0 ]) { -if (virtio_9p__register (kvm,"/" ,"/dev/root" ) <0 ) -die ("Unable to initialize virtio 9p" ); +char tmp[PATH_MAX ]; - using_rootfs =1 ; +kvm_setup_create_new ("default" ); + +snprintf (tmp,PATH_MAX ,"%s%s%s" ,HOME_DIR ,KVM_PID_FILE_PATH ,"default" ); +if (virtio_9p__register (kvm, tmp,"/dev/root" ) <0 ) +die ("Unable to initialize virtio 9p" ); +if (virtio_9p__register (kvm,"/" ,"hostfs" ) <0 ) +die ("Unable to initialize virtio 9p" ); + using_rootfs = custom_rootfs =1 ;if (!strstr (real_cmdline,"init=" ))strlcat (real_cmdline," init=/bin/sh " ,sizeof (real_cmdline));
tools/kvm/builtin-setup.c +10 -3
@@ -159,13 +159,13 @@ static void make_root_dir(void)mkdir (name,0777 ); } -static void make_dir (const char *dir) +static int make_dir (const char *dir) {char name[PATH_MAX ];snprintf (name,PATH_MAX ,"%s%s%s" ,HOME_DIR ,KVM_PID_FILE_PATH , dir); -mkdir (name,0777 ); +return mkdir (name,0777 ); }static void make_guestfs_dir (const char *guestfs_name,const char *dir)
@@ -184,7 +184,9 @@ static int do_setup(const char *guestfs_name)make_root_dir (); -make_dir (guestfs_name); + ret =make_dir (guestfs_name); +if (ret <0 ) +return ret;for (i =0 ; i <ARRAY_SIZE (guestfs_dirs); i++)make_guestfs_dir (guestfs_name, guestfs_dirs[i]);
@@ -200,6 +202,11 @@ static int do_setup(const char *guestfs_name)return copy_init (guestfs_name); } +int kvm_setup_create_new (const char *guestfs_name) +{ +return do_setup (guestfs_name); +} +int kvm_cmd_setup (int argc,const char **argv,const char *prefix) {parse_setup_options (argc, argv);
tools/kvm/include/kvm/builtin-setup.h +1 -0
@@ -3,5 +3,6 @@int kvm_cmd_setup (int argc,const char **argv,const char *prefix);void kvm_setup_help (void ); +int kvm_setup_create_new (const char *guestfs_name);#endif
Signature · 1 line
1.7.6.1
PATCH 2/2 kvm tools: Fix compat message formatting
Signed-off-by Sasha Levin <[email protected]>
--- tools/kvm/virtio/9p.c | 2 +- tools/kvm/virtio/balloon.c | 2 +- tools/kvm/virtio/blk.c | 2 +- tools/kvm/virtio/console.c | 2 +- tools/kvm/virtio/net.c | 2 +- tools/kvm/virtio/rng.c | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-)
tools/kvm/virtio/9p.c +1 -1
@@ -1250,7 +1250,7 @@ int virtio_9p__register(struct kvm *kvm, const char *root, const char *tag_name) p9dev->compat_id =compat__add_message ("virtio-9p device was not detected" ,"While you have requested a virtio-9p device, " "the guest kernel didn't seem to detect it.\n" -"Please make sure that the kernel was compiled" +"Please make sure that the kernel was compiled " "with CONFIG_NET_9P_VIRTIO." );return err;
tools/kvm/virtio/balloon.c +1 -1
@@ -283,6 +283,6 @@ void virtio_bln__init(struct kvm *kvm) bdev.compat_id =compat__add_message ("virtio-balloon device was not detected" ,"While you have requested a virtio-balloon device, " "the guest kernel didn't seem to detect it.\n" -"Please make sure that the kernel was compiled" +"Please make sure that the kernel was compiled " "with CONFIG_VIRTIO_BALLOON." ); }
tools/kvm/virtio/blk.c +1 -1
@@ -223,7 +223,7 @@ void virtio_blk__init(struct kvm *kvm, struct disk_image *disk) bdev->compat_id =compat__add_message ("virtio-blk device was not detected" ,"While you have requested a virtio-blk device, " "the guest kernel didn't seem to detect it.\n" -"Please make sure that the kernel was compiled" +"Please make sure that the kernel was compiled " "with CONFIG_VIRTIO_BLK." ); }
tools/kvm/virtio/console.c +1 -1
@@ -191,6 +191,6 @@ void virtio_console__init(struct kvm *kvm) cdev.compat_id =compat__add_message ("virtio-console device was not detected" ,"While you have requested a virtio-console device, " "the guest kernel didn't seem to detect it.\n" -"Please make sure that the kernel was compiled" +"Please make sure that the kernel was compiled " "with CONFIG_VIRTIO_CONSOLE." ); }
tools/kvm/virtio/net.c +1 -1
@@ -401,6 +401,6 @@ void virtio_net__init(const struct virtio_net_parameters *params) ndev.compat_id =compat__add_message ("virtio-net device was not detected" ,"While you have requested a virtio-net device, " "the guest kernel didn't seem to detect it.\n" -"Please make sure that the kernel was compiled" +"Please make sure that the kernel was compiled " "with CONFIG_VIRTIO_NET." ); }
tools/kvm/virtio/rng.c +1 -1
@@ -167,7 +167,7 @@ void virtio_rng__init(struct kvm *kvm) rdev->compat_id =compat__add_message ("virtio-rng device was not detected" ,"While you have requested a virtio-rng device, " "the guest kernel didn't seem to detect it.\n" -"Please make sure that the kernel was compiled" +"Please make sure that the kernel was compiled " "with CONFIG_HW_RANDOM_VIRTIO." ); }
Signature · 1 line
1.7.6.1