Gentoo Archives: gentoo-catalyst

From: Daniel Cordero <gentoo.catalyst@××××.ws>
To: gentoo-catalyst@l.g.o
Subject: [gentoo-catalyst] [RFC PATCH] Use a 3 stage livecd build
Date: Thu, 29 Oct 2020 15:58:40
Message-Id: 20201029155832.GA875634@dysnomia.localdomain
1 From: Daniel Cordero <catalyst@××××.io>
2
3 The current (2 stage) livecd process requires a full stage3/4 tarball
4 that can install genkernel and compile a kernel for the livecd. Once the
5 kernel is built, packages are then unmerged to reduce the size of the CD
6 image. This means explicity removing every unnecessary package that may
7 be installed from the system set, or additional stage4 world sets.
8
9 Instead, an embedded target could be used, or a stage1 target be
10 abused, to create minimal images for the livecd environment.
11
12 This patch moves some actions from livecd-stage1 and livecd-stage2 into
13 a new target: livecd-stage3.
14
15 livecd-stage1 is now very similar to a regular stage4, where additional
16 packages can be installed through the package manager. This step would
17 be optional for embedded stages without a package manager.
18
19 livecd-stage2 now uses a stage3 to build a kernel and reusable "cdtar".
20 The seed stage is not retained.
21
22 livecd-stage3 takes the built kernel and modules, and a
23 livecd-stage1/embedded/stage3/stage4 tarball. Without package manager
24 interaction, it combines these into a livecd. Modules for the built
25 kernels are extracted into the looped image.
26 ---
27
28 The code basically copies the existing livecd-stage1/livecd-stage2 code
29 in the livecd-stage3 target and support scripts. I'm sure this could be
30 cleaned up to remove the references in livecd-stage1.py/livecd-stage2.py,
31 although I have not done that here.
32
33 I did also remove the module blacklisting, X11 handling and
34 gentoo-release-livecd/dvd file copies that was in the livecd-stage2.
35 They'd need to be re-added.
36
37 The livecd-stage3 specfile requires the 'profile:' keyword, even though
38 it is not required. This is because it is defined as a requirement by
39 StageBase.__init__()
40
41
42 catalyst/targets/livecd_stage1.py | 14 +++++-
43 catalyst/targets/livecd_stage2.py | 69 ++---------------------------
44 catalyst/targets/livecd_stage3.py | 61 +++++++++++++++++++++++++
45 targets/livecd-stage1/controller.sh | 5 +++
46 targets/livecd-stage3/controller.sh | 51 +++++++++++++++++++++
47 5 files changed, 133 insertions(+), 67 deletions(-)
48 create mode 100644 catalyst/targets/livecd_stage3.py
49 create mode 100755 targets/livecd-stage3/controller.sh
50
51 diff --git a/catalyst/targets/livecd_stage1.py b/catalyst/targets/livecd_stage1.py
52 index f0b6be8b..0236eb2f 100644
53 --- a/catalyst/targets/livecd_stage1.py
54 +++ b/catalyst/targets/livecd_stage1.py
55 @@ -4,7 +4,6 @@ LiveCD stage1 target
56 # NOTE: That^^ docstring has influence catalyst-spec(5) man page generation.
57
58 from catalyst.support import normpath
59 -
60 from catalyst.base.stagebase import StageBase
61
62
63 @@ -13,9 +12,14 @@ class livecd_stage1(StageBase):
64 Builder class for LiveCD stage1.
65 """
66 required_values = frozenset([
67 - "livecd/packages",
68 ])
69 valid_values = required_values | frozenset([
70 + "livecd/empty",
71 + "livecd/fsscript",
72 + "livecd/packages",
73 + "livecd/rm",
74 + "livecd/root_overlay",
75 + "livecd/unmerge",
76 "livecd/use",
77 ])
78
79 @@ -32,7 +36,13 @@ class livecd_stage1(StageBase):
80 "chroot_setup",
81 "setup_environment",
82 "build_packages",
83 + "root_overlay",
84 + "fsscript",
85 + "unmerge",
86 + "bootloader",
87 "unbind",
88 + "remove",
89 + "empty",
90 "clean",
91 ]
92 self.set_completion_action_sequences()
93 diff --git a/catalyst/targets/livecd_stage2.py b/catalyst/targets/livecd_stage2.py
94 index 88c0d95c..b459288b 100644
95 --- a/catalyst/targets/livecd_stage2.py
96 +++ b/catalyst/targets/livecd_stage2.py
97 @@ -16,42 +16,11 @@ class livecd_stage2(StageBase):
98 "boot/kernel",
99 ])
100 valid_values = required_values | frozenset([
101 - "livecd/bootargs",
102 - "livecd/cdtar",
103 - "livecd/depclean",
104 - "livecd/empty",
105 - "livecd/fsops",
106 - "livecd/fsscript",
107 - "livecd/fstype",
108 "livecd/gk_mainargs",
109 - "livecd/iso",
110 "livecd/linuxrc",
111 - "livecd/modblacklist",
112 - "livecd/motd",
113 - "livecd/overlay",
114 - "livecd/rcadd",
115 - "livecd/rcdel",
116 - "livecd/readme",
117 - "livecd/rm",
118 - "livecd/root_overlay",
119 - "livecd/type",
120 - "livecd/unmerge",
121 - "livecd/users",
122 - "livecd/verify",
123 - "livecd/volid",
124 - "livecd/xdm",
125 - "livecd/xinitrc",
126 - "livecd/xsession",
127 "portage_overlay",
128 ])
129
130 - def __init__(self, spec, addlargs):
131 - StageBase.__init__(self, spec, addlargs)
132 - if "livecd/type" not in self.settings:
133 - self.settings["livecd/type"] = "generic-livecd"
134 -
135 - file_locate(self.settings, ["cdtar", "controller_file"])
136 -
137 def set_spec_prefix(self):
138 self.settings["spec_prefix"] = "livecd"
139
140 @@ -65,26 +34,9 @@ class livecd_stage2(StageBase):
141 super(livecd_stage2, self).set_target_path()
142 clear_dir(self.settings['target_path'])
143
144 - def run_local(self):
145 - # what modules do we want to blacklist?
146 - if "livecd/modblacklist" in self.settings:
147 - path = normpath(self.settings["chroot_path"] +
148 - "/etc/modprobe.d/blacklist.conf")
149 - try:
150 - with open(path, "a") as myf:
151 - myf.write("\n#Added by Catalyst:")
152 - # workaround until config.py is using configparser
153 - if isinstance(self.settings["livecd/modblacklist"], str):
154 - self.settings["livecd/modblacklist"] = self.settings[
155 - "livecd/modblacklist"].split()
156 - for x in self.settings["livecd/modblacklist"]:
157 - myf.write("\nblacklist "+x)
158 - except:
159 - self.unbind()
160 - raise CatalystError("Couldn't open " +
161 - self.settings["chroot_path"] +
162 - "/etc/modprobe.d/blacklist.conf.",
163 - print_traceback=True)
164 + def set_stage_path(self):
165 + self.set_target_path()
166 + self.settings['stage_path'] = self.settings['target_path']
167
168 def set_action_sequence(self):
169 self.settings['action_sequence'] = [
170 @@ -95,24 +47,11 @@ class livecd_stage2(StageBase):
171 "bind",
172 "chroot_setup",
173 "setup_environment",
174 - "run_local",
175 "build_kernel"
176 ]
177 if "fetch" not in self.settings["options"]:
178 self.settings['action_sequence'] += [
179 "bootloader",
180 - "preclean",
181 - "livecd_update",
182 - "root_overlay",
183 - "fsscript",
184 - "rcupdate",
185 - "unmerge",
186 "unbind",
187 - "remove",
188 - "empty",
189 - "clean",
190 - "target_setup",
191 - "setup_overlay",
192 - "create_iso",
193 ]
194 - self.settings["action_sequence"].append("clear_autoresume")
195 + self.set_completion_action_sequences()
196 diff --git a/catalyst/targets/livecd_stage3.py b/catalyst/targets/livecd_stage3.py
197 new file mode 100644
198 index 00000000..a5df72d3
199 --- /dev/null
200 +++ b/catalyst/targets/livecd_stage3.py
201 @@ -0,0 +1,61 @@
202 +"""
203 +LiveCD stage3 target
204 +"""
205 +# NOTE: That^^ docstring has influence catalyst-spec(5) man page generation.
206 +
207 +from catalyst.support import normpath
208 +from catalyst.fileops import clear_dir
209 +from catalyst.targets.livecd_stage1 import livecd_stage1
210 +
211 +
212 +class livecd_stage3(livecd_stage1):
213 + """
214 + Builder class for LiveCD stage3.
215 +
216 + Wraps any stage into a CD image
217 +
218 + Requires a cached kernel name and cdtar
219 + """
220 + required_values = frozenset([
221 + "boot/kernel",
222 + "livecd/cdtar",
223 + ])
224 + valid_values = required_values | frozenset([
225 + "livecd/bootargs",
226 + "livecd/empty",
227 + "livecd/fsscript",
228 + "livecd/fstype",
229 + "livecd/iso",
230 + "livecd/rm",
231 + "livecd/root_overlay",
232 + "livecd/type",
233 + "livecd/verify",
234 + "livecd/volid",
235 + ])
236 +
237 + def set_action_sequence(self):
238 + self.settings['action_sequence'] = [
239 + "unpack",
240 + "bind",
241 + "setup_environment",
242 + "root_overlay",
243 + "fsscript",
244 + "bootloader",
245 + "unbind",
246 + "remove",
247 + "empty",
248 + "target_setup",
249 + "create_iso",
250 + "clear_autoresume",
251 + "remove_chroot",
252 + ]
253 +
254 + def set_target_path(self):
255 + '''Set the target path for the finished stage.
256 +
257 + This method runs the StageBase.set_target_path method,
258 + and additionally creates a staging directory for assembling
259 + the final components needed to produce the iso image.
260 + '''
261 + super(livecd_stage1, self).set_target_path()
262 + clear_dir(self.settings['target_path'])
263 diff --git a/targets/livecd-stage1/controller.sh b/targets/livecd-stage1/controller.sh
264 index ae897da9..0d472f1f 100755
265 --- a/targets/livecd-stage1/controller.sh
266 +++ b/targets/livecd-stage1/controller.sh
267 @@ -12,5 +12,10 @@ case $1 in
268 exec_in_chroot \
269 ${clst_shdir}/${clst_target}/chroot.sh
270 ;;
271 +
272 + fsscript)
273 + exec_in_chroot ${clst_fsscript}
274 + ;;
275 +
276 esac
277 exit $?
278 diff --git a/targets/livecd-stage3/controller.sh b/targets/livecd-stage3/controller.sh
279 new file mode 100755
280 index 00000000..632e8ccd
281 --- /dev/null
282 +++ b/targets/livecd-stage3/controller.sh
283 @@ -0,0 +1,51 @@
284 +#!/bin/bash
285 +
286 +source ${clst_shdir}/support/functions.sh
287 +
288 +## START RUNSCRIPT
289 +
290 +case $1 in
291 + fsscript)
292 + exec_in_chroot ${clst_fsscript}
293 + ;;
294 +
295 + bootloader)
296 + shift
297 + # Here is where we poke in our identifier
298 + touch $1/livecd
299 +
300 + # We create a firmware directory, if necessary
301 + if [ -e ${clst_chroot_path}/lib/firmware.tar.bz2 ]
302 + then
303 + echo "Creating firmware directory in $1"
304 + mkdir -p $1/firmware
305 + # TODO: Unpack firmware into $1/firmware and remove it from the
306 + # chroot so newer livecd-tools/genkernel can find it and unpack it.
307 + fi
308 +
309 + # Move over the readme (if applicable)
310 + if [ -n "${clst_livecd_readme}" ]
311 + then
312 + cp -f ${clst_livecd_readme} $1/README.txt
313 + else
314 + cp -f ${clst_sharedir}/livecd/files/README.txt $1
315 + fi
316 +
317 + extract_cdtar $1
318 +
319 + for x in ${clst_boot_kernel}; do
320 + extract_modules ${clst_chroot_path} $x
321 + done
322 + ;;
323 +
324 + target_image_setup)
325 + shift
326 + ${clst_shdir}/support/target_image_setup.sh $1
327 + ;;
328 +
329 + iso)
330 + shift
331 + ${clst_shdir}/support/create-iso.sh $1
332 + ;;
333 +esac
334 +exit $?
335 --
336 2.26.2