+ log.write("Couldn't read /tmp/loadedmodules, continuing.\n")
+
+ try:
+ modules = file("/proc/modules", "r")
+
+ # Get usage count for USB
+ usb_usage = 0
+ for line in modules:
+ try:
+ # Module Size UsageCount UsedBy State LoadAddress
+ parts = string.split(line)
+
+ if parts[0] == "usb_storage":
+ usb_usage += int(parts[2])
+ except IndexError as e:
+ log.write("Couldn't parse /proc/modules, continuing.\n")
+
+ modules.seek(0)
+
+ for line in modules:
+ try:
+ # Module Size UsageCount UsedBy State LoadAddress
+ parts = string.split(line)
+
+ # While we would like to remove all "unused" modules,
+ # you can't trust usage count, especially for things
+ # like network drivers or RAID array drivers. Just try
+ # and unload a few specific modules that we know cause
+ # problems during chain boot, such as USB host
+ # controller drivers (HCDs) (PL6577).
+ # if int(parts[2]) == 0:
+ if False and re.search('_hcd$', parts[0]):
+ if usb_usage > 0:
+ log.write("NOT unloading {} since USB may be in use\n".format(parts[0]))
+ else:
+ log.write("Unloading {}\n".format(parts[0]))
+ utils.sysexec_noerr("modprobe -r {}".format(parts[0]), log)
+ except IndexError as e:
+ log.write("Couldn't parse /proc/modules, continuing.\n")
+ except IOError:
+ log.write("Couldn't read /proc/modules, continuing.\n")
+
+
+ kargs = "root={} ramdisk_size=8192".format(PARTITIONS["root"])
+ if NODE_MODEL_OPTIONS & ModelOptions.SMP:
+ kargs = kargs + " " + "acpi=off"
+ try:
+ kargsfb = open("/kargs.txt","r")
+ moreargs = kargsfb.readline()
+ kargsfb.close()
+ moreargs = moreargs.strip()
+ log.write('Parsed in "{}" kexec args from /kargs.txt\n'.format(moreargs))
+ kargs = kargs + " " + moreargs
+ except IOError:
+ # /kargs.txt does not exist, which is fine. Just kexec with default
+ # kargs, which is ramdisk_size=8192
+ pass
+
+ utils.sysexec_noerr('hwclock --systohc --utc ', log)
+# utils.breakpoint("Before kexec");
+ try:
+ utils.sysexec('kexec --force --initrd=/tmp/initrd --append="{}" /tmp/kernel'.format(kargs), log)
+ except BootManagerException as e:
+ # if kexec fails, we've shut the machine down to a point where nothing
+ # can run usefully anymore (network down, all modules unloaded, file
+ # systems unmounted. write out the error, and cancel the boot process
+
+ log.write("\n\n")
+ log.write("-------------------------------------------------------\n")
+ log.write("kexec failed with the following error. Please report\n")
+ log.write("this problem to support@planet-lab.org.\n\n")
+ log.write(str(e) + "\n\n")
+ log.write("The boot process has been canceled.\n")
+ log.write("-------------------------------------------------------\n\n")