Skip to content

Commit

Permalink
remount-ro: nothing to do if device is already read-only
Browse files Browse the repository at this point in the history
  • Loading branch information
osresearch committed May 20, 2020
1 parent b0fdba7 commit 0533d1d
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions sbin/safeboot
Original file line number Diff line number Diff line change
Expand Up @@ -874,15 +874,17 @@ remount_ro()
{
DEV="${1:-${ROOTDEV}}"

warn "${DEV}: remounting read-only"
if [ "$(blockdev --getro "${DEV}")" == 1 ] ; then
warn "${DEV}: already read-only"
return 0
fi

warn "${DEV}: remounting read-only"
if mount -o ro,noatime,remount "${DEV}" ; then

if [ "$(blockdev --getro "${DEV}")" != 1 ] ; then
warn "${DEV}: forcing fsck"
fsck.ext4 -f "${DEV}" \
|| die "${DEV}: Could not fsck"
fi
warn "${DEV}: forcing fsck"
fsck.ext4 -f "${DEV}" \
|| die "${DEV}: Could not fsck"

warn "${DEV}: setting block dev readonly"
blockdev --setro "${DEV}" \
Expand Down

0 comments on commit 0533d1d

Please sign in to comment.