1 |
commit: b799756684d80af07e9cb683d3b6d98897ea0ce6 |
2 |
Author: Andreas K. Hüttel <dilfridge <AT> gentoo <DOT> org> |
3 |
AuthorDate: Sun Aug 30 13:03:54 2020 +0000 |
4 |
Commit: Andreas K. Hüttel <dilfridge <AT> gentoo <DOT> org> |
5 |
CommitDate: Thu Sep 17 21:13:13 2020 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/catalyst.git/commit/?id=b7997566 |
7 |
|
8 |
First steps |
9 |
|
10 |
Signed-off-by: Andreas K. Hüttel <dilfridge <AT> gentoo.org> |
11 |
|
12 |
targets/support/create-image.sh | 169 ++++++++++++++++++++++++++++++++++++++++ |
13 |
1 file changed, 169 insertions(+) |
14 |
|
15 |
diff --git a/targets/support/create-image.sh b/targets/support/create-image.sh |
16 |
new file mode 100755 |
17 |
index 00000000..4b06a9dc |
18 |
--- /dev/null |
19 |
+++ b/targets/support/create-image.sh |
20 |
@@ -0,0 +1,169 @@ |
21 |
+#!/bin/bash |
22 |
+ |
23 |
+source ${clst_shdir}/support/functions.sh |
24 |
+source ${clst_shdir}/support/filesystem-functions.sh |
25 |
+ |
26 |
+## START RUNSCRIPT |
27 |
+ |
28 |
+# WORK IN PROGRESS |
29 |
+ |
30 |
+# This script takes a filesystem tree created by catalyst and converts it |
31 |
+# into a readily bootable disk image for use with QEMU, cloud services, etc. |
32 |
+# Things that should be configurable when it's finished: |
33 |
+# * image type (raw, qcow2, vmdk) |
34 |
+# * disk size |
35 |
+# * system partition size? filesystem? |
36 |
+# * create a blank swap partition? size? |
37 |
+# * boot loader and partition type (mbr&dos, or uefi&gpt; other combos |
38 |
+# not supported) |
39 |
+# * start sshd? |
40 |
+# * root password or (much better) root authorized_keys |
41 |
+# |
42 |
+# For now support is limited to arches where cloud services exist (i.e., |
43 |
+# amd64 and arm64). |
44 |
+ |
45 |
+# Check for our bootable disk image creation tools |
46 |
+# case ${clst_hostarch} in |
47 |
+# *) |
48 |
+# cdmaker="mkisofs" |
49 |
+# cdmakerpkg="app-cdr/cdrkit or app-cdr/cdrtools" |
50 |
+# ;; |
51 |
+# esac |
52 |
+ |
53 |
+# [ ! -f /usr/bin/${cdmaker} ] \ |
54 |
+# && echo && echo && die \ |
55 |
+# "!!! /usr/bin/${cdmaker} is not found. Have you merged ${cdmakerpkg}?" \ |
56 |
+# && echo && echo |
57 |
+ |
58 |
+# If not volume ID is set, make up a sensible default |
59 |
+if [ -z "${clst_image_volume_id}" ] |
60 |
+then |
61 |
+ case ${clst_image_type} in |
62 |
+ gentoo-*) |
63 |
+ case ${clst_hostarch} in |
64 |
+ amd64) |
65 |
+ clst_image_volume_id="Gentoo Linux - AMD64" |
66 |
+ ;; |
67 |
+ arm64) |
68 |
+ clst_image_volume_id="Gentoo Linux - ARM64" |
69 |
+ ;; |
70 |
+ *) |
71 |
+ clst_image_volume_id="Gentoo Linux" |
72 |
+ ;; |
73 |
+ esac |
74 |
+ esac |
75 |
+fi |
76 |
+ |
77 |
+if [ "${#clst_image_volume_id}" -gt 32 ]; then |
78 |
+ old_clst_image_volume_id=${clst_image_volume_id} |
79 |
+ clst_image_volume_id="${clst_image_volume_id:0:32}" |
80 |
+ echo "ISO Volume label is too long, truncating to 32 characters" 1>&2 |
81 |
+ echo "old: '${old_clst_image_volume_id}'" 1>&2 |
82 |
+ echo "new: '${clst_image_volume_id}'" 1>&2 |
83 |
+fi |
84 |
+ |
85 |
+if [ "${clst_fstype}" == "zisofs" ] |
86 |
+then |
87 |
+ mkisofs_zisofs_opts="-z" |
88 |
+else |
89 |
+ mkisofs_zisofs_opts="" |
90 |
+fi |
91 |
+ |
92 |
+#we want to create a checksum for every file on the iso so we can verify it |
93 |
+#from genkernel during boot. Here we make a function to create the sha512sums, and blake2sums |
94 |
+isoroot_checksum() { |
95 |
+ echo "Creating checksums for all files included in the iso, please wait..." |
96 |
+ if [ -z "${1}" ] || [ "${1}" = "sha512" ]; then |
97 |
+ find "${clst_target_path}" -type f ! -name 'isoroot_checksums' ! -name 'isolinux.bin' ! -name 'isoroot_b2sums' -exec sha512sum {} + > "${clst_target_path}"/isoroot_checksums |
98 |
+ ${clst_sed} -i "s#${clst_target_path}/\?##" "${clst_target_path}"/isoroot_checksums |
99 |
+ fi |
100 |
+ if [ -z "${1}" ] || [ "${1}" = "blake2" ]; then |
101 |
+ find "${clst_target_path}" -type f ! -name 'isoroot_checksums' ! -name 'isolinux.bin' ! -name 'isoroot_b2sums' -exec b2sum {} + > "${clst_target_path}"/isoroot_b2sums |
102 |
+ ${clst_sed} -i "s#${clst_target_path}/\?##" "${clst_target_path}"/isoroot_b2sums |
103 |
+ fi |
104 |
+} |
105 |
+ |
106 |
+run_mkisofs() { |
107 |
+ if [ -n "${clst_livecd_verify}" ]; then |
108 |
+ if [ "${clst_livecd_verify}" = "sha512" ]; then |
109 |
+ isoroot_checksum sha512 |
110 |
+ elif [ "${clst_livecd_verify}" = "blake2" ]; then |
111 |
+ isoroot_checksum blake2 |
112 |
+ else |
113 |
+ isoroot_checksum |
114 |
+ fi |
115 |
+ fi |
116 |
+ echo "Running \"mkisofs ${@}\"" |
117 |
+ mkisofs "${@}" || die "Cannot make ISO image" |
118 |
+} |
119 |
+ |
120 |
+# Here we actually create the ISO images for each architecture |
121 |
+case ${clst_hostarch} in |
122 |
+ x86|amd64) |
123 |
+ # detect if an EFI bootloader is desired |
124 |
+ if [ -d "${clst_target_path}/boot/efi" ] || \ |
125 |
+ [ -d "${clst_target_path}/boot/EFI" ] || \ |
126 |
+ [ -e "${clst_target_path}/gentoo.efimg" ] |
127 |
+ then |
128 |
+ if [ -e "${clst_target_path}/gentoo.efimg" ] |
129 |
+ then |
130 |
+ echo "Found prepared EFI boot image at \ |
131 |
+ ${clst_target_path}/gentoo.efimg" |
132 |
+ else |
133 |
+ echo "Preparing EFI boot image" |
134 |
+ if [ -d "${clst_target_path}/boot/efi" ] && [ ! -d "${clst_target_path}/boot/EFI" ]; then |
135 |
+ echo "Moving /boot/efi to /boot/EFI" |
136 |
+ mv "${clst_target_path}/boot/efi" "${clst_target_path}/boot/EFI" |
137 |
+ fi |
138 |
+ # prepare gentoo.efimg from clst_target_path /boot/EFI dir |
139 |
+ iaSizeTemp=$(du -sk --apparent-size "${clst_target_path}/boot/EFI" 2>/dev/null) |
140 |
+ iaSizeB=$(echo ${iaSizeTemp} | cut '-d ' -f1) |
141 |
+ iaSize=$((${iaSizeB}+64)) # add slack, tested near minimum for overhead |
142 |
+ echo "Creating loopback file of size ${iaSize}kB" |
143 |
+ dd if=/dev/zero of="${clst_target_path}/gentoo.efimg" bs=1k \ |
144 |
+ count=${iaSize} |
145 |
+ echo "Formatting loopback file with FAT16 FS" |
146 |
+ mkfs.vfat -F 16 -n GENTOOLIVE "${clst_target_path}/gentoo.efimg" |
147 |
+ |
148 |
+ mkdir "${clst_target_path}/gentoo.efimg.mountPoint" |
149 |
+ echo "Mounting FAT16 loopback file" |
150 |
+ mount -t vfat -o loop "${clst_target_path}/gentoo.efimg" \ |
151 |
+ "${clst_target_path}/gentoo.efimg.mountPoint" || die "Failed to mount EFI image file" |
152 |
+ |
153 |
+ echo "Populating EFI image file from ${clst_target_path}/boot/EFI" |
154 |
+ cp -rv "${clst_target_path}"/boot/EFI/ \ |
155 |
+ "${clst_target_path}/gentoo.efimg.mountPoint" || die "Failed to populate EFI image file" |
156 |
+ |
157 |
+ umount "${clst_target_path}/gentoo.efimg.mountPoint" |
158 |
+ rmdir "${clst_target_path}/gentoo.efimg.mountPoint" |
159 |
+ |
160 |
+ echo "Copying /boot/EFI to /EFI for rufus compatability" |
161 |
+ cp -rv "${clst_target_path}"/boot/EFI/ "${clst_target_path}" |
162 |
+ fi |
163 |
+ fi |
164 |
+ |
165 |
+ if [ -e "${clst_target_path}/isolinux/isolinux.bin" ]; then |
166 |
+ echo '** Found ISOLINUX bootloader' |
167 |
+ if [ -e "${clst_target_path}/gentoo.efimg" ]; then |
168 |
+ # have BIOS isolinux, plus an EFI loader image |
169 |
+ echo '** Found GRUB2 EFI bootloader' |
170 |
+ echo 'Creating ISO using both ISOLINUX and EFI bootloader' |
171 |
+ run_mkisofs -J -R -l ${mkisofs_zisofs_opts} -V "${clst_iso_volume_id}" -o "${1}" -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -eltorito-alt-boot -eltorito-platform efi -b gentoo.efimg -no-emul-boot -z "${clst_target_path}"/ |
172 |
+ isohybrid --uefi "${1}" |
173 |
+ else |
174 |
+ echo 'Creating ISO using ISOLINUX bootloader' |
175 |
+ run_mkisofs -J -R -l ${mkisofs_zisofs_opts} -V "${clst_iso_volume_id}" -o "${1}" -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table "${clst_target_path}"/ |
176 |
+ isohybrid "${1}" |
177 |
+ fi |
178 |
+ elif [ -e "${clst_target_path}/gentoo.efimg" ]; then |
179 |
+ echo '** Found GRUB2 EFI bootloader' |
180 |
+ echo 'Creating ISO using EFI bootloader' |
181 |
+ run_mkisofs -J -R -l ${mkisofs_zisofs_opts} -V "${clst_iso_volume_id}" -o "${1}" -b gentoo.efimg -c boot.cat -no-emul-boot "${clst_target_path}"/ |
182 |
+ else |
183 |
+ echo '** Found no known bootloader' |
184 |
+ echo 'Creating ISO with fingers crossed that you know what you are doing...' |
185 |
+ run_mkisofs -J -R -l ${mkisofs_zisofs_opts} -V "${clst_iso_volume_id}" -o "${1}" "${clst_target_path}"/ |
186 |
+ fi |
187 |
+ ;; |
188 |
+esac |
189 |
+exit $? |