def install(self): # Create extlinux configs bootloader.writeBootmanConfigs(self) logCall('chroot "%s" /sbin/bootman' % self.image_root) self.mkinitrd() if not self.do_install: return # Bind-mount /dev so extlinux can write to the boot sector image_dev = os.path.join(self.image_root, 'dev') logCall('mount -n --bind /dev "%s"' % image_dev) # Install extlinux try: util.mkdirChain(os.path.join(self.image_root, 'boot', 'extlinux')) logCall('chroot "%s" /sbin/extlinux --install ' '--heads %s --sectors %s /boot/extlinux/' % (self.image_root, self.geometry.heads, self.geometry.sectors)) finally: logCall('umount -n "%s"' % image_dev)
def install(self): cfgfile = self._get_grub_conf() grub_conf = util.joinPaths(self.image_root, 'boot/grub', cfgfile) # TODO: clean up the various paths by which mkinitrd gets run, this # workflow doesn't necessarily make sense. mkinitrdWasRun = False # RPM-based images will not populate grub.conf, so do it here. for line in open(grub_conf): line = line.split() if len(line) < 2 or 'vmlinuz-' not in line[1]: continue kver = os.path.basename(line[1])[8:] if kver != 'template': break else: # No non-template kernel entry was found, so populate it by hand. self.add_kernels() mkinitrdWasRun = True # Now that grubby has had a chance to add the new kernel, # remove the template entry added in setup() if os.path.exists(util.joinPaths(self.image_root, 'sbin', 'grubby')): logCall('chroot %s /sbin/grubby ' '--remove-kernel=/boot/vmlinuz-template' % self.image_root, ignoreErrors=True) # If bootman is present, configure it for grub and run it if os.path.exists(util.joinPaths(self.image_root, 'sbin', 'bootman')): bootman_config = open(util.joinPaths(self.image_root, 'etc', 'bootman.conf'), 'w') print >> bootman_config, 'BOOTLOADER=grub' bootman_config.close() bootloader.writeBootmanConfigs(self) logCall('chroot "%s" /sbin/bootman' % self.image_root) irg = rh_initrd.RedhatGenerator(self.image_root) irg.generateFromBootman() mkinitrdWasRun = True elif not mkinitrdWasRun and not is_SUSE(self.image_root): irg = rh_initrd.RedhatGenerator(self.image_root) irg.generateFromGrub(cfgfile) mkinitrdWasRun = True # Workaround for RPL-2423 if os.path.exists(grub_conf): contents = open(grub_conf).read() contents = re.compile('^default .*', re.M ).sub('default 0', contents) open(grub_conf, 'w').write(contents) if cfgfile == 'menu.lst' and os.path.exists(grub_conf): # workaround for bootloader management tools in SUSE writing # menu.lst wrong f = open(grub_conf) newLines = [] rootdev_re = re.compile('root=/dev/.*? ') grubroot_re = re.compile('root \(.*\)') doubleboot_re = re.compile('/boot/boot') kernel_re = re.compile('^\s+kernel') for line in f: line = rootdev_re.sub('root=LABEL=%s ' % self.root_label, line) if (self.jobData['buildType'] == buildtypes.validBuildTypes['AMI']): line = grubroot_re.sub('root (hd0)', line) else: line = grubroot_re.sub('root (hd0,0)', line) line = doubleboot_re.sub('/boot', line) if (kernel_re.match(line) and (self.jobData['buildType'] == buildtypes.validBuildTypes['XEN_OVA'])): line = line.replace('\n', ' console=ttyS0 xencons=ttyS\n') newLines.append(line) contents = ''.join(newLines) f = open(grub_conf, 'w') f.write(contents) f.close()