4 import InstallWriteConfig
5 import UpdateBootStateWithPLC
6 from Exceptions import *
9 from systeminfo import systeminfo
11 import notify_messages
16 Load the kernel off of a node and boot to it.
17 This step assumes the disks are mounted on SYSIMG_PATH.
18 If successful, this function will not return. If it returns, no chain
21 Expect the following variables:
22 BOOT_CD_VERSION A tuple of the current bootcd version
23 SYSIMG_PATH the path where the system image will be mounted
24 (always starts with TEMP_PATH)
25 ROOT_MOUNTED the node root file system is mounted
26 NODE_SESSION the unique session val set when we requested
27 the current boot state
28 PLCONF_DIR The directory to store PL configuration files in
30 Sets the following variables:
31 ROOT_MOUNTED the node root file system is mounted
34 log.write( "\n\nStep: Chain booting node.\n" )
36 # make sure we have the variables we need
38 BOOT_CD_VERSION= vars["BOOT_CD_VERSION"]
39 if BOOT_CD_VERSION == "":
40 raise ValueError, "BOOT_CD_VERSION"
42 SYSIMG_PATH= vars["SYSIMG_PATH"]
44 raise ValueError, "SYSIMG_PATH"
46 PLCONF_DIR= vars["PLCONF_DIR"]
48 raise ValueError, "PLCONF_DIR"
50 # its ok if this is blank
51 NODE_SESSION= vars["NODE_SESSION"]
54 raise BootManagerException, "Missing variable in vars: %s\n" % var
55 except ValueError, var:
56 raise BootManagerException, "Variable in vars, shouldn't be: %s\n" % var
59 if 'ROOT_MOUNTED' in vars.keys():
60 ROOT_MOUNTED= vars['ROOT_MOUNTED']
63 log.write( "Mounting node partitions\n" )
65 # old cds need extra utilities to run lvm
66 if BOOT_CD_VERSION[0] == 2:
67 compatibility.setup_lvm_2x_cd( vars, log )
69 # simply creating an instance of this class and listing the system
70 # block devices will make them show up so vgscan can find the planetlab
72 systeminfo().get_block_device_list()
74 utils.sysexec( "vgscan", log )
75 utils.sysexec( "vgchange -ay planetlab", log )
77 utils.makedirs( SYSIMG_PATH )
79 utils.sysexec( "mount /dev/planetlab/root %s" % SYSIMG_PATH, log )
80 utils.sysexec( "mount /dev/planetlab/vservers %s/vservers" %
84 vars['ROOT_MOUNTED']= 1
87 node_update_cmd= "/usr/local/planetlab/bin/NodeUpdate.py start noreboot"
89 log.write( "Running node update.\n" )
90 utils.sysexec( "chroot %s %s" % (SYSIMG_PATH,node_update_cmd), log )
92 log.write( "Updating ssh public host key with PLC.\n" )
95 ssh_host_key_file= file("%s/etc/ssh/ssh_host_rsa_key.pub"%SYSIMG_PATH,"r")
96 ssh_host_key= ssh_host_key_file.read().strip()
97 ssh_host_key_file.close()
98 ssh_host_key_file= None
102 # write out the session value /etc/planetlab/session
104 session_file_path= "%s/%s/session" % (SYSIMG_PATH,PLCONF_DIR)
105 session_file= file( session_file_path, "w" )
106 session_file.write( str(NODE_SESSION) )
109 log.write( "Updated /etc/planetlab/session\n" )
111 log.write( "Unable to write out /etc/planetlab/session, continuing anyway\n" )
114 update_vals['ssh_host_key']= ssh_host_key
115 BootAPI.call_api_function( vars, "BootUpdateNode", (update_vals,) )
117 # rewrite modprobe.conf in case there were any module changes
118 # from a new kernel installed.
119 log.write( "Rewriting /etc/modprobe.conf\n" )
120 (network_count,storage_count)= \
121 InstallWriteConfig.write_modprobeconf_file( vars, log )
123 log.write( "Copying kernel and initrd for booting.\n" )
124 utils.sysexec( "cp %s/boot/kernel-boot /tmp/kernel" % SYSIMG_PATH, log )
125 utils.sysexec( "cp %s/boot/initrd-boot /tmp/initrd" % SYSIMG_PATH, log )
127 log.write( "Unmounting disks.\n" )
128 utils.sysexec_noerr( "chroot %s umount /rcfs" % SYSIMG_PATH, log )
129 utils.sysexec_noerr( "umount -r /dev/planetlab/vservers", log )
130 utils.sysexec_noerr( "umount -r /dev/planetlab/root", log )
131 utils.sysexec_noerr( "vgchange -an", log )
134 vars['ROOT_MOUNTED']= 0
136 # before we do the real kexec, check to see if we had any
137 # network drivers written to modprobe.conf. if not, return -1,
138 # which will cause this node to be switched to a debug state.
139 if network_count == 0:
140 log.write( "\nIt appears we don't have any network drivers. Aborting.\n" )
142 vars['BOOT_STATE']= 'dbg'
143 vars['STATE_CHANGE_NOTIFY']= 1
144 vars['STATE_CHANGE_NOTIFY_MESSAGE']= \
145 notify_messages.MSG_NO_DETECTED_NETWORK
146 UpdateBootStateWithPLC.Run( vars, log )
150 log.write( "Unloading modules and chain booting to new kernel.\n" )
152 # further use of log after Upload will only output to screen
155 # regardless of whether kexec works or not, we need to stop trying to
157 cancel_boot_flag= "/tmp/CANCEL_BOOT"
158 utils.sysexec( "touch %s" % cancel_boot_flag, log )
160 # on 2.x cds (2.4 kernel) for sure, we need to shutdown everything
161 # to get kexec to work correctly. Even on 3.x cds (2.6 kernel),
162 # there are a few buggy drivers that don't disable their hardware
163 # correctly unless they are first unloaded.
165 utils.sysexec_noerr( "ifconfig eth0 down", log )
167 if BOOT_CD_VERSION[0] == 2:
168 utils.sysexec_noerr( "killall dhcpcd", log )
169 elif BOOT_CD_VERSION[0] == 3:
170 utils.sysexec_noerr( "killall dhclient", log )
172 utils.sysexec_noerr( "umount -a -r -t ext2,ext3", log )
173 utils.sysexec_noerr( "modprobe -r lvm-mod", log )
176 modules= file("/tmp/loadedmodules","r")
179 module= string.strip(line)
181 log.write( "Unloading %s\n" % module )
182 utils.sysexec_noerr( "modprobe -r %s" % module, log )
186 log.write( "Couldn't read /tmp/loadedmodules, continuing.\n" )
189 modules= file("/proc/modules", "r")
191 # Get usage count for USB
195 # Module Size UsageCount UsedBy State LoadAddress
196 parts= string.split(line)
198 if parts[0] == "usb_storage":
199 usb_usage += int(parts[2])
200 except IndexError, e:
201 log.write( "Couldn't parse /proc/modules, continuing.\n" )
207 # Module Size UsageCount UsedBy State LoadAddress
208 parts= string.split(line)
210 # While we would like to remove all "unused" modules,
211 # you can't trust usage count, especially for things
212 # like network drivers or RAID array drivers. Just try
213 # and unload a few specific modules that we know cause
214 # problems during chain boot, such as USB host
215 # controller drivers (HCDs) (PL6577).
216 # if int(parts[2]) == 0:
217 if re.search('_hcd$', parts[0]):
219 log.write( "NOT unloading %s since USB may be in use\n" % parts[0] )
221 log.write( "Unloading %s\n" % parts[0] )
222 utils.sysexec_noerr( "modprobe -r %s" % parts[0], log )
223 except IndexError, e:
224 log.write( "Couldn't parse /proc/modules, continuing.\n" )
226 log.write( "Couldn't read /proc/modules, continuing.\n" )
229 kargs = "ramdisk_size=8192"
231 kargsfb = open("/kargs.txt","r")
232 moreargs = kargsfb.readline()
234 moreargs = moreargs.strip()
235 log.write( 'Parsed in "%s" kexec args from /kargs.txt\n' % moreargs )
236 kargs = kargs + " " + moreargs
238 # /kargs.txt does not exist, which is fine. Just kexec with default
239 # kargs, which is ramdisk_size=8192
243 utils.sysexec( 'kexec --force --initrd=/tmp/initrd ' \
244 '--append="%s" /tmp/kernel' % kargs)
245 except BootManagerException, e:
246 # if kexec fails, we've shut the machine down to a point where nothing
247 # can run usefully anymore (network down, all modules unloaded, file
248 # systems unmounted. write out the error, and cancel the boot process
251 log.write( "-------------------------------------------------------\n" )
252 log.write( "kexec failed with the following error. Please report\n" )
253 log.write( "this problem to support@planet-lab.org.\n\n" )
254 log.write( str(e) + "\n\n" )
255 log.write( "The boot process has been canceled.\n" )
256 log.write( "-------------------------------------------------------\n\n" )