diff options
author | Matt Wilson <msw@redhat.com> | 1999-12-08 18:21:18 +0000 |
---|---|---|
committer | Matt Wilson <msw@redhat.com> | 1999-12-08 18:21:18 +0000 |
commit | 337ce745505ec48d229ee8c2058f2aed8fd933da (patch) | |
tree | 4a3c03595edf2ee7bc764cf861f1dfff2c6ddb06 /fstab.py | |
parent | 730aa2a87c13acfa76992cf7044d18bea2b23398 (diff) | |
download | anaconda-337ce745505ec48d229ee8c2058f2aed8fd933da.tar.gz anaconda-337ce745505ec48d229ee8c2058f2aed8fd933da.tar.xz anaconda-337ce745505ec48d229ee8c2058f2aed8fd933da.zip |
added file erik forgot from his laptop
Diffstat (limited to 'fstab.py')
-rw-r--r-- | fstab.py | 331 |
1 files changed, 331 insertions, 0 deletions
diff --git a/fstab.py b/fstab.py new file mode 100644 index 000000000..2fe8e594c --- /dev/null +++ b/fstab.py @@ -0,0 +1,331 @@ +# this owns partitioning, fstab generation, disk scanning, raid, etc +# +# a fstab is returned as a list of: +# ( mntpoint, device, fsystem, doFormat, size, (file) ) +# tuples, sorted by mntpoint; note that device may be a raid device; the file +# value is optional, and if it exists it names a file which will be created +# on the (already existant!) device and loopback mounted +# +# the swap information is stored as ( device, format ) tuples +# +# raid lists are stored as ( raiddevice, raidlevel, [ device list ] ) +# +# we always store as much of the fstab within the disk druid structure +# as we can -- Don't Duplicate Data. + + #self.todo.setLiloLocation(("raid", liloBoot)) + #self.todo.instClass.addToSkipList("lilo") + +import isys +import iutil +import os + +def _(str): + return str + +class Fstab: + + def rescanPartitions(self): + pass + + def savePartitions(self): + self.ddruid.save() + + def runDruid(self): + self.ddruid.edit() + # yikes! this needs to be smarter + self.beenSaved = 0 + + def updateFsCache(self): + realFs = {} + for (partition, mount, fsystem, size) in self.ddruid.getFstab(): + realFs[(partition, mount)] = 1 + for ((partition, mount)) in self.fsCache.keys(): + if not realFs.has_key((partition, mount)): + del self.fsCache[(partition, mount)] + + def setFormatFilesystem(self, device, format): + for (partition, mount, fsystem, size) in self.ddruid.getFstab(): + if partition == device: + self.fsCache[(partition, mount)] = (format,) + + def partitionList(self): + return self.ddruid.partitionList() + + def swapList(self): + fstab = [] + for (partition, mount, fsystem, size) in self.ddruid.getFstab(): + if fsystem != "swap": continue + + fstab.append((partition, 1)) + return fstab + + def turnOnSwap(self): + # we could be smarter about this + if self.swapOn: return + self.swapOn = 1 + + for (device, doFormat) in self.swapList(): + w = self.waitWindow(_("Formatting"), + _("Formatting swap space on /dev/%s...") % (device,)) + + file = '/tmp/' + device + isys.makeDevInode(device, file) + + rc = iutil.execWithRedirect ("/usr/sbin/mkswap", + [ "mkswap", '-v1', '/tmp/' + device ], + stdout = None, stderr = None, + searchPath = 1) + w.pop() + + if rc: + self.waitWindow("Error creating swap on device " + device) + else: + isys.swapon (file) + + os.unlink(file) + + def createRaidTab(self, file, devPrefix, createDevices = 0): + (devices, raid) = self.ddruid.partitionList() + if not raid: return + + deviceDict = {} + for (device, name, type, start, size) in devices: + deviceDict[name] = device + + rt = open(file, "w") + for (mntpoint, device, fstype, raidType, start, size, makeup) in raid: + + if createDevices: + isys.makeDevInode(device, devPrefix + '/' + device) + + rt.write("raiddev %s/%s\n" % (devPrefix, device,)) + rt.write("raid-level %d\n" % (raidType,)) + rt.write("nr-raid-disks %d\n" % (len(makeup),)) + rt.write("chunk-size 64k\n") + rt.write("persistent-superblock 1\n"); + rt.write("#nr-spare-disks 0\n") + i = 0 + for subDevName in makeup: + isys.makeDevInode(deviceDict[subDevName], '%s/%s' % + (devPrefix, deviceDict[subDevName])) + rt.write(" device %s/%s\n" % + (devPrefix, deviceDict[subDevName],)) + rt.write(" raid-disk %d\n" % (i,)) + i = i + 1 + + rt.write("\n") + rt.close() + + def umountFilesystems(self, messageWindow): + if (not self.setupFilesystems): return + + isys.umount(self.instPath + '/proc') + + for (mntpoint, device, fsystem, doFormat, size) in self.mountList(): + if fsystem != "swap": + try: + mntPoint = self.instPath + n + self.log("unmounting " + mntPoint) + isys.umount(mntPoint) + except SystemError, (errno, msg): + messageWindow(_("Error"), + _("Error unmounting %s: %s") % (device, msg)) + + + def makeFilesystems(self): + # let's make the RAID devices first -- the fstab will then proceed + # naturally + (devices, raid) = self.ddruid.partitionList() + + if raid: + self.createRaidTab("/tmp/raidtab", "/tmp", createDevices = 1) + + w = self.waitWindow(_("Creating"), _("Creating RAID devices...")) + + for (mntpoint, device, fsType, raidType, start, size, makeup) in raid: + iutil.execWithRedirect ("/usr/sbin/mkraid", + [ 'mkraid', '--really-force', '--configfile', + '/tmp/raidtab', '/tmp/' + device ]) + + w.pop() + + # XXX remove extraneous inodes here + + if not self.setupFilesystems: return + + arch = iutil.getArch () + + if arch == "alpha": + if '/boot' in keys: + kernelPart = '/boot' + else: + kernelPart = '/' + + for (mntpoint, device, fsystem, doFormat, size) in self.mountList(): + if not doFormat: continue + isys.makeDevInode(device, '/tmp/' + device) + if fsystem == "ext2": + args = [ "mke2fs", '/tmp/' + device ] + # FORCE the partition that MILO has to read + # to have 1024 block size. It's the only + # thing that our milo seems to read. + if arch == "alpha" and mntpoint == kernelPart: + args = args + ["-b", "1024"] + # set up raid options for md devices. + if device[:2] == 'md': + for (rmnt, rdevice, fsType, raidType, start, size, makeup) in raid: + if rdevice == device: + rtype = raidType + rdisks = len (makeup) + if rtype == 5: + rdisks = rdisks - 1 + args = args + [ '-R', 'stride=%d' % (rdisks * 16) ] + elif rtype == 0: + args = args + [ '-R', 'stride=%d' % (rdisks * 16) ] + + if self.badBlockCheck: + args.append ("-c") + + w = self.waitWindow(_("Formatting"), + _("Formatting %s filesystem...") % (mntpoint,)) + + if self.serial: + messages = "/tmp/mke2fs.log" + else: + messages = "/dev/tty5" + iutil.execWithRedirect ("/usr/sbin/mke2fs", + args, + stdout = messages, stderr = messages, + searchPath = 1) + w.pop() + else: + pass + + os.remove('/tmp/' + device) + + def mountFilesystems(self, instPath): + if (not self.setupFilesystems): return + + for (mntpoint, device, fsystem, doFormat, size) in self.mountList(): + if fsystem == "swap": + continue + elif fsystem == "ext2": + try: + iutil.mkdirChain(instPath + mntpoint) + isys.makeDevInode(device, '/tmp/' + device) + isys.mount('/tmp/' + device, + instPath + mntpoint) + os.remove( '/tmp/' + device); + except SystemError, (errno, msg): + self.intf.messageWindow(_("Error"), + _("Error mounting %s: %s") % (device, msg)) + + try: + os.mkdir (instPath + '/proc') + except: + pass + + isys.mount('/proc', instPath + '/proc', 'proc') + + def writeFstab(self): + format = "%-23s %-23s %-7s %-15s %d %d\n"; + + f = open (self.instPath + "/etc/fstab", "w") + self.setFdDevice () + for (mntpoint, dev, fs, reformat, size) in self.mountList(): + iutil.mkdirChain(self.instPath + mntpoint) + if (mntpoint == '/'): + f.write (format % ( '/dev/' + dev, mntpoint, fs, 'defaults', 1, 1)) + else: + if (fs == "ext2"): + f.write (format % ( '/dev/' + dev, mntpoint, fs, 'defaults', 1, 2)) + elif fs == "iso9660": + f.write (format % ( '/dev/' + dev, mntpoint, fs, 'noauto,owner,ro', 0, 0)) + else: + f.write (format % ( '/dev/' + dev, mntpoint, fs, 'defaults', 0, 0)) + f.write (format % (self.fdDevice, "/mnt/floppy", 'ext2', 'noauto,owner', 0, 0)) + f.write (format % ("none", "/proc", 'proc', 'defaults', 0, 0)) + f.write (format % ("none", "/dev/pts", 'devpts', 'gid=5,mode=620', 0, 0)) + f.close () + # touch mtab + open (self.instPath + "/etc/mtab", "w+") + f.close () + + self.createRaidTab("/mnt/sysimage/etc/raidtab", "/dev") + + def mountList(self): + def sortMounts(one, two): + mountOne = one[0] + mountTwo = two[0] + if (mountOne < mountTwo): + return -1 + elif (mountOne == mountTwo): + return 0 + return 1 + + fstab = [] + for (partition, mount, fsystem, size) in self.ddruid.getFstab(): + if fsystem == "swap": continue + + if not self.fsCache.has_key((partition, mount)): + self.fsCache[(partition, mount)] = (0, ) + (doFormat,) = self.fsCache[(partition, mount)] + fstab.append((mount, partition, fsystem, doFormat, size )) + fstab.sort(sortMounts) + return fstab + + def saveDruidPartitions(self): + if self.beenSaved: return + self.ddruid.save() + self.beenSaved = 1 + + def setBadBlockCheck(self, state): + self.badBlockCheck = state + + def getBadBlockCheck(self): + return self.badBlockCheck + + def __init__(self, setupFilesystems, serial, waitWindow): + self.fsCache = {} + self.swapOn = 0 + self.beenSaved = 1 + self.setupFilesystems = setupFilesystems + self.serial = serial + self.waitWindow = waitWindow + self.badBlockCheck = 0 + +class GuiFstab(Fstab): + + def runDruid(self, callback): + self.ddruid.setCallback (callback) + + bin = self.GtkFrame (None, _obj = self.ddruid.getWindow ()) + bin.set_shadow_type (self.SHADOW_NONE) + self.ddruid.edit () + return bin + + def runDruidFinished(self): + self.ddruid.next () + self.updateFsCache() + # yikes! this needs to be smarter + self.beenSaved = 0 + + def __init__(self, setupFilesystems, serial, zeroMbr, readOnly, waitWindow): + from gnomepyfsedit import fsedit + from gtk import * + + Fstab.__init__(self, setupFilesystems, serial, waitWindow) + self.ddruid = fsedit(0, isys.hardDriveList().keys(), [], + zeroMbr, readOnly) + self.GtkFrame = GtkFrame + self.SHADOW_NONE = SHADOW_NONE + +class NewtFstab(Fstab): + + def __init__(self, setupFilesystems, serial, zeroMbr, readOnly, waitWindow): + from newtpyfsedit import fsedit + + Fstab.__init__(self, setupFilesystems, serial, waitWindow) + self.ddruid = fsedit(0, isys.hardDriveList().keys(), [], + zeroMbr, readOnly) |