Bug 675074

Summary: grub is not installed to expected device in md device with bootloader --driveorder option
Product: Red Hat Enterprise Linux 6 Reporter: Masahiro Matsuya <mmatsuya>
Component: anacondaAssignee: Brian Lane <bcl>
Status: CLOSED NOTABUG QA Contact: Release Test Team <release-test-team>
Severity: medium Docs Contact:
Priority: high    
Version: 6.0CC: prc, rwilliam
Target Milestone: rc   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2011-08-10 15:31:00 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Bug Depends On:    
Bug Blocks: 705163    
Attachments:
Description Flags
proposed patch
none
kickstart file for testing none

Description Masahiro Matsuya 2011-02-04 07:25:52 UTC
Description of problem:

When /boot is on MD device (RAID1) which consists of /dev/sda2 and /dev/sdb1, and the following bootloader entry is in the kickstart file, grub is installed to /dev/sdb.

   bootloader --location=mbr --driveorder=sda,sdb

Upon the order of values of --driveorder, this customer expected that grub was installed to /dev/sda. But, it was installed to /dev/sdb.

anaconda.id.bootloader.drivelist is sorted upon an order of --driveorder.

-------------------------------
def bootloaderSetupChoices(anaconda):
    ...
    if anaconda.id.ksdata and anaconda.id.ksdata.bootloader.driveorder:
        anaconda.id.bootloader.updateDriveList(anaconda.id.ksdata.bootloader.driveorder)
-------------------------------

And, sda is selected correctly in bootloaderChoices().

-------------------------------
    def bootloaderChoices(self, bl):
        ...
        if bootDev.type == "mdarray":
            ret["boot"] = (bootDev.name, N_("RAID Device"))
            ret["mbr"] = (bl.drivelist[0], N_("Master Boot Record (MBR)"))
-------------------------------

And, sda is set to anaconda.id.bootloader.device in bootloaderSetupChoices()

-------------------------------
def bootloaderSetupChoices(anaconda):
    ...
    elif choices and choices.has_key("mbr"):
        anaconda.id.bootloader.setDevice(choices["mbr"][0])
-------------------------------

And, sdb (not sda) is select in installGrub() of x86.py.

-------------------------------
    def installGrub(self, instRoot, bootDev, grubTarget, grubPath, cfPath):
        ...
        stage1Devs = self.getPhysicalDevices(grubTarget) ## stage1Devs = ['sda']
        bootDevs = self.getPhysicalDevices(bootDev.name) ## bootDevs = ['sda2', 'sdb1']
        ...
        if bootDev.type == "mdarray":

            matches = self.matchingBootTargets(stage1Devs, bootDevs)  
                     ## matches = [('sda', 'sda2')]
            ...
            if matches:
                # 1) install stage1 on target disk/partiton
                stage1Dev, mdMemberBootPart = matches[0]
                ...
                matches = self.addMemberMbrs(matches, bootDevs)
                     ## matches = [('sda', 'sda2'), ('sdb', 'sdb1')]
                for stage1Target, mdMemberBootPart in matches[1:]:

In this for statement, first element ('sda', 'sda2') of matches is not checked, and ('sdb', 'sdb1') only checked. As a result, sdb is selected.

I'm not sure why it doesn't see the first element. But, this issue can be fixed by the following change.

                for stage1Target, mdMemberBootPart in matches[1:]:
->
                for stage1Target, mdMemberBootPart in matches[0:]:

Version-Release number of selected component (if applicable):
anaconda-13.21.82-1.el6

How reproducible:
Always

Steps to Reproduce:
1. install RHEL6.0 with the attached kickstart on hardware with 2 disks (sda, sdb).
2. check program.log to know where grub is installed.
  
Actual results:
grub is installed to sdb

 From program.log
 11:14:12,768 INFO    : grub> device (hd0) /dev/sdb

Expected results:
grub is installed to sda, upon an order specified in --driveorder.

Additional info:

Comment 1 Masahiro Matsuya 2011-02-04 07:34:32 UTC
Created attachment 476939 [details]
proposed patch

Comment 2 Masahiro Matsuya 2011-02-04 07:38:42 UTC
Created attachment 476940 [details]
kickstart file for testing

Comment 4 Brian Lane 2011-07-21 20:52:59 UTC
Could you attach program.log? The reason why it isn't checking the first element is that it already installed to the first with stage1Dev, mdMemberBootPart = matches[0]

grub is supposed to be installed to each member of the RAID1 so that it will still boot after one of them is removed.

Comment 5 Brian Lane 2011-07-21 21:13:44 UTC
I have tested your kickstart and don't see a problem. If you look at the program.log you will see it run grub twice:

21:01:10,105 INFO    : grub> device (hd0) /dev/sdb
21:01:10,105 INFO    : grub> root (hd0,0)

tells it to point to /dev/sdb and install there. And then it runs:

21:01:10,421 INFO    : grub> root (hd0,1)

which defaults to /dev/sda so it is installed there as well.

Was there some other problem that led to this?

Comment 11 Brian Lane 2011-08-10 15:31:00 UTC
Looks like everything is fine.