3 # args: source, newroot, mountpoint
8 local img_fullname="${img##*/}";
9 local img_name="${img_fullname%%.*}"
10 local dm_snap_name="${dm_snap_prefix}_${img_name}"
11 local ro_dev ro_dev_size rw_dev
13 ro_dev="$(losetup --find --show --read-only -- "${img}")"
14 echo "${ro_dev}" >> /run/archiso/used_block_devices
15 ro_dev_size="$(blockdev --getsz -- "${ro_dev}")"
17 if [ "${cow_persistent}" = "P" ]; then
18 if [ -f "/run/archiso/cowspace/${cow_directory}/${img_name}.cow" ]; then
19 msg ":: Found '/run/archiso/cowspace/${cow_directory}/${img_name}.cow', using as persistent."
21 msg ":: Creating '/run/archiso/cowspace/${cow_directory}/${img_name}.cow' as persistent."
22 truncate -s "${cow_spacesize}" "/run/archiso/cowspace/${cow_directory}/${img_name}.cow"
25 if [ -f "/run/archiso/cowspace/${cow_directory}/${img_name}.cow" ]; then
26 msg ":: Found '/run/archiso/cowspace/${cow_directory}/${img_name}.cow' but non-persistent requested, removing."
27 rm -f "/run/archiso/cowspace/${cow_directory}/${img_name}.cow"
29 msg ":: Creating '/run/archiso/cowspace/${cow_directory}/${img_name}.cow' as non-persistent."
30 truncate -s "${cow_spacesize}" "/run/archiso/cowspace/${cow_directory}/${img_name}.cow"
33 rw_dev="$(losetup --find --show "/run/archiso/cowspace/${cow_directory}/${img_name}.cow")"
34 echo "${rw_dev}" >> /run/archiso/used_block_devices
36 dmsetup create "${dm_snap_name}" --table \
37 "0 ${ro_dev_size} snapshot ${ro_dev} ${rw_dev} ${cow_persistent} ${cow_chunksize}"
39 if [ "${cow_persistent}" != "P" ]; then
40 rm -f "/run/archiso/cowspace/${cow_directory}/${img_name}.cow"
43 _mnt_dev "/dev/mapper/${dm_snap_name}" "${newroot}${mnt}" "-w" "defaults"
44 readlink -f "/dev/mapper/${dm_snap_name}" >> /run/archiso/used_block_devices
47 # args: source, newroot, mountpoint
52 mkdir -p "/run/archiso/cowspace/${cow_directory}/upperdir" "/run/archiso/cowspace/${cow_directory}/workdir"
54 "lowerdir=${src},upperdir=/run/archiso/cowspace/${cow_directory}/upperdir,workdir=/run/archiso/cowspace/${cow_directory}/workdir" \
55 airootfs "${newroot}${mnt}"
59 # args: /path/to/image_file, mountpoint
63 local img_fullname="${img##*/}"
66 # shellcheck disable=SC2154
67 # defined via initcpio's parse_cmdline()
68 if [ "${copytoram}" = "y" ]; then
69 msg -n ":: Copying squashfs image to RAM..."
70 if ! cp -- "${img}" "/run/archiso/copytoram/${img_fullname}" ; then
71 echo "ERROR: while copy '${img}' to '/run/archiso/copytoram/${img_fullname}'"
72 launch_interactive_shell
74 img="/run/archiso/copytoram/${img_fullname}"
77 sfs_dev="$(losetup --find --show --read-only -- "${img}")"
78 echo "${sfs_dev}" >> /run/archiso/used_block_devices
79 _mnt_dev "${sfs_dev}" "${mnt}" "-r" "defaults"
82 # args: device, mountpoint, flags, opts
91 msg ":: Mounting '${dev}' to '${mnt}'"
93 while ! poll_device "${dev}" 30; do
94 echo "ERROR: '${dev}' device did not show up after 30 seconds..."
95 echo " Falling back to interactive prompt"
96 echo " You can try to fix the problem manually, log out when you are finished"
97 launch_interactive_shell
100 if mount -o "${opts}" "${flg}" "${dev}" "${mnt}"; then
101 msg ":: Device '${dev}' mounted successfully."
103 echo "ERROR; Failed to mount '${dev}'"
104 echo " Falling back to interactive prompt"
105 echo " You can try to fix the problem manually, log out when you are finished"
106 launch_interactive_shell
112 cd "/run/archiso/bootmnt/${archisobasedir}/${arch}" || exit 1
113 sha512sum -c airootfs.sha512 > /tmp/checksum.log 2>&1
115 cd -- "${OLDPWD}" || exit 1
119 _verify_signature() {
121 cd "/run/archiso/bootmnt/${archisobasedir}/${arch}" || exit 1
122 gpg --homedir /gpg --status-fd 1 --verify airootfs.sfs.sig 2>/dev/null | grep -qE '^\[GNUPG:\] GOODSIG'
124 cd -- "${OLDPWD}" || exit 1
129 [ -z "${arch}" ] && arch="$(uname -m)"
130 [ -z "${copytoram_size}" ] && copytoram_size="75%"
131 [ -z "${archisobasedir}" ] && archisobasedir="arch"
132 [ -z "${dm_snap_prefix}" ] && dm_snap_prefix="arch"
133 # shellcheck disable=SC2154
134 # defined via initcpio's parse_cmdline()
135 [ -z "${archisodevice}" ] && archisodevice="/dev/disk/by-label/${archisolabel}"
136 [ -z "${cow_spacesize}" ] && cow_spacesize="256M"
137 # shellcheck disable=SC2154
138 # defined via initcpio's parse_cmdline()
139 if [ -n "${cow_label}" ]; then
140 cow_device="/dev/disk/by-label/${cow_label}"
141 [ -z "${cow_persistent}" ] && cow_persistent="P"
142 elif [ -n "${cow_device}" ]; then
143 [ -z "${cow_persistent}" ] && cow_persistent="P"
148 [ -z "${cow_flags}" ] && cow_flags="defaults"
149 [ -z "${cow_directory}" ] && cow_directory="persistent_${archisolabel}/${arch}"
150 [ -z "${cow_chunksize}" ] && cow_chunksize="8"
152 # set mount handler for archiso
153 export mount_handler="archiso_mount_handler"
156 # This function is called normally from init script, but it can be called
157 # as chain from other mount handlers.
158 # args: /path/to/newroot
159 archiso_mount_handler() {
162 if ! mountpoint -q "/run/archiso/bootmnt"; then
163 _mnt_dev "${archisodevice}" "/run/archiso/bootmnt" "-r" "defaults"
164 if [ "${copytoram}" != "y" ]; then
165 readlink -f "${archisodevice}" >> /run/archiso/used_block_devices
169 # shellcheck disable=SC2154
170 # defined via initcpio's parse_cmdline()
171 if [ "${checksum}" = "y" ]; then
172 if [ -f "/run/archiso/bootmnt/${archisobasedir}/${arch}/airootfs.sha512" ]; then
173 msg -n ":: Self-test requested, please wait..."
174 if _verify_checksum; then
175 msg "done. Checksum is OK, continue booting."
177 echo "ERROR: one or more files are corrupted"
178 echo "see /tmp/checksum.log for details"
179 launch_interactive_shell
182 echo "ERROR: checksum=y option specified but ${archisobasedir}/${arch}/airootfs.sha512 not found"
183 launch_interactive_shell
187 # shellcheck disable=SC2154
188 # defined via initcpio's parse_cmdline()
189 if [ "${verify}" = "y" ]; then
190 if [ -f "/run/archiso/bootmnt/${archisobasedir}/${arch}/airootfs.sfs.sig" ]; then
191 msg -n ":: Signature verification requested, please wait..."
192 if _verify_signature; then
193 msg "done. Signature is OK, continue booting."
195 echo "ERROR: one or more files are corrupted"
196 launch_interactive_shell
199 echo "ERROR: verify=y option specified but ${archisobasedir}/${arch}/airootfs.sfs.sig not found"
200 launch_interactive_shell
204 if [ "${copytoram}" = "y" ]; then
205 msg ":: Mounting /run/archiso/copytoram (tmpfs) filesystem, size=${copytoram_size}"
206 mkdir -p /run/archiso/copytoram
207 mount -t tmpfs -o "size=${copytoram_size}",mode=0755 copytoram /run/archiso/copytoram
210 if [ -n "${cow_device}" ]; then
211 _mnt_dev "${cow_device}" "/run/archiso/cowspace" "-r" "${cow_flags}"
212 readlink -f "${cow_device}" >> /run/archiso/used_block_devices
213 mount -o remount,rw "/run/archiso/cowspace"
215 msg ":: Mounting /run/archiso/cowspace (tmpfs) filesystem, size=${cow_spacesize}..."
216 mkdir -p /run/archiso/cowspace
217 mount -t tmpfs -o "size=${cow_spacesize}",mode=0755 cowspace /run/archiso/cowspace
219 mkdir -p "/run/archiso/cowspace/${cow_directory}"
220 chmod 0700 "/run/archiso/cowspace/${cow_directory}"
222 _mnt_sfs "/run/archiso/bootmnt/${archisobasedir}/${arch}/airootfs.sfs" "/run/archiso/sfs/airootfs"
223 if [ -f "/run/archiso/sfs/airootfs/airootfs.img" ]; then
224 _mnt_dmsnapshot "/run/archiso/sfs/airootfs/airootfs.img" "${newroot}" "/"
226 _mnt_overlayfs "/run/archiso/sfs/airootfs" "${newroot}" "/"
229 if [ "${copytoram}" = "y" ]; then
230 umount -d /run/archiso/bootmnt