[RHEL5] Skip disk label check for autopart all (#758881)

Brian C. Lane bcl at redhat.com
Sat May 18 00:34:08 UTC 2013


From: "Brian C. Lane" <bcl at redhat.com>

When autopart all is selected and all partitions have been removed from
a disk go ahead and apply the correct disk label. This fixed the problem
of trying to autopart all on a gpt disk in a non-EFI system. Also add a
few more lines to the logfile when relabeling the disk.
---
 autopart.py    | 12 ++++++++++--
 partedUtils.py | 23 ++++++++++++++---------
 partitions.py  |  2 +-
 3 files changed, 25 insertions(+), 12 deletions(-)

diff --git a/autopart.py b/autopart.py
index b23f716..ff46eb1 100644
--- a/autopart.py
+++ b/autopart.py
@@ -24,6 +24,7 @@ from anaconda_log import logger, logFile
 import cryptodev
 from partitioning import *
 import partedUtils
+from partedUtils import needGPTLabel, getDefaultDiskType
 import partRequests
 from constants import *
 from partErrors import *
@@ -1203,8 +1204,15 @@ def doClearPartAction(anaconda, partitions, diskset):
             partitions.removeRequest(old)
             partitions.addDelete(delete)
             deletePart(diskset, delete)
-            continue
-    
+
+        if linuxOnly == 0 and disk.get_primary_partition_count() == 0:
+            # The disk is empty and we are clearing all partitions, so relabel it
+            dev = disk.dev
+            label = needGPTLabel(dev, getDefaultDiskType())
+            log.info("Disk %s is empty, creating new %s disklabel on it" % (drive, label.name))
+            new_disk = dev.disk_new_fresh(label)
+            diskset.disks[drive] = new_disk
+
 def doAutoPartition(anaconda):
     instClass = anaconda.id.instClass
     diskset = anaconda.id.diskset
diff --git a/partedUtils.py b/partedUtils.py
index be66426..faef371 100644
--- a/partedUtils.py
+++ b/partedUtils.py
@@ -279,23 +279,27 @@ archLabels = {'i386': ['msdos', 'gpt'],
               'ppc': ['msdos', 'mac', 'amiga', 'gpt'],
               'x86_64': ['msdos', 'gpt']}
 
+def needGPTLabel(dev, label):
+    """ Return gpt label if disk is msdos and size is > 2GiB"""
+    if label.name == 'msdos' and \
+            dev.length > (2L**41) / dev.sector_size and \
+            'gpt' in archLabels[rhpl.getArch()]:
+        label = parted.disk_type_get('gpt')
+    return label
+
 def labelDisk(deviceFile, forceLabelType=None):
     dev = parted.PedDevice.get(deviceFile)
-    label = getDefaultDiskType()
 
     if not forceLabelType is None:
         label = forceLabelType
     else:
-        if label.name == 'msdos' and \
-                dev.length > (2L**41) / dev.sector_size and \
-                'gpt' in archLabels[rhpl.getArch()]:
-            label = parted.disk_type_get('gpt')
+        label = needGPTLabel(dev, getDefaultDiskType())
 
     # remove metadata from partitions
     try:
         disk = parted.PedDisk.new(dev)
     except parted.error, msg:
-        log.debug("parted error: %s" % (msg,))
+        log.debug("labelDisk parted error: %s" % (msg,))
     else:    
         part = disk.next_partition()
         while part:
@@ -308,6 +312,7 @@ def labelDisk(deviceFile, forceLabelType=None):
             lvm.pvremove("/dev/%s" % (device,))
             part = disk.next_partition(part)
 
+    log.info("Creating new %s disklabel on %s" % (label.name, deviceFile))
     disk = dev.disk_new_fresh(label)
     disk.commit()
     return disk
@@ -1202,6 +1207,7 @@ class DiskSet:
         log.info("Reinitializing label for drive %s" % (drive,))
 
         deviceFile = isys.makeDevInode(drive, "/dev/" + drive)
+        dev = parted.PedDevice.get(deviceFile)
 
         try:
             try:
@@ -1211,12 +1217,11 @@ class DiskSet:
                     if self.dasdFmt(drive):
                         raise LabelError, drive
 
-                    dev = parted.PedDevice.get(deviceFile)
                     disk = parted.PedDisk.new(dev)
                 else:
                     disk = labelDisk(deviceFile)
             except parted.error, msg:
-                log.debug("parted error: %s" % (msg,))
+                log.debug("_labelDevice parted error: %s" % (msg,))
                 raise
         except:
             self._removeDisk(drive)
@@ -1298,7 +1303,7 @@ class DiskSet:
                     dev = parted.PedDevice.get(deviceFile)
                     disk = None
             except parted.error, msg:
-                log.debug("parted error: %s" % (msg,))
+                log.debug("openDevices parted error: %s" % (msg,))
                 self._removeDisk(drive, disk)
                 continue
 
diff --git a/partitions.py b/partitions.py
index 208a8d5..f6eb32d 100644
--- a/partitions.py
+++ b/partitions.py
@@ -1066,7 +1066,7 @@ class Partitions:
                 if not ok:
                     errors.append(_("You must create a /boot/efi partition of "
                                     "type FAT and a size of 50 megabytes."))
-            else:
+            elif self.autoClearPartType != CLEARPART_TYPE_ALL:
                 # mactel checks
                 bootreqs = self.getBootableRequest() or []
                 for br in getBaseReqs(bootreqs):
-- 
1.8.1.4



More information about the anaconda-patches mailing list