Added grub.info

master3.3
Mike Hiretsky 14 years ago
parent f8ecff27e5
commit 56decdcf56

@ -228,9 +228,6 @@ class Distributive(object):
raise DistributiveError("Cann't copy file from '%s' to '%s':\n%s"%
(fromdir,todir,errmes))
def installBootloader(self):
pass
def formatPartition(self,format=""):
pass
@ -299,8 +296,6 @@ class DirectoryDistributive(Distributive):
self.copy(dFrom.directory,self.directory)
class PartitionDistributive(Distributive):
reRightPartition = re.compile(r"^/dev/(sd[a-z]\d+|cciss/c\d+d\d+)$")
def __init__(self,partition,parent=None,mdirectory="/mnt/calculate",
check=False,multipartition=None):
"""Initialize partition distributive
@ -312,10 +307,6 @@ class PartitionDistributive(Distributive):
Distributive.__init__(self,parent=parent)
self.partition = partition
self.mdirectory = mdirectory
if check and not partition is None and \
(not self.reRightPartition.match(partition) or \
not pathexists(partition)):
raise DistributiveError("Wrong partition name '%s'"%partition)
def _mountPartition(self,partition,directory):
"""Mount partition to directory"""
@ -346,47 +337,46 @@ class PartitionDistributive(Distributive):
self._mountPartition(self.partition,mdirectory)
return DirectoryDistributive(mdirectory,parent=self)
def formatPartition(self,format=""):
# TODO: need node value for ext2 ext3
formatUtilities = { 'ext2':'/sbin/mkfs.ext2 %s',
'ext3':'/sbin/mkfs.ext3 %s',
'ext4':'/sbin/mkfs.ext4 %s',
'jfs':'/sbin/mkfs.jfs -f %s',
'reiserfs':'/sbin/mkfs.reiserfs -f %s',
'xfs':'/sbin/mkfs.xfs -f %s',
'vfat':'/sbin/mkfs.vfat -F 32 %s',
}
formatId = { 'ext2' : '83',
'ext3' : '83',
'ext4' : '83',
'reiserfs' : '83',
'jfs' : '83',
'xfs' : '83',
'vfat' : 'b',
}
def formatPartition(self,format="reiserfs"):
"""Format partition"""
if isMount(self.partition) == '/':
if not format in self.formatUtilities:
raise DistributiveError(
"Cann't format root partition %s" %
self.partition)
"Specified '%s' format inn't supported" % format)
if isMount(self.partition):
raise DistributiveError(
"Cann't format partition %s, because it is mounted" %
self.partition)
# TODO: need multipartition formating
res,errmes = self.runOsCommand("/sbin/mkfs.reiserfs -f %s" %
self.partition)
if not os.access(self.partition,os.W_OK):
raise DistributiveError("Cann't format partition %s:\n%s"%
(self.partition,_("Permission denied")))
# TODO: need multipartition formating ????
res,errmes = self.runOsCommand(self.formatUtilities[format] %
self.partition)
if res == 0:
return True
else:
raise DistributiveError("Cann't format partition %s:\n%s"%
(self.partition,errmes))
def installBootloader(self):
# TODO: need detect HP hdd which has name c[0-9]d[0-9]
rePartition = re.compile("sd([a-z])(\d+)",re.S)
res = rePartition.search(self.partition)
if res:
hddNum = ord(res.groups()[0])-ord('a')
partitionNum = int(res.groups()[1])
else:
raise DistributiveError("Wrong partition name '%s'"%self.partition)
pipe = Popen(["/sbin/grub",
"--device-map=%s/boot/grub/device.map"%self.getDirectory(),
"--no-floppy",
"--batch"], stdin=PIPE,stdout=PIPE)
# TODO: change hd0 for bootloader install to other disks
pipe.stdin.write("root (hd%d,%d)\n"%(hddNum,partitionNum))
pipe.stdin.write("setup (hd0)\n")
pipe.stdin.write("quit\n")
pipe.stdin.close()
# TODO: break if command is hang
if pipe.wait() != 0:
raise DistributiveError("Cann't install bootloader")
def installFrom(self, source):
"""Install distributive to partition from source distributive"""
# get currect partition as directory

@ -217,16 +217,96 @@ class fillVars(object, glob_attr):
def get_os_grub_info(self):
"""Part of current grub.conf"""
pass
def get_os_grub_devicemap_info(self):
"""Content of device.map file for grub"""
pass
return "\n".join(map(lambda x: "(hd%s) /dev/%s" % (x[0],x[1]),
filter(lambda x:x[2] != "flash",
zip(self.Get('os_device_map'),
self.Get('os_device_dev'),
self.Get('os_device_type')))))
def get_os_fstab_mount_info(self):
"""Information about mount points for fstab"""
pass
devicesForFstab = sorted(
filter(lambda x: x[1] != "" and x[1] != "swap",
zip(self.Get('os_disk_dev'),
self.Get('os_disk_install'),
self.Get('os_disk_format'))),
lambda x,y: cmp(x[1],y[1]))
# rootLine one string, but it correct work if devicesForFstab is empty
rootLine = "\n".join(map(lambda x: "%s\t%s\t%s\tnoatime\t0 2" %
(x[0],x[1],x[2]),devicesForFstab[:1]))
otherLines ="\n".join(map(lambda x: "%s\t%s\t%s\tnoatime\t0 0" %
(x[0],x[1],x[2]),devicesForFstab[1:]))
return "\n".join([rootLine,otherLines])
def get_os_fstab_swap_info(self):
"""Information about swap for fstab"""
pass
return "\n".join(map(lambda x: "%s\tnone\tswap\tsw\t0 0"%x[0],
filter(lambda x: x[1] == "swap",
zip(self.Get('os_disk_dev'),
self.Get('os_disk_install')))))
def get_os_linux_system(self):
"""Get linux system (server or desktop)"""
mapNameSystem = {'CDS':'server',
'CLD':'desktop',
'CLDG':'desktop',
'CLDX':'desktop',
'CLS':'desktop',
'CSS':'server'
}
shortName = self.Get('os_linux_shortname')
if shortName in mapNameSystem:
return mapNameSystem[shortName]
else:
return ""
def get_os_kernel_scheduler(self):
"""Get scheduler for root device"""
root_dev = filter(lambda x: x[1] == '/',
zip(self.Get('os_disk_dev'),
self.Get('os_disk_install')))
if root_dev:
root_dev = root_dev[0][0]
root_dev = filter(lambda x: x in root_dev,
self.Get('os_device_dev'))
if root_dev:
root_dev = root_dev[0]
pathScheduler = '/sys/block/%s/queue/scheduler'%root_dev
if access(pathScheduler,R_OK):
res = re.search("\[([^\]]+)\]",
open(pathScheduler).read(),re.S)
if res:
return res.groups()[0]
return "cfq"
def get_os_kernel_attr(self):
"""Kernel attributes"""
# TODO: on usb-hdd install must be "delay=5"
return ""
def get_os_kernel_resume(self):
"""Kernel resume parameter"""
for dev, install in zip(self.Get('os_disk_dev'),
self.Get('os_disk_install')):
if install == "swap":
return "resume=%s"%dev
return ""
def get_os_grub_info(self):
pathGrubConf = "/boot/grub/grub.conf"
if access(pathGrubConf,R_OK):
reRemoveComments = re.compile("(^|\n)\s*#[^\n]*?(?=\n|$)", re.S)
reGrubEntry = re.compile("title.*?(?=title|$)", re.S | re.I )
grubconf = reRemoveComments.sub("",open(pathGrubConf,'r').read())
roothd = filter(lambda x: x[1] == '/',
zip(self.Get('os_disk_grub'),
self.Get('os_disk_install')))
if roothd:
roothd = "root (hd%s)" % roothd[0][0]
return ("".join(filter(lambda x: not roothd in x,
reGrubEntry.findall(grubconf)))).strip()
return ""

@ -124,11 +124,8 @@ class cl_install(color_print):
self.clVars.Get('os_clock_timezone'))
self.defaultPrint(_("Location\n"))
workingVol = filter(lambda x: x[1] == '/',
zip(self.clVars.Get('os_disk_dev'),
self.clVars.Get('os_disk_load'))) or [("unknown",)]
self.printSUCCESS(_("Working volume")+": %s"%
workingVol[0][0])
self.getDeviceByField("load",'/') or "unknown" )
self.printSUCCESS(_("Installation volume")+": %s"%
self.clVars.Get('os_root_dev'))
self.printSUCCESS(_("File system")+": %s"%
@ -146,7 +143,10 @@ class cl_install(color_print):
self.printSUCCESS(_("Authentification")+": %s"%
"<needed>")
self.printSUCCESS("Found update: %s"%self.clVars.Get('os_linux_name'))
self.printSUCCESS("Found update: %s %s %s"%
(self.clVars.Get('os_linux_name'),
self.clVars.Get('os_linux_subname'),
self.clVars.Get('os_linux_ver')))
def wait(self,sec=10):
self.printSUCCESS(_("Press %s to cancel")%"Ctrl+C"+"... %d"%sec, printBR=False)
@ -156,7 +156,7 @@ class cl_install(color_print):
self.defaultPrint("\b\b \n")
def prepareBoot(self,targetDistr):
targetDistr.installBootloader()
self.installBootloader(targetDistr)
def getTargetDistributive(self,disk,buildermode):
if buildermode:
@ -177,6 +177,63 @@ class cl_install(color_print):
else:
return dirsFiles
def setInstallDisk(self,disk):
if not disk in self.clVars.Get('os_disk_dev'):
raise InstallError(_("Wrong target drive name %s"%disk))
else:
osdiskload = \
filter(lambda x: (x[1] or x[2] == "extended") and x[0] == disk,
zip(self.clVars.Get('os_disk_dev'),
self.clVars.Get('os_disk_load'),
self.clVars.Get('os_disk_part')))
if len(osdiskload) > 0:
if osdiskload[0][2] == "extended":
raise InstallError(
_("Specified drive '%s' is extended"%disk))
else:
raise InstallError(
_("Specified drive '%s' mounted to '%s'")%
(disk,osdiskload[0][1]))
else:
self.clVars.Set('os_root_dev',disk,True)
def getDeviceByField(self,field,value):
"""Get device by fields (install load format uuid grub part name)"""
return self.getFieldByField('dev',field,value)
def getFieldByField(self,resfield,field,value):
res = filter(lambda x: x[1] == value,
zip(self.clVars.Get('os_disk_%s'%resfield),
self.clVars.Get('os_disk_%s'%field))) or [("","")]
return res[0][0]
def getFieldByDevice(self,field,device):
"""Get value of field by device"""
device_hash = self.clVars.Get('os_disk_hash')
if device in device_hash and field in device_hash[device]:
return device_hash[device][field]
else:
return ""
def installBootloader(self,target):
"""Install boot loader
Perform grub installation to disk, which has root partition
"""
pipe = Popen(["/sbin/grub",
"--device-map=%s/boot/grub/device.map"%target.getDirectory(),
"--batch"], stdin=PIPE,stdout=PIPE)
pipe.stdin.write("root (hd%s)\n"%
self.getFieldByField("grub","install","/"))
# TODO: change hd0 for bootloader install to other disks
# may be another parameters
pipe.stdin.write("setup (hd0)\n")
pipe.stdin.write("quit\n")
pipe.stdin.close()
# TODO: break if command is hang (KeyboardInterrupt is supported)
if pipe.wait() != 0:
raise DistributiveError("Cann't install bootloader")
def installSystem(self,buildermode=False):
"""install System by current variable enviroment"""
sourceDistr = None
@ -199,7 +256,8 @@ class cl_install(color_print):
self.wait(waittime)
# format partition if needed
self.printSUCCESS(_("Formating partition"))
targetDistr.formatPartition("reiserfs")
targetDistr.formatPartition(
self.getFieldByField("format","install","/") or "reiserfs")
# install distributive
self.printSUCCESS(_("Unpacking system image into target"))
targetDistr.installFrom(sourceDistr)

@ -105,21 +105,13 @@ class install_cmd(cl_install,opt,share_cmd):
self.printERROR(_('variable %s not found')%k)
return False
if options.d:
if not options.d in self.clVars.Get('os_disk_dev'):
self.error(_("Wrong target drive name %s"%options.d))
else:
osdiskload = filter(lambda x: x[1] and x[0] == options.d,
zip(self.clVars.Get('os_disk_dev'),
self.clVars.Get('os_disk_load')))
if len(osdiskload) > 0:
self.error(
_("Specified drive '%s' mounted to '%s' on loaded system"%
(options.d,osdiskload[0][1])))
else:
self.clVars.Set('os_root_dev',options.d,True)
try:
self.setInstallDisk(options.d)
except InstallError,e:
self.error(str(e))
self.old_os_linux_name = self.clVars.Get('os_linux_shortname')
self.old_os_linux_ver = self.clVars.Get('os_linux_ver')
if options.s:
self.old_os_linux_name = self.clVars.Get('os_linux_shortname')
self.old_os_linux_ver = self.clVars.Get('os_linux_ver')
self.clVars.Set('os_linux_shortname',options.s.upper(),True)
return True

@ -90,3 +90,15 @@ class Data:
# information about swap for fstab
os_fstab_swap_info = {}
# system: server or desktop
os_linux_system = {}
# scheduler
os_kernel_scheduler = {}
# kernel attributes
os_kernel_attr = {}
# kernel resume
os_kernel_resume = {}

@ -1,2 +1,2 @@
# Calculate belong()!=&&pkg(sys-boot/grub)!= path=/boot
# Calculate belong()!=&&pkg(sys-boot/grub)!= path=/boot/grub

@ -0,0 +1 @@
#-os_grub_devicemap_info-#

@ -0,0 +1,37 @@
timeout 5
default 0
fallback 1
#?os_linux_ver<9.8#
splashimage=(hd#-disk(/boot,grub)-#)/boot/grub/calculate.xpm.gz
#linuxver#
#?os_linux_ver>=9.8#
splashimage=(hd#-disk(/boot,grub)-#)/boot/grub/grub-calculate.xpm.gz
#linuxver#
#?os_linux_system==desktop&&os_linux_subname!=#
title #-os_linux_name-# #-os_arch_machine-# #-os_linux_ver-# #-os_linux_subname-#
#os_linux_system#
#?os_linux_system==desktop&&os_linux_subname==#
title #-os_linux_name-# #-os_arch_machine-# #-os_linux_ver-#
#os_linux_system#
#?os_linux_system=server#
title #-os_linux_name-# #-os_arch_machine-# #-os_linux_ver-#
#os_linux_system#
root (hd#-disk(/boot,grub)-#)
#?os_linux_system=desktop#
kernel /boot/vmlinuz root=#-root_install_set-# video=uvesafb:ywrap,1024x768-32@60,mtrr:3,splash=silent,theme:tty1 CONSOLE=/dev/tty1 udev quiet #-os_kernel_resume-# elevator=#-os_kernel_scheduler-# doscsi#-os_kernel_attr-#
#os_linux_system#
#?os_linux_system=server&os_linux_shortname!=CSS#
kernel /boot/vmlinuz root=#-root_install_set-# video=uvesafb:ywrap,1024x768-32@60,mtrr:3,splash=silent,theme:tty1 CONSOLE=/dev/tty1 udev quiet #-os_kernel_resume-# elevator=#-os_kerenl_scheduler-# doscsi#-os_kernel_attr-#
#os_linux_system#
#?os_linux_shortname=CSS#
kernel /boot/vmlinuz root=#-root_install_set-# video=uvesafb:ywrap,1024x768-32@60,mtrr:3 udev quiet #-os_kernel_resume-# elevator=#-os_kernel_scheduler-# doscsi#-os_kernel_attr-#
#os_linux_shortname#
initrd /boot/initrd
#-os_grub_info-#
# Uncomment if you have Windows on hard disk
# title Microsoft Windows
# rootnoverify (hd0,0)
# chainloader +1

@ -1,2 +1,2 @@
# Calculate belong()!=&&pkg(sys-apps/openrc)!= append=skip
# Calculate belong()!=&&pkg(sys-apps/openrc)!= append=skip path=/etc

@ -1 +1 @@
# Calculate path=/etc
# Calculate

@ -0,0 +1,6 @@
#-os_fstab_mount_info-#
#-os_fstab_swap_info-#
proc /proc proc defaults 0 0
shm /dev/shm tmpfs nodev,nosuid,noexec 0 0
Loading…
Cancel
Save