6 # Copyright (c) 2003 Intel Corporation
9 # Copyright (c) 2004-2006 The Trustees of Princeton University
10 # All rights reserved.
14 from Exceptions import *
19 def kernelHasMkinitrd():
20 # Older bootcds only support LinuxThreads. This hack is to get mkinitrd
21 # to run without segfaulting by using /lib/obsolete/linuxthreads
22 kver = os.popen("/bin/uname -r", "r").readlines()[0].rstrip().split(".")
25 elif int(kver[1]) <=4:
30 # 14:42:27(UTC) No module dm-mem-cache found for kernel 2.6.22.19-vs2.3.0.34.33.onelab, aborting.
31 # http://kbase.redhat.com/faq/docs/DOC-16528;jsessionid=7E984A99DE8DB094D9FB08181C71717C.ab46478d
32 def bypassRaidIfNeeded(sysimg_path):
34 [ a,b,c,d]=file('%s/etc/redhat-release'%sysimg_path).readlines()[0].strip().split()
35 if a !='CentOS': return
36 [major,minor]=[int(x) for x in c.split('.')]
38 utils.sysexec_noerr('echo "DMRAID=no" >> %s/etc/sysconfig/mkinitrd/noraid' % sysimg_path)
39 utils.sysexec_noerr('chmod 755 %s/etc/sysconfig/mkinitrd/noraid' % sysimg_path)
46 Rebuilds the system initrd, on first install or in case the
50 log.write( "\n\nStep: Rebuilding initrd\n" )
52 # make sure we have the variables we need
54 SYSIMG_PATH= vars["SYSIMG_PATH"]
56 raise ValueError, "SYSIMG_PATH"
58 PARTITIONS= vars["PARTITIONS"]
59 if PARTITIONS == None:
60 raise ValueError, "PARTITIONS"
63 raise BootManagerException, "Missing variable in vars: %s\n" % var
64 except ValueError, var:
65 raise BootManagerException, "Variable in vars, shouldn't be: %s\n" % var
67 # mkinitrd needs /dev and /proc to do the right thing.
68 # /proc is already mounted, so bind-mount /dev here
69 utils.sysexec("mount -o bind /dev %s/dev" % SYSIMG_PATH)
70 utils.sysexec("mount -t sysfs none %s/sys" % SYSIMG_PATH)
72 initrd, kernel_version= systeminfo.getKernelVersion(vars,log)
74 utils.removefile( "%s/boot/%s" % (SYSIMG_PATH, initrd) )
76 print "%s/boot/%s is already removed" % (SYSIMG_PATH, initrd)
79 bypassRaidIfNeeded(SYSIMG_PATH)
80 if kernelHasMkinitrd() == True:
81 utils.sysexec_chroot( SYSIMG_PATH, "mkinitrd -v /boot/initrd-%s.img %s" % \
82 (kernel_version, kernel_version), log )
84 shutil.copy("./mkinitrd.sh","%s/tmp/mkinitrd.sh" % SYSIMG_PATH)
85 os.chmod("%s/tmp/mkinitrd.sh" % SYSIMG_PATH, 755)
86 utils.sysexec_chroot( SYSIMG_PATH, "/tmp/mkinitrd.sh %s" % (kernel_version))
88 utils.sysexec_noerr("umount %s/sys" % SYSIMG_PATH)
89 utils.sysexec_noerr("umount %s/dev" % SYSIMG_PATH)