/dev might be present but not populated. fixes the boot issue on f8/f12.
[bootmanager.git] / source / steps / MakeInitrd.py
1 #!/usr/bin/python
2
3 # Copyright (c) 2003 Intel Corporation
4 # All rights reserved.
5 #
6 # Copyright (c) 2004-2006 The Trustees of Princeton University
7 # All rights reserved.
8
9 import os
10
11 from Exceptions import *
12 import utils
13 import systeminfo
14
15 def kernelHasMkinitrd():
16     #  Older bootcds only support LinuxThreads.  This hack is to get mkinitrd
17     #  to run without segfaulting by using /lib/obsolete/linuxthreads
18     kver = os.popen("/bin/uname -r", "r").readlines()[0].rstrip().split(".")
19     if int(kver[1]) > 4:
20         return True
21     elif int(kver[1]) <=4:
22         return False
23
24
25 # for centos5.3
26 # 14:42:27(UTC) No module dm-mem-cache found for kernel 2.6.22.19-vs2.3.0.34.33.onelab, aborting.
27 # http://kbase.redhat.com/faq/docs/DOC-16528;jsessionid=7E984A99DE8DB094D9FB08181C71717C.ab46478d
28 def bypassRaidIfNeeded(sysimg_path):
29     try:
30         [ a,b,c,d]=file('%s/etc/redhat-release'%sysimg_path).readlines()[0].strip().split()
31         if a !='CentOS': return
32         [major,minor]=[int(x) for x in c.split('.')]
33         if minor >= 3:
34             utils.sysexec_noerr('echo "DMRAID=no" >> %s/etc/sysconfig/mkinitrd/noraid' % sysimg_path)
35             utils.sysexec_noerr('chmod 755 %s/etc/sysconfig/mkinitrd/noraid' % sysimg_path)
36     except:
37         pass
38             
39         
40 def Run( vars, log ):
41     """
42     Rebuilds the system initrd, on first install or in case the
43     hardware changed.
44     """
45
46     log.write( "\n\nStep: Rebuilding initrd\n" )
47     
48     # make sure we have the variables we need
49     try:
50         SYSIMG_PATH= vars["SYSIMG_PATH"]
51         if SYSIMG_PATH == "":
52             raise ValueError, "SYSIMG_PATH"
53
54         PARTITIONS= vars["PARTITIONS"]
55         if PARTITIONS == None:
56             raise ValueError, "PARTITIONS"
57
58     except KeyError, var:
59         raise BootManagerException, "Missing variable in vars: %s\n" % var
60     except ValueError, var:
61         raise BootManagerException, "Variable in vars, shouldn't be: %s\n" % var
62
63     # mkinitrd needs /dev and /proc to do the right thing.
64     # /proc is already mounted, so bind-mount /dev here
65     # looks like this dir somehow already exists under f14
66     utils.sysexec_noerr("mount -o bind /dev %s/dev" % SYSIMG_PATH)
67     utils.sysexec("mount -t sysfs none %s/sys" % SYSIMG_PATH)
68
69     initrd, kernel_version= systeminfo.getKernelVersion(vars,log)
70     try:
71         utils.removefile( "%s/boot/%s" % (SYSIMG_PATH, initrd) )
72     except:
73         print "%s/boot/%s is already removed" % (SYSIMG_PATH, initrd)
74
75     # hack for CentOS 5.3
76     bypassRaidIfNeeded(SYSIMG_PATH)
77     if kernelHasMkinitrd() == True:
78         utils.sysexec_chroot( SYSIMG_PATH, "mkinitrd -v --allow-missing /boot/initrd-%s.img %s" % \
79                    (kernel_version, kernel_version), log )
80     else:
81         shutil.copy("./mkinitrd.sh","%s/tmp/mkinitrd.sh" % SYSIMG_PATH)
82         os.chmod("%s/tmp/mkinitrd.sh" % SYSIMG_PATH, 755)
83         utils.sysexec_chroot( SYSIMG_PATH, "/tmp/mkinitrd.sh %s" % (kernel_version))
84
85     utils.sysexec_noerr("umount %s/sys" % SYSIMG_PATH)
86     utils.sysexec_noerr("umount %s/dev" % SYSIMG_PATH)
87