do not umount root, remount it. do not mount ro if not specified

also mount /usr readonly if "ro" is specified on the command line
if /usr is a btrfs subvolume of root, use the same mount options
master
Harald Hoyer 2012-06-30 11:29:30 +02:00
parent 0e95d84892
commit 7209df9e91
3 changed files with 22 additions and 13 deletions

View File

@ -15,7 +15,6 @@ filter_rootopts() {
local v
while [ $# -gt 0 ]; do
case $1 in
rw|ro);;
defaults);;
*)
v="$v,${1}";;
@ -82,7 +81,7 @@ mount_root() {
# the root filesystem,
# remount it with the proper options
rootopts="defaults"
while read dev mp fs opts rest; do
while read dev mp fs opts dump fsck; do
# skip comments
[ "${dev%%#*}" != "$dev" ] && continue

@ -90,6 +89,7 @@ mount_root() {
# sanity - determine/fix fstype
rootfs=$(det_fs "${root#block:}" "$fs")
rootopts=$opts
rootfsck=$fsck
break
fi
done < "$NEWROOT/etc/fstab"
@ -99,28 +99,26 @@ mount_root() {

# we want rootflags (rflags) to take precedence so prepend rootopts to
# them; rflags is guaranteed to not be empty
rflags="${rootopts:+"${rootopts},"}${rflags}"
rflags="${rootopts:+${rootopts},}${rflags}"

# backslashes are treated as escape character in fstab
# esc_root=$(echo ${root#block:} | sed 's,\\,\\\\,g')
# printf '%s %s %s %s 1 1 \n' "$esc_root" "$NEWROOT" "$rootfs" "$rflags" >/etc/fstab

ran_fsck=0
if [ -z "$fastboot" -a "$READONLY" != "yes" ] && \
! strstr "${rflags},${rootopts}" _netdev && \
if [ "$rootfsck" != "0" -a -z "$fastboot" -a "$READONLY" != "yes" ] && \
! strstr "${rflags}" _netdev && \
! getargbool 0 rd.skipfsck; then
umount "$NEWROOT"
fsck_single "${root#block:}" "$rootfs" "$rflags" "$fsckoptions"
_ret=$?
[ $_ret -ne 255 ] && echo $_ret >/run/initramfs/root-fsck
ran_fsck=1
fi

if [ -n "$rootopts" -o "$ran_fsck" = "1" ]; then
info "Remounting ${root#block:} with -o ${rflags}"
umount "$NEWROOT" &>/dev/null
mount -t "$rootfs" -o "$rflags" "${root#block:}" "$NEWROOT" 2>&1 | vinfo
fi
echo "${root#block:} $NEWROOT $rootfs ${rflags:-defaults} 0 $rootfsck" >> /etc/fstab

info "Remounting ${root#block:} with -o ${rflags}"
mount -o remount "$NEWROOT" 2>&1 | vinfo

[ -f "$NEWROOT"/forcefsck ] && rm -f "$NEWROOT"/forcefsck 2>/dev/null
[ -f "$NEWROOT"/.autofsck ] && rm -f "$NEWROOT"/.autofsck 2>/dev/null

View File

@ -52,6 +52,15 @@ mount_usr()
_dev="/dev/disk/by-uuid/${_dev#UUID=}"
;;
esac
if strstr "$_opts" "subvol=" && \
[ "${root#block:}" -ef $_dev ]
[ -n "$rflags" ]; then
# for btrfs subvolumes we have to mount /usr with the same rflags
_opts="${_opts:+${_opts},}${rflags}"
elif getarg ro; then
# if "ro" is specified, we want /usr to be readonly, too
_opts="${_opts:+${_opts},}ro"
fi
echo "$_dev ${NEWROOT}${_mp} $_fs ${_opts} $_freq $_passno"
_usr_found="1"
break

View File

@ -5,9 +5,11 @@
root=$(getarg root=)

if rflags="$(getarg rootflags=)"; then
getarg rw && rflags="${rflags},rw" || rflags="${rflags},ro"
getarg rw && rflags="${rflags},rw"
getarg ro && rflags="${rflags},ro"
else
getarg rw && rflags=rw || rflags=ro
getarg rw && rflags=rw
getarg ro && rflags=ro
fi

fstype="$(getarg rootfstype=)"