/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 # for centos5.3
16 # 14:42:27(UTC) No module dm-mem-cache found for kernel 2.6.22.19-vs2.3.0.34.33.onelab, aborting.
17 # http://kbase.redhat.com/faq/docs/DOC-16528;jsessionid=7E984A99DE8DB094D9FB08181C71717C.ab46478d
18 def bypassRaidIfNeeded(sysimg_path):
19     try:
20         [ a,b,c,d]=file('%s/etc/redhat-release'%sysimg_path).readlines()[0].strip().split()
21         if a !='CentOS': return
22         [major,minor]=[int(x) for x in c.split('.')]
23         if minor >= 3:
24             utils.sysexec_noerr('echo "DMRAID=no" >> %s/etc/sysconfig/mkinitrd/noraid' % sysimg_path)
25             utils.sysexec_noerr('chmod 755 %s/etc/sysconfig/mkinitrd/noraid' % sysimg_path)
26     except:
27         pass
28             
29         
30 def Run( vars, log ):
31     """
32     Rebuilds the system initrd, on first install or in case the
33     hardware changed.
34     """
35
36     log.write( "\n\nStep: Rebuilding initrd\n" )
37     
38     # make sure we have the variables we need
39     try:
40         SYSIMG_PATH= vars["SYSIMG_PATH"]
41         if SYSIMG_PATH == "":
42             raise ValueError, "SYSIMG_PATH"
43
44         PARTITIONS= vars["PARTITIONS"]
45         if PARTITIONS == None:
46             raise ValueError, "PARTITIONS"
47
48     except KeyError, var:
49         raise BootManagerException, "Missing variable in vars: %s\n" % var
50     except ValueError, var:
51         raise BootManagerException, "Variable in vars, shouldn't be: %s\n" % var
52
53     # mkinitrd needs /dev and /proc to do the right thing.
54     # /proc is already mounted, so bind-mount /dev here
55     # looks like this dir somehow already exists under f14
56     utils.sysexec_noerr("mount -o bind /dev %s/dev" % SYSIMG_PATH)
57     utils.sysexec("mount -t sysfs none %s/sys" % SYSIMG_PATH)
58
59     initrd, kernel_version= systeminfo.getKernelVersion(vars,log)
60     try:
61         utils.removefile( "%s/boot/%s" % (SYSIMG_PATH, initrd) )
62     except:
63         print "%s/boot/%s is already removed" % (SYSIMG_PATH, initrd)
64
65     # hack for CentOS 5.3
66     bypassRaidIfNeeded(SYSIMG_PATH)
67     utils.sysexec_chroot( SYSIMG_PATH, "mkinitrd -v --allow-missing /boot/initrd-%s.img %s" % \
68                (kernel_version, kernel_version), log )
69
70     utils.sysexec_noerr("umount %s/sys" % SYSIMG_PATH)
71     utils.sysexec_noerr("umount %s/dev" % SYSIMG_PATH)
72