Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 29 Apr 2010 08:49:07 +0300
From:      Andriy Gapon <avg@freebsd.org>
To:        freebsd-hackers@freebsd.org
Subject:   [Fwd: rc.d/root: handle filesystems with r/o support only]
Message-ID:  <4BD91DD3.90108@freebsd.org>

next in thread | raw e-mail | index | archive | help

There was no excitement over the proposed patch on rc@, perhaps more luck here :-)

-------- Original Message --------
Subject: rc.d/root: handle filesystems with r/o support only
Date: Sat, 17 Apr 2010 22:16:30 +0300
From: Andriy Gapon <avg@icyb.net.ua>
To: freebsd-rc@freebsd.org


Could you please review the following patch?
The idea is to not try to remount root R/W if root filesystem supports only R/O.
For example, cd9660.
This should make life easier for live CDs that use standard rc startup.
Currently one has to either put a root fs entry into fstab (and thus guess root
device name, e.g. cd0 vs acd0) or to specify root_rw_mount="NO" in rc.conf.
This change attempts to guess that automatically.

I think that things like ro_fs_list, in_list and is_readonly_fs could be shared
with other rc scripts.
E.g. see http://www.freebsd.org/cgi/query-pr.cgi?pr=conf/116931

P.S. sorry if the code style and structure differs from conventions.

--- a/etc/rc.d/root
+++ b/etc/rc.d/root
@@ -13,11 +13,54 @@ name="root"
 start_cmd="root_start"
 stop_cmd=":"

+ro_fs_list="cd9660 udf"
+
+in_list()
+{
+	local _x _list _i
+
+	_x=$1
+	_list=$2
+	for _i in ${_list}; do
+		[ "${_x}" = "${_i}" ] && return 0
+	done
+	return 1
+}
+
+is_readonly_fs()
+{
+	local _arg _ret
+
+	_arg="$1" ; shift
+	_ret=`mount -p | while read _dev _mp _type _rest; do
+		[ $_mp  = "$_arg" ] || continue
+		echo $_type
+		break
+	done`
+
+	if [ -z "${_ret}" ]; then
+		warn "root filesystem not found"
+		return 1
+	fi
+	if in_list "${_ret}" "${ro_fs_list}"; then
+		info "read-only root filesystem type: ${_ret}"
+		return 0
+	else
+		info "read-write root filesystem type: ${_ret}"
+		return 1
+	fi
+}
+
 root_start()
 {
 	# root normally must be read/write, but if this is a BOOTP NFS
 	# diskless boot it does not have to be.
 	#
+
+	if is_readonly_fs '/' ; then
+		root_rw_mount="NO"
+	fi
+
 	case ${root_rw_mount} in
 	[Nn][Oo] | '')
 		;;

-- 
Andriy Gapon


-- 
Andriy Gapon



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?4BD91DD3.90108>