|
|
|
@ -851,6 +851,8 @@ class PartitionDistributive(Distributive):
|
|
|
|
|
|
|
|
|
|
def formatAllPartitions(self):
|
|
|
|
|
"""Format all partitions"""
|
|
|
|
|
FS,DEV,NEEDFORMAT,NEWID,PARTTABLE = 0,1,2,3,4
|
|
|
|
|
# get all information to matrix
|
|
|
|
|
dataPartitions = zip(self.multipartition.getFileSystems() +\
|
|
|
|
|
[self.fileSystem],
|
|
|
|
|
self.multipartition.getPartitions() + \
|
|
|
|
@ -861,21 +863,24 @@ class PartitionDistributive(Distributive):
|
|
|
|
|
[self.systemId],
|
|
|
|
|
self.multipartition.getPartitionTable() + \
|
|
|
|
|
[self.partitionTable])
|
|
|
|
|
formatPartitions = map(lambda x: (x[0],x[1]),
|
|
|
|
|
filter(lambda x: x[2] and x[0]!="bind",
|
|
|
|
|
dataPartitions))
|
|
|
|
|
# get partition which need format
|
|
|
|
|
formatPartitions = map(lambda x: (x[FS],x[DEV]),
|
|
|
|
|
filter(lambda x: x[NEEDFORMAT] and x[FS]!="bind",
|
|
|
|
|
dataPartitions))
|
|
|
|
|
# format all get partition
|
|
|
|
|
for fileSystem, dev in formatPartitions:
|
|
|
|
|
if fileSystem=="swap":
|
|
|
|
|
self.formatSwapPartition(dev)
|
|
|
|
|
else:
|
|
|
|
|
if dev == self.partition:
|
|
|
|
|
self.formatPartition(dev, format=fileSystem,
|
|
|
|
|
label=self.rootLabel)
|
|
|
|
|
label=self.rootLabel)
|
|
|
|
|
else:
|
|
|
|
|
self.formatPartition(dev, format=fileSystem)
|
|
|
|
|
changeidPartitions = map(lambda x: (x[3],x[1],x[4]),
|
|
|
|
|
filter(lambda x: x[3],
|
|
|
|
|
dataPartitions))
|
|
|
|
|
# change system id for partitions
|
|
|
|
|
changeidPartitions = map(lambda x: (x[NEWID],x[DEV],x[PARTTABLE]),
|
|
|
|
|
filter(lambda x: x[NEWID],
|
|
|
|
|
dataPartitions))
|
|
|
|
|
for systemid, dev, partTable in changeidPartitions:
|
|
|
|
|
self.changeSystemID(dev,systemid,partTable)
|
|
|
|
|
return True
|
|
|
|
@ -920,13 +925,14 @@ class PartitionDistributive(Distributive):
|
|
|
|
|
label=self.rootLabel)
|
|
|
|
|
|
|
|
|
|
def changeSystemID(self,dev,systemid,parttable):
|
|
|
|
|
parentDir = path.split(dev)[0]
|
|
|
|
|
reDeviceSplit = re.compile("^(.*/)?(.*?)(\d+)$")
|
|
|
|
|
|
|
|
|
|
"""Change partition id, specified by systemid"""
|
|
|
|
|
deviceName = detectDeviceForPartition(dev)
|
|
|
|
|
if deviceName is None:
|
|
|
|
|
raise DistributiveError(
|
|
|
|
|
_("Can not determine parent device for %s")%dev)
|
|
|
|
|
# device hasn't any partition
|
|
|
|
|
elif deviceName == "":
|
|
|
|
|
return True
|
|
|
|
|
fdiskProg, gdiskProg = checkUtils('/sbin/fdisk','/usr/sbin/gdisk')
|
|
|
|
|
partitionNumber = getUdevDeviceInfo(dev).get('ID_PART_ENTRY_NUMBER','')
|
|
|
|
|
devicePartitionCount = countPartitions(deviceName)
|
|
|
|
@ -935,43 +941,26 @@ class PartitionDistributive(Distributive):
|
|
|
|
|
_("Can not determine partition number for %s")%dev)
|
|
|
|
|
if parttable == "dos":
|
|
|
|
|
fdisk = process(fdiskProg,deviceName,stderr=STDOUT)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pipe = Popen([fdiskProg,
|
|
|
|
|
path.join('/dev',deviceName)],
|
|
|
|
|
pipe = Popen([fdiskProg,deviceName],
|
|
|
|
|
stdin=PIPE, stdout=PIPE,stderr=PIPE)
|
|
|
|
|
if len(filter(lambda x: deviceName in x and deviceName != x,
|
|
|
|
|
listDirectory('/dev'))) > 1:
|
|
|
|
|
numPart = reDeviceSplit.search(dev)
|
|
|
|
|
if numPart:
|
|
|
|
|
numPart = numPart.groups()[-1]
|
|
|
|
|
else:
|
|
|
|
|
pipe.stdin.close()
|
|
|
|
|
raise DistributiveError(
|
|
|
|
|
_("Can not determine partition number for %s")%dev)
|
|
|
|
|
pipe.stdin.write("t\n%s\n%s\nw\n"%(numPart,systemid))
|
|
|
|
|
if devicePartitionCount > 1:
|
|
|
|
|
pipe.stdin.write("t\n%s\n%s\nw\n"%(partitionNumber,
|
|
|
|
|
systemid))
|
|
|
|
|
else:
|
|
|
|
|
pipe.stdin.write("t\n%s\nw\n"%systemid)
|
|
|
|
|
pipe.stdin.close()
|
|
|
|
|
pipe.wait()
|
|
|
|
|
if parttable == "gpt":
|
|
|
|
|
pipe = Popen([gdiskProg,
|
|
|
|
|
path.join('/dev',deviceName)],
|
|
|
|
|
elif parttable == "gpt":
|
|
|
|
|
pipe = Popen([gdiskProg,deviceName],
|
|
|
|
|
stdin=PIPE, stdout=PIPE,stderr=PIPE)
|
|
|
|
|
if len(filter(lambda x: deviceName in x and deviceName != x,
|
|
|
|
|
listDirectory('/dev'))) > 1:
|
|
|
|
|
numPart = reDeviceSplit.search(dev)
|
|
|
|
|
if numPart:
|
|
|
|
|
numPart = numPart.groups()[-1]
|
|
|
|
|
else:
|
|
|
|
|
pipe.stdin.close()
|
|
|
|
|
raise DistributiveError(
|
|
|
|
|
_("Can not determine partition number for %s")%dev)
|
|
|
|
|
pipe.stdin.write("t\n%s\n%s\nw\ny\n"%(numPart,systemid))
|
|
|
|
|
if devicePartitionCount > 1:
|
|
|
|
|
pipe.stdin.write("t\n%s\n%s\nw\ny\n"%(devicePartitionCount,
|
|
|
|
|
systemid))
|
|
|
|
|
else:
|
|
|
|
|
pipe.stdin.write("t\n%s\nw\n\y"%systemid)
|
|
|
|
|
pipe.stdin.write("t\n%s\nw\ny\n"%systemid)
|
|
|
|
|
pipe.stdin.close()
|
|
|
|
|
pipe.wait()
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
def formatSwapPartition(self, dev):
|
|
|
|
|
"""Format swap partition"""
|
|
|
|
|