[elbe-devel] [PATCH v2 4/4] grubinstaller: sort the mountpoints

bage at linutronix.de bage at linutronix.de
Fri Aug 23 11:03:32 CEST 2019


From: Bastian Germann <bage at linutronix.de>

Reuse the fstab code to mount the boot requisite mount points in the
right order. Get rid of the extra root field.

Signed-off-by: Bastian Germann <bage at linutronix.de>
---
 elbepack/hdimg.py | 29 ++++++++---------------------
 1 file changed, 8 insertions(+), 21 deletions(-)

diff --git a/elbepack/hdimg.py b/elbepack/hdimg.py
index af278ee4..1b3d4057 100644
--- a/elbepack/hdimg.py
+++ b/elbepack/hdimg.py
@@ -146,15 +146,12 @@ def build_image_mtd(outf, mtd, target):
 class grubinstaller_base(object):
     def __init__(self, outf, fw_type=[]):
         self.outf = outf
-        self.root = None
-        self.fs = []
+        self.fs = mountpoint_dict()
         self.fw_type = fw_type
 
     def add_fs_entry(self, entry):
-        self.fs.append(entry)
-
-    def set_root_entry(self, entry):
-        self.root = entry
+        if entry.mountpoint not in ['dev', 'proc', 'sys']:
+            self.fs[entry.mountpoint] = entry
 
     def install(self, target):
         pass
@@ -163,20 +160,17 @@ class grubinstaller_base(object):
 class grubinstaller202(grubinstaller_base):
 
     def install(self, target):
-        if not self.root:
+        if '/' not in self.fs:
             return
 
         imagemnt = os.path.join(target, "imagemnt")
         try:
             self.outf.do('cp -a /dev/loop0 /dev/poop0')
 
-            self.outf.do('losetup /dev/poop0 "%s"' % self.root.filename)
+            self.outf.do('losetup /dev/poop0 "%s"' % self.fs['/'].filename)
             self.outf.do('kpartx -as /dev/poop0')
-            self.outf.do(
-                'mount /dev/mapper/poop0p%d %s' %
-                (self.root.partnum, imagemnt))
 
-            for entry in self.fs:
+            for entry in self.fs.depthlist():
                 self.outf.do(
                     'mount /dev/mapper/poop0p%d %s' %
                     (entry.partnum, os.path.join(
@@ -248,15 +242,11 @@ class grubinstaller202(grubinstaller_base):
                     "sys"),
                 allow_fail=True)
 
-            for entry in self.fs:
+            for entry in reversed(self.fs.depthlist()):
                 self.outf.do(
                     'umount /dev/mapper/poop0p%d' %
                     entry.partnum, allow_fail=True)
 
-            self.outf.do(
-                'umount /dev/mapper/poop0p%d' %
-                self.root.partnum, allow_fail=True)
-
             self.outf.do('kpartx -d /dev/poop0', allow_fail=True)
             self.outf.do("losetup -d /dev/poop0", allow_fail=True)
 
@@ -315,10 +305,7 @@ def create_label(outf, disk, part, ppart, fslabel, target, grub):
     entry = fslabel[part.text("label")]
     entry.set_geometry(ppart, disk)
 
-    if entry.mountpoint == "/":
-        grub.set_root_entry(entry)
-    else:
-        grub.add_fs_entry(entry)
+    grub.add_fs_entry(entry)
 
     entry.losetup(outf, "loop0")
     outf.do(
-- 
2.20.1




More information about the elbe-devel mailing list