Add GPT support.

netsetup
Mike Hiretsky 13 years ago
parent bbeba65b19
commit def1a2659b

Binary file not shown.

@ -24,7 +24,8 @@ import re
import sys
import operator
from cl_utils import runOsCommand,isMount,removeDir,typeFile,pathJoin, \
process,getRunCommands,getTupleVersion,cmpVersion
process,getRunCommands,getTupleVersion,cmpVersion, \
detectDeviceForPartition, getProgPath
from shutil import copyfile,copytree
from cl_template import _terms
from subprocess import Popen,PIPE,STDOUT
@ -626,6 +627,7 @@ class DataPartition:
fileSystem = "reiserfs"
isFormat = False
systemId = None
partitionTable = None
class MultiPartitions:
"""Data partition list"""
@ -665,6 +667,10 @@ class MultiPartitions:
"""Get systemID for change [None,82,...]"""
return map(lambda x: x.systemId, self.listPartitions)
def getPartitionTable(self):
"""Get systemID for change [msdos,gpt,...]"""
return map(lambda x: x.partitionTable, self.listPartitions)
def getIsFormat(self):
"""Get list is format [True,...]"""
return map(lambda x: x.isFormat, self.listPartitions)
@ -711,14 +717,24 @@ class PartitionDistributive(Distributive):
'reiserfs' : '83',
'jfs' : '83',
'xfs' : '83',
'vfat' : 'b',
'vfat' : '0b',
'swap' : '82'
}
formatIdGpt = { 'ext2' : '0700',
'ext3' : '0700',
'ext4' : '0700',
'reiserfs' : '0700',
'jfs' : '0700',
'xfs' : '0700',
'vfat' : '0700',
'swap' : '8200'
}
def __init__(self,partition,parent=None,mdirectory="/mnt/calculate",
check=False,multipartition=None,flagRemoveDir=True,
fileSystem="reiserfs", isFormat=True,systemId=None,
rootLabel="Calculate"):
rootLabel="Calculate", partitionTable=None):
"""Initialize partition distributive
mdirectory - directory for mount
@ -735,6 +751,7 @@ class PartitionDistributive(Distributive):
self.DirectoryObject = None
self.systemId = systemId
self.rootLabel = rootLabel
self.partitionTable = partitionTable
def _mountPartition(self,partition,directory,opts=""):
"""Mount partition to directory"""
@ -782,7 +799,8 @@ class PartitionDistributive(Distributive):
mulipartData = zip(self.multipartition.getPartitions(),
self.multipartition.getMountPoints(),
self.multipartition.getFileSystems(),
self.multipartition.getIsFormat())
self.multipartition.getIsFormat(),
self.multipartition.getPartitionTable())
return mulipartData
def convertToDirectory(self):
@ -798,7 +816,8 @@ class PartitionDistributive(Distributive):
if self.multipartition:
mulipartDataNotBind = filter(lambda x: x[2]!="bind",
self.getMultipartData())
for dev, mountPoint, fileSystem, isFormat in mulipartDataNotBind:
for dev, mountPoint, fileSystem, isFormat, partTable\
in mulipartDataNotBind:
if fileSystem!="swap":
realMountPoint = pathJoin(mdirectory, mountPoint)
self._mountPartition(dev,realMountPoint,"-t %s"%fileSystem)
@ -820,7 +839,9 @@ class PartitionDistributive(Distributive):
self.multipartition.getIsFormat() + \
[self.isFormat],
self.multipartition.getSystemId() + \
[self.systemId])
[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))
@ -833,11 +854,11 @@ class PartitionDistributive(Distributive):
label=self.rootLabel)
else:
self.formatPartition(dev, format=fileSystem)
changeidPartitions = map(lambda x: (x[3],x[1]),
changeidPartitions = map(lambda x: (x[3],x[1],x[4]),
filter(lambda x: x[3],
dataPartitions))
for systemid, dev in changeidPartitions:
self.changeSystemID(dev,systemid)
for systemid, dev, partTable in changeidPartitions:
self.changeSystemID(dev,systemid,partTable)
return True
def formatPartition(self, dev,format="reiserfs",label=""):
@ -879,45 +900,54 @@ class PartitionDistributive(Distributive):
self.formatPartition(self.partition,format=self.fileSystem,
label=self.rootLabel)
def changeSystemID(self,dev,systemid):
def changeSystemID(self,dev,systemid,parttable):
parentDir = path.split(dev)[0]
reDeviceSplit = re.compile("^(.*/)?(.*?)(\d+)$")
def detectDeviceForPartition(dev):
"""Detect parent device for partition by /sys/block (sysfs)"""
device = map(lambda x:filter(lambda x:x in dev,
x[1]),
os.walk('/sys/block'))
if device:
device = device[0]
parentdevices = \
filter(lambda x: path.split(dev)[-1] in \
reduce(lambda y,z:y+z[1],
os.walk(path.join('/sys/block',x)),[]), device)
if parentdevices:
return parentdevices[0]
res = reDeviceSplit.search(dev)
if res:
return res.groups()[1]
raise DistributiveError(_("Can not determine parent device for %s")%dev)
deviceName = detectDeviceForPartition(dev)
pipe = Popen(["/sbin/fdisk",
path.join('/dev',deviceName)],
stdin=PIPE, stdout=PIPE,stderr=PIPE)
if len(filter(lambda x: deviceName in x and deviceName != x,
os.listdir('/dev'))) > 1:
numPart = reDeviceSplit.search(dev)
if numPart:
numPart = numPart.groups()[-1]
if deviceName is None:
raise DistributiveError(_("Can not determine parent device for %s")%dev)
fdiskProg = getProgPath("/sbin/fdisk")
gdiskProg = getProgPath("/usr/sbin/gdisk")
for prog,name in [(fdiskProg,"fdisk"),(gdiskProg,"gdisk")]:
if not prog:
raise DistributiveError(_("Can not find '%s'")%name)
if parttable == "msdos":
pipe = Popen([fdiskProg,
path.join('/dev',deviceName)],
stdin=PIPE, stdout=PIPE,stderr=PIPE)
if len(filter(lambda x: deviceName in x and deviceName != x,
os.listdir('/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))
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))
else:
pipe.stdin.write("t\n%s\nw\n"%systemid)
pipe.stdin.close()
pipe.wait()
pipe.stdin.write("t\n%s\nw\n"%systemid)
pipe.stdin.close()
pipe.wait()
if parttable == "gpt":
pipe = Popen([gdiskProg,
path.join('/dev',deviceName)],
stdin=PIPE, stdout=PIPE,stderr=PIPE)
if len(filter(lambda x: deviceName in x and deviceName != x,
os.listdir('/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))
else:
pipe.stdin.write("t\n%s\nw\n\y"%systemid)
pipe.stdin.close()
pipe.wait()
def formatSwapPartition(self, dev):
"""Format swap partition"""

@ -23,7 +23,7 @@ from cl_datavars import glob_attr
from os import path
from os import readlink,listdir,access,R_OK
from cl_utils import isMount,typeFile,getTupleVersion,pathJoin,isFstabMount
from cl_distr import DistributiveRepository
from cl_distr import DistributiveRepository,PartitionDistributive
from cl_fill import clLocale
from operator import itemgetter
from cl_template import _terms
@ -150,9 +150,26 @@ class fillVars(object, glob_attr):
devices = filter( lambda x: not reWrongDevice.search(x),
listdir('/sys/block'))
device_hash = {}
execParted = self.getProgPath("/usr/sbin/parted")
if not execParted:
cl_overriding.printERROR(_("Command not found '%s'")%"parted")
cl_overriding.exit(1)
for mapnum,device in enumerate(sorted(devices,key=self.separateDevice)):
device_hash[device] = {}
device_hash[device]['map'] = mapnum
device_hash[device]['table'] = None
execStr = '%(prog)s %(device)s print'% \
{'prog':execParted,
'device':"/dev/%s"%device}
floppyData = self.removeFloppy()
res = self._runos(execStr,env={"LANG":"C"})
self.restoreFloppy(floppyData)
if res:
res = map(lambda x:x.rpartition("Partition Table:")[2],
filter(lambda x:x.startswith("Partition Table:"),
res))
if res:
device_hash[device]['table'] = res[-1].strip()
if device in usbdevices:
removablePath = '/sys/block/%s/removable'%device
if os.access(removablePath,R_OK) and \
@ -167,11 +184,15 @@ class fillVars(object, glob_attr):
def get_os_disk_hash(self):
reSdaPart = re.compile("^/dev/sd([a-z])(\d+)$")
devices = self.Get('os_device_hash').keys()
disks = reduce( lambda x,y: x +
map( lambda x: "/dev/%s"%x,
devicesHash = self.Get('os_device_hash')
devices = devicesHash.keys()
disksDevs = reduce( lambda x,y: x +
map( lambda x: ["/dev/%s"%x,y],
filter(lambda x: y in x,listdir('/sys/block/%s'%y))),
devices, [] )
disks = map(lambda x:x[0],disksDevs)
disksDevs = dict(disksDevs)
disk_hash = {}
# fill grub info
for dev in disks:
@ -184,31 +205,51 @@ class fillVars(object, glob_attr):
curDevice = None
# getting id
execProg = '/sbin/fdisk'
execStr = '%s -l'%execProg
if not path.exists(execProg):
cl_overriding.printERROR(_("Command not found '%s'")%execProg)
cl_overriding.exit(1)
execStr = '%s -l'%execProg
res = self._runos(execStr,env={"LANG":"C"})
if res is False:
cl_overriding.printERROR(_("Cann't execute '%s'")%execStr)
cl_overriding.exit(1)
partedLines = filter(lambda x: x.startswith('/dev/'), res or [] )
partedMatrix = map(lambda x: filter(lambda y: y and y!="*",
x.split())[:6],
partedLines)
for part,nm,nm,nm,sysid,nm in filter(lambda x:len(x)>5,partedMatrix):
if not part in disk_hash:
disk_hash[part] = {}
disk_hash[part]['id'] = sysid
execFdisk = self.getProgPath("/sbin/fdisk")
execGdisk = self.getProgPath("/usr/sbin/gdisk")
# check on error utils path
for utilPath,name in [(execFdisk,"fdisk"),(execGdisk,"gdisk")]:
if not utilPath:
cl_overriding.printERROR(_("Command not found '%s'")%name)
cl_overriding.exit(1)
for device in devices:
if devicesHash[device]['table'] == 'msdos':
execStr = '%s -l %s'%(execFdisk,"/dev/%s"%device)
res = self._runos(execStr,env={"LANG":"C"})
if res is False:
cl_overriding.printERROR(_("Cann't execute '%s'")%execStr)
cl_overriding.exit(1)
partedLines = filter(lambda x: x.startswith('/dev/'),res or [] )
partedMatrix = map(lambda x: filter(lambda y: y and y!="*",
x.split())[:6],
partedLines)
for part,nm,nm,nm,sysid,nm in \
filter(lambda x:len(x)>5,partedMatrix):
if not part in disk_hash:
disk_hash[part] = {}
disk_hash[part]['id'] = sysid
disk_hash[part]['table'] = 'msdos'
elif devicesHash[device]['table'] == 'gpt':
execStr = '%s -l %s'%(execGdisk,"/dev/%s"%device)
res = self._runos(execStr,env={"LANG":"C"})
if res is False:
cl_overriding.printERROR(_("Cann't execute '%s'")%execStr)
cl_overriding.exit(1)
for dev,partid in filter(lambda x:x[0] in disk_hash,
map(lambda x:["/dev/%s%s"%(device,x[0]),x[1]],
map(lambda x:x.split()[0:6:5],
reduce(lambda x,y:x+[y] \
if x or y.startswith("Number") else x,
res,[])[1:]))):
disk_hash[dev]['id'] = partid
disk_hash[dev]['table'] = 'gpt'
# parse all parted lines started with Disk and started with number
floppyData = self.removeFloppy()
execProg = '/usr/sbin/parted'
execProg = self.getProgPath("/usr/sbin/parted")
execStr = '%s -l'%execProg
if not path.exists(execProg):
cl_overriding.printERROR(_("Command not found '%s'")%execProg)
if not execProg:
cl_overriding.printERROR(_("Command not found '%s'")%"parted")
cl_overriding.exit(1)
res = self._runos(execStr,env={"LANG":"C"})
self.restoreFloppy(floppyData)
@ -232,12 +273,15 @@ class fillVars(object, glob_attr):
# create entry if hash hasn't it
if not partition in disk_hash:
disk_hash[partition] = {}
disk_hash[partition]['part'] = parts[4]
if disk_hash[partition].get('table',None) == "gpt":
disk_hash[partition]['part'] = "gpt"
else:
disk_hash[partition]['part'] = parts[4]
disk_hash[partition]['size'] = parts[3]
# fill format, name and uuid
execStr = '/sbin/blkid'
if not path.exists(execStr):
cl_overriding.printERROR(_("Command not found '%s'")%execStr)
execStr = self.getProgPath('/sbin/blkid')
if not execStr:
cl_overriding.printERROR(_("Command not found '%s'")%"blkid")
cl_overriding.exit(1)
res = self._runos(execStr)
if res is False:
@ -319,18 +363,18 @@ class fillVars(object, glob_attr):
def get_os_install_disk_id(self):
"""List id for partition after installation"""
formatId = { 'ext2' : '83',
'ext3' : '83',
'ext4' : '83',
'reiserfs' : '83',
'jfs' : '83',
'xfs' : '83',
'vfat' : 'b',
'swap' : '82'
}
return map(lambda x:formatId[x[0]] if x[0] in formatId else x[1],
diskHash = self.Get('os_disk_hash')
def getIdByFS(fs,parttable,oldid):
if parttable == "msdos":
return PartitionDistributive.formatId.get(fs,oldid)
elif parttable == "gpt":
return PartitionDistributive.formatIdGpt.get(fs,oldid)
return oldid
return map(lambda x:getIdByFS(x[0],
diskHash.get(x[2],{}).get('table',None),x[1]),
zip(self.Get('os_install_disk_format'),
self.Get('os_disk_id')))
self.Get('os_disk_id'),
self.Get('os_disk_dev')))
def get_os_disk_id(self):
"""List id for partition devices"""
@ -1193,8 +1237,9 @@ class fillVars(object, glob_attr):
return ""
category = "0300"
vendor = "10de"
lsPciProg = self.getProgPath("/usr/sbin/lspci")
nvidiacards = filter(lambda x:" %s: "%category in x,
self._runos('/usr/sbin/lspci -d %s: -n'%vendor))
self._runos('%s -d %s: -n'%(lsPciProg,vendor)))
if not nvidiaeclass:
return ""
cardsid = map(lambda x:x.groups()[0],
@ -1233,3 +1278,7 @@ class fillVars(object, glob_attr):
if imagename in ('/mnt/flash', '/mnt/squash', '/mnt/livecd', '/mnt/cdrom'):
return self.Get('os_linux_build')
return ""
def get_os_device_partition(self):
"""Get partition table list"""
return self.getAttributeFromHash('os_device_hash','table')

@ -24,7 +24,8 @@ import traceback
from os import path
from cl_utils import runOsCommand,appendProgramToEnvFile, \
removeProgramToEnvFile,pathJoin, \
scanDirectory,process,getTupleVersion
scanDirectory,process,getTupleVersion, \
detectDeviceForPartition
from cl_kernel_utils import KernelConfig,InitRamFs
@ -890,20 +891,28 @@ class cl_install(color_print, SignalInterrupt):
"""Get target distributive by params"""
rootLabelName = "%s-%s"%(self.clVars.Get('os_install_linux_shortname'),
self.clVars.Get('os_install_linux_ver'))
mapDevice = self.clVars.Get('os_device_hash')
mapPartPT = dict(
map(lambda x:[x,mapDevice.get(detectDeviceForPartition(x),
{'table':None})['table']],
self.clVars.Get('os_disk_dev')))
if buildermode:
return ScratchPartitionDistributive(disk,mdirectory="/mnt/install",
check=True, fileSystem=fileSystem,
isFormat=isFormat, systemId=systemId,
rootLabel=rootLabelName)
rootLabel=rootLabelName,
partitionTable=mapPartPT.get(disk,None))
elif self.clVars.Get('os_install_root_type')=="flash":
return FlashDistributive(disk,mdirectory="/mnt/install",
check=True, fileSystem=fileSystem,
isFormat=isFormat, systemId=systemId)
isFormat=isFormat, systemId=systemId,
partitionTable=mapPartPT.get(disk,None))
else:
target = PartitionDistributive(disk,mdirectory="/mnt/install",
check=True, fileSystem=fileSystem,
isFormat=isFormat, systemId=systemId,
rootLabel=rootLabelName)
rootLabel=rootLabelName,
partitionTable=mapPartPT.get(disk,None))
noRootPartDisksOptions = filter(lambda x: x['mountPoint']!="/",
self.listDisksOptions)
flagMultipartition = False
@ -918,11 +927,13 @@ class cl_install(color_print, SignalInterrupt):
fileSystem = diskOptions["fileSystem"]
isFormat = diskOptions["isFormat"]
systemId = diskOptions["systemId"]
partitionTable = mapPartPT.get(dev,None)
objMultiPartitions.addPartition(dev=dev,
mountPoint=mountPoint,
fileSystem=fileSystem,
isFormat=isFormat,
systemId=systemId)
mountPoint=mountPoint,
fileSystem=fileSystem,
isFormat=isFormat,
systemId=systemId,
partitionTable=partitionTable)
# Swap multipartitions
if self.listSwapsOptions:
flagMultipartition = True
@ -934,11 +945,13 @@ class cl_install(color_print, SignalInterrupt):
fileSystem = diskOptions["fileSystem"]
isFormat = diskOptions["isFormat"]
systemId = diskOptions["systemId"]
partitionTable = mapPartPT.get(dev,None)
objMultiPartitions.addPartition(dev=dev,
mountPoint=mountPoint,
fileSystem=fileSystem,
isFormat=isFormat,
systemId=systemId)
mountPoint=mountPoint,
fileSystem=fileSystem,
isFormat=isFormat,
systemId=systemId,
partitionTable=partitionTable)
# Bind multipartitions
if self.listBindsOptions:
flagMultipartition = True

@ -123,6 +123,9 @@ class Data:
# device type (hdd,cdrom,usb-flash)
os_device_type = {}
# device partition table
os_device_partition = {}
# map number for grub
os_device_map = {}

Loading…
Cancel
Save