X-Git-Url: http://git.annexia.org/?a=blobdiff_plain;f=mclu_boot.ml;h=c1054e5226f949cc29385dc4c5490c29c0509907;hb=5f5bfbd6da3c0994be68d163bc3d0bc5205d8609;hp=16b8ac9305356b5d3dd9d03fd3cee42cb7b6d1a6;hpb=00c6b7f0a9371df0212dbe84abb1f95c162609a0;p=mclu.git diff --git a/mclu_boot.ml b/mclu_boot.ml index 16b8ac9..c1054e5 100644 --- a/mclu_boot.ml +++ b/mclu_boot.ml @@ -165,6 +165,27 @@ 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 + let remote_arch = node.MS.node_status.node_info.model in + + (* Guest arch defaults to the node host arch, but can be overridden + * in the template. + *) + let guest_arch = + match template_info.Template.guest_arch with + | Some arch -> arch + | None -> remote_arch in + + (* UEFI firmware and NVRAM on remote, if required. *) + let nvram = + match guest_arch with + | "aarch64" -> + Some ("/usr/share/edk2.git/aarch64/QEMU_EFI-pflash.raw", + "/usr/share/edk2.git/aarch64/vars-template-pflash.raw", + remote_image ^ ".nvram") + | _ -> None in (* Get ready to generate the guest XML. *) let vcpus = !vcpus in @@ -184,16 +205,52 @@ Try: `mclu on %s'\n" hostname hostname; %Ld %Ld %d +" name (memory /^ 1024L) (memory /^ 1024L) vcpus in + + let xml = xml ^ "\ - hvm +" in + let xml = + match guest_arch with + | "arm" | "armv7" | "armv7l" | "armv7hl" -> + xml ^ "\ + hvm +" + | "aarch64" -> + xml ^ "\ + hvm +" + | _ -> + xml ^ "\ + hvm +" in + + let xml = + match nvram with + | Some (loader, nvram_template, nvram) -> + xml ^ sprintf "\ + %s + %s +" loader nvram_template nvram + | None -> xml 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 +260,7 @@ Try: `mclu on %s'\n" hostname hostname; restart restart -" name (memory /^ 1024L) (memory /^ 1024L) vcpus in +" in let xml = xml ^ sprintf "\ @@ -250,6 +307,12 @@ Try: `mclu on %s'\n" hostname hostname; +" in + let xml = + match guest_arch with + | "i386" | "i486" | "i586" | "i686" + | "x86_64" -> + xml ^ "\ @@ -257,6 +320,9 @@ Try: `mclu on %s'\n" hostname hostname; +" + | _ -> xml in + let xml = xml ^ "\ " in xml @@ -270,6 +336,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,11 +394,13 @@ 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); fpf "export format=%s\n" (quote format); + fpf "export guest_arch=%s\n" (quote guest_arch); fpf "export name=%s\n" (quote name); fpf "export output=%s\n" (quote remote_image); (match size with @@ -341,7 +411,21 @@ Try: `mclu on %s'\n" hostname hostname; | "" -> () | tz -> fpf "export timezone=%s\n" (quote (sprintf "--timezone %s" tz)) ); + (match nvram with + | Some (_, nvram_template, nvram) -> + fpf "cp %s %s\n" (quote nvram_template) (quote nvram) + | None -> () + ); 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