QEMU provides a networking stack so that the guest OS running on this virtual
machine can access the internet, or ssh to the host.
The only extra setup needed is to run Gobo’s DHCP client inside the guest.
dhcpcd
By default QEMU acts as a firewall and does not permit any incoming traffic. It
also doesn’t support protocols other than TCP and UDP. This means that ping and
other ICMP utilities won’t work.
The script has some library dependencies. The most convenient way to install
them (and any CPAN modules) is to use cpanminus (cpanm). So install
cpanminus, then the dependencies:
The script follows below. Edit the QEMU options to your liking, put the script
in somewhere in your $PATH, and make it executable with something like
chmod a+x ~/bin/qemust.
#!/usr/bin/env perluse strict;
use warnings;
# qemust - start QEMUuse5.012;
use Getopt::Long::Descriptive;
my ($opt, $usage) = describe_options(
'%c %o',
[ 'iso=s', "ISO file to boot" ],
[ 'image=s',"OS disk image file" ],
[ 'help', "print usage message and exit" ],
[ 'n', "print QEMU startup command and exit" ],
);
print($usage->text), exit if$opt->{help} or ! keys %$opt;
my$boot_drive = $opt->{iso} ? 'd' : 'c';
my@cmd = grep{! /^\s*$/} map{s/\s*#.*$//; $_} split "\n",<<"CMD";
sudo # run as root
qemu-system-x86_64 # for 64-bit CPUs
-enable-kvm # faster virtualization
-show-cursor #
-boot $boot_drive # boot from DVD/CDROM if present
-m 768 # use memory 768MB
-cpu host # same CPU model as host
-daemonize # avoid race conditions when QEMU started by external program
-vga std # probably -vga vmware would work, too
-soundhw ac97 # typical soundcard, -soundhw hda should also work
-rtc base=utc # timer related
-usb # enable USB driver
-usbdevice tablet # so QEMU can report mouse position without grabbing mouse
-device usb-mouse #
-clock unix #
CMDpush @cmd, "-cdrom $opt->{iso}"if$opt->{iso};
push @cmd, "-hda $opt->{image}"if$opt->{image};
my$cmd = join " \\\n",@cmd;
say $cmd;
system($cmd) unless$opt->{n};
__END__