mirror of
https://git.proxmox.com/git/qemu-server
synced 2025-05-28 18:30:17 +00:00
cloud-init: use qemu-img dd instead of nbd
We now have a patch on top of qemu to allow 'qemu-img dd' to read from stdin when specifying input and output sizes, as well as a way to tell it that the size of the source is not known. Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
parent
0c9a7596f6
commit
3db6e4ab70
@ -11,36 +11,14 @@ use PVE::Tools qw(run_command file_set_contents);
|
||||
use PVE::Storage;
|
||||
use PVE::QemuServer;
|
||||
|
||||
sub nbd_stop {
|
||||
my ($vmid) = @_;
|
||||
|
||||
PVE::QemuServer::vm_mon_cmd($vmid, 'nbd-server-stop');
|
||||
}
|
||||
|
||||
sub next_free_nbd_dev {
|
||||
for(my $i = 0;;$i++) {
|
||||
my $dev = "/dev/nbd$i";
|
||||
last if ! -b $dev;
|
||||
next if -f "/sys/block/nbd$i/pid"; # busy
|
||||
return $dev;
|
||||
}
|
||||
die "unable to find free nbd device\n";
|
||||
}
|
||||
|
||||
sub commit_cloudinit_disk {
|
||||
my ($file_path, $iso_path, $format) = @_;
|
||||
|
||||
my $nbd_dev = next_free_nbd_dev();
|
||||
run_command(['qemu-nbd', '-c', $nbd_dev, $iso_path, '-f', $format]);
|
||||
my $size = PVE::Storage::file_size_info($iso_path);
|
||||
|
||||
eval {
|
||||
run_command([['genisoimage', '-R', '-V', 'config-2', $file_path],
|
||||
['dd', "of=$nbd_dev", 'conv=fsync']]);
|
||||
};
|
||||
my $err = $@;
|
||||
eval { run_command(['qemu-nbd', '-d', $nbd_dev]); };
|
||||
warn $@ if $@;
|
||||
die $err if $err;
|
||||
run_command([['genisoimage', '-R', '-V', 'config-2', $file_path],
|
||||
['qemu-img', 'dd', '-f', 'raw', '-O', $format,
|
||||
'isize=0', "osize=$size", "of=$iso_path"]]);
|
||||
}
|
||||
|
||||
sub generate_cloudinitconfig {
|
||||
|
Loading…
Reference in New Issue
Block a user