3 # Copyright (c) 2003 Intel Corporation
6 # Copyright (c) 2004-2006 The Trustees of Princeton University
14 import UpdateNodeConfiguration
16 from Exceptions import *
20 import notify_messages
27 Load the kernel off of a node and boot to it.
28 This step assumes the disks are mounted on SYSIMG_PATH.
29 If successful, this function will not return. If it returns, no chain
32 Expect the following variables:
33 SYSIMG_PATH the path where the system image will be mounted
34 (always starts with TEMP_PATH)
35 ROOT_MOUNTED the node root file system is mounted
36 NODE_SESSION the unique session val set when we requested
37 the current boot state
38 PLCONF_DIR The directory to store PL configuration files in
40 Sets the following variables:
41 ROOT_MOUNTED the node root file system is mounted
44 log.write( "\n\nStep: Chain booting node.\n" )
46 # make sure we have the variables we need
48 SYSIMG_PATH= vars["SYSIMG_PATH"]
50 raise ValueError, "SYSIMG_PATH"
52 PLCONF_DIR= vars["PLCONF_DIR"]
54 raise ValueError, "PLCONF_DIR"
56 # its ok if this is blank
57 NODE_SESSION= vars["NODE_SESSION"]
59 NODE_MODEL_OPTIONS= vars["NODE_MODEL_OPTIONS"]
61 PARTITIONS= vars["PARTITIONS"]
62 if PARTITIONS == None:
63 raise ValueError, "PARTITIONS"
66 raise BootManagerException, "Missing variable in vars: %s\n" % var
67 except ValueError, var:
68 raise BootManagerException, "Variable in vars, shouldn't be: %s\n" % var
71 if vars.has_key('ROOT_MOUNTED'):
72 ROOT_MOUNTED= vars['ROOT_MOUNTED']
75 log.write( "Mounting node partitions\n" )
77 # simply creating an instance of this class and listing the system
78 # block devices will make them show up so vgscan can find the planetlab
80 systeminfo.get_block_device_list(vars, log)
82 utils.sysexec( "vgscan", log )
83 utils.sysexec( "vgchange -ay planetlab", log )
85 utils.makedirs( SYSIMG_PATH )
87 cmd = "mount %s %s" % (PARTITIONS["root"],SYSIMG_PATH)
88 utils.sysexec( cmd, log )
89 cmd = "mount -t proc none %s/proc" % SYSIMG_PATH
90 utils.sysexec( cmd, log )
91 cmd = "mount %s %s/vservers" % (PARTITIONS["vservers"],SYSIMG_PATH)
92 utils.sysexec( cmd, log )
95 vars['ROOT_MOUNTED']= 1
98 # write out the session value /etc/planetlab/session
100 session_file_path= "%s/%s/session" % (SYSIMG_PATH,PLCONF_DIR)
101 session_file= file( session_file_path, "w" )
102 session_file.write( str(NODE_SESSION) )
105 log.write( "Updated /etc/planetlab/session\n" )
107 log.write( "Unable to write out /etc/planetlab/session, continuing anyway\n" )
109 # update configuration files
110 log.write( "Updating configuration files.\n" )
112 cmd = "/etc/init.d/conf_files start --noscripts"
113 utils.sysexec_chroot( SYSIMG_PATH, cmd, log )
115 log.write("conf_files failed with \n %s" % e)
117 # update node packages
118 log.write( "Running node update.\n" )
119 if os.path.exists( SYSIMG_PATH + "/usr/bin/NodeUpdate.py" ):
120 cmd = "/usr/bin/NodeUpdate.py start noreboot"
122 # for backwards compatibility
123 cmd = "/usr/local/planetlab/bin/NodeUpdate.py start noreboot"
124 utils.sysexec_chroot( SYSIMG_PATH, cmd, log )
126 # Re-generate initrd right before kexec call
127 MakeInitrd.Run( vars, log )
129 # the following step should be done by NM
130 UpdateNodeConfiguration.Run( vars, log )
132 log.write( "Updating ssh public host key with PLC.\n" )
135 ssh_host_key_file= file("%s/etc/ssh/ssh_host_rsa_key.pub"%SYSIMG_PATH,"r")
136 ssh_host_key= ssh_host_key_file.read().strip()
137 ssh_host_key_file.close()
138 ssh_host_key_file= None
143 update_vals['ssh_host_key']= ssh_host_key
144 BootAPI.call_api_function( vars, "BootUpdateNode", (update_vals,) )
146 # get the kernel version
148 if NODE_MODEL_OPTIONS & ModelOptions.SMP:
151 log.write( "Copying kernel and initrd for booting.\n" )
152 utils.sysexec( "cp %s/boot/kernel-boot%s /tmp/kernel" % (SYSIMG_PATH,option), log )
153 utils.sysexec( "cp %s/boot/initrd-boot%s /tmp/initrd" % (SYSIMG_PATH,option), log )
157 log.write( "Unmounting disks.\n" )
158 utils.sysexec( "umount %s/vservers" % SYSIMG_PATH, log )
159 utils.sysexec( "umount %s/proc" % SYSIMG_PATH, log )
160 utils.sysexec( "umount %s" % SYSIMG_PATH, log )
161 utils.sysexec( "vgchange -an", log )
164 vars['ROOT_MOUNTED']= 0
166 log.write( "Unloading modules and chain booting to new kernel.\n" )
168 # further use of log after Upload will only output to screen
171 # regardless of whether kexec works or not, we need to stop trying to
173 cancel_boot_flag= "/tmp/CANCEL_BOOT"
174 utils.sysexec( "touch %s" % cancel_boot_flag, log )
176 # on 2.x cds (2.4 kernel) for sure, we need to shutdown everything
177 # to get kexec to work correctly. Even on 3.x cds (2.6 kernel),
178 # there are a few buggy drivers that don't disable their hardware
179 # correctly unless they are first unloaded.
181 utils.sysexec_noerr( "ifconfig eth0 down", log )
183 utils.sysexec_noerr( "killall dhclient", log )
185 utils.sysexec_noerr( "umount -a -r -t ext2,ext3", log )
186 utils.sysexec_noerr( "modprobe -r lvm-mod", log )
188 # modules that should not get unloaded
189 # unloading cpqphp causes a kernel panic
190 blacklist = [ "floppy", "cpqphp", "i82875p_edac", "mptspi"]
192 modules= file("/tmp/loadedmodules","r")
195 module= string.strip(line)
196 if module in blacklist :
197 log.write("Skipping unload of kernel module '%s'.\n"%module)
199 log.write( "Unloading %s\n" % module )
200 utils.sysexec_noerr( "modprobe -r %s" % module, log )
201 if "e1000" in module:
202 log.write("Unloading e1000 driver; sleeping 4 seconds...\n")
207 log.write( "Couldn't read /tmp/loadedmodules, continuing.\n" )
210 modules= file("/proc/modules", "r")
212 # Get usage count for USB
216 # Module Size UsageCount UsedBy State LoadAddress
217 parts= string.split(line)
219 if parts[0] == "usb_storage":
220 usb_usage += int(parts[2])
221 except IndexError, e:
222 log.write( "Couldn't parse /proc/modules, continuing.\n" )
228 # Module Size UsageCount UsedBy State LoadAddress
229 parts= string.split(line)
231 # While we would like to remove all "unused" modules,
232 # you can't trust usage count, especially for things
233 # like network drivers or RAID array drivers. Just try
234 # and unload a few specific modules that we know cause
235 # problems during chain boot, such as USB host
236 # controller drivers (HCDs) (PL6577).
237 # if int(parts[2]) == 0:
238 if False and re.search('_hcd$', parts[0]):
240 log.write( "NOT unloading %s since USB may be in use\n" % parts[0] )
242 log.write( "Unloading %s\n" % parts[0] )
243 utils.sysexec_noerr( "modprobe -r %s" % parts[0], log )
244 except IndexError, e:
245 log.write( "Couldn't parse /proc/modules, continuing.\n" )
247 log.write( "Couldn't read /proc/modules, continuing.\n" )
250 kargs = "root=%s ramdisk_size=8192" % PARTITIONS["mapper-root"]
251 if NODE_MODEL_OPTIONS & ModelOptions.SMP:
252 kargs = kargs + " " + "acpi=off"
254 kargsfb = open("/kargs.txt","r")
255 moreargs = kargsfb.readline()
257 moreargs = moreargs.strip()
258 log.write( 'Parsed in "%s" kexec args from /kargs.txt\n' % moreargs )
259 kargs = kargs + " " + moreargs
261 # /kargs.txt does not exist, which is fine. Just kexec with default
262 # kargs, which is ramdisk_size=8192
265 utils.sysexec_noerr( 'hwclock --systohc --utc ' )
266 utils.breakpoint ("Before kexec");
268 utils.sysexec( 'kexec --force --initrd=/tmp/initrd ' \
269 '--append="%s" /tmp/kernel' % kargs)
270 except BootManagerException, e:
271 # if kexec fails, we've shut the machine down to a point where nothing
272 # can run usefully anymore (network down, all modules unloaded, file
273 # systems unmounted. write out the error, and cancel the boot process
276 log.write( "-------------------------------------------------------\n" )
277 log.write( "kexec failed with the following error. Please report\n" )
278 log.write( "this problem to support@planet-lab.org.\n\n" )
279 log.write( str(e) + "\n\n" )
280 log.write( "The boot process has been canceled.\n" )
281 log.write( "-------------------------------------------------------\n\n" )