Exemplo n.º 1
0
def get_partition_file_system_type(part):
    """Return the file system type of the PedPartition part.

    Arguments:
    part -- PedPartition object

    Return:
    Filesystem object (as defined in fsset.py)
    """
    if part.fs_type is None and part.native_type == 0x41:
        ptype = fsset.fileSystemTypeGet("PPC PReP Boot")
    elif part.fs_type == None:
        return None
    elif part.fs_type.name == "linux-swap":
        ptype = fsset.fileSystemTypeGet("swap")
    elif (part.fs_type.name == "FAT" or part.fs_type.name == "fat16"
          or part.fs_type.name == "fat32"):
        ptype = fsset.fileSystemTypeGet("vfat")
    else:
        try:
            ptype = fsset.fileSystemTypeGet(part.fs_type.name)
        except:
            ptype = fsset.fileSystemTypeGet("foreign")

    return ptype
Exemplo n.º 2
0
    def getBootableRequest(self):
        """Return the name of the current 'boot' mount point."""
        bootreq = None

        if iutil.getArch() == "ia64":
            bootreq = self.getRequestByMountPoint("/boot/efi")
            if bootreq:
                return [bootreq]
            else:
                return None
        elif iutil.getPPCMachine() == "iSeries":
            for req in self.requests:
                if req.fstype == fsset.fileSystemTypeGet("PPC PReP Boot"):
                    return [req]
            return None
        elif iutil.getPPCMachine() == "pSeries":
            # pSeries bootable requests are odd.
            # have to consider both the PReP partition (with potentially > 1
            # existing) as well as /boot,/

            # for the prep partition, we want either the first or the
            # first non-preexisting one
            bestprep = None
            for req in self.requests:
                if req.fstype == fsset.fileSystemTypeGet("PPC PReP Boot"):
                    if ((bestprep is None) or (bestprep.getPreExisting()
                                               and not req.getPreExisting())):
                        bestprep = req

            if bestprep:
                ret = [bestprep]
            else:
                ret = []

            # now add the /boot
            bootreq = self.getRequestByMountPoint("/boot")
            if not bootreq:
                bootreq = self.getRequestByMountPoint("/")
            if bootreq:
                ret.append(bootreq)

            if len(ret) >= 1:
                return ret
            return None

        if not bootreq:
            bootreq = self.getRequestByMountPoint("/boot")
        if not bootreq:
            bootreq = self.getRequestByMountPoint("/")

        if bootreq:
            return [bootreq]
        return None
Exemplo n.º 3
0
def checkForSwapNoMatch(intf, diskset, partitions):
    """Check for any partitions of type 0x82 which don't have a swap fs."""
    for request in partitions.requests:
        if not request.device or not request.fstype:
            continue

        part = partedUtils.get_partition_by_name(diskset.disks, request.device)
        if (part and (not part.type & parted.PARTITION_FREESPACE)
                and (part.native_type == 0x82)
                and (request.fstype and request.fstype.getName() != "swap")
                and (not request.format)):
            rc = intf.messageWindow(_("Format as Swap?"),
                                    _("/dev/%s has a partition type of 0x82 "
                                      "(Linux swap) but does not appear to "
                                      "be formatted as a Linux swap "
                                      "partition.\n\n"
                                      "Would you like to format this "
                                      "partition as a swap partition?") %
                                    (request.device),
                                    type="yesno",
                                    custom_icon="question")
            if rc == 1:
                request.format = 1
                request.fstype = fsset.fileSystemTypeGet("swap")
                if request.fstype.getName() == "software RAID":
                    part.set_flag(parted.PARTITION_RAID, 1)
                else:
                    part.set_flag(parted.PARTITION_RAID, 0)

                partedUtils.set_partition_file_system_type(
                    part, request.fstype)
Exemplo n.º 4
0
    def __init__(self, fstype =None, format = None,
                 vgname = None, physvols = None,
                 pesize = 32768, preexist = 0,
                 preexist_size = 0):
        """Create a new VolumeGroupRequestSpec object.

        fstype is the fsset filesystem type.
        format is whether or not the volume group should be created.
        vgname is the name of the volume group.
        physvols is a list of the ids for the physical volumes in the vg.
        pesize is the size of a physical extent in kilobytes.
        preexist is whether the volume group is preexisting.
        preexist_size is the size of a preexisting VG read from /proc
            (note that this is unclamped)
        """

        if not fstype:
            fstype = fsset.fileSystemTypeGet("volume group (LVM)")
        RequestSpec.__init__(self, fstype = fstype, format = format)
        self.type = REQUEST_VG

        self.volumeGroupName = vgname
        self.physicalVolumes = physvols
        self.pesize = pesize
        self.preexist = preexist

        # FIXME: this is a hack so that we can set the vg name automagically
        # with autopartitioning to not conflict with existing vgs
        self.autoname = 0

        if preexist and preexist_size:
            self.preexist_size = preexist_size
            log.debug("VolumeGroupRequestSpec('%s').preexist_size is %s" % (vgname, preexist_size))
        else:
            self.preexist_size = None
Exemplo n.º 5
0
    def __init__(self,
                 fstype=None,
                 format=None,
                 vgname=None,
                 physvols=None,
                 pesize=4096,
                 preexist=0,
                 preexist_size=0):
        """Create a new VolumeGroupRequestSpec object.

        fstype is the fsset filesystem type.
        format is whether or not the volume group should be created.
        vgname is the name of the volume group.
        physvols is a list of the ids for the physical volumes in the vg.
        pesize is the size of a physical extent in kilobytes.
        preexist is whether the volume group is preexisting.
        preexist_size is the size of a preexisting VG read from /proc
            (note that this is unclamped)
        """

        if not fstype:
            fstype = fsset.fileSystemTypeGet("volume group (LVM)")
        RequestSpec.__init__(self, fstype=fstype, format=format)
        self.type = REQUEST_VG

        self.volumeGroupName = vgname
        self.physicalVolumes = physvols
        self.pesize = pesize
        self.preexist = preexist

        if preexist and preexist_size:
            self.preexist_size = preexist_size
        else:
            self.preexist_size = None
Exemplo n.º 6
0
def checkForSwapNoMatch(anaconda):
    """Check for any partitions of type 0x82 which don't have a swap fs."""
    for request in anaconda.id.partitions.requests:
        if not request.device or not request.fstype:
            continue
        
        part = partedUtils.get_partition_by_name(anaconda.id.diskset.disks,
                                                 request.device)
        if (part and (not part.type & parted.PARTITION_FREESPACE)
            and (part.native_type == 0x82)
            and (request.fstype and request.fstype.getName() != "swap")
            and (not request.format)):
            rc = anaconda.intf.messageWindow(_("Format as Swap?"),
                                    _("/dev/%s has a partition type of 0x82 "
                                      "(Linux swap) but does not appear to "
                                      "be formatted as a Linux swap "
                                      "partition.\n\n"
                                      "Would you like to format this "
                                      "partition as a swap partition?")
                                    % (request.device), type = "yesno",
				    custom_icon="question")
            if rc == 1:
                request.format = 1
                request.fstype = fsset.fileSystemTypeGet("swap")
                if request.fstype.getName() == "software RAID":
                    part.set_flag(parted.PARTITION_RAID, 1)
                else:
                    part.set_flag(parted.PARTITION_RAID, 0)
                    
                partedUtils.set_partition_file_system_type(part,
                                                           request.fstype)
Exemplo n.º 7
0
 def check(self, chroot="/mnt/sysimage"):
     """
     Will automatically check if the nfs export is availble or not and also update internal values.
     """
     filesystem=fsset.fileSystemTypeGet("nfs")
     filesystem.mount(self.device, chroot)
     dfoutput=ComSystem.execLocalOutput("df %s" %chroot )
     spaces=re.match(self.getExport()+"\W+\s(?P<all>\d+)\s+(?P<used>\d+)\s+(?P<available>\d+)\s", "\n".join(dfoutput[1:]))
     if spaces:
         self.size=int(spaces.group("all"))
         self.used=int(spaces.group("used"))
         self.available=int(spaces.group("available"))
     filesystem.umount(self.device, chroot)
Exemplo n.º 8
0
    def __init__(self,
                 fstype=None,
                 format=None,
                 vgname=None,
                 physvols=None,
                 pesize=32768,
                 preexist=0,
                 preexist_size=0):
        """Create a new VolumeGroupRequestSpec object.

        fstype is the fsset filesystem type.
        format is whether or not the volume group should be created.
        vgname is the name of the volume group.
        physvols is a list of the ids for the physical volumes in the vg.
        pesize is the size of a physical extent in kilobytes.
        preexist is whether the volume group is preexisting.
        preexist_size is the size of a preexisting VG read from /proc
            (note that this is unclamped)
        """

        if not fstype:
            fstype = fsset.fileSystemTypeGet("volume group (LVM)")
        RequestSpec.__init__(self, fstype=fstype, format=format)
        self.type = REQUEST_VG

        self.volumeGroupName = vgname
        self.physicalVolumes = physvols
        self.pesize = pesize
        self.preexist = preexist

        # FIXME: this is a hack so that we can set the vg name automagically
        # with autopartitioning to not conflict with existing vgs
        self.autoname = 0

        if preexist and preexist_size:
            self.preexist_size = preexist_size
            log.debug("VolumeGroupRequestSpec('%s').preexist_size is %s" %
                      (vgname, preexist_size))
        else:
            self.preexist_size = None
Exemplo n.º 9
0
    def setFromDisk(self, diskset):
        """Clear the delete list and set self.requests to reflect disk."""
        self.deletes = []
        self.requests = []
        diskset.refreshDevices()
        labels = diskset.getLabels()
        drives = diskset.disks.keys()
        drives.sort()
        for drive in drives:
            disk = diskset.disks[drive]
            part = disk.next_partition()
            while part:
                if part.type & parted.PARTITION_METADATA:
                    part = disk.next_partition(part)
                    continue

                format = None
                if part.type & parted.PARTITION_FREESPACE:
                    ptype = None
                elif part.type & parted.PARTITION_EXTENDED:
                    ptype = None
                elif part.get_flag(parted.PARTITION_RAID) == 1:
                    ptype = fsset.fileSystemTypeGet("software RAID")
                elif part.get_flag(parted.PARTITION_LVM) == 1:
                    ptype = fsset.fileSystemTypeGet("physical volume (LVM)")
                else:
                    ptype = partedUtils.get_partition_file_system_type(part)

                    # FIXME: we don't handle ptype being None very well, so
                    # just say it's foreign.  Should probably fix None
                    # handling instead some day.
                    if ptype is None:
                        ptype = fsset.fileSystemTypeGet("foreign")

                start = part.geom.start
                end = part.geom.end
                size = partedUtils.getPartSizeMB(part)
                drive = partedUtils.get_partition_drive(part)

                spec = partRequests.PreexistingPartitionSpec(ptype,
                                                             size=size,
                                                             start=start,
                                                             end=end,
                                                             drive=drive,
                                                             format=format)
                spec.device = fsset.PartedPartitionDevice(part).getDevice()

                # set label if makes sense
                if ptype and ptype.isMountable() and \
                   (ptype.getName() == "ext2" or ptype.getName() == "ext3"):
                    if spec.device in labels.keys():
                        if labels[spec.device] and len(
                                labels[spec.device]) > 0:
                            spec.fslabel = labels[spec.device]

                self.addRequest(spec)
                part = disk.next_partition(part)

        # now we need to read in all pre-existing RAID stuff
        diskset.startAllRaid()
        mdList = diskset.mdList
        for raidDev in mdList:
            (theDev, devices, level, numActive) = raidDev

            level = "RAID%s" % (level, )
            try:
                chunk = isys.getRaidChunkFromDevice(theDev)
            except Exception, e:
                log("couldn't get chunksize of %s: %s" % (theDev, e))
                chunk = None

            # is minor always mdN ?
            minor = int(theDev[2:])
            raidvols = []
            for dev in devices:
                req = self.getRequestByDeviceName(dev)
                if not req:
                    log("RAID device %s using non-existent partition %s" %
                        (theDev, dev))
                    continue
                raidvols.append(req.uniqueID)

            fs = partedUtils.sniffFilesystemType(theDev)
            if fs is None:
                fsystem = fsset.fileSystemTypeGet("foreign")
            else:
                fsystem = fsset.fileSystemTypeGet(fs)

            mnt = None
            format = 0

            spares = len(devices) - numActive
            spec = partRequests.RaidRequestSpec(fsystem,
                                                format=format,
                                                raidlevel=level,
                                                raidmembers=raidvols,
                                                raidminor=minor,
                                                raidspares=spares,
                                                mountpoint=mnt,
                                                preexist=1,
                                                chunksize=chunk)
            spec.size = spec.getActualSize(self, diskset)
            self.addRequest(spec)
Exemplo n.º 10
0
    def sanityCheckAllRequests(self, diskset, baseChecks=0):
        """Do a sanity check of all of the requests.

        This function is called at the end of partitioning so that we
        can make sure you don't have anything silly (like no /, a really
        small /, etc).  Returns (errors, warnings) where each is a list
        of strings or None if there are none.
        If baseChecks is set, the basic sanity tests which the UI runs prior to
        accepting a partition will be run on the requests as well.
        """
        checkSizes = [('/usr', 250), ('/tmp', 50), ('/var', 384),
                      ('/home', 100), ('/boot', 75)]
        warnings = []
        errors = []

        slash = self.getRequestByMountPoint('/')
        if not slash:
            errors.append(
                _("You have not defined a root partition (/), "
                  "which is required for installation of %s "
                  "to continue.") % (productName, ))

        if slash and slash.getActualSize(self, diskset) < 250:
            warnings.append(
                _("Your root partition is less than 250 "
                  "megabytes which is usually too small to "
                  "install %s.") % (productName, ))

        if iutil.getArch() == "ia64":
            bootreq = self.getRequestByMountPoint("/boot/efi")
            if not bootreq or bootreq.getActualSize(self, diskset) < 50:
                errors.append(
                    _("You must create a /boot/efi partition of "
                      "type FAT and a size of 50 megabytes."))

        if (iutil.getPPCMachine() == "pSeries"
                or iutil.getPPCMachine() == "iSeries"):
            reqs = self.getBootableRequest()
            found = 0

            bestreq = None
            if reqs:
                for req in reqs:
                    if req.fstype == fsset.fileSystemTypeGet("PPC PReP Boot"):
                        found = 1
                        # the best one is either the first or the first
                        # newly formatted one
                        if ((bestreq is None) or ((bestreq.format == 0) and
                                                  (req.format == 1))):
                            bestreq = req
                        break
            if iutil.getPPCMachine() == "iSeries" and iutil.hasIbmSis():
                found = 1

            if not found:
                errors.append(_("You must create a PPC PReP Boot partition."))

            if bestreq is not None:
                if (iutil.getPPCMachine() == "pSeries"):
                    minsize = 4
                else:
                    minsize = 16
                if bestreq.getActualSize(self, diskset) < minsize:
                    warnings.append(
                        _("Your %s partition is less than %s "
                          "megabytes which is lower than "
                          "recommended for a normal %s install.") %
                        (_("PPC PReP Boot"), minsize, productName))

        for (mount, size) in checkSizes:
            req = self.getRequestByMountPoint(mount)
            if not req:
                continue
            if req.getActualSize(self, diskset) < size:
                warnings.append(
                    _("Your %s partition is less than %s "
                      "megabytes which is lower than recommended "
                      "for a normal %s install.") % (mount, size, productName))

        foundSwap = 0
        swapSize = 0
        for request in self.requests:
            if request.fstype and request.fstype.getName() == "swap":
                foundSwap = foundSwap + 1
                swapSize = swapSize + request.getActualSize(self, diskset)
            if baseChecks:
                rc = request.doSizeSanityCheck()
                if rc:
                    warnings.append(rc)
                rc = request.doMountPointLinuxFSChecks()
                if rc:
                    errors.append(rc)
                if isinstance(request, partRequests.RaidRequestSpec):
                    rc = request.sanityCheckRaid(self)
                    if rc:
                        errors.append(rc)

        bootreqs = self.getBootableRequest()
        if bootreqs:
            for bootreq in bootreqs:
                if (bootreq
                        and (isinstance(bootreq, partRequests.RaidRequestSpec))
                        and (not raid.isRaid1(bootreq.raidlevel))):
                    errors.append(
                        _("Bootable partitions can only be on RAID1 "
                          "devices."))

                # can't have bootable partition on LV
                if (bootreq and (isinstance(
                        bootreq, partRequests.LogicalVolumeRequestSpec))):
                    errors.append(
                        _("Bootable partitions cannot be on a "
                          "logical volume."))

                # most arches can't have boot on RAID
                if (bootreq
                        and (isinstance(bootreq, partRequests.RaidRequestSpec))
                        and (iutil.getArch() not in raid.raidBootArches)):
                    errors.append("Bootable partitions cannot be on a RAID "
                                  "device.")

        if foundSwap == 0:
            warnings.append(
                _("You have not specified a swap partition.  "
                  "Although not strictly required in all cases, "
                  "it will significantly improve performance for "
                  "most installations."))

        # XXX number of swaps not exported from kernel and could change
        if foundSwap >= 32:
            warnings.append(
                _("You have specified more than 32 swap devices.  "
                  "The kernel for %s only supports 32 "
                  "swap devices.") % (productName, ))

        mem = iutil.memInstalled()
        rem = mem % 16384
        if rem:
            mem = mem + (16384 - rem)
        mem = mem / 1024

        if foundSwap and (swapSize < (mem - 8)) and (mem < 1024):
            warnings.append(
                _("You have allocated less swap space (%dM) than "
                  "available RAM (%dM) on your system.  This "
                  "could negatively impact performance.") % (swapSize, mem))

        if warnings == []:
            warnings = None
        if errors == []:
            errors = None

        return (errors, warnings)
Exemplo n.º 11
0
class Partitions:
    """Defines all of the partition requests and delete requests."""
    def __init__(self, diskset=None):
        """Initializes a Partitions object.

        Can pass in the diskset if it already exists.
        """
        self.requests = []
        """A list of RequestSpec objects for all partitions."""

        self.deletes = []
        """A list of DeleteSpec objects for partitions to be deleted."""

        self.autoPartitionRequests = []
        """A list of RequestSpec objects for autopartitioning.
        These are setup by the installclass and folded into self.requests
        by auto partitioning."""

        self.autoClearPartType = CLEARPART_TYPE_NONE
        """What type of partitions should be cleared?"""

        self.autoClearPartDrives = None
        """Drives to clear partitions on (note that None is equiv to all)."""

        self.nextUniqueID = 1
        """Internal counter.  Don't touch unless you're smarter than me."""

        self.reinitializeDisks = 0
        """Should the disk label be reset on all disks?"""

        self.zeroMbr = 0
        """Should the mbr be zero'd?"""

        # partition method to be used.  not to be touched externally
        self.useAutopartitioning = 1
        self.useFdisk = 0

        # autopartitioning info becomes kickstart partition requests
        # and its useful to be able to differentiate between the two
        self.isKickstart = 0

        if diskset:
            self.setFromDisk(diskset)

    def setFromDisk(self, diskset):
        """Clear the delete list and set self.requests to reflect disk."""
        self.deletes = []
        self.requests = []
        diskset.refreshDevices()
        labels = diskset.getLabels()
        drives = diskset.disks.keys()
        drives.sort()
        for drive in drives:
            disk = diskset.disks[drive]
            part = disk.next_partition()
            while part:
                if part.type & parted.PARTITION_METADATA:
                    part = disk.next_partition(part)
                    continue

                format = None
                if part.type & parted.PARTITION_FREESPACE:
                    ptype = None
                elif part.type & parted.PARTITION_EXTENDED:
                    ptype = None
                elif part.get_flag(parted.PARTITION_RAID) == 1:
                    ptype = fsset.fileSystemTypeGet("software RAID")
                elif part.get_flag(parted.PARTITION_LVM) == 1:
                    ptype = fsset.fileSystemTypeGet("physical volume (LVM)")
                else:
                    ptype = partedUtils.get_partition_file_system_type(part)

                    # FIXME: we don't handle ptype being None very well, so
                    # just say it's foreign.  Should probably fix None
                    # handling instead some day.
                    if ptype is None:
                        ptype = fsset.fileSystemTypeGet("foreign")

                start = part.geom.start
                end = part.geom.end
                size = partedUtils.getPartSizeMB(part)
                drive = partedUtils.get_partition_drive(part)

                spec = partRequests.PreexistingPartitionSpec(ptype,
                                                             size=size,
                                                             start=start,
                                                             end=end,
                                                             drive=drive,
                                                             format=format)
                spec.device = fsset.PartedPartitionDevice(part).getDevice()

                # set label if makes sense
                if ptype and ptype.isMountable() and \
                   (ptype.getName() == "ext2" or ptype.getName() == "ext3"):
                    if spec.device in labels.keys():
                        if labels[spec.device] and len(
                                labels[spec.device]) > 0:
                            spec.fslabel = labels[spec.device]

                self.addRequest(spec)
                part = disk.next_partition(part)

        # now we need to read in all pre-existing RAID stuff
        diskset.startAllRaid()
        mdList = diskset.mdList
        for raidDev in mdList:
            (theDev, devices, level, numActive) = raidDev

            level = "RAID%s" % (level, )
            try:
                chunk = isys.getRaidChunkFromDevice(theDev)
            except Exception, e:
                log("couldn't get chunksize of %s: %s" % (theDev, e))
                chunk = None

            # is minor always mdN ?
            minor = int(theDev[2:])
            raidvols = []
            for dev in devices:
                req = self.getRequestByDeviceName(dev)
                if not req:
                    log("RAID device %s using non-existent partition %s" %
                        (theDev, dev))
                    continue
                raidvols.append(req.uniqueID)

            fs = partedUtils.sniffFilesystemType(theDev)
            if fs is None:
                fsystem = fsset.fileSystemTypeGet("foreign")
            else:
                fsystem = fsset.fileSystemTypeGet(fs)

            mnt = None
            format = 0

            spares = len(devices) - numActive
            spec = partRequests.RaidRequestSpec(fsystem,
                                                format=format,
                                                raidlevel=level,
                                                raidmembers=raidvols,
                                                raidminor=minor,
                                                raidspares=spares,
                                                mountpoint=mnt,
                                                preexist=1,
                                                chunksize=chunk)
            spec.size = spec.getActualSize(self, diskset)
            self.addRequest(spec)

        # now to read in pre-existing LVM stuff
        lvm.vgscan()
        lvm.vgactivate()

        pvs = lvm.pvlist()
        for (vg, size) in lvm.vglist():
            # FIXME: need to find the pe size of the vg
            pesize = 4096
            try:
                preexist_size = float(size) / 1024.0
            except:
                log("preexisting size for %s not a valid integer, ignoring" %
                    (vg, ))
                preexist_size = None

            pvids = []
            for (dev, pvvg, size) in pvs:
                if vg != pvvg:
                    continue
                req = self.getRequestByDeviceName(dev[5:])
                if not req:
                    log("Volume group %s using non-existent partition %s" %
                        (vg, dev))
                    continue
                pvids.append(req.uniqueID)
            spec = partRequests.VolumeGroupRequestSpec(
                format=0,
                vgname=vg,
                physvols=pvids,
                pesize=pesize,
                preexist=1,
                preexist_size=preexist_size)
            vgid = self.addRequest(spec)

            for (lvvg, lv, size) in lvm.lvlist():
                if lvvg != vg:
                    continue

                # size is number of bytes, we want size in megs
                lvsize = float(size) / (1024.0 * 1024.0)

                theDev = "/dev/%s/%s" % (vg, lv)
                fs = partedUtils.sniffFilesystemType(theDev)
                if fs is None:
                    fsystem = fsset.fileSystemTypeGet("foreign")
                else:
                    fsystem = fsset.fileSystemTypeGet(fs)

                mnt = 0
                format = 0

                spec = partRequests.LogicalVolumeRequestSpec(fsystem,
                                                             format=format,
                                                             size=lvsize,
                                                             volgroup=vgid,
                                                             lvname=lv,
                                                             mountpoint=mnt,
                                                             preexist=1)
                self.addRequest(spec)
        lvm.vgdeactivate()

        diskset.stopAllRaid()