From patchwork Tue Aug 2 18:46:29 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sasha Levin X-Patchwork-Id: 1029872 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.4) with ESMTP id p72Ilauj025291 for ; Tue, 2 Aug 2011 18:47:37 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754990Ab1HBSr3 (ORCPT ); Tue, 2 Aug 2011 14:47:29 -0400 Received: from mail-ww0-f42.google.com ([74.125.82.42]:56335 "EHLO mail-ww0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754934Ab1HBSr1 (ORCPT ); Tue, 2 Aug 2011 14:47:27 -0400 Received: by mail-ww0-f42.google.com with SMTP id 11so2783318wwg.1 for ; Tue, 02 Aug 2011 11:47:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=//10vBDBAIuPR9muBLmEEYNur9k94xbXuwRqHsEtJeY=; b=v7egAY9+KEwG/fktZqt8ZzFYsxgvTKU3oHe0SdRhW+xjbU8yv7X+7Ljaz82NNUhF6w jljCTs8JOLFeEepdmB5pBQD/s+40SwyAFRTJgCXuSrPhYk1lbY6eAedlE52MRmoH1UAJ rFTD6g+jvtghuw/MpVAMRCZoaHkYZHyXlOcZ8= Received: by 10.227.207.206 with SMTP id fz14mr7528122wbb.76.1312310847224; Tue, 02 Aug 2011 11:47:27 -0700 (PDT) Received: from localhost.localdomain (bzq-79-180-210-116.red.bezeqint.net [79.180.210.116]) by mx.google.com with ESMTPS id em16sm31956wbb.33.2011.08.02.11.47.24 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 02 Aug 2011 11:47:26 -0700 (PDT) From: Sasha Levin To: penberg@kernel.org Cc: kvm@vger.kernel.org, aneesh.kumar@linux.vnet.ibm.com, mingo@elte.hu, asias.hejun@gmail.com, gorcunov@gmail.com, Sasha Levin Subject: [PATCH v2 2/2] kvm tools: Add '--rootfs' and '--binsh' Date: Tue, 2 Aug 2011 21:46:29 +0300 Message-Id: <1312310789-22817-2-git-send-email-levinsasha928@gmail.com> X-Mailer: git-send-email 1.7.6 In-Reply-To: <1312310789-22817-1-git-send-email-levinsasha928@gmail.com> References: <1312310789-22817-1-git-send-email-levinsasha928@gmail.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Tue, 02 Aug 2011 18:47:37 +0000 (UTC) This patch adds 2 new flags: --rootfs [path] - Specifies a path to use as rootfs. The path will be mounted using virtio-9p and booted from. Easiest way to test it is to mount the sample image we recommend with kvm tool (http://wiki.qemu.org/download/linux-0.2.img.bz2) and mounting it somewhere. *PLEASE DO NOT TRY BOOTING FROM YOUR REAL ROOT AKA '/', EVEN WITH READ ONLY SET* - Lets make sure the code is bulletproof before we delete your rootfs :) --binsh - This flag will boot into simple /bin/sh shell instead of going through /sbin/init. This is usefull for more complex distribution rootfs where we have to deal with /etc/fstab and such. Signed-off-by: Sasha Levin Reviewed-by: Aneesh Kumar K.V --- 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..78680ec 100644 --- a/tools/kvm/builtin-run.c +++ b/tools/kvm/builtin-run.c @@ -76,11 +76,13 @@ static const char *guest_mac; static const char *host_mac; static const char *script; static const char *guest_name; +static const char *rootfs; static bool single_step; static bool readonly_image[MAX_DISK_IMAGES]; static bool vnc; static bool sdl; static bool balloon; +static bool bin_sh; extern bool ioport_debug; extern int active_console; extern int debug_iodelay; @@ -156,6 +158,8 @@ static const struct option options[] = { OPT_BOOLEAN('\0', "balloon", &balloon, "Enable virtio balloon"), OPT_BOOLEAN('\0', "vnc", &vnc, "Enable VNC framebuffer"), OPT_BOOLEAN('\0', "sdl", &sdl, "Enable SDL framebuffer"), + OPT_STRING('\0', "rootfs", &rootfs, "path", "Use path as rootfs"), + OPT_BOOLEAN('\0', "binsh", &bin_sh, "Boot rootfs to /bin/sh instead of /sbin/init"), OPT_GROUP("Kernel options:"), OPT_STRING('k', "kernel", &kernel_filename, "kernel", @@ -615,7 +619,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 (!rootfs && !image_filename[0]) { hi = host_image(real_cmdline, sizeof(real_cmdline)); if (hi) { image_filename[0] = hi; @@ -627,6 +631,18 @@ 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 (rootfs) { + char tmp[PATH_MAX]; + + if (realpath(rootfs, tmp) == 0 || + virtio_9p__init(kvm, tmp, "/dev/root") < 0) + die("Unable to initialize virtio 9p"); + strcat(real_cmdline, " root=/dev/root rootflags=rw,trans=virtio,version=9p2000.u rootfstype=9p"); + + if (bin_sh) + strcat(real_cmdline, " init=/bin/sh"); + } + if (image_count) { kvm->nr_disks = image_count; kvm->disks = disk_image__open_all(image_filename, readonly_image, image_count);