From 737ffdb932c89d8ec0b2c3d9731ca325da9d84f3 Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Mon, 18 May 2015 13:11:46 +0100 Subject: [PATCH] Allow an external kernel to be used to boot guests. Required for armv7 guests. --- mclu_boot.ml | 33 +++++++++++++++++++++++++++++++-- template.ml | 10 +++++++++- template.mli | 1 + 3 files changed, 41 insertions(+), 3 deletions(-) diff --git a/mclu_boot.ml b/mclu_boot.ml index 16b8ac9..5aa8290 100644 --- a/mclu_boot.ml +++ b/mclu_boot.ml @@ -165,6 +165,9 @@ Try: `mclu on %s'\n" hostname hostname; 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 @@ -184,9 +187,23 @@ Try: `mclu on %s'\n" hostname hostname; %Ld %Ld %d +" name (memory /^ 1024L) (memory /^ 1024L) vcpus in + + let xml = xml ^ "\ hvm +" in + + let xml = xml ^ + if template_info.Template.needs_external_kernel then + sprintf "\ + %s + %s +" remote_external_kernel remote_external_initrd + else "" in + + let xml = xml ^ "\ @@ -203,7 +220,7 @@ Try: `mclu on %s'\n" hostname hostname; restart restart -" name (memory /^ 1024L) (memory /^ 1024L) vcpus in +" in let xml = xml ^ sprintf "\ @@ -270,6 +287,8 @@ Try: `mclu on %s'\n" hostname hostname; 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); @@ -326,7 +345,8 @@ Try: `mclu on %s'\n" hostname hostname; 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); @@ -342,6 +362,15 @@ Try: `mclu on %s'\n" hostname hostname; | 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 diff --git a/template.ml b/template.ml index 428ffe4..4db0b66 100644 --- a/template.ml +++ b/template.ml @@ -79,6 +79,7 @@ type template_info = { disk_bus : string option; network_model : string option; has_xml_target : bool; + needs_external_kernel : bool; } let probe ?(verbose = false) filename = @@ -138,10 +139,17 @@ 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; } diff --git a/template.mli b/template.mli index 470baeb..bb1d7f2 100644 --- a/template.mli +++ b/template.mli @@ -32,6 +32,7 @@ type template_info = { disk_bus : string option; network_model : string option; has_xml_target : bool; + needs_external_kernel : bool; } val probe : ?verbose:bool -> string -> template_info -- 1.8.3.1