Skip to content

Commit

Permalink
Add mount failed attempt
Browse files Browse the repository at this point in the history
  • Loading branch information
ophub committed Apr 12, 2023
1 parent 568e720 commit 01879aa
Showing 1 changed file with 35 additions and 5 deletions.
40 changes: 35 additions & 5 deletions make
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#
# error_msg : Output error message
# process_msg : Output process message
# mount_again : Mount the image file, fail again
# get_textoffset : Get kernel TEXT_OFFSET
#
# init_var : Initialize all variables
Expand Down Expand Up @@ -120,6 +121,37 @@ process_msg() {
echo -e " [\033[1;92m ${board} - ${kernel} \033[0m] ${1}"
}

mount_again() {
# Check mount parameters
m_type="${1}"
m_dev="${2}"
m_target="${3}"
[[ -n "${m_type}" && -n "${m_dev}" && -n "${m_target}" ]] || {
error_msg "Mount parameter is missing: [ ${m_type}, ${m_dev}, ${m_target} ]"
}

i="1"
max_try="10"
while [[ "${i}" -le "${max_try}" ]]; do
# Mount according to the image partition format
if [[ "${m_type}" == "btrfs" ]]; then
mount -t ${m_type} -o discard,compress=zstd:6 ${m_dev} ${m_target}
else
mount -t ${m_type} -o discard ${m_dev} ${m_target}
fi

# Mount failed and continue trying
if [[ "${?}" -eq "0" ]]; then
break
else
sync && sleep 3
umount -f ${m_target} 2>/dev/null
i="$((i + 1))"
fi
done
[[ "${i}" -gt "${max_try}" ]] && error_msg "[ ${i} ] attempts to mount failed."
}

get_textoffset() {
vmlinuz_name="${1}"
need_overload="yes"
Expand Down Expand Up @@ -620,15 +652,13 @@ extract_openwrt() {

# Mount bootfs
if [[ "${bootfs_type}" == "fat32" ]]; then
mount -t vfat -o discard ${loop_new}p1 ${tag_bootfs}
mount_again vfat ${loop_new}p1 ${tag_bootfs}
else
mount -t ext4 -o discard ${loop_new}p1 ${tag_bootfs}
mount_again ext4 ${loop_new}p1 ${tag_bootfs}
fi
[[ "${?}" -eq "0" ]] || error_msg "mount ${loop_new}p1 failed!"

# Mount rootfs
mount -t btrfs -o discard,compress=zstd:6 ${loop_new}p2 ${tag_rootfs}
[[ "${?}" -eq "0" ]] || error_msg "mount ${loop_new}p2 failed!"
mount_again btrfs ${loop_new}p2 ${tag_rootfs}

# Create snapshot directory
btrfs subvolume create ${tag_rootfs}/etc >/dev/null 2>&1
Expand Down

0 comments on commit 01879aa

Please sign in to comment.