From 7af554c2e298701f712922f99512d6b81053df66 Mon Sep 17 00:00:00 2001 From: Mark Huang Date: Tue, 22 Aug 2006 22:01:47 +0000 Subject: [PATCH] always regenerate initrd before booting in case hardware changes or new kernel is installed --- source/BootManager.py | 1 + source/steps/InstallUninitHardware.py | 3 -- source/steps/InstallWriteConfig.py | 27 ------------- source/steps/MakeInitrd.py | 57 +++++++++++++++++++++++++++ 4 files changed, 58 insertions(+), 30 deletions(-) create mode 100644 source/steps/MakeInitrd.py diff --git a/source/BootManager.py b/source/BootManager.py index 76b42e5..c4eea37 100755 --- a/source/BootManager.py +++ b/source/BootManager.py @@ -191,6 +191,7 @@ class BootManager: InstallInit.Run( self.VARS, self.LOG ) if ValidateNodeInstall.Run( self.VARS, self.LOG ): WriteModprobeConfig.Run( self.VARS, self.LOG ) + MakeInitrd.Run( self.VARS, self.LOG ) WriteNetworkConfig.Run( self.VARS, self.LOG ) # the following step should be done by NM UpdateNodeConfiguration.Run( self.VARS, self.LOG ) diff --git a/source/steps/InstallUninitHardware.py b/source/steps/InstallUninitHardware.py index a54534f..df99515 100644 --- a/source/steps/InstallUninitHardware.py +++ b/source/steps/InstallUninitHardware.py @@ -70,9 +70,6 @@ def Run( vars, log ): except OSError, e: pass - log.write( "Unmounting proc.\n" ) - utils.sysexec( "umount %s/proc" % SYSIMG_PATH, log ) - log.write( "Shutting down swap\n" ) utils.sysexec( "swapoff %s" % PARTITIONS["swap"], log ) diff --git a/source/steps/InstallWriteConfig.py b/source/steps/InstallWriteConfig.py index 2d1582c..ee5a0cc 100644 --- a/source/steps/InstallWriteConfig.py +++ b/source/steps/InstallWriteConfig.py @@ -130,33 +130,6 @@ def Run( vars, log ): if method == "dhcp": utils.sysexec( "cp /etc/resolv.conf %s/etc/" % SYSIMG_PATH, log ) - # the kernel rpm should have already done this, so don't fail the - # install if it fails - log.write( "Mounting /proc in system image\n" ) - utils.sysexec_noerr( "mount -t proc proc %s/proc" % SYSIMG_PATH, log ) - - # mkinitrd references both /etc/modprobe.conf and /etc/fstab - # as well as /proc/lvm/global. The kernel RPM installation - # likely created an improper initrd since these files did not - # yet exist. Re-create the initrd here. - log.write( "Making initrd\n" ) - - # trick mkinitrd in case the current environment does not have device mapper - fake_root_lvm= False - if not os.path.exists( "%s/%s" % (SYSIMG_PATH,PARTITIONS["mapper-root"]) ): - fake_root_lvm= True - utils.makedirs( "%s/dev/mapper" % SYSIMG_PATH ) - rootdev= file( "%s/%s" % (SYSIMG_PATH,PARTITIONS["mapper-root"]), "w" ) - rootdev.close() - - initrd, kernel_version= systeminfo.getKernelVersion(vars,log) - utils.removefile( "%s/boot/%s" % (SYSIMG_PATH, initrd) ) - utils.sysexec( "chroot %s mkinitrd /boot/initrd-%s.img %s" % \ - (SYSIMG_PATH, kernel_version, kernel_version), log ) - - if fake_root_lvm == True: - utils.removefile( "%s/%s" % (SYSIMG_PATH,PARTITIONS["mapper-root"]) ) - log.write( "Writing node install version\n" ) utils.makedirs( "%s/etc/planetlab" % SYSIMG_PATH ) ver= file( "%s/etc/planetlab/install_version" % SYSIMG_PATH, "w" ) diff --git a/source/steps/MakeInitrd.py b/source/steps/MakeInitrd.py new file mode 100644 index 0000000..4854da7 --- /dev/null +++ b/source/steps/MakeInitrd.py @@ -0,0 +1,57 @@ +#!/usr/bin/python2 -u + +# Copyright (c) 2003 Intel Corporation +# All rights reserved. +# +# Copyright (c) 2004-2006 The Trustees of Princeton University +# All rights reserved. + +import os, string + +from Exceptions import * +import utils +import systeminfo + +def Run( vars, log ): + """ + Rebuilds the system initrd, on first install or in case the + hardware changed. + """ + + log.write( "\n\nStep: Rebuilding initrd\n" ) + + # make sure we have the variables we need + try: + SYSIMG_PATH= vars["SYSIMG_PATH"] + if SYSIMG_PATH == "": + raise ValueError, "SYSIMG_PATH" + + PARTITIONS= vars["PARTITIONS"] + if PARTITIONS == None: + raise ValueError, "PARTITIONS" + + except KeyError, var: + raise BootManagerException, "Missing variable in vars: %s\n" % var + except ValueError, var: + raise BootManagerException, "Variable in vars, shouldn't be: %s\n" % var + + # mkinitrd attempts to determine if the root fs is on a logical + # volume by checking if the root device contains /dev/mapper in + # its path. The device node must exist for the check to succeed, + # but since it's usually managed by devfs or udev, so is probably + # not present, we just create a dummy file. + + fake_root_lvm= False + if not os.path.exists( "%s/%s" % (SYSIMG_PATH,PARTITIONS["mapper-root"]) ): + fake_root_lvm= True + utils.makedirs( "%s/dev/mapper" % SYSIMG_PATH ) + rootdev= file( "%s/%s" % (SYSIMG_PATH,PARTITIONS["mapper-root"]), "w" ) + rootdev.close() + + initrd, kernel_version= systeminfo.getKernelVersion(vars,log) + utils.removefile( "%s/boot/%s" % (SYSIMG_PATH, initrd) ) + utils.sysexec( "chroot %s mkinitrd -v /boot/initrd-%s.img %s" % \ + (SYSIMG_PATH, kernel_version, kernel_version), log ) + + if fake_root_lvm == True: + utils.removefile( "%s/%s" % (SYSIMG_PATH,PARTITIONS["mapper-root"]) ) -- 2.43.0