diff --git a/bin/cros_update_image.sh b/bin/cros_update_image.sh index 4ffe59ec1f..ebca9fbf83 100755 --- a/bin/cros_update_image.sh +++ b/bin/cros_update_image.sh @@ -66,10 +66,10 @@ if [[ ${PKGS/kernel/} != ${PKGS} ]]; then sudo dd if="./rootfs/boot/vmlinuz" of=part_2 bs=512 count=8192 conv=notrunc fi -sudo umount rootfs/usr/local -sudo umount rootfs/var -sudo umount rootfs -sudo umount stateful_part +safe_umount rootfs/usr/local +safe_umount rootfs/var +safe_umount rootfs +safe_umount stateful_part ./pack_partitions.sh ${IMAGE} cd - diff --git a/build_library/disk_layout_util.sh b/build_library/disk_layout_util.sh index 29ce67cd85..e75c07dac2 100644 --- a/build_library/disk_layout_util.sh +++ b/build_library/disk_layout_util.sh @@ -64,7 +64,7 @@ run_partition_script() { sudo mount -o loop "${root_fs_img}" "${root_fs_dir}" . "${root_fs_dir}/${PARTITION_SCRIPT_PATH}" write_partition_table "${outdev}" "${pmbr_img}" - sudo umount "${root_fs_dir}" + safe_umount "${root_fs_dir}" } get_fs_block_size() { diff --git a/common.sh b/common.sh index 78a0cc3f8b..7693d6ea84 100644 --- a/common.sh +++ b/common.sh @@ -705,7 +705,33 @@ safe_umount_tree() { # Run umount as root. safe_umount() { - $([[ ${UID:-$(id -u)} != 0 ]] && echo sudo) umount "$@" + local ret=0 + local out="" + set +e + for i in $(seq 1 4); do + out=`$([[ ${UID:-$(id -u)} != 0 ]] && echo sudo) umount "$@" 2>&1` + ret=$? + if [[ $ret -eq 0 ]]; then + set -e + return 0 + fi + # Mount is not found + if [[ `expr index "${out}" "not found"` -ne "0" ]]; then + set -e + return 0 + fi + # Mount is not mounted. + if [[ `expr index "${out}" "not mounted"` -ne "0" ]]; then + set -e + return 0 + fi + sleep 1 + # Mount is actually busy. + if [[ `expr index "${out}" "busy"` -ne "0" ]]; then + continue + fi + done + return $ret } get_git_id() {