let remote_template_wrapper = sprintf "/tmp/mclu%s.sh" (string_random8 ()) in
let xml_template_wrapper = sprintf "/tmp/mclu%s.sh" (string_random8 ()) in
let remote_image = sprintf "/var/tmp/%s.%s" name extension in
+ let remote_external_kernel_dir = sprintf "/var/tmp/%s.boot" name in
+ let remote_external_kernel = sprintf "/var/tmp/%s.boot/kernel" name in
+ let remote_external_initrd = sprintf "/var/tmp/%s.boot/initrd" name in
(* Get ready to generate the guest XML. *)
let vcpus = !vcpus in
<memory unit='KiB'>%Ld</memory>
<currentMemory unit='KiB'>%Ld</currentMemory>
<vcpu>%d</vcpu>
+" name (memory /^ 1024L) (memory /^ 1024L) vcpus in
+
+ let xml = xml ^ "\
<os>
<type>hvm</type>
<boot dev='hd'/>
+" in
+
+ let xml = xml ^
+ if template_info.Template.needs_external_kernel then
+ sprintf "\
+ <kernel>%s</kernel>
+ <initrd>%s</initrd>
+" remote_external_kernel remote_external_initrd
+ else "" in
+
+ let xml = xml ^ "\
</os>
<features>
<acpi/>
<on_reboot>restart</on_reboot>
<on_crash>restart</on_crash>
<devices>
-" name (memory /^ 1024L) (memory /^ 1024L) vcpus in
+" in
let xml = xml ^ sprintf "\
<disk type='file' device='disk'>
let fpf fs = fprintf chan fs in
fpf "#!/bin/sh\n";
fpf "export format=%s\n" (quote format);
+ fpf "export initrd=%s\n" (quote remote_external_initrd);
+ fpf "export kernel=%s\n" (quote remote_external_kernel);
fpf "export mac_addr=%s\n" (quote mac_addr);
fpf "export memory_kb=%Ld\n" (memory /^ 1024L);
fpf "export name=%s\n" (quote name);
let () =
let chan = open_out remote_template_wrapper in
let fpf fs = fprintf chan fs in
- fpf "#!/bin/sh\n";
+ fpf "#!/bin/bash\n";
+ fpf "set -e\n";
(* XXX Don't hard-code network_bridge here. *)
fpf "export LIBGUESTFS_BACKEND_SETTINGS=network_bridge=br0\n";
fpf "export base_image=%s\n" (quote template_info.Template.base_image);
| tz -> fpf "export timezone=%s\n" (quote (sprintf "--timezone %s" tz))
);
fpf "%s build\n" remote_template;
+ if template_info.Template.needs_external_kernel then (
+ fpf "rm -rf %s\n" (quote remote_external_kernel_dir);
+ fpf "mkdir %s\n" (quote remote_external_kernel_dir);
+ fpf "pushd %s\n" (quote remote_external_kernel_dir);
+ fpf "virt-builder --get-kernel %s\n" (quote remote_image);
+ fpf "ln vmlinuz-* kernel\n";
+ fpf "ln init* initrd\n";
+ fpf "popd\n";
+ );
close_out chan;
Unix.chmod remote_template_wrapper 0o755 in
disk_bus : string option;
network_model : string option;
has_xml_target : bool;
+ needs_external_kernel : bool;
}
let probe ?(verbose = false) filename =
let has_xml_target = run_template ~verbose filename "xml" [] <> None in
+ let needs_external_kernel =
+ match run_template ~verbose filename "needs-external-kernel" [] with
+ | None -> false
+ | Some ["1"|"yes"] -> true
+ | Some _ -> false in
+
{ base_image = base_image;
minimum_memory = minimum_memory;
recommended_memory = recommended_memory;
minimum_size = minimum_size;
disk_bus = disk_bus;
network_model = network_model;
- has_xml_target = has_xml_target }
+ has_xml_target = has_xml_target;
+ needs_external_kernel = needs_external_kernel; }