Skip to content

Commit a5d718c

Browse files
committed
[update] : Added latest mkinitcpio-archiso
1 parent 356d38c commit a5d718c

13 files changed

Lines changed: 110 additions & 90 deletions

system/initcpio/archiso_shutdown

Lines changed: 0 additions & 39 deletions
This file was deleted.

system/initcpio/hooks/archiso

Lines changed: 69 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ _mnt_dmsnapshot() {
77
local img="${1}"
88
local newroot="${2}"
99
local mnt="${3}"
10-
local img_fullname="${img##*/}";
10+
local img_fullname="${img##*/}"
1111
local img_name="${img_fullname%%.*}"
1212
local dm_snap_name="${dm_snap_prefix}_${img_name}"
1313
local ro_dev ro_dev_size rw_dev
1414

1515
ro_dev="$(losetup --find --show --read-only -- "${img}")"
16-
echo "${ro_dev}" >> /run/archiso/used_block_devices
16+
printf '%s\n' "${ro_dev}" >>/run/archiso/used_block_devices
1717
ro_dev_size="$(blockdev --getsz "${ro_dev}")"
1818

1919
if [ "${cow_persistent}" = "P" ]; then
@@ -33,7 +33,7 @@ _mnt_dmsnapshot() {
3333
fi
3434

3535
rw_dev="$(losetup --find --show "/run/archiso/cowspace/${cow_directory}/${img_name}.cow")"
36-
echo "${rw_dev}" >> /run/archiso/used_block_devices
36+
printf '%s\n' "${rw_dev}" >>/run/archiso/used_block_devices
3737

3838
dmsetup create "${dm_snap_name}" --table \
3939
"0 ${ro_dev_size} snapshot ${ro_dev} ${rw_dev} ${cow_persistent} ${cow_chunksize}"
@@ -43,7 +43,7 @@ _mnt_dmsnapshot() {
4343
fi
4444

4545
_mnt_dev "/dev/mapper/${dm_snap_name}" "${newroot}${mnt}" "-w" "defaults"
46-
readlink -f "/dev/mapper/${dm_snap_name}" >> /run/archiso/used_block_devices
46+
readlink -f "/dev/mapper/${dm_snap_name}" >>/run/archiso/used_block_devices
4747
}
4848

4949
# args: source, newroot, mountpoint
@@ -53,11 +53,10 @@ _mnt_overlayfs() {
5353
local mnt="${3}"
5454
mkdir -p "/run/archiso/cowspace/${cow_directory}/upperdir" "/run/archiso/cowspace/${cow_directory}/workdir"
5555
mount -t overlay -o \
56-
"lowerdir=${src},upperdir=/run/archiso/cowspace/${cow_directory}/upperdir,workdir=/run/archiso/cowspace/${cow_directory}/workdir" \
57-
airootfs "${newroot}${mnt}"
56+
"lowerdir=${src},upperdir=/run/archiso/cowspace/${cow_directory}/upperdir,workdir=/run/archiso/cowspace/${cow_directory}/workdir" \
57+
airootfs "${newroot}${mnt}"
5858
}
5959

60-
6160
# args: /path/to/image_file, mountpoint
6261
_mnt_sfs() {
6362
local img="${1}"
@@ -69,24 +68,61 @@ _mnt_sfs() {
6968
# defined via initcpio's parse_cmdline()
7069
if [ "${copytoram}" = "y" ]; then
7170
msg -n ":: Copying squashfs image to RAM..."
72-
if ! cp -- "${img}" "/run/archiso/copytoram/${img_fullname}" ; then
71+
72+
# in case we have pv use it to display copy progress feedback otherwise
73+
# fallback to using plain cp
74+
if command -v pv >/dev/null 2>&1; then
75+
echo ""
76+
(pv "${img}" >"/run/archiso/copytoram/${img_fullname}")
77+
local rc=$?
78+
else
79+
(cp -- "${img}" "/run/archiso/copytoram/${img_fullname}")
80+
local rc=$?
81+
fi
82+
83+
if [ $rc != 0 ]; then
7384
echo "ERROR: while copy '${img}' to '/run/archiso/copytoram/${img_fullname}'"
7485
launch_interactive_shell
7586
fi
87+
7688
img="/run/archiso/copytoram/${img_fullname}"
7789
msg "done."
7890
fi
7991
sfs_dev="$(losetup --find --show --read-only -- "${img}")"
80-
echo "${sfs_dev}" >> /run/archiso/used_block_devices
92+
echo "${sfs_dev}" >>/run/archiso/used_block_devices
8193
_mnt_dev "${sfs_dev}" "${mnt}" "-r" "defaults"
8294
}
8395

96+
# args: /path/to/image_file, mountpoint
97+
_mnt_erofs() {
98+
local img="${1}"
99+
local mnt="${2}"
100+
local img_fullname="${img##*/}"
101+
local erofs_dev
102+
103+
# shellcheck disable=SC2154
104+
# defined via initcpio's parse_cmdline()
105+
if [ "${copytoram}" = "y" ]; then
106+
msg -n ":: Copying EROFS image to RAM..."
107+
if ! cp -- "${img}" "/run/archiso/copytoram/${img_fullname}"; then
108+
echo "ERROR: while copy '${img}' to '/run/archiso/copytoram/${img_fullname}'"
109+
launch_interactive_shell
110+
fi
111+
img="/run/archiso/copytoram/${img_fullname}"
112+
msg "done."
113+
fi
114+
erofs_dev="$(losetup --find --show --read-only -- "${img}")"
115+
echo "${erofs_dev}" >>/run/archiso/used_block_devices
116+
_mnt_dev "${erofs_dev}" "${mnt}" "-r" "defaults" "erofs"
117+
}
118+
84119
# args: device, mountpoint, flags, opts
85120
_mnt_dev() {
86121
local dev="${1}"
87122
local mnt="${2}"
88123
local flg="${3}"
89124
local opts="${4}"
125+
local fstype="${5:-auto}"
90126

91127
mkdir -p "${mnt}"
92128

@@ -99,7 +135,7 @@ _mnt_dev() {
99135
launch_interactive_shell
100136
done
101137

102-
if mount -o "${opts}" "${flg}" "${dev}" "${mnt}"; then
138+
if mount -t "${fstype}" -o "${opts}" "${flg}" "${dev}" "${mnt}"; then
103139
msg ":: Device '${dev}' mounted successfully."
104140
else
105141
echo "ERROR; Failed to mount '${dev}'"
@@ -112,16 +148,17 @@ _mnt_dev() {
112148
_verify_checksum() {
113149
local _status
114150
cd "/run/archiso/bootmnt/${archisobasedir}/${arch}" || exit 1
115-
sha512sum -c airootfs.sha512 > /tmp/checksum.log 2>&1
151+
sha512sum -c airootfs.sha512 >/tmp/checksum.log 2>&1
116152
_status=$?
117153
cd -- "${OLDPWD}" || exit 1
118154
return "${_status}"
119155
}
120156

121157
_verify_signature() {
122158
local _status
159+
local sigfile="${1}"
123160
cd "/run/archiso/bootmnt/${archisobasedir}/${arch}" || exit 1
124-
gpg --homedir /gpg --status-fd 1 --verify airootfs.sfs.sig 2>/dev/null | grep -qE '^\[GNUPG:\] GOODSIG'
161+
gpg --homedir /gpg --status-fd 1 --verify "${sigfile}" 2>/dev/null | grep -qE '^\[GNUPG:\] GOODSIG'
125162
_status=$?
126163
cd -- "${OLDPWD}" || exit 1
127164
return ${_status}
@@ -135,8 +172,7 @@ run_hook() {
135172
# shellcheck disable=SC2154
136173
# defined via initcpio's parse_cmdline()
137174
[ -z "${archisodevice}" ] && archisodevice="/dev/disk/by-label/${archisolabel}"
138-
#[ -z "${cow_spacesize}" ] && cow_spacesize="256M"
139-
[ -z "${cow_spacesize}" ] && cow_spacesize="%COWSPACE%"
175+
[ -z "${cow_spacesize}" ] && cow_spacesize="256M"
140176
# shellcheck disable=SC2154
141177
# defined via initcpio's parse_cmdline()
142178
if [ -n "${cow_label}" ]; then
@@ -161,11 +197,12 @@ run_hook() {
161197
# args: /path/to/newroot
162198
archiso_mount_handler() {
163199
local newroot="${1}"
200+
local sigfile
164201

165202
if ! mountpoint -q "/run/archiso/bootmnt"; then
166203
_mnt_dev "${archisodevice}" "/run/archiso/bootmnt" "-r" "defaults"
167204
if [ "${copytoram}" != "y" ]; then
168-
readlink -f "${archisodevice}" >> /run/archiso/used_block_devices
205+
readlink -f "${archisodevice}" >>/run/archiso/used_block_devices
169206
fi
170207
fi
171208

@@ -191,15 +228,20 @@ archiso_mount_handler() {
191228
# defined via initcpio's parse_cmdline()
192229
if [ "${verify}" = "y" ]; then
193230
if [ -f "/run/archiso/bootmnt/${archisobasedir}/${arch}/airootfs.sfs.sig" ]; then
231+
sigfile="airootfs.sfs.sig"
232+
elif [ -f "/run/archiso/bootmnt/${archisobasedir}/${arch}/airootfs.erofs.sig" ]; then
233+
sigfile="airootfs.erofs.sig"
234+
fi
235+
if [ -n "${sigfile}" ]; then
194236
msg -n ":: Signature verification requested, please wait..."
195-
if _verify_signature; then
237+
if _verify_signature "${sigfile}"; then
196238
msg "done. Signature is OK, continue booting."
197239
else
198240
echo "ERROR: one or more files are corrupted"
199241
launch_interactive_shell
200242
fi
201243
else
202-
echo "ERROR: verify=y option specified but ${archisobasedir}/${arch}/airootfs.sfs.sig not found"
244+
echo "ERROR: verify=y option specified but GPG signature not found in ${archisobasedir}/${arch}/"
203245
launch_interactive_shell
204246
fi
205247
fi
@@ -212,7 +254,7 @@ archiso_mount_handler() {
212254

213255
if [ -n "${cow_device}" ]; then
214256
_mnt_dev "${cow_device}" "/run/archiso/cowspace" "-r" "${cow_flags}"
215-
readlink -f "${cow_device}" >> /run/archiso/used_block_devices
257+
readlink -f "${cow_device}" >>/run/archiso/used_block_devices
216258
mount -o remount,rw "/run/archiso/cowspace"
217259
else
218260
msg ":: Mounting /run/archiso/cowspace (tmpfs) filesystem, size=${cow_spacesize}..."
@@ -222,15 +264,20 @@ archiso_mount_handler() {
222264
mkdir -p "/run/archiso/cowspace/${cow_directory}"
223265
chmod 0700 "/run/archiso/cowspace/${cow_directory}"
224266

225-
_mnt_sfs "/run/archiso/bootmnt/${archisobasedir}/${arch}/airootfs.sfs" "/run/archiso/sfs/airootfs"
226-
if [ -f "/run/archiso/sfs/airootfs/airootfs.img" ]; then
227-
_mnt_dmsnapshot "/run/archiso/sfs/airootfs/airootfs.img" "${newroot}" "/"
267+
if [ -f "/run/archiso/bootmnt/${archisobasedir}/${arch}/airootfs.sfs" ]; then
268+
_mnt_sfs "/run/archiso/bootmnt/${archisobasedir}/${arch}/airootfs.sfs" "/run/archiso/airootfs"
269+
elif [ -f "/run/archiso/bootmnt/${archisobasedir}/${arch}/airootfs.erofs" ]; then
270+
_mnt_erofs "/run/archiso/bootmnt/${archisobasedir}/${arch}/airootfs.erofs" "/run/archiso/airootfs"
271+
fi
272+
if [ -f "/run/archiso/airootfs/airootfs.img" ]; then
273+
_mnt_dmsnapshot "/run/archiso/airootfs/airootfs.img" "${newroot}" "/"
228274
else
229-
_mnt_overlayfs "/run/archiso/sfs/airootfs" "${newroot}" "/"
275+
_mnt_overlayfs "/run/archiso/airootfs" "${newroot}" "/"
230276
fi
231277

232278
if [ "${copytoram}" = "y" ]; then
233279
umount -d /run/archiso/bootmnt
280+
rmdir /run/archiso/bootmnt
234281
fi
235282
}
236283

system/initcpio/hooks/archiso_loop_mnt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#
33
# SPDX-License-Identifier: GPL-3.0-or-later
44

5-
run_hook () {
5+
run_hook() {
66
# shellcheck disable=SC2154
77
# defined via initcpio's parse_cmdline()
88
[ -n "${img_label}" ] && img_dev="/dev/disk/by-label/${img_label}"
@@ -14,7 +14,7 @@ run_hook () {
1414
fi
1515
}
1616

17-
archiso_loop_mount_handler () {
17+
archiso_loop_mount_handler() {
1818
newroot="${1}"
1919

2020
local _dev_loop
@@ -24,7 +24,7 @@ archiso_loop_mount_handler () {
2424
# shellcheck disable=SC2154
2525
# defined via initcpio's parse_cmdline()
2626
if [ "${copytoram}" != "y" ]; then
27-
readlink -f "${img_dev}" >> /run/archiso/used_block_devices
27+
readlink -f "${img_dev}" >>/run/archiso/used_block_devices
2828
fi
2929

3030
if _dev_loop=$(losetup --find --show --read-only "/run/archiso/img_dev/${img_loop}"); then

system/initcpio/hooks/archiso_pxe_common

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#
33
# SPDX-License-Identifier: GPL-3.0-or-later
44

5-
run_hook () {
5+
run_hook() {
66
# Do *not* declare 'bootif_dev' local! We need it in run_latehook().
77
local i net_mac bootif_mac
88
local DNSDOMAIN HOSTNAME IPV4DNS0 IPV4DNS1 ROOTSERVER
@@ -13,11 +13,11 @@ run_hook () {
1313
if [ -n "${ip}" ]; then
1414
if [ -n "${BOOTIF}" ]; then
1515
bootif_mac="${BOOTIF#01-}"
16-
# shellcheck disable=SC2169
16+
# shellcheck disable=SC2169,SC3060
1717
# ash supports bash-like string replacment
1818
bootif_mac="${bootif_mac//-/:}"
1919
for i in /sys/class/net/*/address; do
20-
read -r net_mac < "${i}"
20+
read -r net_mac <"${i}"
2121
if [ "${bootif_mac}" = "${net_mac}" ]; then
2222
bootif_dev=${i#/sys/class/net/}
2323
bootif_dev=${bootif_dev%/address}
@@ -47,20 +47,20 @@ run_hook () {
4747

4848
# setup DNS resolver
4949
if [ "${IPV4DNS0}" != "0.0.0.0" ]; then
50-
echo "# added by archiso_pxe_common hook" > /etc/resolv.conf
51-
echo "nameserver ${IPV4DNS0}" >> /etc/resolv.conf
50+
echo "# added by archiso_pxe_common hook" >/etc/resolv.conf
51+
echo "nameserver ${IPV4DNS0}" >>/etc/resolv.conf
5252
fi
5353
if [ "${IPV4DNS1}" != "0.0.0.0" ]; then
54-
echo "nameserver ${IPV4DNS1}" >> /etc/resolv.conf
54+
echo "nameserver ${IPV4DNS1}" >>/etc/resolv.conf
5555
fi
5656
if [ -n "${DNSDOMAIN}" ]; then
57-
echo "search ${DNSDOMAIN}" >> /etc/resolv.conf
58-
echo "domain ${DNSDOMAIN}" >> /etc/resolv.conf
57+
echo "search ${DNSDOMAIN}" >>/etc/resolv.conf
58+
echo "domain ${DNSDOMAIN}" >>/etc/resolv.conf
5959
fi
6060
fi
6161
}
6262

63-
run_latehook () {
63+
run_latehook() {
6464
if [ -n "${ip}" ]; then
6565
[ -z "${copy_resolvconf}" ] && copy_resolvconf="y"
6666

@@ -73,8 +73,8 @@ run_latehook () {
7373
ip link set "${netdev}" down
7474
done
7575
elif [ "${copy_resolvconf}" != "n" ] && [ -f /etc/resolv.conf ]; then
76-
rm -f /new_root/etc/resolv.conf
77-
cp /etc/resolv.conf /new_root/etc/resolv.conf
76+
rm -f -- /new_root/etc/resolv.conf
77+
cp -- /etc/resolv.conf /new_root/etc/resolv.conf
7878
fi
7979
fi
8080
}

system/initcpio/hooks/archiso_pxe_http

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,22 @@ _curl_get() {
3737
fi
3838
}
3939

40-
archiso_pxe_http_mount_handler () {
40+
archiso_pxe_http_mount_handler() {
4141
newroot="${1}"
42+
local img_type="sfs"
4243

4344
msg ":: Mounting /run/archiso/httpspace (tmpfs) filesystem, size='${archiso_http_spc}'"
4445
mkdir -p "/run/archiso/httpspace"
4546
mount -t tmpfs -o size="${archiso_http_spc}",mode=0755 httpspace "/run/archiso/httpspace"
4647

4748
# shellcheck disable=SC2154
4849
# defined via initcpio's parse_cmdline()
49-
_curl_get "${archiso_http_srv}${archisobasedir}/${arch}/airootfs.sfs" "/${arch}"
50+
if ! curl -L -f -o /dev/null -s -r 0-0 "${archiso_http_srv}${archisobasedir}/${arch}/airootfs.sfs"; then
51+
if curl -L -f -o /dev/null -s -r 0-0 "${archiso_http_srv}${archisobasedir}/${arch}/airootfs.erofs"; then
52+
img_type="erofs"
53+
fi
54+
fi
55+
_curl_get "${archiso_http_srv}${archisobasedir}/${arch}/airootfs.${img_type}" "/${arch}"
5056

5157
# shellcheck disable=SC2154
5258
# defined via initcpio's parse_cmdline()
@@ -56,7 +62,7 @@ archiso_pxe_http_mount_handler () {
5662
# shellcheck disable=SC2154
5763
# defined via initcpio's parse_cmdline()
5864
if [ "${verify}" = "y" ]; then
59-
_curl_get "${archiso_http_srv}${archisobasedir}/${arch}/airootfs.sfs.sig" "/${arch}"
65+
_curl_get "${archiso_http_srv}${archisobasedir}/${arch}/airootfs.${img_type}.sig" "/${arch}"
6066
fi
6167

6268
mkdir -p "/run/archiso/bootmnt"

0 commit comments

Comments
 (0)