summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaulo Alcantara <palcantara@suse.de>2018-04-29 14:59:57 -0300
committerPaulo Alcantara <palcantara@suse.de>2018-04-29 14:59:57 -0300
commit1b8dbf06efd78b096618cf3ef44b9fa15806809c (patch)
treebde621221f1358772efb34910b2bcb4b293e965f
parent3a2ab6f42dd62cef0b575a8589dae7df090f3c54 (diff)
downloadvmhtool-1b8dbf06efd78b096618cf3ef44b9fa15806809c.tar.gz
vmhtool-1b8dbf06efd78b096618cf3ef44b9fa15806809c.tar.xz
vmhtool-1b8dbf06efd78b096618cf3ef44b9fa15806809c.zip
Introduce --disk|-D cmdline option
Allow the user to pass his own hdd images into the guest. Signed-off-by: Paulo Alcantara <palcantara@suse.de>
-rwxr-xr-xvmhelper32
1 files changed, 30 insertions, 2 deletions
diff --git a/vmhelper b/vmhelper
index dca7716..731a4f2 100755
--- a/vmhelper
+++ b/vmhelper
@@ -26,6 +26,7 @@ my $initrd_img = '';
my $shared_dirs = '';
my $gen_new_conf;
my $nographic;
+my $vm_hdds = '';
sub usage {
print STDERR "Usage: " . basename($0). " [name] [options]
@@ -43,6 +44,7 @@ sub usage {
-w, --win MS windows specifics
-n, --new generate new config file
-N, --nographic disable graphics when running vm
+ -D, --disk=img0,img1,... boot up a vm with additional hdd images
";
exit 1;
}
@@ -60,6 +62,7 @@ GetOptions("install=s" => \$install_iso_path,
"win" => \$windows_guest,
"share=s" => \$shared_dirs,
"new" => \$gen_new_conf,
+ "disk|D=s" => \$vm_hdds,
"nographic|N" => \$nographic) or usage();
usage() if $print_help;
@@ -71,6 +74,20 @@ die "$vm_path does not exist" unless -e $vm_path and -d $vm_path;
my $vm_info = $vm_path . '/.vminfo';
my $vm_conf = $vm_path . '/.vmconf';
+sub parse_user_hdds {
+ return '' unless $vm_hdds;
+ my $args = '';
+ my $num = 1;
+ print "$vm_hdds\n";
+ my @hdds = split(/,/, $vm_hdds);
+ foreach (@hdds) {
+ my $id = sprintf "hd%02x", rand(256);
+ $args .= " -device scsi-hd,drive=$id -drive if=none,file=$_,cache=writeback,id=$id,format=raw,unit=$num ";
+ $num++;
+ }
+ return $args;
+}
+
my %vm_conf_opts = (
ETH_IFACE => 'eth0',
BRIDGE_IFACE => 'br0',
@@ -226,7 +243,7 @@ my %qemu_linux_opts = (
mach => "-machine q35",
cpu => "-enable-kvm -cpu host -smp sockets=1,cores=1,threads=1",
mem => "-m 1024",
- bus => "-device ich9-ahci,id=ahci -device qemu-xhci,id=xhci",
+ bus => "-device ich9-ahci,id=ahci -device qemu-xhci,id=xhci -device virtio-scsi-pci,id=scsi",
hdd => " -device ide-hd,drive=hd,bus=ahci.0 -drive if=none,id=hd,cache=writeback,format=raw,file=%s",
net => "-device e1000,netdev=net0,mac=%s -netdev type=tap,id=net0,ifname=%s,script=no,downscript=no",
usb => "-device usb-tablet",
@@ -242,7 +259,7 @@ my %qemu_win_opts = (
cpu => "-enable-kvm -cpu host -smp sockets=1,cores=1,threads=1",
mem => "-m 1024",
bus => "-device ich9-ahci,id=ahci -device virtio-scsi-pci,id=scsi -device qemu-xhci,id=xhci",
- hdd => "-device scsi-hd,drive=hd,bootindex=0 -drive if=none,file=%s,cache=writeback,id=hd,format=raw,unit=0",
+ hdd => "-device scsi-hd,drive=hd,bootindex=0 -drive if=none,file=%s,cache=writeback,id=hd,format=raw,unit=0",
cdrom => "-device scsi-cd,drive=cd,bootindex=1 -drive if=none,file=%s,format=raw,id=cd",
virtio => "-device ide-cd,drive=drv,bus=ahci.0 -drive if=none,file=%s,format=raw,id=drv",
usb => "-device usb-tablet",
@@ -330,6 +347,10 @@ if ($install_iso_path) {
$qemu_cmd .= " $qemu_win_opts{'mach'} $qemu_win_opts{'cpu'}";
$qemu_cmd .= " $qemu_win_opts{'mem'} $qemu_win_opts{'bus'}";
$qemu_cmd .= " " . sprintf $qemu_win_opts{'hdd'}, $vm_img_path;
+
+ my $user_hdds = parse_user_hdds();
+ $qemu_cmd .= " $user_hdds" if $user_hdds;
+
$qemu_cmd .= " " . sprintf $qemu_win_opts{'cdrom'}, $install_iso_path;
if ($virtio_drv_path) {
$qemu_cmd .= " " . sprintf $qemu_win_opts{'virtio'}, $virtio_drv_path;
@@ -372,6 +393,10 @@ if ($windows_guest) {
$qemu_cmd .= " $qemu_win_opts{'mach'} $qemu_win_opts{'cpu'}";
$qemu_cmd .= " $qemu_win_opts{'mem'} $qemu_win_opts{'bus'}";
$qemu_cmd .= " " . sprintf $qemu_win_opts{'hdd'}, $vm_img_path;
+
+ my $user_hdds = parse_user_hdds();
+ $qemu_cmd .= $user_hdds if $user_hdds;
+
if ($virtio_drv_path) {
$qemu_cmd .= " " . sprintf $qemu_win_opts{'virtio'}, $virtio_drv_path;
}
@@ -482,6 +507,9 @@ $qemu_cmd .= " $qemu_linux_opts{'mem'} $qemu_linux_opts{'bus'}";
$qemu_cmd .= " $qemu_linux_opts{'usb'}";
$qemu_cmd .= " " . sprintf $qemu_linux_opts{'hdd'}, $vm_img_path;
+my $user_hdds = parse_user_hdds();
+$qemu_cmd .= " $user_hdds" if $user_hdds;
+
setup_shared_dirs();
$qemu_cmd .= " $qemu_linux_opts{'share'}";