copy efivars disk on create

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>
This commit is contained in:
Dominik Csapak 2016-09-08 11:03:00 +02:00 committed by Dietmar Maurer
parent 6470743ff9
commit 1a35631aab

View File

@ -123,10 +123,32 @@ my $create_disks = sub {
die "no storage ID specified (and no default storage)\n" if !$storeid; die "no storage ID specified (and no default storage)\n" if !$storeid;
my $defformat = PVE::Storage::storage_default_format($storecfg, $storeid); my $defformat = PVE::Storage::storage_default_format($storecfg, $storeid);
my $fmt = $disk->{format} || $defformat; my $fmt = $disk->{format} || $defformat;
my $volid = PVE::Storage::vdisk_alloc($storecfg, $storeid, $vmid,
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); $fmt, undef, $size*1024*1024);
$disk->{file} = $volid; $disk->{file} = $volid;
$disk->{size} = $size*1024*1024*1024; $disk->{size} = $size*1024*1024*1024;
}
push @$vollist, $volid; push @$vollist, $volid;
delete $disk->{format}; # no longer needed delete $disk->{format}; # no longer needed
$res->{$ds} = PVE::QemuServer::print_drive($vmid, $disk); $res->{$ds} = PVE::QemuServer::print_drive($vmid, $disk);