autogenerating ks partitioning

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



A few days back, I was asked if we have any script that can examine a
running system and generate the kickstart partitioning section to match.
Well, we do now.  Check it out below.

It works for regular partitioning, LVM, and RAID.  For encryption, I
need to commit one more patch to anaconda but it needs a little more
testing first.

Anyway, what to do with this thing?  I've got one person lined up who
wants to use it.  It seems like it could be of use elsewhere.  Where to
commit?

- Chris

#!/usr/bin/python
#
# Examine a running system and generate a part-XXXXXX.ks file that could be
# included in another kickstart file to reproduce the layout.
#
# Limitations:
#   - Doesn't know how to write out any of clearpart/ignoredisk.
#   - Can't write out LUKS passphrases

import os
import tempfile

from pyanaconda import storage

class PreexistingStorage(storage.Storage):
    # We have to do our own writeKS method here, since the default one is based
    # on actions instead of devicetree contents.
    def writeKS(self, f):
        f.write("# The following is the partition information you requested\n")
        f.write("# Note that any partitions you deleted are not expressed\n")
        f.write("# here so unless you clear all partitions first, this is\n")
        f.write("# not guaranteed to work\n")

        for device in filter(lambda d: d.format.type != "luks",
                             self.devices):
            device.writeKS(f, preexisting=False, noformat=False)
            f.write("\n")

        self.iscsi.writeKS(f)
        self.fcoe.writeKS(f)
        self.zfcp.writeKS(f)

# Return a device -> mountpoint mapping.
def getMountpoints():
    mountpoints = {}
    f = open("/proc/mounts")
    for line in f:
        line = line.strip().split()
        dev = line[0]
        mountpoint = line[1]

        mountpoints[dev] = mountpoint

    f.close()
    return mountpoints

os.system("udevadm control --env=ANACONDA=1")
os.system("udevadm trigger --subsystem-match block")
os.system("udevadm settle")

s = PreexistingStorage()
s.reset(cleanupOnly=True)

mountpoints = getMountpoints()

for dev in s.devicetree.devices:
    # All the writeKS methods are based on req_size since size is not set
    # when creating actions and requests.  Thus, we need to set each req_size
    # attribute to the current device's size in order to get --size= output.
    if hasattr(dev, "req_size"):
        dev.req_size = long(dev.size)

    # Likewise, we need to set the mountpoint if we want it in the writeKS
    # output.  Otherwise we get None.
    if hasattr(dev.format, "mountpoint") and dev.path in mountpoints:
        dev.format.mountpoint = mountpoints[dev.path]

f = tempfile.NamedTemporaryFile(prefix="part-", suffix=".ks", delete=False)
s.writeKS(f)
f.close()

os.system("udevadm control --env=ANACONDA=0")

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/anaconda-devel-list


[Index of Archives]     [Kickstart]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]
  Powered by Linux