Skip to content

Commit 15e53f1

Browse files
committed
[update] : New mkinitcpio-archiso
1 parent 539e213 commit 15e53f1

File tree

3 files changed

+25
-52
lines changed

3 files changed

+25
-52
lines changed

system/initcpio/hooks/archiso

Lines changed: 20 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ _mnt_dmsnapshot() {
1313
local ro_dev ro_dev_size rw_dev
1414

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

1918
if [ "${cow_persistent}" = "P" ]; then
@@ -33,7 +32,6 @@ _mnt_dmsnapshot() {
3332
fi
3433

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

3836
dmsetup create "${dm_snap_name}" --table \
3937
"0 ${ro_dev_size} snapshot ${ro_dev} ${rw_dev} ${cow_persistent} ${cow_chunksize}"
@@ -43,7 +41,6 @@ _mnt_dmsnapshot() {
4341
fi
4442

4543
_mnt_dev "/dev/mapper/${dm_snap_name}" "${newroot}${mnt}" "-w" "defaults"
46-
readlink -f "/dev/mapper/${dm_snap_name}" >>/run/archiso/used_block_devices
4744
}
4845

4946
# args: source, newroot, mountpoint
@@ -58,16 +55,16 @@ _mnt_overlayfs() {
5855
}
5956

6057
# args: /path/to/image_file, mountpoint
61-
_mnt_sfs() {
58+
_mnt_fs() {
6259
local img="${1}"
6360
local mnt="${2}"
6461
local img_fullname="${img##*/}"
65-
local sfs_dev
62+
local img_loopdev
6663

6764
# shellcheck disable=SC2154
6865
# defined via initcpio's parse_cmdline()
6966
if [ "${copytoram}" = "y" ]; then
70-
msg -n ":: Copying squashfs image to RAM..."
67+
msg -n ":: Copying rootfs image to RAM..."
7168

7269
# in case we have pv use it to display copy progress feedback otherwise
7370
# fallback to using plain cp
@@ -88,32 +85,8 @@ _mnt_sfs() {
8885
img="/run/archiso/copytoram/${img_fullname}"
8986
msg "done."
9087
fi
91-
sfs_dev="$(losetup --find --show --read-only -- "${img}")"
92-
echo "${sfs_dev}" >>/run/archiso/used_block_devices
93-
_mnt_dev "${sfs_dev}" "${mnt}" "-r" "defaults"
94-
}
95-
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"
88+
img_loopdev="$(losetup --find --show --read-only -- "${img}")"
89+
_mnt_dev "${img_loopdev}" "${mnt}" "-r" "defaults"
11790
}
11891

11992
# args: device, mountpoint, flags, opts
@@ -122,7 +95,6 @@ _mnt_dev() {
12295
local mnt="${2}"
12396
local flg="${3}"
12497
local opts="${4}"
125-
local fstype="${5:-auto}"
12698

12799
mkdir -p "${mnt}"
128100

@@ -135,7 +107,7 @@ _mnt_dev() {
135107
launch_interactive_shell
136108
done
137109

138-
if mount -t "${fstype}" -o "${opts}" "${flg}" "${dev}" "${mnt}"; then
110+
if mount -o "${opts}" "${flg}" "${dev}" "${mnt}"; then
139111
msg ":: Device '${dev}' mounted successfully."
140112
else
141113
echo "ERROR; Failed to mount '${dev}'"
@@ -158,7 +130,7 @@ _verify_signature() {
158130
local _status
159131
local sigfile="${1}"
160132
cd "/run/archiso/bootmnt/${archisobasedir}/${arch}" || exit 1
161-
gpg --homedir /gpg --status-fd 1 --verify "${sigfile}" 2>/dev/null | grep -qE '^\[GNUPG:\] GOODSIG'
133+
gpg --homedir /gpg --status-fd 1 --verify "${sigfile}" 2>/dev/null | grep -E '^\[GNUPG:\] GOODSIG'
162134
_status=$?
163135
cd -- "${OLDPWD}" || exit 1
164136
return ${_status}
@@ -197,22 +169,19 @@ run_hook() {
197169
# args: /path/to/newroot
198170
archiso_mount_handler() {
199171
local newroot="${1}"
200-
local sigfile
172+
local sigfile fs_img
201173

202174
if ! mountpoint -q "/run/archiso/bootmnt"; then
203175
_mnt_dev "${archisodevice}" "/run/archiso/bootmnt" "-r" "defaults"
204-
if [ "${copytoram}" != "y" ]; then
205-
readlink -f "${archisodevice}" >>/run/archiso/used_block_devices
206-
fi
207176
fi
208177

209178
# shellcheck disable=SC2154
210179
# defined via initcpio's parse_cmdline()
211180
if [ "${checksum}" = "y" ]; then
212181
if [ -f "/run/archiso/bootmnt/${archisobasedir}/${arch}/airootfs.sha512" ]; then
213-
msg -n ":: Self-test requested, please wait..."
182+
msg ":: Self-test requested, please wait..."
214183
if _verify_checksum; then
215-
msg "done. Checksum is OK, continue booting."
184+
msg "Checksum is OK, continue booting."
216185
else
217186
echo "ERROR: one or more files are corrupted"
218187
echo "see /tmp/checksum.log for details"
@@ -233,9 +202,9 @@ archiso_mount_handler() {
233202
sigfile="airootfs.erofs.sig"
234203
fi
235204
if [ -n "${sigfile}" ]; then
236-
msg -n ":: Signature verification requested, please wait..."
205+
msg ":: Signature verification requested, please wait..."
237206
if _verify_signature "${sigfile}"; then
238-
msg "done. Signature is OK, continue booting."
207+
msg "Signature is OK, continue booting."
239208
else
240209
echo "ERROR: one or more files are corrupted"
241210
launch_interactive_shell
@@ -253,8 +222,9 @@ archiso_mount_handler() {
253222
fi
254223

255224
if [ -n "${cow_device}" ]; then
225+
# Mount cow_device read-only at first and remount it read-write right after. This prevents errors when the
226+
# device is already mounted read-only somewhere else (e.g. if cow_device and archisodevice are the same).
256227
_mnt_dev "${cow_device}" "/run/archiso/cowspace" "-r" "${cow_flags}"
257-
readlink -f "${cow_device}" >>/run/archiso/used_block_devices
258228
mount -o remount,rw "/run/archiso/cowspace"
259229
else
260230
msg ":: Mounting /run/archiso/cowspace (tmpfs) filesystem, size=${cow_spacesize}..."
@@ -265,10 +235,14 @@ archiso_mount_handler() {
265235
chmod 0700 "/run/archiso/cowspace/${cow_directory}"
266236

267237
if [ -f "/run/archiso/bootmnt/${archisobasedir}/${arch}/airootfs.sfs" ]; then
268-
_mnt_sfs "/run/archiso/bootmnt/${archisobasedir}/${arch}/airootfs.sfs" "/run/archiso/airootfs"
238+
fs_img="/run/archiso/bootmnt/${archisobasedir}/${arch}/airootfs.sfs"
269239
elif [ -f "/run/archiso/bootmnt/${archisobasedir}/${arch}/airootfs.erofs" ]; then
270-
_mnt_erofs "/run/archiso/bootmnt/${archisobasedir}/${arch}/airootfs.erofs" "/run/archiso/airootfs"
240+
fs_img="/run/archiso/bootmnt/${archisobasedir}/${arch}/airootfs.erofs"
241+
else
242+
echo "ERROR: no root file system image found"
243+
launch_interactive_shell
271244
fi
245+
_mnt_fs "${fs_img}" "/run/archiso/airootfs"
272246
if [ -f "/run/archiso/airootfs/airootfs.img" ]; then
273247
_mnt_dmsnapshot "/run/archiso/airootfs/airootfs.img" "${newroot}" "/"
274248
else

system/initcpio/hooks/archiso_loop_mnt

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,6 @@ archiso_loop_mount_handler() {
2121

2222
msg ":: Setup a loop device from ${img_loop} located at device ${img_dev}"
2323
_mnt_dev "${img_dev}" "/run/archiso/img_dev" "-r" "${img_flags}"
24-
# shellcheck disable=SC2154
25-
# defined via initcpio's parse_cmdline()
26-
if [ "${copytoram}" != "y" ]; then
27-
readlink -f "${img_dev}" >>/run/archiso/used_block_devices
28-
fi
2924

3025
if _dev_loop=$(losetup --find --show --read-only "/run/archiso/img_dev/${img_loop}"); then
3126
export archisodevice="${_dev_loop}"
@@ -36,6 +31,8 @@ archiso_loop_mount_handler() {
3631

3732
archiso_mount_handler "${newroot}"
3833

34+
# shellcheck disable=SC2154
35+
# defined via initcpio's parse_cmdline()
3936
if [ "${copytoram}" = "y" ]; then
4037
losetup -d "${_dev_loop}" 2>/dev/null
4138
umount /run/archiso/img_dev

system/initcpio/hooks/archiso_pxe_common

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ run_hook() {
3232
fi
3333

3434
# setup network and save some values
35-
if ! ipconfig -t 20 "ip=${ip}"; then
35+
# Timeout is set to 60 by default to avoid issues with STP default values
36+
# (15 second listening, 15 seconds learning and 20 seconds for max age)
37+
if ! ipconfig -t 60 "ip=${ip}"; then
3638
echo "ERROR; Failed to configure network"
3739
echo " Falling back to interactive prompt"
3840
echo " You can try to fix the problem manually, log out when you are finished"

0 commit comments

Comments
 (0)