summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaulo Alcantara <paulo@paulo.ac>2018-05-25 10:28:59 -0300
committerPaulo Alcantara <paulo@paulo.ac>2018-05-25 10:28:59 -0300
commit1a3e1bc29592daffcd4a17be434d1b9258a8932a (patch)
tree1ec29f31650a9fa414001d0d3a2f82e441595312
parentd99fc5abe5475add91e5457910b2aa2f7ee7879c (diff)
downloadvmhtool-1a3e1bc29592daffcd4a17be434d1b9258a8932a.tar.gz
vmhtool-1a3e1bc29592daffcd4a17be434d1b9258a8932a.tar.xz
vmhtool-1a3e1bc29592daffcd4a17be434d1b9258a8932a.zip
Introduce --gdb and --serial cmd options
The --gdb option will make it listening on a random TCP port and wait for a gdb conn, and --serial will make the kernel output through serial. Signed-off-by: Paulo Alcantara <paulo@paulo.ac>
-rwxr-xr-xvmhelper48
1 files changed, 36 insertions, 12 deletions
diff --git a/vmhelper b/vmhelper
index 32041fb..eb0e377 100755
--- a/vmhelper
+++ b/vmhelper
@@ -11,28 +11,42 @@ use Getopt::Long;
use File::Copy;
use Cwd 'abs_path';
use File::Basename;
+use Net::EmptyPort 'empty_port';
sub usage {
print STDERR "Usage: " . basename($0). " [name] [options]
+
+General options:
--help print this help
+ --new generate new config file
+ --list list all vms
+ --delete delete vm
--install image create a new vm and install it from an ISO image
- --virtio image attach virtio drivers ISO image into guest
+ --hdd=img0,img1,... boot up a vm with additional hdd images
+ --bridge force creating a network bridge
+
+Windows options:
+ --win MS windows specifics (required)
+ --virtio image attach virtio drivers ISO image into Windows guest
+
+Linux options:
--initrd pass initramfs image to kernel
--kernel path run the guest with a custom kernel image
+ (requires: --rootfs)
--rootfs path specify the rootfs that will get passed through the
- kernel cmdline
+ kernel cmdline (requires: --kernel)
--build build custom kernel before running guest
+ (requires: --kernel)
--config file custom kernel config file
+ (requires: --build)
--modules install kernel modules in rootfs image
+ (requires: --kernel,--rootfs,--build)
--share=foo,bar,... share directories between host and guest
- --list list all vms
- --delete delete vm
- --win MS windows specifics
- --new generate new config file
--nographic disable graphics when running vm
- --hdd=img0,img1,... boot up a vm with additional hdd images
- --bridge create a network bridge
(this overrides current settings)
+ --gdb wait for gdb conn on a random TCP port
+ --serial enable kernel output on serial
+ (requires: --kernel,--rootfs)
";
exit 1;
}
@@ -55,6 +69,8 @@ GetOptions("install=s" => \$cmd_opts{install_iso_path},
"hdd=s" => \$cmd_opts{vm_hdds},
"rootfs=s" => \$cmd_opts{rootfs_path},
"bridge" => \$cmd_opts{create_bridge},
+ "gdb" => \$cmd_opts{gdb_conn},
+ "serial" => \$cmd_opts{kernel_serial},
"nographic" => \$cmd_opts{nographic}) or usage();
usage() if $cmd_opts{print_help};
@@ -66,6 +82,8 @@ die "$vm_path does not exist" if ! -e $vm_path || ! -d $vm_path;
my $vm_info = $vm_path . '/.vminfo';
my $vm_conf = $vm_path . '/.vmconf';
+my $vm_gdb_port = $cmd_opts{gdb_conn} ? empty_port() : -1;
+
sub parse_user_hdds {
return '' unless $cmd_opts{vm_hdds};
my $args = '';
@@ -299,10 +317,10 @@ my %qemu_linux_opts = (
usb => "-device usb-tablet",
cdrom => "-cdrom %s",
kernel => "-kernel %s",
- cmdline => "-append \"root=%s rw console=ttyS0\"",
initrd => "-initrd %s",
share => '',
- mon => "-device virtio-serial-pci -monitor stdio"
+ mon => "-device virtio-serial-pci -monitor stdio",
+ dbg => $vm_gdb_port != -1 ? "-gdb tcp::$vm_gdb_port" : ""
);
my %qemu_win_opts = (
@@ -402,6 +420,7 @@ sub do_run_vm {
print "[*] macaddr: " . get_vm_macaddr() . "\n";
print "[*] host iface: " . ($bridge_enabled ? $bridge_iface : $tap_bridge_iface) . " ($ipaddr)\n";
print "[*] vm iface: " . "$tap_iface\n";
+ print "[*] debug: listening on localhost:$vm_gdb_port\n" if $vm_gdb_port != -1;
print "[*] cmd: " . "$cmd\n";
my $ret = system($cmd);
@@ -591,6 +610,7 @@ $qemu_cmd .= " $qemu_linux_opts{'mach'} $qemu_linux_opts{'cpu'}";
$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;
+$qemu_cmd .= " $qemu_linux_opts{'dbg'}";
my $user_hdds = parse_user_hdds();
$qemu_cmd .= $user_hdds if $user_hdds;
@@ -655,8 +675,12 @@ if ($cmd_opts{kernel_path}) {
}
$qemu_cmd .= " " . sprintf $qemu_linux_opts{'kernel'}, $linux_img;
- $qemu_cmd .= " " . sprintf $qemu_linux_opts{'cmdline'}, $cmd_opts{rootfs_path};
- $qemu_cmd .= " -nographic";
+ $qemu_cmd .= " -append \"root=$cmd_opts{rootfs_path} rw";
+ unless ($cmd_opts{kernel_serial}) {
+ $qemu_cmd .= "\" -display none $qemu_linux_opts{'mon'}";
+ } else {
+ $qemu_cmd .= " console=ttyS0\" -nographic";
+ }
if ($cmd_opts{initrd_img}) {
if (! -e $cmd_opts{initrd_img} || ! -e $cmd_opts{initrd_img}) {
$err = "$cmd_opts{initrd_img} does not exist";