Fix detect root device.

develop
Mike Hiretsky 13 years ago
parent 04a8d63c3a
commit 44395261d8

@ -23,7 +23,8 @@ import cl_overriding
from cl_vars_share import varsShare, clLocale from cl_vars_share import varsShare, clLocale
from os.path import exists as pathexists from os.path import exists as pathexists
from os import path from os import path
from cl_utils import isMount, genpassword, getAvailableX11Drivers from cl_utils import isMount, genpassword, getAvailableX11Drivers, \
listDirectory
from encrypt import getHash from encrypt import getHash
class fillVars(varsShare): class fillVars(varsShare):
@ -206,80 +207,59 @@ class fillVars(varsShare):
def get_os_root_dev(self): def get_os_root_dev(self):
"""Root filesystem device""" """Root filesystem device"""
for record in open('/proc/cmdline','rb').readlines(): record = open('/proc/cmdline','rb').read().strip()
re_res=re.search('(?:^|\s)root=(\S+)(\s|$)',record.strip()) re_resRealRoot=re.search('(?:^|\s)real_root=(\S+)(\s|$)',record)
if re_res: re_resFakeRoot=re.search('(?:^|\s)root=(\S+)(\s|$)',record)
rootparam=re_res.group(1) # param real_root priority that root
# check root for /dev/sd view re_res = re_resRealRoot or re_resFakeRoot
if re.match("^\/dev\/[a-z]+[0-9]$",rootparam): if re_res:
return rootparam rootparam=re_res.group(1)
# check root set by uuid # check root for /dev/sd view
uuidpath = '/dev/disk/by-uuid' if re.match("^\/dev\/[a-z]+.*$", rootparam):
if os.access(uuidpath,os.R_OK): return rootparam
uuidDevs = filter(path.islink, # check root set by uuid
map(lambda x: path.join(uuidpath,x), uuidpath = '/dev/disk/by-uuid'
os.listdir(uuidpath))) if os.access(uuidpath,os.R_OK):
mapUuidDev = dict(map(lambda x:(path.basename(x), uuidDevs = filter(path.islink,
path.normpath(path.join(uuidpath, map(lambda x: path.join(uuidpath,x),
os.readlink(x)))), uuidDevs)) os.listdir(uuidpath)))
else: mapUuidDev = dict(map(lambda x:(path.basename(x),
mapUuidDev = {} path.normpath(path.join(uuidpath,
if re.match("^UUID=.*$",rootparam): os.readlink(x)))), uuidDevs))
uuid = rootparam[5:] else:
if uuid in mapUuidDev: mapUuidDev = {}
return mapUuidDev[uuid] if re.match("^UUID=.*$",rootparam):
mountLunes = self._runos("mount") uuid = rootparam[5:]
if not mountLunes: if uuid in mapUuidDev:
return "" return mapUuidDev[uuid]
if type(mountLunes) == types.ListType: # get device mounted to root
root_dev = mountLunes[0].split("on / type")[0].strip() dfLines = self._runos("LANG=C df /")
if root_dev: if not dfLines:
return root_dev
return "" return ""
if type(dfLines) == types.ListType and len(dfLines)>1:
root_dev = dfLines[1].split(" ")[0].strip()
if root_dev:
return {'none':'/dev/ram0'}.get(root_dev,root_dev)
return ""
def get_os_root_type(self): def get_os_root_type(self):
"""Root device type (ram, hdd, livecd)""" """Root device type (ram, hdd, livecd)"""
mountLunes = self._runos("mount") def link2pair(linkfile):
if not mountLunes: """Return pair (target,link) from link"""
return "" basedir = os.path.dirname(linkfile)
rootType = "hdd" targetfile = os.readlink(linkfile)
if type(mountLunes) == types.ListType: return (path.normpath(os.path.join(basedir,targetfile)),linkfile)
flagCD = False rootDev = self.Get("os_root_dev")
for line in mountLunes: if rootDev:
if "/dev/loop0 on / type" in line: if "/dev/ram" in rootDev:
rootType = "ram" return "livecd"
break idDict = dict(map(link2pair,
elif "/dev/loop0 on /newroot/mnt/livecd type" in line: filter(lambda x:path.islink(x),
rootType = "ram" map(lambda x:path.join('/dev/disk/by-id',x),
flagCD = True listDirectory('/dev/disk/by-id')))))
break if "usb-" in idDict.get(rootDev,""):
if rootType == "ram": return "usb-hdd"
if path.exists("/mnt/livecd") or flagCD: return "hdd"
rootType = "livecd"
return rootType
rootDev = self.Get("os_root_dev")
if rootType != "ram" and rootDev:
slpRootDev = rootDev.split("/dev/")
if len(slpRootDev) == 2:
rDev = slpRootDev[1]
if os.path.exists('/dev/disk/by-id'):
devLines = os.listdir("/dev/disk/by-id")
for name in devLines:
pathname = path.join("/dev/disk/by-id", name)
if path.islink(pathname):
if rDev in os.readlink(pathname) and \
"usb-" in name:
rootType = "usb-hdd"
break
else:
devLines = None
if not devLines:
return ""
if rootType == "ram":
rootType = "hdd"
return rootType
else:
return ""
def get_hr_cdrom_set(self): def get_hr_cdrom_set(self):
"""Cdrom variable""" """Cdrom variable"""

Loading…
Cancel
Save