summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRicardo Ribalda Delgado <ricardo.ribalda@gmail.com>2020-04-19 08:35:36 +0200
committerRichard Purdie <richard.purdie@linuxfoundation.org>2020-04-26 14:00:50 +0100
commita293c76c53f985efb4cfbb97aa4facb59c0ccfb6 (patch)
tree453ffcaf321a7a27d4b43dc5a45b9a5d2cf2a314
parentfc2589384bbf40b2c2b3e81b668eac71762c192f (diff)
downloadpoky-a293c76c53f985efb4cfbb97aa4facb59c0ccfb6.tar.gz
wic: root: Add an opt. destination on include-path
Allow specifying an optional destination to include-path and make the option aware of permissions and owners. It is very useful for making a partition that contains the rootfs for a host and a target Eg: / -> Roofs for the host /export/ -> Rootfs for the target (which will netboot) Although today we support making a partition for "/export" this might not be compatible with some upgrade systems, or we might be limited by the number of partitions. With this patch we can use something like: part / --source rootfs --fstype=ext4 --include-path core-image-minimal-mtdutils export/ --include-path hello on the .wks file. Cc: Paul Barker <pbarker@konsulko.com> (From OE-Core rev: e8c21c6ebaebde88151697381bdb2452f1171090) Signed-off-by: Ricardo Ribalda Delgado <ricardo@ribalda.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--meta/recipes-core/meta/wic-tools.bb2
-rw-r--r--scripts/lib/wic/help.py20
-rw-r--r--scripts/lib/wic/ksparser.py2
-rw-r--r--scripts/lib/wic/plugins/source/rootfs.py60
4 files changed, 72 insertions, 12 deletions
diff --git a/meta/recipes-core/meta/wic-tools.bb b/meta/recipes-core/meta/wic-tools.bb
index 09eb409e87..8aeb942ed2 100644
--- a/meta/recipes-core/meta/wic-tools.bb
+++ b/meta/recipes-core/meta/wic-tools.bb
@@ -6,7 +6,7 @@ DEPENDS = "\
6 parted-native syslinux-native gptfdisk-native dosfstools-native \ 6 parted-native syslinux-native gptfdisk-native dosfstools-native \
7 mtools-native bmap-tools-native grub-efi-native cdrtools-native \ 7 mtools-native bmap-tools-native grub-efi-native cdrtools-native \
8 btrfs-tools-native squashfs-tools-native pseudo-native \ 8 btrfs-tools-native squashfs-tools-native pseudo-native \
9 e2fsprogs-native util-linux-native \ 9 e2fsprogs-native util-linux-native tar-native\
10 " 10 "
11DEPENDS_append_x86 = " syslinux grub-efi systemd-boot" 11DEPENDS_append_x86 = " syslinux grub-efi systemd-boot"
12DEPENDS_append_x86-64 = " syslinux grub-efi systemd-boot" 12DEPENDS_append_x86-64 = " syslinux grub-efi systemd-boot"
diff --git a/scripts/lib/wic/help.py b/scripts/lib/wic/help.py
index 62a2a90e79..bd3a2b97df 100644
--- a/scripts/lib/wic/help.py
+++ b/scripts/lib/wic/help.py
@@ -971,14 +971,18 @@ DESCRIPTION
971 has an effect with the rootfs source plugin. 971 has an effect with the rootfs source plugin.
972 972
973 --include-path: This option is specific to wic. It adds the contents 973 --include-path: This option is specific to wic. It adds the contents
974 of the given path to the resulting image. The path is 974 of the given path or a rootfs to the resulting image.
975 relative to the directory in which wic is running not 975 The option contains two fields, the origin and the
976 the rootfs itself so use of an absolute path is 976 destination. When the origin is a rootfs, it follows
977 recommended. This option is most useful when multiple 977 the same logic as the rootfs-dir argument and the
978 copies of the rootfs are added to an image and it is 978 permissions and owners are kept. When the origin is a
979 required to add extra content to only one of these 979 path, it is relative to the directory in which wic is
980 copies. This option only has an effect with the rootfs 980 running not the rootfs itself so use of an absolute
981 source plugin. 981 path is recommended, and the owner and group is set to
982 root:root. If no destination is given it is
983 automatically set to the root of the rootfs. This
984 option only has an effect with the rootfs source
985 plugin.
982 986
983 --change-directory: This option is specific to wic. It changes to the 987 --change-directory: This option is specific to wic. It changes to the
984 given directory before copying the files. This 988 given directory before copying the files. This
diff --git a/scripts/lib/wic/ksparser.py b/scripts/lib/wic/ksparser.py
index c60869d397..b8befe78e3 100644
--- a/scripts/lib/wic/ksparser.py
+++ b/scripts/lib/wic/ksparser.py
@@ -137,7 +137,7 @@ class KickStart():
137 part.add_argument('--active', action='store_true') 137 part.add_argument('--active', action='store_true')
138 part.add_argument('--align', type=int) 138 part.add_argument('--align', type=int)
139 part.add_argument('--exclude-path', nargs='+') 139 part.add_argument('--exclude-path', nargs='+')
140 part.add_argument('--include-path', nargs='+') 140 part.add_argument('--include-path', nargs='+', action='append')
141 part.add_argument('--change-directory') 141 part.add_argument('--change-directory')
142 part.add_argument("--extra-space", type=sizetype) 142 part.add_argument("--extra-space", type=sizetype)
143 part.add_argument('--fsoptions', dest='fsopts') 143 part.add_argument('--fsoptions', dest='fsopts')
diff --git a/scripts/lib/wic/plugins/source/rootfs.py b/scripts/lib/wic/plugins/source/rootfs.py
index 247f61ff7c..544e868b5e 100644
--- a/scripts/lib/wic/plugins/source/rootfs.py
+++ b/scripts/lib/wic/plugins/source/rootfs.py
@@ -17,6 +17,7 @@ import shutil
17import sys 17import sys
18 18
19from oe.path import copyhardlinktree 19from oe.path import copyhardlinktree
20from pathlib import Path
20 21
21from wic import WicError 22from wic import WicError
22from wic.pluginbase import SourcePlugin 23from wic.pluginbase import SourcePlugin
@@ -126,8 +127,63 @@ class RootfsPlugin(SourcePlugin):
126 orig_dir, new_rootfs) 127 orig_dir, new_rootfs)
127 exec_native_cmd(pseudo_cmd, native_sysroot) 128 exec_native_cmd(pseudo_cmd, native_sysroot)
128 129
129 for path in part.include_path or []: 130 for in_path in part.include_path or []:
130 copyhardlinktree(path, new_rootfs) 131 #parse arguments
132 include_path = in_path[0]
133 if len(in_path) > 2:
134 logger.error("'Invalid number of arguments for include-path")
135 sys.exit(1)
136 if len(in_path) == 2:
137 path = in_path[1]
138 else:
139 path = None
140
141 # Pack files to be included into a tar file.
142 # We need to create a tar file, because that way we can keep the
143 # permissions from the files even when they belong to different
144 # pseudo enviroments.
145 # If we simply copy files using copyhardlinktree/copytree... the
146 # copied files will belong to the user running wic.
147 tar_file = os.path.realpath(
148 os.path.join(cr_workdir, "include-path%d.tar" % part.lineno))
149 if os.path.isfile(include_path):
150 parent = os.path.dirname(os.path.realpath(include_path))
151 tar_cmd = "tar c --owner=root --group=root -f %s -C %s %s" % (
152 tar_file, parent, os.path.relpath(include_path, parent))
153 exec_native_cmd(tar_cmd, native_sysroot)
154 else:
155 if include_path in krootfs_dir:
156 include_path = krootfs_dir[include_path]
157 include_path = cls.__get_rootfs_dir(include_path)
158 include_pseudo = os.path.join(include_path, "../pseudo")
159 if os.path.lexists(include_pseudo):
160 pseudo = cls.__get_pseudo(native_sysroot, include_path,
161 include_pseudo)
162 tar_cmd = "tar cf %s -C %s ." % (tar_file, include_path)
163 else:
164 pseudo = None
165 tar_cmd = "tar c --owner=root --group=root -f %s -C %s ." % (
166 tar_file, include_path)
167 exec_native_cmd(tar_cmd, native_sysroot, pseudo)
168
169 #create destination
170 if path:
171 destination = os.path.realpath(os.path.join(new_rootfs, path))
172 if not destination.startswith(new_rootfs):
173 logger.error("%s %s" % (destination, new_rootfs))
174 sys.exit(1)
175 Path(destination).mkdir(parents=True, exist_ok=True)
176 else:
177 destination = new_rootfs
178
179 #extract destination
180 untar_cmd = "tar xf %s -C %s" % (tar_file, destination)
181 if new_pseudo:
182 pseudo = cls.__get_pseudo(native_sysroot, new_rootfs, new_pseudo)
183 else:
184 pseudo = None
185 exec_native_cmd(untar_cmd, native_sysroot, pseudo)
186 os.remove(tar_file)
131 187
132 for orig_path in part.exclude_path or []: 188 for orig_path in part.exclude_path or []:
133 path = orig_path 189 path = orig_path