summaryrefslogtreecommitdiffstats
path: root/scripts/lib
diff options
context:
space:
mode:
authorRicardo Ribalda Delgado <ricardo@ribalda.com>2019-07-18 15:13:56 +0200
committerRichard Purdie <richard.purdie@linuxfoundation.org>2019-07-19 08:41:40 +0100
commit58589bc5382b5c77825bc963a1c84a4e8f54498f (patch)
tree7686606e107336337c65e3a2aadda9cd78a44e46 /scripts/lib
parent050a96fe030f5669898e8cc6589d37b1e3da365b (diff)
downloadpoky-58589bc5382b5c77825bc963a1c84a4e8f54498f.tar.gz
wic: Fix (again) partition files UIDs on multi rootfs images
Commit 450335ba5e73a375eb9932b4c4cf37979640dbfc copies the pseudo database to the working directory in order to have ownership information when the filesystem is generated. Unfortunately this does not work anymore. The filenames on the database are absolute and there is no information about the new directory. Instead of fixing the database, we could redo a bit the way we patch the fstab file. Now I am saving the old contents of fstab, modifying the file and then reverting the changes on exit. This is faster than the previous approach, although it can cause indeterminism if the application is killed before finishing. (From OE-Core rev: dcbf7b864dd1713b54a172d8714ce1508482f086) Signed-off-by: Ricardo Ribalda Delgado <ricardo@ribalda.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts/lib')
-rw-r--r--scripts/lib/wic/plugins/imager/direct.py37
1 files changed, 12 insertions, 25 deletions
diff --git a/scripts/lib/wic/plugins/imager/direct.py b/scripts/lib/wic/plugins/imager/direct.py
index 67addeff3e..91fc5e70f6 100644
--- a/scripts/lib/wic/plugins/imager/direct.py
+++ b/scripts/lib/wic/plugins/imager/direct.py
@@ -49,7 +49,6 @@ class DirectPlugin(ImagerPlugin):
49 49
50 # parse possible 'rootfs=name' items 50 # parse possible 'rootfs=name' items
51 self.rootfs_dir = dict(rdir.split('=') for rdir in rootfs_dir.split(' ')) 51 self.rootfs_dir = dict(rdir.split('=') for rdir in rootfs_dir.split(' '))
52 self.replaced_rootfs_paths = {}
53 self.bootimg_dir = bootimg_dir 52 self.bootimg_dir = bootimg_dir
54 self.kernel_dir = kernel_dir 53 self.kernel_dir = kernel_dir
55 self.native_sysroot = native_sysroot 54 self.native_sysroot = native_sysroot
@@ -59,6 +58,7 @@ class DirectPlugin(ImagerPlugin):
59 self.compressor = options.compressor 58 self.compressor = options.compressor
60 self.bmap = options.bmap 59 self.bmap = options.bmap
61 self.no_fstab_update = options.no_fstab_update 60 self.no_fstab_update = options.no_fstab_update
61 self.original_fstab = None
62 62
63 self.name = "%s-%s" % (os.path.splitext(os.path.basename(wks_file))[0], 63 self.name = "%s-%s" % (os.path.splitext(os.path.basename(wks_file))[0],
64 strftime("%Y%m%d%H%M")) 64 strftime("%Y%m%d%H%M"))
@@ -104,24 +104,13 @@ class DirectPlugin(ImagerPlugin):
104 104
105 with open(fstab_path) as fstab: 105 with open(fstab_path) as fstab:
106 fstab_lines = fstab.readlines() 106 fstab_lines = fstab.readlines()
107 self.original_fstab = fstab_lines.copy()
107 108
108 if self._update_fstab(fstab_lines, self.parts): 109 if self._update_fstab(fstab_lines, self.parts):
109 # copy rootfs dir to workdir to update fstab
110 # as rootfs can be used by other tasks and can't be modified
111 new_pseudo = os.path.realpath(os.path.join(self.workdir, "pseudo"))
112 from_dir = os.path.join(os.path.join(image_rootfs, ".."), "pseudo")
113 from_dir = os.path.realpath(from_dir)
114 copyhardlinktree(from_dir, new_pseudo)
115 new_rootfs = os.path.realpath(os.path.join(self.workdir, "rootfs_copy"))
116 copyhardlinktree(image_rootfs, new_rootfs)
117 fstab_path = os.path.join(new_rootfs, 'etc/fstab')
118
119 os.unlink(fstab_path)
120
121 with open(fstab_path, "w") as fstab: 110 with open(fstab_path, "w") as fstab:
122 fstab.writelines(fstab_lines) 111 fstab.writelines(fstab_lines)
123 112 else:
124 return new_rootfs 113 self.original_fstab = None
125 114
126 def _update_fstab(self, fstab_lines, parts): 115 def _update_fstab(self, fstab_lines, parts):
127 """Assume partition order same as in wks""" 116 """Assume partition order same as in wks"""
@@ -170,14 +159,8 @@ class DirectPlugin(ImagerPlugin):
170 filesystems from the artifacts directly and combine them into 159 filesystems from the artifacts directly and combine them into
171 a partitioned image. 160 a partitioned image.
172 """ 161 """
173 if self.no_fstab_update: 162 if not self.no_fstab_update:
174 new_rootfs = None 163 self._write_fstab(self.rootfs_dir.get("ROOTFS_DIR"))
175 else:
176 new_rootfs = self._write_fstab(self.rootfs_dir.get("ROOTFS_DIR"))
177 if new_rootfs:
178 # rootfs was copied to update fstab
179 self.replaced_rootfs_paths[new_rootfs] = self.rootfs_dir['ROOTFS_DIR']
180 self.rootfs_dir['ROOTFS_DIR'] = new_rootfs
181 164
182 for part in self.parts: 165 for part in self.parts:
183 # get rootfs size from bitbake variable if it's not set in .ks file 166 # get rootfs size from bitbake variable if it's not set in .ks file
@@ -253,8 +236,6 @@ class DirectPlugin(ImagerPlugin):
253 else: 236 else:
254 suffix = '["%s"]:' % (part.mountpoint or part.label) 237 suffix = '["%s"]:' % (part.mountpoint or part.label)
255 rootdir = part.rootfs_dir 238 rootdir = part.rootfs_dir
256 if rootdir in self.replaced_rootfs_paths:
257 rootdir = self.replaced_rootfs_paths[rootdir]
258 msg += ' ROOTFS_DIR%s%s\n' % (suffix.ljust(20), rootdir) 239 msg += ' ROOTFS_DIR%s%s\n' % (suffix.ljust(20), rootdir)
259 240
260 msg += ' BOOTIMG_DIR: %s\n' % self.bootimg_dir 241 msg += ' BOOTIMG_DIR: %s\n' % self.bootimg_dir
@@ -292,6 +273,12 @@ class DirectPlugin(ImagerPlugin):
292 if os.path.isfile(path): 273 if os.path.isfile(path):
293 shutil.move(path, os.path.join(self.outdir, fname)) 274 shutil.move(path, os.path.join(self.outdir, fname))
294 275
276 #Restore original fstab
277 if self.original_fstab:
278 fstab_path = self.rootfs_dir.get("ROOTFS_DIR") + "/etc/fstab"
279 with open(fstab_path, "w") as fstab:
280 fstab.writelines(self.original_fstab)
281
295 # remove work directory 282 # remove work directory
296 shutil.rmtree(self.workdir, ignore_errors=True) 283 shutil.rmtree(self.workdir, ignore_errors=True)
297 284