summaryrefslogtreecommitdiffstats
path: root/scripts/lib/wic/partition.py
diff options
context:
space:
mode:
authorPaul Barker <pbarker@konsulko.com>2021-01-19 16:26:10 +0000
committerRichard Purdie <richard.purdie@linuxfoundation.org>2021-02-03 14:13:54 +0000
commit7723cbe607bb988a85be6edea3e92420c421e03a (patch)
tree519a2bd3ad97ff7a3b2ef1570cdceecc2df5ab17 /scripts/lib/wic/partition.py
parent14dcd18f6cf77d119fc9436f5afdf33437a6c01c (diff)
downloadpoky-7723cbe607bb988a85be6edea3e92420c421e03a.tar.gz
wic: Optimise fstab modification for ext2/3/4 and msdos partitions
The fix for [Yocto #13994] required the rootfs directory to be copied (using hardlinks if possible) when modifying the fstab file under wic. We can optimise this copy away for filesystems where we have the tools to modify the contents of the partition image after it is created. For ext2/3/4 filesystems we have the debugfs tool and for msdos/vfat filesystems we have the mcopy tool. So for any of these filesystems we skip the modification of the fstab file in the rootfs directory (and skip the associated copy unless it is otherwise necessary) and update the contents of fstab directly in the partition image. (From OE-Core rev: 1988d07b65ad38bdf8fac8615f11fb6536a75806) Signed-off-by: Paul Barker <pbarker@konsulko.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org> (cherry picked from commit 5fb8ae0e9159597d7eaa9307a3a8543800bf9405) Signed-off-by: Steve Sakoman <steve@sakoman.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts/lib/wic/partition.py')
-rw-r--r--scripts/lib/wic/partition.py27
1 files changed, 22 insertions, 5 deletions
diff --git a/scripts/lib/wic/partition.py b/scripts/lib/wic/partition.py
index f59eceb23d..e574f40c47 100644
--- a/scripts/lib/wic/partition.py
+++ b/scripts/lib/wic/partition.py
@@ -55,6 +55,8 @@ class Partition():
55 self.fsuuid = args.fsuuid 55 self.fsuuid = args.fsuuid
56 self.type = args.type 56 self.type = args.type
57 self.updated_fstab_path = None 57 self.updated_fstab_path = None
58 self.has_fstab = False
59 self.update_fstab_in_rootfs = False
58 60
59 self.lineno = lineno 61 self.lineno = lineno
60 self.source_file = "" 62 self.source_file = ""
@@ -125,6 +127,8 @@ class Partition():
125 partition command parameters. 127 partition command parameters.
126 """ 128 """
127 self.updated_fstab_path = updated_fstab_path 129 self.updated_fstab_path = updated_fstab_path
130 if self.updated_fstab_path and not (self.fstype.startswith("ext") or self.fstype == "msdos"):
131 self.update_fstab_in_rootfs = True
128 132
129 if not self.source: 133 if not self.source:
130 if not self.size and not self.fixed_size: 134 if not self.size and not self.fixed_size:
@@ -250,7 +254,7 @@ class Partition():
250 254
251 prefix = "ext" if self.fstype.startswith("ext") else self.fstype 255 prefix = "ext" if self.fstype.startswith("ext") else self.fstype
252 method = getattr(self, "prepare_rootfs_" + prefix) 256 method = getattr(self, "prepare_rootfs_" + prefix)
253 method(rootfs, oe_builddir, rootfs_dir, native_sysroot, pseudo) 257 method(rootfs, cr_workdir, oe_builddir, rootfs_dir, native_sysroot, pseudo)
254 self.source_file = rootfs 258 self.source_file = rootfs
255 259
256 # get the rootfs size in the right units for kickstart (kB) 260 # get the rootfs size in the right units for kickstart (kB)
@@ -258,7 +262,7 @@ class Partition():
258 out = exec_cmd(du_cmd) 262 out = exec_cmd(du_cmd)
259 self.size = int(out.split()[0]) 263 self.size = int(out.split()[0])
260 264
261 def prepare_rootfs_ext(self, rootfs, oe_builddir, rootfs_dir, 265 def prepare_rootfs_ext(self, rootfs, cr_workdir, oe_builddir, rootfs_dir,
262 native_sysroot, pseudo): 266 native_sysroot, pseudo):
263 """ 267 """
264 Prepare content for an ext2/3/4 rootfs partition. 268 Prepare content for an ext2/3/4 rootfs partition.
@@ -282,10 +286,19 @@ class Partition():
282 (self.fstype, extraopts, rootfs, label_str, self.fsuuid, rootfs_dir) 286 (self.fstype, extraopts, rootfs, label_str, self.fsuuid, rootfs_dir)
283 exec_native_cmd(mkfs_cmd, native_sysroot, pseudo=pseudo) 287 exec_native_cmd(mkfs_cmd, native_sysroot, pseudo=pseudo)
284 288
289 if self.updated_fstab_path and self.has_fstab:
290 debugfs_script_path = os.path.join(cr_workdir, "debugfs_script")
291 with open(debugfs_script_path, "w") as f:
292 f.write("cd etc\n")
293 f.write("rm fstab\n")
294 f.write("write %s fstab\n" % (self.updated_fstab_path))
295 debugfs_cmd = "debugfs -w -f %s %s" % (debugfs_script_path, rootfs)
296 exec_native_cmd(debugfs_cmd, native_sysroot)
297
285 mkfs_cmd = "fsck.%s -pvfD %s" % (self.fstype, rootfs) 298 mkfs_cmd = "fsck.%s -pvfD %s" % (self.fstype, rootfs)
286 exec_native_cmd(mkfs_cmd, native_sysroot, pseudo=pseudo) 299 exec_native_cmd(mkfs_cmd, native_sysroot, pseudo=pseudo)
287 300
288 def prepare_rootfs_btrfs(self, rootfs, oe_builddir, rootfs_dir, 301 def prepare_rootfs_btrfs(self, rootfs, cr_workdir, oe_builddir, rootfs_dir,
289 native_sysroot, pseudo): 302 native_sysroot, pseudo):
290 """ 303 """
291 Prepare content for a btrfs rootfs partition. 304 Prepare content for a btrfs rootfs partition.
@@ -308,7 +321,7 @@ class Partition():
308 self.mkfs_extraopts, self.fsuuid, rootfs) 321 self.mkfs_extraopts, self.fsuuid, rootfs)
309 exec_native_cmd(mkfs_cmd, native_sysroot, pseudo=pseudo) 322 exec_native_cmd(mkfs_cmd, native_sysroot, pseudo=pseudo)
310 323
311 def prepare_rootfs_msdos(self, rootfs, oe_builddir, rootfs_dir, 324 def prepare_rootfs_msdos(self, rootfs, cr_workdir, oe_builddir, rootfs_dir,
312 native_sysroot, pseudo): 325 native_sysroot, pseudo):
313 """ 326 """
314 Prepare content for a msdos/vfat rootfs partition. 327 Prepare content for a msdos/vfat rootfs partition.
@@ -337,12 +350,16 @@ class Partition():
337 mcopy_cmd = "mcopy -i %s -s %s/* ::/" % (rootfs, rootfs_dir) 350 mcopy_cmd = "mcopy -i %s -s %s/* ::/" % (rootfs, rootfs_dir)
338 exec_native_cmd(mcopy_cmd, native_sysroot) 351 exec_native_cmd(mcopy_cmd, native_sysroot)
339 352
353 if self.updated_fstab_path and self.has_fstab:
354 mcopy_cmd = "mcopy -i %s %s ::/etc/fstab" % (rootfs, self.updated_fstab_path)
355 exec_native_cmd(mcopy_cmd, native_sysroot)
356
340 chmod_cmd = "chmod 644 %s" % rootfs 357 chmod_cmd = "chmod 644 %s" % rootfs
341 exec_cmd(chmod_cmd) 358 exec_cmd(chmod_cmd)
342 359
343 prepare_rootfs_vfat = prepare_rootfs_msdos 360 prepare_rootfs_vfat = prepare_rootfs_msdos
344 361
345 def prepare_rootfs_squashfs(self, rootfs, oe_builddir, rootfs_dir, 362 def prepare_rootfs_squashfs(self, rootfs, cr_workdir, oe_builddir, rootfs_dir,
346 native_sysroot, pseudo): 363 native_sysroot, pseudo):
347 """ 364 """
348 Prepare content for a squashfs rootfs partition. 365 Prepare content for a squashfs rootfs partition.