Ignore swap devices on install

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

 



Hi list:

It has been a problem to tell anaconda to not use some swap devices at install time.  I have created a solution (if you can call it that) that adds a argument for kickstart in RHEL5.  It basically tells anaconda : "Do not touch this list of swap devices".  And anaconda does not use them at install time and does not add them to /etc/fstab at the end of installation.
The solution involves code for anaconda and for pykickstart.

Patch is attached.  comments greatly appreciated.
--
Joel Andres Granados
Red Hat / Brno, Czech Republic
diff --git a/fsset.py b/fsset.py
index 903811e..c63ffdf 100644
--- a/fsset.py
+++ b/fsset.py
@@ -1286,7 +1286,7 @@ class FileSystemSet:
         format = "%-23s %-23s %-7s %-15s %d %d\n"
         fstab = ""
         for entry in self.entries:
-            if entry.mountpoint:
+            if entry.mountpoint and entry.device.getDevice() not in partedUtils.DiskSet.skippedSwapDevs:
                 # use LABEL if the device has a label except for multipath
                 # devices.  always use devname on mpath devices
                 if entry.getLabel() and \
@@ -1305,7 +1305,7 @@ class FileSystemSet:
         format = "%s %s %s %s 0 0\n"
         mtab = ""
         for entry in self.entries:
-            if not entry.isMounted():
+            if not entry.isMounted() and entry.device.getDevice() not in partedUtils.DiskSet.skippedSwapDevs:
                 continue
             if entry.mountpoint:
                 # swap doesn't end up in the mtab
@@ -1617,7 +1617,7 @@ MAILADDR root
 
         for entry in self.entries:
             if (entry.fsystem and entry.fsystem.getName() == "swap"
-                and not entry.isMounted()):
+                and not entry.isMounted() and entry.device.getDevice() not in partedUtils.DiskSet.skippedSwapDevs):
                 try:
                     entry.mount(chroot)
                     self.mountcount = self.mountcount + 1
diff --git a/installclass.py b/installclass.py
index 1c132c5..0636656 100644
--- a/installclass.py
+++ b/installclass.py
@@ -456,6 +456,12 @@ class BaseInstallClass:
 	#id.setPackageSelection()
 	#id.setGroupSelection()
 
+    def setIgnoreSwapDevs(self, id, devs):
+        diskset = id.diskset
+        for dev in devs:
+            if not dev in diskset.skippedSwapDevs:
+                diskset.skippedSwapDevs.append(dev)
+
     def __init__(self, expert):
 	pass
 
diff --git a/kickstart.py b/kickstart.py
index 3c18853..2bc7a40 100644
--- a/kickstart.py
+++ b/kickstart.py
@@ -630,6 +630,11 @@ class AnacondaKSHandlers(KickstartHandlers):
 
         isys.flushDriveDict()
 
+    def doIgnoreSwapDevs(self, args):
+        KickstartHandlers.doIgnoreSwapDevs(self, args)
+        self.id.instClass.setIgnoreSwapDevs(self.id, self.ksdata.ignoreswapdevs["devs"])
+
+
 class VNCHandlers(KickstartHandlers):
     # We're only interested in the handler for the VNC command.
     def __init__ (self, ksdata):
diff --git a/partedUtils.py b/partedUtils.py
index 51fc9bd..197448f 100644
--- a/partedUtils.py
+++ b/partedUtils.py
@@ -583,6 +583,7 @@ class DiskSet:
     """The disks in the system."""
 
     skippedDisks = []
+    skippedSwapDevs = []
     mdList = []
     dmList = None
     mpList = None
diff -ur pykickstart-0.43/pykickstart/data.py pykickstart-0.43-new/pykickstart/data.py
--- pykickstart-0.43/pykickstart/data.py	2006-10-16 22:25:00.000000000 +0200
+++ pykickstart-0.43-new/pykickstart/data.py	2008-02-11 21:31:35.000000000 +0100
@@ -54,6 +54,7 @@
         self.timezone = {"isUtc": False, "timezone": ""}
         self.upgrade = False
         self.vnc = {"enabled": False, "password": "", "host": "", "port": ""}
+        self.ignoreswapdevs = {}
         self.xconfig = {"driver": "", "defaultdesktop": "", "depth": 0,
                         "resolution": "", "startX": False, "videoRam": ""}
         self.zerombr = False
diff -ur pykickstart-0.43/pykickstart/parser.py pykickstart-0.43-new/pykickstart/parser.py
--- pykickstart-0.43/pykickstart/parser.py	2006-12-01 16:52:18.000000000 +0100
+++ pykickstart-0.43-new/pykickstart/parser.py	2008-02-11 21:45:39.000000000 +0100
@@ -275,6 +275,7 @@
                      "user"         : self.doUser,
                      "upgrade"      : self.doUpgrade,
                      "vnc"          : self.doVnc,
+                     "ignoreswapdevs": self.doIgnoreSwapDevs,
                      "volgroup"     : self.doVolumeGroup,
                      "xconfig"      : self.doXConfig,
                      "zerombr"      : self.doZeroMbr,
@@ -893,6 +894,17 @@
         (opts, extra) = op.parse_args(args=args)
         self._setToDict(op, opts, self.ksdata.vnc)
 
+    def doIgnoreSwapDevs(self, args):
+        def dev_cb(option, opt_str, value, parser):
+            for d in value.split(','):
+                parser.values.ensure_value(option.dest, []).append(d)
+        op = KSOptionParser(lineno=self.lineno)
+        op.add_option("--devs", dest="devs", action="callback", callback=dev_cb, nargs=1, type="string")
+
+        (opts, extra) = op.parse_args(args=args)
+        self._setToDict(op, opts, self.ksdata.ignoreswapdevs)
+
+
     def doVolumeGroup(self, args):
         # Have to be a little more complicated to set two values.
         def vg_cb (option, opt_str, value, parser):
diff -ur pykickstart-0.43/pykickstart/writer.py pykickstart-0.43-new/pykickstart/writer.py
--- pykickstart-0.43/pykickstart/writer.py	2006-12-04 17:05:11.000000000 +0100
+++ pykickstart-0.43-new/pykickstart/writer.py	2008-02-11 19:41:43.000000000 +0100
@@ -559,6 +559,13 @@
 
         return retval.rstrip()
 
+    def doIgnoreSwapDevs(self):
+        import pdb
+        pdb.set_trace()
+        if self.ksdata.ignoreswapdevs:
+            return
+        return " ignoreswapspace --devs=%s\n" % string.join(self.ksdata.ignoreswapdevs, ",")
+
     def doVnc(self):
         if self.ksdata.vnc["enabled"]:
             if self.ksdata.vnc["password"] != "":
_______________________________________________
Kickstart-list mailing list
Kickstart-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/kickstart-list

[Index of Archives]     [Red Hat General]     [CentOS Users]     [Fedora Users]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]

  Powered by Linux