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

[PATCH 1/2] Make /etc/mtab a symlink to /proc/self/mounts. (#670381)



---
 pyanaconda/livecd.py           |    5 +---
 pyanaconda/rescue.py           |   17 +------------
 pyanaconda/storage/__init__.py |   50 +++++++++++++++------------------------
 pyanaconda/yuminstall.py       |   19 ++------------
 4 files changed, 24 insertions(+), 67 deletions(-)

diff --git a/pyanaconda/livecd.py b/pyanaconda/livecd.py
index d2f1165..2c7c862 100644
--- a/pyanaconda/livecd.py
+++ b/pyanaconda/livecd.py
@@ -320,10 +320,7 @@ class LiveCDCopyBackend(backend.AnacondaBackend):
 
         # now write out the "real" fstab and mtab
         anaconda.storage.write(anaconda.rootPath)
-        f = open(anaconda.rootPath + "/etc/mtab", "w+")
-        f.write(anaconda.storage.mtab)
-        f.close()        
-        
+
         # copy over the modprobe.conf
         if os.path.exists("/etc/modprobe.conf"):
             shutil.copyfile("/etc/modprobe.conf", 
diff --git a/pyanaconda/rescue.py b/pyanaconda/rescue.py
index 181fe26..e8a25a2 100644
--- a/pyanaconda/rescue.py
+++ b/pyanaconda/rescue.py
@@ -136,21 +136,6 @@ class RescueInterface(InstallInterfaceBase):
         InstallInterfaceBase.__init__(self)
         self.screen = screen
 
-# XXX grub-install is stupid and uses df output to figure out
-# things when installing grub.  make /etc/mtab be at least
-# moderately useful.  
-def makeMtab(instPath, storage):
-    try:
-        f = open(instPath + "/etc/mtab", "w+")
-    except IOError, e:
-        log.info("failed to open /etc/mtab for write: %s" % e)
-        return
-
-    try:
-        f.write(storage.mtab)
-    finally:
-        f.close()
-
 def makeFStab(instPath = ""):
     if os.access("/proc/mounts", os.R_OK):
         f = open("/proc/mounts", "r")
@@ -509,7 +494,7 @@ def runRescue(anaconda):
     msgStr = ""
 
     if rootmounted and not readOnly:
-        makeMtab(anaconda.rootPath, anaconda.storage)
+        anaconda.storage.makeMtab(root=anaconda.rootPath)
         try:
             makeResolvConf(anaconda.rootPath)
         except Exception, e:
diff --git a/pyanaconda/storage/__init__.py b/pyanaconda/storage/__init__.py
index 6c9939c..270e005 100644
--- a/pyanaconda/storage/__init__.py
+++ b/pyanaconda/storage/__init__.py
@@ -1134,6 +1134,7 @@ class Storage(object):
 
     def write(self, instPath):
         self.fsset.write(instPath)
+        self.makeMtab(root=instPath)
         self.iscsi.write(instPath, self.anaconda)
         self.fcoe.write(instPath, self.anaconda)
         self.zfcp.write(instPath)
@@ -1208,10 +1209,6 @@ class Storage(object):
         self.fsset.createSwapFile(device, size)
 
     @property
-    def mtab(self):
-        return self.fsset.mtab()
-
-    @property
     def mountpoints(self):
         return self.fsset.mountpoints
 
@@ -1223,6 +1220,24 @@ class Storage(object):
     def rootDevice(self):
         return self.fsset.rootDevice
 
+    def makeMtab(self, root=None):
+        path = "/etc/mtab"
+        target = "/proc/self/mounts"
+        if root and root != "/" and os.path.isdir(root):
+            path = os.path.normpath("%s/%s" % (root, path))
+
+        if os.path.islink(path):
+            # return early if the mtab symlink is already how we like it
+            current_target = os.path.normpath(os.path.dirname(path) +
+                                              "/" + os.readlink(path))
+            if current_target == target:
+                return
+
+        if os.path.exists(path):
+            os.unlink(path)
+
+        os.symlink(target, path)
+
     def compareDisks(self, first, second):
         if self.eddDict.has_key(first) and self.eddDict.has_key(second):
             one = self.eddDict[first]
@@ -1817,33 +1832,6 @@ class FSSet(object):
                         # just write duplicates back out post-install
                         self.preserveLines.append(line)
 
-    def mtab(self):
-        format = "%s %s %s %s 0 0\n"
-        mtab = ""
-        devices = self.mountpoints.values() + self.swapDevices
-        devices.extend([self.devshm, self.devpts, self.sysfs, self.proc])
-        devices.sort(key=lambda d: getattr(d.format, "mountpoint", None))
-        for device in devices:
-            if not device.format.status:
-                continue
-            if not device.format.mountable:
-                continue
-            if device.format.mountpoint:
-                options = device.format.mountopts
-                if options:
-                    options = options.replace("defaults,", "")
-                    options = options.replace("defaults", "")
-
-                if options:
-                    options = "rw," + options
-                else:
-                    options = "rw"
-                mtab = mtab + format % (device.path,
-                                        device.format.mountpoint,
-                                        device.format.type,
-                                        options)
-        return mtab
-
     def turnOnSwap(self, anaconda, upgrading=None):
         def swapErrorDialog(msg, device):
             if not anaconda.intf:
diff --git a/pyanaconda/yuminstall.py b/pyanaconda/yuminstall.py
index 53f38f8..2870b28 100644
--- a/pyanaconda/yuminstall.py
+++ b/pyanaconda/yuminstall.py
@@ -1560,17 +1560,6 @@ reposdir=/etc/anaconda.repos.d,/tmp/updates/anaconda.repos.d,/tmp/product/anacon
         self.ayum.dsCallback = None
 
     def doPreInstall(self, anaconda):
-        if anaconda.upgrade:
-            # An old mtab can cause confusion (esp if loop devices are
-            # in it).  Be extra special careful and delete any mtab first,
-            # in case the user has done something funny like make it into
-            # a symlink.
-            if os.access(anaconda.rootPath + "/etc/mtab", os.F_OK):
-                os.remove(anaconda.rootPath + "/etc/mtab")
-
-            f = open(anaconda.rootPath + "/etc/mtab", "w+")
-            f.close()
-
         dirList = ['/var', '/var/lib', '/var/lib/rpm', '/tmp', '/dev', '/etc',
                    '/etc/sysconfig', '/etc/sysconfig/network-scripts',
                    '/etc/X11', '/root', '/var/tmp', '/etc/rpm', '/var/cache',
@@ -1602,11 +1591,9 @@ reposdir=/etc/anaconda.repos.d,/tmp/updates/anaconda.repos.d,/tmp/product/anacon
             anaconda.storage.write(anaconda.rootPath)
             if not anaconda.isHeadless:
                 anaconda.keyboard.write(anaconda.rootPath)
-
-        # make a /etc/mtab so mkinitrd can handle certain hw (usb) correctly
-        f = open(anaconda.rootPath + "/etc/mtab", "w+")
-        f.write(anaconda.storage.mtab)
-        f.close()
+        else:
+            # ensure that /etc/mtab is a symlink to /proc/self/mounts
+            anaconda.storage.writeMtab(root=anaconda.rootPath)
 
     def checkSupportedUpgrade(self, anaconda):
         if anaconda.dir == DISPATCH_BACK:
-- 
1.7.2.3


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