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,12 +207,15 @@ 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)
re_resFakeRoot=re.search('(?:^|\s)root=(\S+)(\s|$)',record)
# param real_root priority that root
re_res = re_resRealRoot or re_resFakeRoot
if re_res: if re_res:
rootparam=re_res.group(1) rootparam=re_res.group(1)
# check root for /dev/sd view # check root for /dev/sd view
if re.match("^\/dev\/[a-z]+[0-9]$",rootparam): if re.match("^\/dev\/[a-z]+.*$", rootparam):
return rootparam return rootparam
# check root set by uuid # check root set by uuid
uuidpath = '/dev/disk/by-uuid' uuidpath = '/dev/disk/by-uuid'
@ -228,58 +232,34 @@ class fillVars(varsShare):
uuid = rootparam[5:] uuid = rootparam[5:]
if uuid in mapUuidDev: if uuid in mapUuidDev:
return mapUuidDev[uuid] return mapUuidDev[uuid]
mountLunes = self._runos("mount") # get device mounted to root
if not mountLunes: dfLines = self._runos("LANG=C df /")
if not dfLines:
return "" return ""
if type(mountLunes) == types.ListType: if type(dfLines) == types.ListType and len(dfLines)>1:
root_dev = mountLunes[0].split("on / type")[0].strip() root_dev = dfLines[1].split(" ")[0].strip()
if root_dev: if root_dev:
return root_dev return {'none':'/dev/ram0'}.get(root_dev,root_dev)
return "" 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
for line in mountLunes:
if "/dev/loop0 on / type" in line:
rootType = "ram"
break
elif "/dev/loop0 on /newroot/mnt/livecd type" in line:
rootType = "ram"
flagCD = True
break
if rootType == "ram":
if path.exists("/mnt/livecd") or flagCD:
rootType = "livecd"
return rootType
rootDev = self.Get("os_root_dev") rootDev = self.Get("os_root_dev")
if rootType != "ram" and rootDev: if rootDev:
slpRootDev = rootDev.split("/dev/") if "/dev/ram" in rootDev:
if len(slpRootDev) == 2: return "livecd"
rDev = slpRootDev[1] idDict = dict(map(link2pair,
if os.path.exists('/dev/disk/by-id'): filter(lambda x:path.islink(x),
devLines = os.listdir("/dev/disk/by-id") map(lambda x:path.join('/dev/disk/by-id',x),
for name in devLines: listDirectory('/dev/disk/by-id')))))
pathname = path.join("/dev/disk/by-id", name) if "usb-" in idDict.get(rootDev,""):
if path.islink(pathname): return "usb-hdd"
if rDev in os.readlink(pathname) and \ return "hdd"
"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