On Fri, 2013-05-17 at 17:34 -0700, Brian C. Lane wrote:
From: "Brian C. Lane" <bcl(a)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
+
Is the size really in bytes? Wow. However, the docstring should say
2 TiB not 2 GiB. Otherwise this looks good to me.
--
Vratislav Podzimek
Anaconda Rider | Red Hat, Inc. | Brno - Czech Republic