- add more disk space
[os-autoinst:os-autoinst.git] / inst / startqemu.pm
1 #!/usr/bin/perl -w
2 use strict;
3 use bmwqemu;
4 my $basedir="raid";
5 my $qemuimg="/usr/bin/kvm-img";
6 if(!-e $qemuimg) {$qemuimg="/usr/bin/qemu-img"}
7 my $iso=$ENV{ISO};
8 $ENV{HDDMODEL}||="virtio";
9 $ENV{NICMODEL}||="virtio";
10 $ENV{NUMDISKS}||=1;
11 if(defined($ENV{RAIDLEVEL})) {$ENV{NUMDISKS}=4}
12 my @cdrom=("-cdrom", $iso);
13
14 $ENV{QEMU_AUDIO_DRV}="wav";
15 $ENV{QEMU_WAV_PATH}="/dev/null";
16
17 my $ison=$iso; $ison=~s{.*/}{}; # drop path
18 if($ison=~m/LiveCD/i) {$ENV{LIVECD}=1}
19 if($ison=~m/Promo/) {$ENV{PROMO}=1}
20 if($ison=~m/-i[3-6]86-/) {$ENV{QEMUCPU}||="qemu32"}
21 if($ison=~m/openSUSE-Smeegol/) {$ENV{DESKTOP}||="gnome"}
22 if($ison=~m/openSUSE-(DVD|NET|KDE|GNOME|LXDE|XFCE)/) {
23         $ENV{$1}=1; $ENV{NETBOOT}=$ENV{NET};
24         if($ENV{LIVECD}) {
25                 $ENV{DESKTOP}=lc($1);
26         }
27 }
28
29 system(qw"/bin/mkdir -p", $basedir);
30
31 if($ENV{UPGRADE} && !$ENV{LIVECD}) {
32         my $file=$ENV{UPGRADE};
33         if(!-e $file) {die "'$ENV{UPGRADE}' should be old img.gz"}
34         $ENV{KEEPHDDS}=1;
35         # use qemu snapshot/cow feature to work on old image without writing it
36         unlink "$basedir/l1";
37         unlink "$basedir/1";
38         system($qemuimg, "create", "-b", $file, "-f", "qcow2", "$basedir/l1");
39 }
40
41 if(!qemualive) {
42         if(!$ENV{KEEPHDDS}) {
43                 # fresh HDDs
44                 for my $i (1..4) {
45                         unlink("$basedir/l$i");
46                         if(-e "$basedir/$i.lvm") {
47                                 symlink("$i.lvm","$basedir/l$i");
48                                 system("/bin/dd", "if=/dev/zero", "count=1", "of=$basedir/l1"); # for LVM
49                         } else {
50                                 system($qemuimg, "create" ,"$basedir/$i", "8G");
51                                 symlink($i,"$basedir/l$i");
52                         }
53                 }
54                 if($ENV{USBBOOT}) {
55                         system("dd", "if=$iso", "of=$basedir/l1", "bs=1M", "conv=notrunc");
56                         @cdrom=();
57                 }
58         }
59         system("sync"); sleep 5;
60
61         $qemupid=fork();
62         die "fork failed" if(!defined($qemupid));
63         if($qemupid==0) {
64                 my @params=(qw(-m 1024 -net user -monitor), "tcp:127.0.0.1:$ENV{QEMUPORT},server,wait", "-net", "nic,model=$ENV{NICMODEL},macaddr=52:54:00:12:34:56", "-serial", "file:serial0", "-soundhw", "ac97", "-S");
65                 for my $i (1..$ENV{NUMDISKS}) {
66                         my $boot="";#$i==1?",boot=on":""; # workaround bnc#696890
67                         push(@params, "-drive", "file=$basedir/l$i,if=$ENV{HDDMODEL}$boot");
68                 }
69                 push(@params, "-boot", "dc", @cdrom) if($iso);
70                 if($ENV{VNC}) {
71                         if($ENV{VNC}!~/:/) {$ENV{VNC}=":$ENV{VNC}"}
72                         push(@params, "-vnc", $ENV{VNC});
73                         push(@params, "-k", $ENV{VNCKB}) if($ENV{VNCKB});
74                 }
75                 if($ENV{QEMUCPU}) { push(@params, "-cpu", $ENV{QEMUCPU}); }
76                 push(@params, "-usb", "-usbdevice", "tablet");
77         #       push(@params, "-smp", "4");
78                 exec($qemubin, @params);
79                 die "exec $qemubin failed";
80         }
81         open(my $pidf, ">", $bmwqemu::qemupidfilename) or die "can not write $bmwqemu::qemupidfilename";
82         print $pidf $qemupid,"\n";
83         close $pidf;
84         sleep 6; # time to let qemu start
85 }
86
87 1;