Beispiel #1
0
def umount_dev(mntdir, rmdir=True):
    def umount_loop_dev(mntdir):
        cmd = '/bin/umount'
        argv = [mntdir]
        cmdres = run_bash(cmd, argv)
        if cmdres['ret']:
            return False, str(cmdres['err'])
        else:
            loop_dev, isopath = LOOP_DEVICES[mntdir]
            cmd = '/sbin/losetup'
            argv = ['-d', loop_dev]
            cmdres = run_bash(cmd, argv)
            if cmdres['ret']:
                return False, str(cmdres['err'])
            else:
                free_loop(loop_dev)
                LOOP_DEVICES.pop(mntdir, '')
                return True, ''

    isys.sync()
    if USE_ISYS:
        try:
            isys.umount(mntdir)
        except SystemError, e:
            errmsg = "umount_dev: umount failed: %s\n" % str(e)
            logger.e(errmsg)
            return False, errmsg
Beispiel #2
0
def umount_dev(mntdir, rmdir=True):
    def umount_loop_dev(mntdir):
        cmd = '/bin/umount'
        argv = [mntdir]
        cmdres = run_bash(cmd, argv)
        if cmdres['ret']:
            return False, str(cmdres['err'])
        else:
            loop_dev, isopath = LOOP_DEVICES[mntdir]
            cmd = '/sbin/losetup'
            argv = ['-d', loop_dev]
            cmdres = run_bash(cmd, argv)
            if cmdres['ret']:
                return False, str(cmdres['err'])
            else:
                free_loop(loop_dev)
                LOOP_DEVICES.pop(mntdir, '')
                return True, ''

    isys.sync()
    if USE_ISYS:
        try:
            isys.umount(mntdir)
        except SystemError, e:
            errmsg = "umount_dev: umount failed: %s\n" % str(e)
            logger.e(errmsg)
            return False, errmsg
Beispiel #3
0
def do_mkinitrd(mia, operid, dummy):
    mia.set_step(operid, 0, -1)
    os.system('rm -f %s' % os.path.join(CONF_TGTSYS_ROOT, 'boot', CONF_INITRD_FN))
    isys.sync()
    time.sleep(1)
    # Remove Dirty Work
    #os.system('cp -f %s/tmp/fstab.* %s/etc/fstab' % (CONF_TGTSYS_ROOT, CONF_TGTSYS_ROOT))
    if CONF_USEUDEV:
        os.system('cp -f %s/etc/fstab %s/etc/mtab' % (CONF_TGTSYS_ROOT, CONF_TGTSYS_ROOT)) # make udev happy
    #dolog('/sbin/mkinitrd --fstab=/etc/fstab /boot/%s %s\n' % (CONF_INITRD_FN, CONF_DISTKERNELVER))
    #os.system('/usr/sbin/chroot %s /sbin/mkinitrd --fstab=/etc/fstab /boot/%s %s' % (CONF_TGTSYS_ROOT, CONF_INITRD_FN, CONF_DISTKERNELVER))
    dolog('/sbin/new-kernel-pkg --install --mkinitrd --depmod %s\n' % CONF_DISTKERNELVER)
    os.system('/usr/sbin/chroot %s /sbin/new-kernel-pkg --install --mkinitrd --depmod %s' % (CONF_TGTSYS_ROOT, CONF_DISTKERNELVER))
    return 0
Beispiel #4
0
    def writeYaboot(self, instRoot, bl, kernelList, chainList, defaultDev):

        yabootTarget = string.join(self.getBootDevs(bl))

        try:
            bootDev = self.storage.mountpoints["/boot"]

            cf = "/boot/etc/yaboot.conf"
            cfPath = ""
            if not os.path.isdir(instRoot + "/boot/etc"):
                os.mkdir(instRoot + "/boot/etc")
        except KeyError:
            bootDev = self.storage.rootDevice

            cfPath = "/boot"
            cf = "/etc/yaboot.conf"

        if bootDev.type == "mdarray":
            partNumber = bootDev.parents[0].partedPartition.number
        else:
            partNumber = bootDev.partedPartition.number

        f = open(instRoot + cf, "w+")

        f.write("# yaboot.conf generated by anaconda\n\n")
        f.write("boot=%s\n" % (yabootTarget,))
        f.write('init-message="Welcome to %s!\\nHit <TAB> for boot options"\n\n' % productName)

        f.write("partition=%s\n" % partNumber)
        f.write("timeout=%s\n" % ((self.timeout or 8) * 10))
        f.write("install=/usr/lib/yaboot/yaboot\n")
        f.write("delay=5\n")
        f.write("enablecdboot\n")
        f.write("enableofboot\n")
        f.write("enablenetboot\n")

        yabootProg = "/sbin/mkofboot"
        if iutil.getPPCMachine() == "PMac":
            # write out the first hfs/hfs+ partition as being macosx
            for (label, longlabel, device) in chainList:
                if (not label) or (label == ""):
                    continue
                f.write("macosx=/dev/%s\n" % (device,))
                break

            f.write("magicboot=/usr/lib/yaboot/ofboot\n")

        elif iutil.getPPCMachine() == "pSeries":
            f.write("nonvram\n")
            f.write("fstype=raw\n")

        else:  #  Default non-destructive case for anything else.
            f.write("nonvram\n")
            f.write("mntpoint=/boot/yaboot\n")
            f.write("usemount\n")
            if not os.access(instRoot + "/boot/yaboot", os.R_OK):
                os.mkdir(instRoot + "/boot/yaboot")
            yabootProg = "/sbin/ybin"

        if self.password:
            f.write("password=%s\n" % (self.password,))
            f.write("restricted\n")

        f.write("\n")

        rootDev = self.storage.rootDevice

        for (label, longlabel, version) in kernelList:
            kernelTag = "-" + version
            kernelFile = "%s/vmlinuz%s" % (cfPath, kernelTag)

            f.write("image=%s\n" % (kernelFile,))
            f.write("\tlabel=%s\n" % (label,))
            f.write("\tread-only\n")

            initrd = self.makeInitrd(kernelTag, instRoot)
            if initrd:
                f.write("\tinitrd=%s/%s\n" % (cfPath, initrd))

            append = "%s" % (self.args.get(),)

            realroot = rootDev.fstabSpec
            if rootIsDevice(realroot):
                f.write("\troot=%s\n" % (realroot,))
            else:
                if len(append) > 0:
                    append = "%s root=%s" % (append, realroot)
                else:
                    append = "root=%s" % (realroot,)

            if len(append) > 0:
                f.write('\tappend="%s"\n' % (append,))
            f.write("\n")

        f.close()
        os.chmod(instRoot + cf, 0600)

        # FIXME: hack to make sure things are written to disk
        import isys

        isys.sync()
        isys.sync()
        isys.sync()

        ybinargs = [yabootProg, "-f", "-C", cf]

        rc = iutil.execWithRedirect(ybinargs[0], ybinargs[1:], stdout="/dev/tty5", stderr="/dev/tty5", root=instRoot)
        if rc:
            return rc

        if not os.access(instRoot + "/etc/yaboot.conf", os.R_OK) and os.access(
            instRoot + "/boot/etc/yaboot.conf", os.R_OK
        ):
            os.symlink("../boot/etc/yaboot.conf", instRoot + "/etc/yaboot.conf")

        return 0
Beispiel #5
0
 def dosync():
     isys.sync()
     isys.sync()
     isys.sync()
    def writeYaboot(self, instRoot, bl, kernelList, 
                    chainList, defaultDev):

        yabootTarget = string.join(self.getBootDevs(bl))

        try:
            bootDev = self.storage.mountpoints["/boot"]

            cf = "/boot/etc/yaboot.conf"
            cfPath = ""
            if not os.path.isdir(instRoot + "/boot/etc"):
                os.mkdir(instRoot + "/boot/etc")
        except KeyError:
            bootDev = self.storage.rootDevice

            cfPath = "/boot"
            cf = "/etc/yaboot.conf"

        if bootDev.type == "mdarray":
            partNumber = bootDev.parents[0].partedPartition.number
        else:
            partNumber = bootDev.partedPartition.number

        f = open(instRoot + cf, "w+")

        f.write("# yaboot.conf generated by anaconda\n\n")
        f.write("boot=%s\n" %(yabootTarget,))
        f.write("init-message=\"Welcome to %s!\\nHit <TAB> for boot options\"\n\n"
                % productName)

        f.write("partition=%s\n" % partNumber)
        f.write("timeout=%s\n" % ((self.timeout or 8) * 10))
        f.write("install=/usr/lib/yaboot/yaboot\n")
        f.write("delay=5\n")
        f.write("enablecdboot\n")
        f.write("enableofboot\n")
        f.write("enablenetboot\n")        

        yabootProg = "/sbin/mkofboot"
        if iutil.getPPCMachine() == "PMac":
            # write out the first hfs/hfs+ partition as being macosx
            for (label, longlabel, device) in chainList:
                if ((not label) or (label == "")):
                    continue
                f.write("macosx=/dev/%s\n" %(device,))
                break
            
            f.write("magicboot=/usr/lib/yaboot/ofboot\n")

        elif iutil.getPPCMachine() == "pSeries":
            f.write("nonvram\n")
            f.write("fstype=raw\n")

        else: #  Default non-destructive case for anything else.
            f.write("nonvram\n")
            f.write("mntpoint=/boot/yaboot\n")
            f.write("usemount\n")
            if not os.access(instRoot + "/boot/yaboot", os.R_OK):
                os.mkdir(instRoot + "/boot/yaboot")
            yabootProg = "/sbin/ybin"

        if self.password:
            f.write("password=%s\n" %(self.password,))
            f.write("restricted\n")

        f.write("\n")

        rootDev = self.storage.rootDevice

        for (label, longlabel, version) in kernelList:
            kernelTag = "-" + version
            kernelFile = "%s/vmlinuz%s" %(cfPath, kernelTag)

            f.write("image=%s\n" %(kernelFile,))
            f.write("\tlabel=%s\n" %(label,))
            f.write("\tread-only\n")

            initrd = self.makeInitrd(kernelTag, instRoot)
            if initrd:
                f.write("\tinitrd=%s/%s\n" %(cfPath, initrd))

            append = "%s" %(self.args.get(),)

            realroot = rootDev.fstabSpec
            if rootIsDevice(realroot):
                f.write("\troot=%s\n" %(realroot,))
            else:
                if len(append) > 0:
                    append = "%s root=%s" %(append,realroot)
                else:
                    append = "root=%s" %(realroot,)

            if len(append) > 0:
                f.write("\tappend=\"%s\"\n" %(append,))
            f.write("\n")

        f.close()
        os.chmod(instRoot + cf, 0600)

        # FIXME: hack to make sure things are written to disk
        import isys
        isys.sync()
        isys.sync()
        isys.sync()

        ybinargs = [ yabootProg, "-f", "-C", cf ]

        rc = iutil.execWithRedirect(ybinargs[0],
                                    ybinargs[1:],
                                    stdout = "/dev/tty5",
                                    stderr = "/dev/tty5",
                                    root = instRoot)
        if rc:
            return rc

        if (not os.access(instRoot + "/etc/yaboot.conf", os.R_OK) and
            os.access(instRoot + "/boot/etc/yaboot.conf", os.R_OK)):
            os.symlink("../boot/etc/yaboot.conf",
                       instRoot + "/etc/yaboot.conf")

        return 0
        # Test ejectcdrom function.
        print "eject cdrom"
        iso_dev = "/dev/loop1"
        f_cd = os.open(iso_dev, os.O_RDONLY | os.O_NONBLOCK)
        try:
            isys.ejectcdrom(f_cd)
        except SystemError, e:
            # like (22, 'Invalid argument')
            #      (5, 'Input/output error')
            # and so on
            print e
        if f_cd:
            os.close(f_cd)

    if case == "6":
        isys.sync()
    if case == "7":
        my_swap = "/dev/sda7"
        isys.swapon(my_swap)
    if case == "8":
        my_swap = "/dev/sda7"
        isys.swapoff(my_swap)
    procpath = "tgtsys/proc"
    syspath = "tgtsys/sys"
    if case == "9":
        if not os.path.exists(procpath):
            os.makedirs(procpath)
        if not os.path.exists(syspath):
            os.makedirs(syspath)
        isys.mount("proc", "proc", procpath)
        isys.mount("sysfs", "sys", syspath)
Beispiel #8
0
    def dasdFmt (self, intf = None, drive = None):
        """Format dasd devices (s390)."""

        if self.disks.has_key(drive):
            del self.disks[drive]

        w = intf.progressWindow (_("Initializing"),
                             _("Please wait while formatting drive %s...\n"
                               ) % (drive,), 100)
        try:
            isys.makeDevInode(drive, '/tmp/' + drive)
        except:
            pass

        argList = [ "/sbin/dasdfmt",
                    "-y",
                    "-b", "4096",
                    "-d", "cdl",
                    "-P",
                    "-F",
                    "-f",
                    "/tmp/%s" % drive]
        
        fd = os.open("/dev/null", os.O_RDWR | os.O_CREAT | os.O_APPEND)
        p = os.pipe()
        childpid = os.fork()
        if not childpid:
            os.close(p[0])
            os.dup2(p[1], 1)
            os.dup2(fd, 2)
            os.close(p[1])
            os.close(fd)
            os.execv(argList[0], argList)
            log("failed to exec %s", argList)
            sys.exit(1)
			    
        os.close(p[1])

        num = ''
        sync = 0
        s = 'a'
        while s:
            try:
                s = os.read(p[0], 1)
                os.write(fd, s)

                if s != '\n':
                    try:
                        num = num + s
                    except:
                        pass
                else:
                    if num:
                        val = string.split(num)
                        if (val[0] == 'cyl'):
                            # printf("cyl %5d of %5d |  %3d%%\n",
                            val = int(val[5][:-1])
                            w and w.set(val)
                            # sync every 10%
                            if sync + 10 <= val:
                                isys.sync()
                                sync = val
                    num = ''
            except OSError, args:
                (errno, str) = args
                if (errno != 4):
                    raise IOError, args
Beispiel #9
0
 def dosync():
     isys.sync()
     isys.sync()
     isys.sync()
Beispiel #10
0
    def writeSilo(self, instRoot, bl, kernelList, chainList, defaultDev):

        try:
            bootDev = self.storage.mountpoints["/boot"]

            mf = "/silo.message"
            cf = "/boot/silo.conf"
            mfdir = "/boot"
            cfPath = ""
            if not os.path.isdir(instRoot + "/boot"):
                os.mkdir(instRoot + "/boot")
        except KeyError:
            bootDev = self.storage.rootDevice

            cf = "/etc/silo.conf"
            mfdir = "/etc"
            cfPath = "/boot"

        f = open(instRoot + mfdir + mf, "w+")
        f.write("Welcome to %s!\nHit <TAB> for boot options\n\n" % productName)
        f.close()
        os.chmod(instRoot + mfdir + mf, 0600)

        f = open(instRoot + cf, "w+")
        f.write("# silo.conf generated by anaconda\n\n")

        f.write("#boot=%s\n" % (bootDev.path,))
        f.write("message=%s\n" % (mf,))
        f.write("timeout=%s\n" % (self.timeout or 50))

        (name, partNum) = getDiskPart(bootDev.name, self.storage)
        partno = partNum + 1
        f.write("partition=%s\n" % (partno,))

        if self.password:
            f.write("password=%s\n" % (self.password,))
            f.write("restricted\n")

        f.write("default=%s\n" % (kernelList[0][0],))
        f.write("\n")

        rootDev = self.storage.rootDevice

        for (label, longlabel, version) in kernelList:
            kernelTag = "-" + version
            kernelFile = "%s/vmlinuz%s" % (cfPath, kernelTag)

            f.write("image=%s\n" % (kernelFile,))
            f.write("\tlabel=%s\n" % (label,))
            f.write("\tread-only\n")

            initrd = self.makeInitrd(kernelTag, instRoot)
            if initrd:
                f.write("\tinitrd=%s/%s\n" % (cfPath, initrd))

            append = "%s" % (self.args.get(),)

            realroot = rootDev.fstabSpec
            if rootIsDevice(realroot):
                f.write("\troot=%s\n" % (realroot,))
            else:
                if len(append) > 0:
                    append = "%s root=%s" % (append, realroot)
                else:
                    append = "root=%s" % (realroot,)

            if len(append) > 0:
                f.write('\tappend="%s"\n' % (append,))
            f.write("\n")

        f.close()
        os.chmod(instRoot + cf, 0600)

        # FIXME: hack to make sure things are written to disk
        import isys

        isys.sync()
        isys.sync()
        isys.sync()

        backup = "%s/backup.b" % (cfPath,)
        sbinargs = ["/sbin/silo", "-f", "-C", cf, "-S", backup]
        if iutil.getSparcMachine() == "sun4u" or iutil.getSparcMachine() == "sun4v":
            sbinargs += ["-u"]
        else:
            sbinargs += ["-U"]

        rc = iutil.execWithRedirect(sbinargs[0], sbinargs[1:], stdout="/dev/tty5", stderr="/dev/tty5", root=instRoot)
        if rc:
            return rc

        if not os.access(instRoot + "/etc/silo.conf", os.R_OK) and os.access(instRoot + "/boot/silo.conf", os.R_OK):
            os.symlink("../boot/silo.conf", instRoot + "/etc/silo.conf")

        return 0
Beispiel #11
0
# if (os.path.exists('isys')):
#     sys.path.append('isys')

#['EARLY_SWAP_RAM', 'MIN_GUI_RAM', 'MIN_RAM', '__builtins__', '__doc__', '__file__', '__name__', '_isys', '_readFATLabel',
# 'auditDaemon', 'bind_textdomain_codeset', 'biosdisks', 'block', 'cachedDrives', 'cdRwList', 'cdromList',
# 'checkBoot', 'chroot', 'classMap', 'compareDrives', 'compareNetDevices', 'configNetDevice', 'd', 'ddfile',
# 'deviceIsReadOnly', 'dhcpNetDevice', 'disk', 'doGetBiosDisk', 'doProbeBiosDisks', 'driveDict', 'driveIsIscsi',
#
# 'driveUsesModule', 'ejectCdrom', 'ext2Clobber', 'ext2HasJournal', 'ext2IsDirty', 'fbconProbe', 'fbinfo',
# 'floppyDriveDict', 'flushDriveDict', 'fsSpaceAvailable', 'getDasdDevPort', 'getDasdPorts', 'getDasdState',
# 'getIPAddress', 'getLinkStatus', 'getMacAddress', 'getMpathModel', 'getRaidChunkFromDevice', 'getopt',
# 'handleSegv', 'hardDriveDict', 'htavailable', 'ideCdRwList', 'inet_calcNetBroad', 'isIsoImage', 'isLdlDasd',
# 'isPAE', 'isPaeAvailable', 'isPsudoTTY', 'isUsableDasd', 'isVioConsole', 'isWireless', 'iutil', 'kudzu',
# 'loadFont', 'loadKeymap', 'lochangefd', 'log', 'logging', 'losetup', 'makeDevInode', 'makedev', 'mediaPresent',
# 'mknod', 'mount', 'mountCount', 'netmask2prefix', 'os', 'pathSpaceAvailable', 'posix', 'prefix2netmask',
# 'printObject', 'raidCount', 'raidsb', 'raidsbFromDevice', 'raidstart', 'raidstop', 're', 'readExt2Label',
# 'readFATLabel', 'readFSLabel', 'readJFSLabel', 'readJFSLabel_int', 'readReiserFSLabel', 'readReiserFSLabel_int',
# 'readSwapLabel', 'readSwapLabel_int', 'readXFSLabel', 'readXFSLabel_int', 'resetFileContext', 'resetResolv',
# 'resource', 'rhpl', 'setResolvRetry', 'smpAvailable', 'socket', 'spaceAvailable', 'string', 'struct',
#  'swapoff', 'swapon', 'sync', 'sys', 'tapeDriveList', 'umount', 'unlosetup', 'vtActivate', 'warnings',
# 'wipeRaidSB']

sys.path.append('/usr/lib/anaconda')

import isys

print dir("isys")
print dir(isys)
#isys.rmrf("/tmp/c");
isys.sync()
Beispiel #12
0
    def writeSilo(self, instRoot, bl, kernelList, chainList, defaultDev):

        try:
            bootDev = self.storage.mountpoints["/boot"]

            mf = '/silo.message'
            cf = "/boot/silo.conf"
            mfdir = '/boot'
            cfPath = ""
            if not os.path.isdir(instRoot + "/boot"):
                os.mkdir(instRoot + "/boot")
        except KeyError:
            bootDev = self.storage.rootDevice

            cf = "/etc/silo.conf"
            mfdir = '/etc'
            cfPath = "/boot"

        f = open(instRoot + mfdir + mf, "w+")
        f.write("Welcome to %s!\nHit <TAB> for boot options\n\n" % productName)
        f.close()
        os.chmod(instRoot + mfdir + mf, 0600)

        f = open(instRoot + cf, "w+")
        f.write("# silo.conf generated by anaconda\n\n")

        f.write("#boot=%s\n" % (bootDev.path, ))
        f.write("message=%s\n" % (mf, ))
        f.write("timeout=%s\n" % (self.timeout or 50))

        (name, partNum) = getDiskPart(bootDev, self.storage)
        partno = partNum + 1
        f.write("partition=%s\n" % (partno, ))

        if self.password:
            f.write("password=%s\n" % (self.password, ))
            f.write("restricted\n")

        f.write("default=%s\n" % (kernelList[0][0], ))
        f.write("\n")

        rootDev = self.storage.rootDevice

        for (label, longlabel, version) in kernelList:
            kernelTag = "-" + version
            kernelFile = "%s/vmlinuz%s" % (cfPath, kernelTag)

            f.write("image=%s\n" % (kernelFile, ))
            f.write("\tlabel=%s\n" % (label, ))
            f.write("\tread-only\n")

            initrd = self.makeInitrd(kernelTag, instRoot)
            if initrd:
                f.write("\tinitrd=%s/%s\n" % (cfPath, initrd))

            append = "%s" % (self.args.get(), )

            realroot = rootDev.fstabSpec
            if rootIsDevice(realroot):
                f.write("\troot=%s\n" % (realroot, ))
            else:
                if len(append) > 0:
                    append = "%s root=%s" % (append, realroot)
                else:
                    append = "root=%s" % (realroot, )

            if len(append) > 0:
                f.write("\tappend=\"%s\"\n" % (append, ))
            f.write("\n")

        f.close()
        os.chmod(instRoot + cf, 0600)

        # FIXME: hack to make sure things are written to disk
        import isys
        isys.sync()
        isys.sync()
        isys.sync()

        backup = "%s/backup.b" % (cfPath, )
        sbinargs = ["/sbin/silo", "-f", "-C", cf, "-S", backup]
        # TODO!!!  FIXME!!!  XXX!!!
        # butil is not defined!!!  - assume this is in rhpl now?
        if butil.getSparcMachine() == "sun4u":
            sbinargs += ["-u"]
        else:
            sbinargs += ["-U"]

        rc = iutil.execWithRedirect(sbinargs[0],
                                    sbinargs[1:],
                                    stdout="/dev/tty5",
                                    stderr="/dev/tty5",
                                    root=instRoot)
        if rc:
            return rc

        if (not os.access(instRoot + "/etc/silo.conf", os.R_OK)
                and os.access(instRoot + "/boot/etc/silo.conf", os.R_OK)):
            os.symlink("../boot/etc/silo.conf", instRoot + "/etc/silo.conf")

        return 0