[node-patches] Change in ovirt-node[master]: add efi partition to software based iscsi installs in efi mo...

jboggs at redhat.com jboggs at redhat.com
Thu Feb 21 03:08:05 UTC 2013


Joey Boggs has uploaded a new change for review.

Change subject: add efi partition to software based iscsi installs in efi mode
......................................................................

add efi partition to software based iscsi installs in efi mode

This expands the the iscsi root partition to be inline with
the other partition sizes of 256MB and allows for the creation
of an efi partition if booted in efi mode. Patch completes 99%
of the iscsi root installation on efi. The efi bootloader entry
in this scenario still has reliability issues and will be fixed
in a followup patch.

Change-Id: I7bb36a4a3b13f13a23a8e72f3e3028f2f5738cfd
Signed-off-by: Joey Boggs <jboggs at redhat.com>
---
M scripts/ovirt-init-functions.sh
M scripts/ovirtnode/install.py
M scripts/ovirtnode/ovirtfunctions.py
M scripts/ovirtnode/storage.py
4 files changed, 87 insertions(+), 49 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-node refs/changes/53/12253/1

diff --git a/scripts/ovirt-init-functions.sh b/scripts/ovirt-init-functions.sh
index c62087a..781085d 100644
--- a/scripts/ovirt-init-functions.sh
+++ b/scripts/ovirt-init-functions.sh
@@ -390,12 +390,6 @@
     # save boot parameters like console= for local disk boot menu
     bootparams=
     cat /etc/system-release >> $OVIRT_LOGFILE
-    # determine iscsi_install status
-    if grep -q iscsi_install /proc/cmdline; then
-        iscsi_install=0
-    else
-        iscsi_install=1
-    fi
 
     for i in $(cat /proc/cmdline); do
         case $i in
diff --git a/scripts/ovirtnode/install.py b/scripts/ovirtnode/install.py
index 039c4c2..e9ce728 100755
--- a/scripts/ovirtnode/install.py
+++ b/scripts/ovirtnode/install.py
@@ -210,7 +210,8 @@
 }    """
         if _functions.is_iscsi_install():
             disk = re.sub("p[1,2,3]$", "", \
-                                    _functions.findfs(self.boot_candidate))
+                                    _functions.findfs("BootNew"))
+            self.grub_dict["partN"] = int(_functions.findfs("BootNew")[-1:])
         else:
             disk = self.disk
         if _functions.is_efi_boot():
@@ -223,6 +224,7 @@
                           " --efi-directory=" + boot_dir +
                           " --bootloader-id=" + self.efi_dir_name +
                           " --force")
+        _functions.system("echo '%s' >> /liveos/efi/cmd" % grub_setup_cmd)
         logger.info(grub_setup_cmd)
         grub_setup = _functions.subprocess_closefds(grub_setup_cmd, \
                                          shell=True,
@@ -235,6 +237,9 @@
             return False
         else:
             logger.debug("Generating Grub2 Templates")
+            if _functions.is_efi_boot():
+                if not os.path.exists("/liveos/efi/EFI/%s" % self.efi_dir_name):
+                    os.makedirs("/liveos/efi/EFI/%s" % self.efi_dir_name)
             grub_conf = open(self.grub_config_file, "w")
             grub_conf.write(GRUB2_CONFIG_TEMPLATE % self.grub_dict)
         if self.oldtitle is not None:
@@ -315,12 +320,43 @@
                     self.oldtitle = self.oldtitle.replace('"','').strip(" {")
         _functions.system("umount /liveos/efi")
         _functions.system("umount /liveos")
-        if _functions.findfs("BootBackup"):
-            self.boot_candidate = "BootBackup"
-        elif _functions.findfs("Boot"):
-            self.boot_candidate = "Boot"
-            # Grab OVIRT_ISCSI VARIABLES from boot partition for upgrading
-            # file created only if OVIRT_ISCSI_ENABLED=y
+        if _functions.is_iscsi_install():
+            self.boot_candidate = None
+            boot_candidate_names = ["BootBackup", "BootUpdate", "BootNew"]
+            for trial in range(1, 3):
+                time.sleep(1)
+                _functions.system("partprobe")
+                for candidate_name in boot_candidate_names:
+                    if _functions.findfs(candidate_name):
+                        self.boot_candidate = candidate_name
+                        break
+                logger.debug("Trial %s to find candidate (%s)" % \
+                             (trial, self.boot_candidate))
+                if self.boot_candidate:
+                    logger.debug("Found candidate: %s" % self.boot_candidate)
+                    break
+
+            if not self.boot_candidate:
+                logger.error("Unable to find boot partition")
+                label_debug = ''
+                for label in os.listdir("/dev/disk/by-label"):
+                    label_debug += "%s\n" % label
+                label_debug += _functions.subprocess_closefds("blkid", \
+                                          shell=True, stdout=subprocess.PIPE,
+                                          stderr=subprocess.STDOUT).stdout.read()
+                logger.debug(label_debug)
+                return False
+            else:
+                boot_candidate_dev = _functions.findfs(self.boot_candidate)
+            # prepare Root partition update
+            if self.boot_candidate != "BootNew":
+                e2label_cmd = "e2label \"%s\" BootNew" % boot_candidate_dev
+                logger.debug(e2label_cmd)
+                if not _functions.system(e2label_cmd):
+                    logger.error("Failed to label new Boot partition")
+                    return False
+            _functions.system("mount LABEL=%s /boot &>/dev/null" % self.boot_candidate)
+
             if os.path.exists("/boot/ovirt"):
                 try:
                     f = open("/boot/ovirt", 'r')
@@ -371,8 +407,6 @@
             logger.debug(label_debug)
             return False
 
-        if _functions.is_iscsi_install():
-            _functions.system("mount LABEL=%s /boot &>/dev/null" % self.boot_candidate)
         try:
             candidate_dev = self.disk = _functions.findfs(candidate)
             logger.info(candidate_dev)
@@ -519,7 +553,14 @@
         if _functions.is_iscsi_install():
             # copy default for when Root/HostVG is inaccessible(iscsi upgrade)
             shutil.copy(_functions.OVIRT_DEFAULTS, "/boot")
-            _functions.system("umount /boot")
+            # mark new Root ready to go, reboot() in ovirt-function switches it
+            # to active
+            e2label_cmd = "e2label \"%s\" BootUpdate" % boot_candidate_dev
+
+            if not _functions.system(e2label_cmd):
+                logger.error("Unable to relabel " + boot_candidate_dev +
+                             " to RootUpdate ")
+                return False
         else:
             _functions.system("umount /liveos/efi")
         _functions.system("umount /liveos")
diff --git a/scripts/ovirtnode/ovirtfunctions.py b/scripts/ovirtnode/ovirtfunctions.py
index 7fa366a..79eccde 100644
--- a/scripts/ovirtnode/ovirtfunctions.py
+++ b/scripts/ovirtnode/ovirtfunctions.py
@@ -517,7 +517,10 @@
 def mount_efi(target="/liveos/efi"):
     if os.path.ismount(target):
         return True
-    efi_part = findfs("Root")
+    if is_iscsi_install():
+        efi_part = findfs("Boot")
+    else:
+        efi_part = findfs("Root")
     efi_part = efi_part[:-1] + "1"
     if not os.path.exists(target):
         if not system("mkdir -v -p %s" % target):
@@ -1052,10 +1055,10 @@
         boot_dev = findfs("Boot")
         e2label_bootbackup_cmd = "e2label '%s' BootBackup" % boot_dev
         e2label_boot_cmd = "e2label '%s' Boot" % boot_update_dev
-        logger.debug(e2label_bootbackup_cmd)
-        logger.debug(e2label_boot_cmd)
-        subprocess_closefds(e2label_bootbackup_cmd, shell=True, stdout=PIPE, stderr=STDOUT)
-        subprocess_closefds(e2label_boot_cmd, shell=True, stdout=PIPE, stderr=STDOUT)
+        system(e2label_bootbackup_cmd)
+        system(e2label_boot_cmd)
+        system("cp /tmp/ovirt.log /boot/ovirt.log")
+
     # run post-install hooks
     # e.g. to avoid reboot loops using Cobbler PXE only once
     # Cobbler XMLRPC post-install trigger (XXX is there cobbler SRV record?):
@@ -1652,10 +1655,6 @@
 def is_iscsi_install():
     if OVIRT_VARS.has_key("OVIRT_ISCSI_INSTALL") and OVIRT_VARS["OVIRT_ISCSI_INSTALL"].upper() == "Y":
         return True
-    elif findfs("Boot"):
-        return True
-    else:
-        return False
 
 def load_keyboard_config():
     import system_config_keyboard.keyboard as keyboard
diff --git a/scripts/ovirtnode/storage.py b/scripts/ovirtnode/storage.py
index 7091990..d988d60 100644
--- a/scripts/ovirtnode/storage.py
+++ b/scripts/ovirtnode/storage.py
@@ -35,7 +35,7 @@
         logger.propagate = False
         OVIRT_VARS = _functions.parse_defaults()
         self.overcommit = 0.5
-        self.BOOT_SIZE = 50
+        self.BOOT_SIZE = 256
         self.ROOT_SIZE = 256
         self.CONFIG_SIZE = 5
         self.LOGGING_SIZE = 2048
@@ -562,6 +562,22 @@
         logger.info("Completed HostVG Setup!")
         return True
 
+    def create_efi_partition(self):
+        if _functions.is_iscsi_install():
+            disk = self.BOOTDRIVE
+        else:
+            disk = self.ROOTDRIVE
+        parted_cmd = ("parted \"" + disk +
+                     "\" -s \"mkpart EFI 1M " +
+                     str(self.EFI_SIZE) + "M\"")
+        _functions.system(parted_cmd)
+        partefi = disk + "1"
+        if not os.path.exists(partefi):
+            partefi = disk + "p1"
+            _functions.system("ln -snf \"" + partefi + \
+                              "\" /dev/disk/by-label/EFI")
+            _functions.system("mkfs.vfat \"" + partefi + "\"")
+
     def create_iscsiroot(self):
         logger.info("Partitioning iscsi root drive: " + self.ISCSIDRIVE)
         _functions.wipe_partitions(self.ISCSIDRIVE)
@@ -765,27 +781,29 @@
             parted_cmd = "parted %s -s \"mklabel %s\"" % (self.BOOTDRIVE,
                                                           self.LABEL_TYPE)
             _functions.system(parted_cmd)
-            parted_cmd = ("parted \"%s\" -s \"mkpart primary ext2 1M %sM\"" %
-                         (self.BOOTDRIVE, self.BOOT_SIZE))
+            self.create_efi_partition()
+            boot_end_mb = self.EFI_SIZE + self.BOOT_SIZE
+            parted_cmd = ("parted \"%s\" -s \"mkpart primary ext2 %sM %sM\"" %
+                         (self.BOOTDRIVE, self.EFI_SIZE, boot_end_mb))
             _functions.system(parted_cmd)
             parted_cmd = ("parted \"%s\" -s \"mkpart primary ext2 %sM %sM\"" %
-                         (self.BOOTDRIVE, self.BOOT_SIZE, self.BOOT_SIZE*2))
+                         (self.BOOTDRIVE , boot_end_mb, boot_end_mb + self.BOOT_SIZE))
             _functions.system(parted_cmd)
             parted_cmd = ("parted \"" + self.BOOTDRIVE + "\" -s \"set 1 " +
                          "boot on\"")
             _functions.system(parted_cmd)
             self.reread_partitions(self.BOOTDRIVE)
-            partboot = self.BOOTDRIVE + "1"
+            partboot = self.BOOTDRIVE + "2"
             if not os.path.exists(partboot):
                 logger.debug("%s does not exist" % partboot)
-                partboot = self.BOOTDRIVE + "p1"
-            partbootbackup = self.BOOTDRIVE + "2"
+                partboot = self.BOOTDRIVE + "p2"
+            partbootbackup = self.BOOTDRIVE + "3"
             if not os.path.exists(partbootbackup):
                 logger.debug("%s does not exist" % partbootbackup)
-                partbootbackup = self.BOOTDRIVE + "p2"
+                partbootbackup = self.BOOTDRIVE + "p3"
+
             # sleep to ensure filesystems are created before continuing
             _functions.system("udevadm settle")
-            time.sleep(10)
             _functions.system("mke2fs \"" + str(partboot) + "\" -L Boot")
             _functions.system("tune2fs -c 0 -i 0 \"" + str(partboot) + "\"")
             _functions.system("ln -snf \"" + partboot + \
@@ -816,12 +834,8 @@
                          self.LABEL_TYPE + "\"")
             _functions.passthrough(parted_cmd, logger.debug)
             logger.debug("Creating Root and RootBackup Partitions")
-            # efi partition should at 0M
             if _functions.is_efi_boot():
-                parted_cmd = ("parted \"" + self.ROOTDRIVE +
-                             "\" -s \"mkpart EFI 1M " +
-                             str(self.EFI_SIZE) + "M\"")
-                _functions.passthrough(parted_cmd, logger.debug)
+                self.create_efi_partition()
             else:
                 # create partition labeled bios_grub
                 parted_cmd = ("parted \"" + self.ROOTDRIVE +
@@ -846,24 +860,14 @@
                          "\" -s \"set 2 boot on\"")
             logger.debug(parted_cmd)
             _functions.system(parted_cmd)
-            # sleep to ensure filesystems are created before continuing
-            time.sleep(5)
             # force reload some cciss devices will fail to mkfs
             _functions.system("multipath -r &>/dev/null")
             self.reread_partitions(self.ROOTDRIVE)
-            partefi = self.ROOTDRIVE + "1"
             partroot = self.ROOTDRIVE + "2"
             partrootbackup = self.ROOTDRIVE + "3"
             if not os.path.exists(partroot):
-                partefi = self.ROOTDRIVE + "p1"
                 partroot = self.ROOTDRIVE + "p2"
                 partrootbackup = self.ROOTDRIVE + "p3"
-            if _functions.is_efi_boot():
-                _functions.system("ln -snf \"" + partefi + \
-                                  "\" /dev/disk/by-label/EFI")
-                _functions.system("mkfs.vfat \"" + partefi + "\"")
-            _functions.system("ln -snf \"" + partroot + \
-                              "\" /dev/disk/by-label/Root")
             _functions.system("mke2fs \"" + partroot + "\" -L Root")
             _functions.system("tune2fs -c 0 -i 0 \"" + partroot + "\"")
             _functions.system("ln -snf \"" + partrootbackup +


--
To view, visit http://gerrit.ovirt.org/12253
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I7bb36a4a3b13f13a23a8e72f3e3028f2f5738cfd
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-node
Gerrit-Branch: master
Gerrit-Owner: Joey Boggs <jboggs at redhat.com>



More information about the node-patches mailing list