Generate more complete device.map grub file when upgrading grub (#533621).
Hi,
Looks ok, so ack.
Regards,
Hans
On 11/13/2009 11:01 AM, Radek Vykydal wrote:
When updating device.map during upgrade of grub, I missed case when driveorder
changes between install and upgrade (e.g. when driveorder different from that
detected during upgrade had been specified when isntalling) in my previous
patch. To fix it, I generate device.map in similar way as when installing (only
updating it with some devices that we can know about only from updated
device.map - e.g. chainloaded devices). This brought me to another
consolidation of the code (started in previous grub installation patches):
* remove updateGrub, use writeGrub with upgrade flag instead
* move code from writeGrub into separate methods
writeGrubConf (called only for grub (re)install)
writeSysconfig (called both for grub (re)install and upgrade)
writeDeviceMap (called both for grub (re)install and upgrade)
* remove old writeSysconfig and updateDeviceMap that were called
only from upgradeGrub, use new writeSysconfig and writeDeviceMap
with upgrade flag instead.
---
booty/x86.py | 164 ++++++++++++++++++++++-----------------------------------
1 files changed, 63 insertions(+), 101 deletions(-)
- grubTarget = bl.getDevice()
-
f = open(cf, "w+")
f.write("# grub.conf generated by anaconda
")
@@ -221,24 +254,16 @@ class x86BootloaderInfo(efiBootloaderInfo):
f.write("# Note that you do not have to rerun grub "
"after making changes to this file
")
- try:
- bootDev = self.storage.mountpoints["/boot"]
- grubPath = "/grub"
- cfPath = "/"
+ if grubPath == "/grub":
f.write("# NOTICE: You have a /boot partition. This means "
"that
")
f.write("# all kernel and initrd paths are relative "
"to /boot/, eg.
")
- except KeyError:
- bootDev = rootDev
- grubPath = "/boot/grub"
- cfPath = "/boot/"
+ else:
f.write("# NOTICE: You do not have a /boot partition. "
"This means that
")
f.write("# all kernel and initrd paths are relative "
"to /, eg.
")
-
- bootDevs = self.getPhysicalDevices(bootDev.name)
@@ -369,24 +389,31 @@ class x86BootloaderInfo(efiBootloaderInfo):
os.symlink(".." + self.configfile, etcgrub)
except:
pass
-
- for dev in self.getPhysicalDevices(rootDev.name) + bootDevs:
- usedDevs[dev] = 1
+
+ def writeDeviceMap(self, instRoot, usedDevs, upgrade=False):
if os.access(instRoot + "/boot/grub/device.map", os.R_OK):
+ # For upgrade, we want also e.g. devs that has been added
+ # to file during install for chainloading.
+ if upgrade:
+ f = open(instRoot + "/boot/grub/device.map", "r")
+ for line in f:
+ if line.startswith('(hd'):
+ (grubdisk, dev) = line.split()[:2]
+ dev = dev[5:]
+ if dev in self.drivelist:
+ usedDevs.add(dev)
+ f.close()
os.rename(instRoot + "/boot/grub/device.map",
instRoot + "/boot/grub/device.map.rpmsave")
f = open(instRoot + "/boot/grub/device.map", "w+")
f.write("# this device map was generated by anaconda
")
- devs = usedDevs.keys()
- usedDevs = {}
- for dev in devs:
+ usedDiskDevs = set()
+ for dev in usedDevs:
drive = getDiskPart(dev, self.storage)[0]
- if usedDevs.has_key(drive):
- continue
- usedDevs[drive] = 1
- devs = usedDevs.keys()
+ usedDiskDevs.add(drive)
+ devs = list(usedDiskDevs)
devs.sort()
for drive in devs:
# XXX hack city. If they're not the sort of thing that'll
@@ -396,25 +423,25 @@ class x86BootloaderInfo(efiBootloaderInfo):
f.write("(%s) %s
" % (self.grubbyDiskName(drive), dev.path))
f.close()
+ def writeSysconfig(self, instRoot, grubTarget, upgrade):
sysconf = '/etc/sysconfig/grub'
if os.access (instRoot + sysconf, os.R_OK):
+ if upgrade:
+ return
self.perms = os.stat(instRoot + sysconf)[0]& 0777
os.rename(instRoot + sysconf,
instRoot + sysconf + '.rpmsave')
# if it's an absolute symlink, just get it out of our way
elif (os.path.islink(instRoot + sysconf) and
os.readlink(instRoot + sysconf)[0] == '/'):
+ if upgrade:
+ return
os.rename(instRoot + sysconf,
instRoot + sysconf + '.rpmsave')
f = open(instRoot + sysconf, 'w+')
f.write("boot=/dev/%s
" %(grubTarget,))
f.write("forcelba=0
")
f.close()
-
- if not justConfigFile:
- return self.installGrub(instRoot, bootDev, grubTarget, grubPath, cfPath)
-
- return 0