Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sync disks before freeing loop device #7593

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/functions/image/loop.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ function check_loop_device_internal() {
if [[ $CONTAINER_COMPAT == yes && -b "/tmp/${device}" ]]; then
display_alert "Creating device node" "${device}"
run_host_command_logged mknod -m0660 "${device}" b "0x$(stat -c '%t' "/tmp/${device}")" "0x$(stat -c '%T' "/tmp/${device}")"
wait_for_disk_sync
if [[ ! -b "${device}" ]]; then # try again after creating node
return 1 # fail, it will be retried, and should exist on next retry.
else
Expand Down Expand Up @@ -114,5 +115,7 @@ function free_loop_device_retried() {
if [[ ${RETRY_RUNS} -gt 1 ]]; then
display_alert "Freeing loop device (try ${RETRY_RUNS})" "${1}"
fi
losetup -d "${1}"
# check if the device (still) exists / needs to be freed
[[ ! -f "${1}" ]] && return 0;
losetup -d "${1}" || (display_alert "losetup -d ${1} - return code:" "$?"; return 1)
}
10 changes: 8 additions & 2 deletions lib/functions/image/partitioning.sh
Original file line number Diff line number Diff line change
Expand Up @@ -252,15 +252,21 @@ function prepare_partitions() {

# stage: mount image
# lock access to loop devices
if [[ -z $LOOP ]]; then
if [[ -z "${LOOP}" ]]; then
exec {FD}> /var/lock/armbian-debootstrap-losetup
flock -x $FD

LOOP=$(losetup -f)
[[ -z $LOOP ]] && exit_with_error "Unable to find free loop device"
display_alert "Allocated loop device" "LOOP=${LOOP}"


check_loop_device "${LOOP}"
losetup $LOOP ${SDCARD}.raw
run_host_command_logged losetup "${LOOP}" || true

losetup --partscan "${LOOP}" ${SDCARD}.raw

run_host_command_logged losetup "${LOOP}" || true

# loop device was grabbed here, unlock
flock -u $FD
Expand Down