]> git.proxmox.com Git - qemu-server.git/commitdiff
copy efivars disk on create
authorDominik Csapak <d.csapak@proxmox.com>
Thu, 8 Sep 2016 09:03:00 +0000 (11:03 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Thu, 8 Sep 2016 09:19:04 +0000 (11:19 +0200)
when we create the efidisk0 over the api,
we discard the size, and create a 128kbyte vdisk
and copy it there with qemu-img convert

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
PVE/API2/Qemu.pm

index dd42538b1fb747df921c72ef3420ba4079f13fb9..60d653f91d8846fcf129a0af87ad4e0d4f642937 100644 (file)
@@ -123,10 +123,32 @@ my $create_disks = sub {
            die "no storage ID specified (and no default storage)\n" if !$storeid;
            my $defformat = PVE::Storage::storage_default_format($storecfg, $storeid);
            my $fmt = $disk->{format} || $defformat;
-           my $volid = PVE::Storage::vdisk_alloc($storecfg, $storeid, $vmid,
-                                                 $fmt, undef, $size*1024*1024);
-           $disk->{file} = $volid;
-           $disk->{size} = $size*1024*1024*1024;
+
+           my $volid;
+           if ($ds eq 'efidisk0') {
+               # handle efidisk
+               my $ovmfvars = '/usr/share/kvm/OVMF_VARS-pure-efi.fd';
+               die "uefi vars image not found\n" if ! -f $ovmfvars;
+               $volid = PVE::Storage::vdisk_alloc($storecfg, $storeid, $vmid,
+                                                     $fmt, undef, 128);
+               $disk->{file} = $volid;
+               $disk->{size} = 128*1024;
+               my ($storeid, $volname) = PVE::Storage::parse_volume_id($volid);
+               my $scfg = PVE::Storage::storage_config($storecfg, $storeid);
+               my $qemufmt = PVE::QemuServer::qemu_img_format($scfg, $volname);
+               my $path = PVE::Storage::path($storecfg, $volid);
+               my $efidiskcmd = ['/usr/bin/qemu-img', 'convert', '-f', 'raw', '-O', $qemufmt];
+               push @$efidiskcmd, $ovmfvars;
+               push @$efidiskcmd, $path;
+               eval { PVE::Tools::run_command($efidiskcmd); };
+               my $err = $@;
+               die "Copying of EFI Vars image failed: $err" if $err;
+           } else {
+               $volid = PVE::Storage::vdisk_alloc($storecfg, $storeid, $vmid,
+                                                     $fmt, undef, $size*1024*1024);
+               $disk->{file} = $volid;
+               $disk->{size} = $size*1024*1024*1024;
+           }
            push @$vollist, $volid;
            delete $disk->{format}; # no longer needed
            $res->{$ds} = PVE::QemuServer::print_drive($vmid, $disk);