- log.write( "Copying kernel and initrd for booting.\n" )
- utils.sysexec( "cp %s/boot/kernel-boot%s /tmp/kernel" % (SYSIMG_PATH,option), log )
- utils.sysexec( "cp %s/boot/initrd-boot%s /tmp/initrd" % (SYSIMG_PATH,option), log )
-
- log.write( "Unmounting disks.\n" )
- try:
- # backwards compat, though, we should never hit this case post PL 3.2
- os.stat("%s/rcfs/taskclass"%SYSIMG_PATH)
- utils.sysexec_noerr( "chroot %s umount /rcfs" % SYSIMG_PATH, log )
- except OSError, e:
- pass
- utils.sysexec_noerr( "umount -r /dev/planetlab/vservers", log )
- utils.sysexec_noerr( "umount -r /dev/planetlab/root", log )
- utils.sysexec_noerr( "vgchange -an", log )
-
- ROOT_MOUNTED= 0
- vars['ROOT_MOUNTED']= 0
-
- # before we do the real kexec, check to see if we had any
- # network drivers written to modprobe.conf. if not, return -1,
- # which will cause this node to be switched to a debug state.
- if network_count == 0:
- log.write( "\nIt appears we don't have any network drivers. Aborting.\n" )
-
- vars['BOOT_STATE']= 'dbg'
- vars['STATE_CHANGE_NOTIFY']= 1
- vars['STATE_CHANGE_NOTIFY_MESSAGE']= \
- notify_messages.MSG_NO_DETECTED_NETWORK
- UpdateBootStateWithPLC.Run( vars, log )
-
- return
-
- log.write( "Unloading modules and chain booting to new kernel.\n" )
+ 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')
+
+ BootAPI.save(vars)
+
+ log.write("Unmounting disks.\n")
+
+ if (vars['ONE_PARTITION'] != '1'):
+ utils.sysexec("umount {}/vservers".format(SYSIMG_PATH), log)
+ utils.sysexec("umount {}/proc".format(SYSIMG_PATH), log)
+ utils.sysexec_noerr("umount {}/dev".format(SYSIMG_PATH), log)
+ utils.sysexec_noerr("umount {}/sys".format(SYSIMG_PATH), log)
+ utils.sysexec("umount {}".format(SYSIMG_PATH), log)
+ utils.sysexec("vgchange -an", log)
+
+ ROOT_MOUNTED = 0
+ vars['ROOT_MOUNTED'] = 0
+
+ # Change runlevel to 'boot' prior to kexec.
+ StopRunlevelAgent.Run(vars, log)
+
+ log.write("Unloading modules and chain booting to new kernel.\n")