6 # Copyright (c) 2003 Intel Corporation
9 # Copyright (c) 2004-2006 The Trustees of Princeton University
10 # All rights reserved.
17 import UpdateNodeConfiguration
18 from Exceptions import *
22 import notify_messages
29 Load the kernel off of a node and boot to it.
30 This step assumes the disks are mounted on SYSIMG_PATH.
31 If successful, this function will not return. If it returns, no chain
34 Expect the following variables:
35 SYSIMG_PATH the path where the system image will be mounted
36 (always starts with TEMP_PATH)
37 ROOT_MOUNTED the node root file system is mounted
38 NODE_SESSION the unique session val set when we requested
39 the current boot state
40 PLCONF_DIR The directory to store PL configuration files in
42 Sets the following variables:
43 ROOT_MOUNTED the node root file system is mounted
46 log.write( "\n\nStep: Chain booting node.\n" )
48 # make sure we have the variables we need
50 SYSIMG_PATH= vars["SYSIMG_PATH"]
52 raise ValueError, "SYSIMG_PATH"
54 PLCONF_DIR= vars["PLCONF_DIR"]
56 raise ValueError, "PLCONF_DIR"
58 # its ok if this is blank
59 NODE_SESSION= vars["NODE_SESSION"]
61 NODE_MODEL_OPTIONS= vars["NODE_MODEL_OPTIONS"]
63 PARTITIONS= vars["PARTITIONS"]
64 if PARTITIONS == None:
65 raise ValueError, "PARTITIONS"
68 raise BootManagerException, "Missing variable in vars: %s\n" % var
69 except ValueError, var:
70 raise BootManagerException, "Variable in vars, shouldn't be: %s\n" % var
73 if vars.has_key('ROOT_MOUNTED'):
74 ROOT_MOUNTED= vars['ROOT_MOUNTED']
77 log.write( "Mounting node partitions\n" )
79 # simply creating an instance of this class and listing the system
80 # block devices will make them show up so vgscan can find the planetlab
82 systeminfo.get_block_device_list(vars, log)
84 utils.sysexec( "vgscan", log )
85 utils.sysexec( "vgchange -ay planetlab", log )
87 utils.makedirs( SYSIMG_PATH )
89 cmd = "mount %s %s" % (PARTITIONS["root"],SYSIMG_PATH)
90 utils.sysexec( cmd, log )
91 cmd = "mount -t proc none %s/proc" % SYSIMG_PATH
92 utils.sysexec( cmd, log )
93 cmd = "mount %s %s/vservers" % (PARTITIONS["vservers"],SYSIMG_PATH)
94 utils.sysexec( cmd, log )
97 vars['ROOT_MOUNTED']= 1
100 # write out the session value /etc/planetlab/session
102 session_file_path= "%s/%s/session" % (SYSIMG_PATH,PLCONF_DIR)
103 session_file= file( session_file_path, "w" )
104 session_file.write( str(NODE_SESSION) )
107 log.write( "Updated /etc/planetlab/session\n" )
109 log.write( "Unable to write out /etc/planetlab/session, continuing anyway\n" )
111 # update configuration files
112 log.write( "Updating configuration files.\n" )
114 cmd = "/etc/init.d/conf_files start --noscripts"
115 utils.sysexec_chroot( SYSIMG_PATH, cmd, log )
117 log.write("conf_files failed with \n %s" % e)
119 # update node packages
120 log.write( "Running node update.\n" )
121 if os.path.exists( SYSIMG_PATH + "/usr/bin/NodeUpdate.py" ):
122 cmd = "/usr/bin/NodeUpdate.py start noreboot"
124 # for backwards compatibility
125 cmd = "/usr/local/planetlab/bin/NodeUpdate.py start noreboot"
126 utils.sysexec_chroot( SYSIMG_PATH, cmd, log )
128 # the following step should be done by NM
129 UpdateNodeConfiguration.Run( vars, log )
131 log.write( "Updating ssh public host key with PLC.\n" )
134 ssh_host_key_file= file("%s/etc/ssh/ssh_host_rsa_key.pub"%SYSIMG_PATH,"r")
135 ssh_host_key= ssh_host_key_file.read().strip()
136 ssh_host_key_file.close()
137 ssh_host_key_file= None
142 update_vals['ssh_host_key']= ssh_host_key
143 BootAPI.call_api_function( vars, "BootUpdateNode", (update_vals,) )
145 # get the kernel version
147 if NODE_MODEL_OPTIONS & ModelOptions.SMP:
150 log.write( "Copying kernel and initrd for booting.\n" )
151 utils.sysexec( "cp %s/boot/kernel-boot%s /tmp/kernel" % (SYSIMG_PATH,option), log )
152 utils.sysexec( "cp %s/boot/initrd-boot%s /tmp/initrd" % (SYSIMG_PATH,option), log )
156 log.write( "Unmounting disks.\n" )
157 utils.sysexec( "umount %s/vservers" % SYSIMG_PATH, log )
158 utils.sysexec( "umount %s/proc" % SYSIMG_PATH, log )
159 utils.sysexec( "umount %s" % SYSIMG_PATH, log )
160 utils.sysexec( "vgchange -an", log )
163 vars['ROOT_MOUNTED']= 0
165 log.write( "Unloading modules and chain booting to new kernel.\n" )
167 # further use of log after Upload will only output to screen
170 # regardless of whether kexec works or not, we need to stop trying to
172 cancel_boot_flag= "/tmp/CANCEL_BOOT"
173 utils.sysexec( "touch %s" % cancel_boot_flag, log )
175 # on 2.x cds (2.4 kernel) for sure, we need to shutdown everything
176 # to get kexec to work correctly. Even on 3.x cds (2.6 kernel),
177 # there are a few buggy drivers that don't disable their hardware
178 # correctly unless they are first unloaded.
180 utils.sysexec_noerr( "ifconfig eth0 down", log )
182 utils.sysexec_noerr( "killall dhclient", log )
184 utils.sysexec_noerr( "umount -a -r -t ext2,ext3", log )
185 utils.sysexec_noerr( "modprobe -r lvm-mod", log )
187 # modules that should not get unloaded
188 # unloading cpqphp causes a kernel panic
189 blacklist = [ "floppy", "cpqphp", "i82875p_edac", "mptspi"]
191 modules= file("/tmp/loadedmodules","r")
194 module= string.strip(line)
195 if module in blacklist :
196 log.write("Skipping unload of kernel module '%s'.\n"%module)
198 log.write( "Unloading %s\n" % module )
199 utils.sysexec_noerr( "modprobe -r %s" % module, log )
200 if "e1000" in module:
201 log.write("Unloading e1000 driver; sleeping 4 seconds...\n")
206 log.write( "Couldn't read /tmp/loadedmodules, continuing.\n" )
209 modules= file("/proc/modules", "r")
211 # Get usage count for USB
215 # Module Size UsageCount UsedBy State LoadAddress
216 parts= string.split(line)
218 if parts[0] == "usb_storage":
219 usb_usage += int(parts[2])
220 except IndexError, e:
221 log.write( "Couldn't parse /proc/modules, continuing.\n" )
227 # Module Size UsageCount UsedBy State LoadAddress
228 parts= string.split(line)
230 # While we would like to remove all "unused" modules,
231 # you can't trust usage count, especially for things
232 # like network drivers or RAID array drivers. Just try
233 # and unload a few specific modules that we know cause
234 # problems during chain boot, such as USB host
235 # controller drivers (HCDs) (PL6577).
236 # if int(parts[2]) == 0:
237 if False and re.search('_hcd$', parts[0]):
239 log.write( "NOT unloading %s since USB may be in use\n" % parts[0] )
241 log.write( "Unloading %s\n" % parts[0] )
242 utils.sysexec_noerr( "modprobe -r %s" % parts[0], log )
243 except IndexError, e:
244 log.write( "Couldn't parse /proc/modules, continuing.\n" )
246 log.write( "Couldn't read /proc/modules, continuing.\n" )
249 kargs = "root=%s ramdisk_size=8192" % PARTITIONS["mapper-root"]
250 if NODE_MODEL_OPTIONS & ModelOptions.SMP:
251 kargs = kargs + " " + "acpi=off"
253 kargsfb = open("/kargs.txt","r")
254 moreargs = kargsfb.readline()
256 moreargs = moreargs.strip()
257 log.write( 'Parsed in "%s" kexec args from /kargs.txt\n' % moreargs )
258 kargs = kargs + " " + moreargs
260 # /kargs.txt does not exist, which is fine. Just kexec with default
261 # kargs, which is ramdisk_size=8192
264 utils.sysexec_noerr( 'hwclock --systohc --utc ' )
265 utils.breakpoint ("Before kexec");
267 utils.sysexec( 'kexec --force --initrd=/tmp/initrd ' \
268 '--append="%s" /tmp/kernel' % kargs)
269 except BootManagerException, e:
270 # if kexec fails, we've shut the machine down to a point where nothing
271 # can run usefully anymore (network down, all modules unloaded, file
272 # systems unmounted. write out the error, and cancel the boot process
275 log.write( "-------------------------------------------------------\n" )
276 log.write( "kexec failed with the following error. Please report\n" )
277 log.write( "this problem to support@planet-lab.org.\n\n" )
278 log.write( str(e) + "\n\n" )
279 log.write( "The boot process has been canceled.\n" )
280 log.write( "-------------------------------------------------------\n\n" )