+ log.write("Copying kernel and initrd for booting.\n")
+ if vars['virt'] == 'vs':
+ utils.sysexec("cp {}/boot/kernel-boot{} /tmp/kernel".format(SYSIMG_PATH, option), log)
+ utils.sysexec("cp {}/boot/initrd-boot{} /tmp/initrd".format(SYSIMG_PATH, option), log)
+ else:
+ # Use chroot to call rpm, b/c the bootimage&nodeimage rpm-versions may not work together
+ try:
+ kversion = os.popen("chroot {} rpm -qa kernel | tail -1 | cut -c 8-"\
+ .format(SYSIMG_PATH)).read().rstrip()
+ major_version = int(kversion[0]) # Check if the string looks like a kernel version
+ except:
+ # Try a different method for non-rpm-based distributions
+ kversion = os.popen("ls -lrt {}/lib/modules | tail -1 | awk '{{print $9;}}'"\
+ .format(SYSIMG_PATH)).read().rstrip()
+
+ # kernel and initrd come in various locations depending on the distro
+
+ kernel_candidates = []
+ kernel_candidates.append("/boot/vmlinuz-{}*".format(kversion))
+ # on f23 starting dec. 2015 - what a twisted naming scheme
+ kernel_candidates.append("/boot/*/{}*/linux".format(kversion))
+
+ initrd_candidates = []
+ # f16/18: expect initramfs image here
+ initrd_candidates.append ("/boot/initramfs-{}.img".format(kversion))
+ # f20: uses a uid of some kind, e.g. /boot/543f88c129de443baaa65800cf3927ce/<kversion>/initrd
+ initrd_candidates.append ("/boot/*/{}/initrd".format(kversion))
+ # Ubuntu:
+ initrd_candidates.append ("/boot/initrd.img-{}".format(kversion))
+
+ def install_from_sysimg_to_tmp (candidates, name):
+ import glob
+ found = None
+ for pattern in candidates:
+ matches = glob.glob(SYSIMG_PATH+pattern)
+ log.write("locating {}: found {} matches in {}\n".format(name, len(matches), pattern))
+ if matches:
+ found = matches[0]
+ break
+ if not found:
+ raise Exception("Unable to locate {} for kexec'ing".format(name))
+ utils.sysexec("cp {} /tmp/{}".format(found, name))
+
+ install_from_sysimg_to_tmp(kernel_candidates, 'kernel')
+ install_from_sysimg_to_tmp(initrd_candidates, 'initrd')