@ -28,7 +28,8 @@ from cl_utils import isMount,typeFile,getTupleVersion,pathJoin,isFstabMount,\
isPkgInstalled , process , checkUtils , readLinesFile , \
FStab , lspci , getInstalledVideo , getDeviceType , \
getPartitionType , getOsProberHash , getProgPath , \
getRaidPartitions , getLvmPartitions , getLvmGroups
getRaidPartitions , getLvmPartitions , getLvmGroups , \
refreshLVM , refreshUdev
from cl_distr import DistributiveRepository , PartitionDistributive
from cl_fill import clLocale
from operator import itemgetter
@ -244,10 +245,14 @@ class fillVars(object, glob_attr):
return " "
def get_os_device_hash ( self ) :
""" Generate hash information about device """
def onlyDisk ( devpath ) :
""" Check by udevadm that devpath is device (disk) """
prop = getUdevDeviceInfo ( devpath )
return prop . get ( " ID_TYPE " , " " ) == " disk " and \
prop . get ( " DEVTYPE " , " " ) == " disk "
# get usb device by '/dev/disk/by-id' (usb devices contain 'usb' in name)
diskIdPath = ' /dev/disk/by-id '
if path . exists ( diskIdPath ) :
usbdevices = \
@ -255,31 +260,39 @@ class fillVars(object, glob_attr):
filter ( lambda x : x . startswith ( ' usb- ' ) , listDirectory ( diskIdPath ) ) )
else :
usbdevices = [ ]
# get devices from /sys/block directories (discard mem,sr,loop and other)
sysBlockPath = ' /sys/block '
devices = map ( lambda x : path . join ( sysBlockPath , x ) ,
filter ( lambda x : onlyDisk ( path . join ( sysBlockPath , x ) ) ,
filter ( lambda x : not self . reWrongDevice . search ( x ) ,
listDirectory ( sysBlockPath ) ) ) )
device_hash = { }
# filling hash
for mapnum , device in enumerate ( sorted ( devices , key = self . separateDevice ) ) :
# get information by udev
props = getUdevDeviceInfo ( device )
if not " DEVNAME " in props :
continue
# DEVNAME - /dev/(device_name)
device = props [ ' DEVNAME ' ]
device_hash [ device ] = { }
# get partition table (if PART_TABLE_TYPE absent then get by child partition)
device_hash [ device ] [ ' table ' ] = props . get ( ' ID_PART_TABLE_TYPE ' ,
self . getTableByChild ( device ) )
# enumerate disk for legecy grub
device_hash [ device ] [ ' map ' ] = mapnum
# if device is usb device
if path . basename ( device ) in usbdevices :
# check for usb flash (removeable fiel in sysfs contains "1")
removablePath = ' /sys/block/ %s /removable ' % path . basename ( device )
if os . access ( removablePath , R_OK ) and \
open ( removablePath , ' r ' ) . read ( ) . strip ( ) == " 1 " :
devtype = " flash "
devtype = " flash "
else :
devtype = " usb-hdd "
devtype = " usb-hdd "
else :
devtype = " hdd "
devtype = " hdd "
# set detect device type (hdd,flash or usb-hdd)
device_hash [ device ] [ ' type ' ] = devtype
return device_hash
@ -288,9 +301,11 @@ class fillVars(object, glob_attr):
def selfOrPartition ( devpath ) :
""" Return self device or partitions if it has them """
# search partition in device
# get devices in sysfs which startswith devname
partitions = \
filter ( lambda x : x . startswith ( path . basename ( devpath ) ) ,
listDirectory ( devpath ) )
# if partition found then return them or partition on them
if partitions :
return filter ( lambda x : x ,
map ( lambda x : selfOrPartition ( path . join ( devpath , x ) ) ,
@ -298,17 +313,14 @@ class fillVars(object, glob_attr):
else :
return devpath
# refresh LVM
vgscan = getProgPath ( ' /sbin/vgscan ' )
vgchange = getProgPath ( ' /sbin/vgchange ' )
lvchange = getProgPath ( ' /sbin/lvchange ' )
if vgscan and vgchange and lvchange :
process ( vgscan ) . success ( )
process ( vgchange , ' -ay ' , ' --refresh ' ) . success ( )
for group in getLvmGroups ( ) :
process ( lvchange , ' -ay ' , ' --refresh ' , group ) . success ( )
# refresh information about LVM
refreshLVM ( )
# refresh information about device in udevadm info
refreshUdev ( )
devicesHash = self . Get ( ' os_device_hash ' )
sysBlockPath = ' /sys/block '
# get disks from sys block which not contains partitions
new_disks = reduce ( lambda x , y : x + ( [ y ] if type ( y ) == str else y ) ,
map ( lambda x : selfOrPartition ( path . join ( sysBlockPath , x ) ) ,
filter ( lambda x : not self . reWrongDevice . search ( x ) ,
@ -318,6 +330,11 @@ class fillVars(object, glob_attr):
fstab = FStab ( ' /etc/fstab ' )
raidUsedDisks = [ ]
lvmUsedDisks = [ ]
mapTypeUUID = { ' ebd0a0a2-b9e5-4433-87c0-68b6b72699c7 ' : ' 0700 ' ,
' 0657fd6d-a4ab-43c4-84e5-0933c84b4f4f ' : ' 8200 ' ,
' a19d880f-05fc-4d3b-a006-743f0f84911e ' : ' FD00 ' ,
' 21686148-6449-6e6f-744e-656564454649 ' : ' EF02 ' }
# filling information about disks
for disk in new_disks :
props = getUdevDeviceInfo ( disk )
if not " DEVNAME " in props :
@ -330,12 +347,17 @@ class fillVars(object, glob_attr):
props . get ( ' ID_FS_TYPE ' , ' ' )
dev_hash [ ' name ' ] = props . get ( ' ID_FS_LABEL ' , ' ' )
dev_hash [ ' table ' ] = props . get ( ' ID_PART_ENTRY_SCHEME ' , ' ' )
# schema device (disk-partition or disk-partition-raid and etc)
dev_hash [ ' type ' ] = getDeviceType ( disk )
dev_hash [ ' id ' ] = props . get ( ' ID_PART_ENTRY_TYPE ' , ' ' ) . partition ( " x " ) [ 2 ]
dev_hash [ ' id ' ] = props . get ( ' ID_PART_ENTRY_TYPE ' , ' ' ) . rpartition ( " x " ) [ 2 ]
dev_hash [ ' id ' ] = mapTypeUUID . get ( dev_hash [ ' id ' ] , dev_hash [ ' id ' ] )
devParent = getPartitionDevice ( disk )
dev_hash [ ' parent ' ] = devParent
# primary, extended or logical
dev_hash [ ' part ' ] = getPartitionType ( props )
# get options from fstab
dev_hash [ ' options ' ] = fstab . getBy ( what = fstab . OPTS , eq = devName ) or " "
# get disk size
dev_hash [ ' size ' ] = getPartitionSize ( disk )
if devParent in devicesHash and ' ID_PART_ENTRY_NUMBER ' in props :
dev_hash [ ' grub ' ] = " %s , %d " % ( devicesHash [ devParent ] [ ' map ' ] ,
@ -343,17 +365,21 @@ class fillVars(object, glob_attr):
else :
dev_hash [ ' grub ' ] = " "
disk_hash [ devName ] = dev_hash
# if device raid then get its partition and add to raid partitions list
if " raid " in dev_hash [ ' type ' ] :
raidUsedDisks . extend ( map ( lambda x : ( devName , x ) , getRaidPartitions ( disk ) ) )
# if device lvm then get its partition and add to lvm partitions list
if dev_hash [ ' type ' ] . endswith ( " lvm " ) :
prop = getUdevDeviceInfo ( path = disk )
lvmUsedDisks . extend ( map ( lambda x : ( devName , x ) ,
getLvmPartitions ( prop . get ( ' DM_VG_NAME ' , ' ' ) ,
prop . get ( ' DM_LV_NAME ' , ' ' ) ) ) )
# fix type information for raid disks
for disk , part in raidUsedDisks :
if part in disk_hash :
disk_hash [ part ] [ ' type ' ] = " %s -raidmember( %s ) " % (
disk_hash [ part ] [ ' type ' ] , disk )
# fix type information for lvm disks
for disk , part in lvmUsedDisks :
if part in disk_hash :
disk_hash [ part ] [ ' type ' ] = " %s -lvmmember( %s ) " % (