Module Name:    src
Committed By:   chopps
Date:           Mon Mar 30 10:58:37 UTC 2015

Modified Files:
        src/distrib/sets/lists/etc: mi
        src/etc/defaults: rc.conf
        src/etc/rc.d: Makefile root
        src/share/man/man5: rc.conf.5
Added Files:
        src/etc/rc.d: resize_root

Log Message:
Add resize_root boot operation. If resize_root=YES in rc.conf then
the system attempts to resize the root file system to fill it's
partition prior to mounting read-write. Useful for things like AMI
file system images. May eventually be used by arm images after
coming up with similar solution for increasing the parition size.


To generate a diff of this commit:
cvs rdiff -u -r1.236 -r1.237 src/distrib/sets/lists/etc/mi
cvs rdiff -u -r1.132 -r1.133 src/etc/defaults/rc.conf
cvs rdiff -u -r1.92 -r1.93 src/etc/rc.d/Makefile
cvs rdiff -u -r0 -r1.1 src/etc/rc.d/resize_root
cvs rdiff -u -r1.4 -r1.5 src/etc/rc.d/root
cvs rdiff -u -r1.157 -r1.158 src/share/man/man5/rc.conf.5

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/distrib/sets/lists/etc/mi
diff -u src/distrib/sets/lists/etc/mi:1.236 src/distrib/sets/lists/etc/mi:1.237
--- src/distrib/sets/lists/etc/mi:1.236	Sat Mar 21 19:10:43 2015
+++ src/distrib/sets/lists/etc/mi	Mon Mar 30 10:58:37 2015
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.236 2015/03/21 19:10:43 jmcneill Exp $
+# $NetBSD: mi,v 1.237 2015/03/30 10:58:37 chopps Exp $
 #
 # Note: end-user configuration files that are moved to another location
 #	should not be marked "obsolete"; they should just be removed from
@@ -266,6 +266,7 @@
 ./etc/rc.d/random_seed				etc-sys-rc
 ./etc/rc.d/rarpd				etc-bootserver-rc
 ./etc/rc.d/rbootd				etc-bootserver-rc
+./etc/rc.d/resize_root				etc-sys-rc
 ./etc/rc.d/rndctl				etc-sys-rc
 ./etc/rc.d/root					etc-sys-rc
 ./etc/rc.d/route6d				etc-router-rc

Index: src/etc/defaults/rc.conf
diff -u src/etc/defaults/rc.conf:1.132 src/etc/defaults/rc.conf:1.133
--- src/etc/defaults/rc.conf:1.132	Sat Mar 21 19:10:43 2015
+++ src/etc/defaults/rc.conf	Mon Mar 30 10:58:37 2015
@@ -1,4 +1,4 @@
-#	$NetBSD: rc.conf,v 1.132 2015/03/21 19:10:43 jmcneill Exp $
+#	$NetBSD: rc.conf,v 1.133 2015/03/30 10:58:37 chopps Exp $
 #
 # /etc/defaults/rc.conf --
 #	default configuration of /etc/rc.conf
@@ -120,6 +120,7 @@ lvm=NO
 #
 savecore=YES		savecore_flags="-z"
 			savecore_dir="/var/crash"
+resize_root=NO					# resize root to fill partition
 per_user_tmp=NO					# per-user /tmp directories
 per_user_tmp_dir="/private/tmp"			# real storage for /tmp
 clear_tmp=YES					# clear /tmp after reboot

Index: src/etc/rc.d/Makefile
diff -u src/etc/rc.d/Makefile:1.92 src/etc/rc.d/Makefile:1.93
--- src/etc/rc.d/Makefile:1.92	Sat Mar 21 19:10:43 2015
+++ src/etc/rc.d/Makefile	Mon Mar 30 10:58:37 2015
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.92 2015/03/21 19:10:43 jmcneill Exp $
+# $NetBSD: Makefile,v 1.93 2015/03/30 10:58:37 chopps Exp $
 
 .include <bsd.own.mk>
 
@@ -33,8 +33,8 @@ CONFIGFILES=\
 		perusertmp pf pf_boot pflogd postfix powerd ppp pwcheck \
 		quota \
 		racoon rpcbind raidframe raidframeparity random_seed rarpd \
-		rbootd rndctl root route6d routed rtadvd rtclocaltime \
-		rwho \
+		rbootd resize_root rndctl root route6d routed rtadvd \
+		rtclocaltime rwho \
 		savecore screenblank securelevel sshd \
 		staticroute swap1 swap2 sysctl sysdb syslogd \
 		timed tpctl ttys \

Index: src/etc/rc.d/root
diff -u src/etc/rc.d/root:1.4 src/etc/rc.d/root:1.5
--- src/etc/rc.d/root:1.4	Tue Apr 21 16:08:57 2009
+++ src/etc/rc.d/root	Mon Mar 30 10:58:37 2015
@@ -1,10 +1,10 @@
 #!/bin/sh
 #
-# $NetBSD: root,v 1.4 2009/04/21 16:08:57 joerg Exp $
+# $NetBSD: root,v 1.5 2015/03/30 10:58:37 chopps Exp $
 #
 
 # PROVIDE: root
-# REQUIRE: fsck_root
+# REQUIRE: fsck_root resize_root
 
 $_rc_subr_loaded . /etc/rc.subr
 

Index: src/share/man/man5/rc.conf.5
diff -u src/share/man/man5/rc.conf.5:1.157 src/share/man/man5/rc.conf.5:1.158
--- src/share/man/man5/rc.conf.5:1.157	Wed Jan 15 11:42:43 2014
+++ src/share/man/man5/rc.conf.5	Mon Mar 30 10:58:37 2015
@@ -1,4 +1,4 @@
-.\"	$NetBSD: rc.conf.5,v 1.157 2014/01/15 11:42:43 apb Exp $
+.\"	$NetBSD: rc.conf.5,v 1.158 2015/03/30 10:58:37 chopps Exp $
 .\"
 .\" Copyright (c) 1996 Matthew R. Green
 .\" All rights reserved.
@@ -320,6 +320,13 @@ unbootable even if the file system check
 Boolean value.
 Should be true if you have deliberately configured your system with no swap.
 If false and no swap devices are configured, the system will warn you.
+.It Sy resize_root
+Boolean value.
+Set to true to have the system resize the root file system to fill it's
+partition.
+Will only attempt to resize the root file system if it is of type ffs and does
+not have logging enabled.
+Defaults to false.
 .It Sy swapoff
 Boolean value.
 Remove block-type swap devices at shutdown time.

Added files:

Index: src/etc/rc.d/resize_root
diff -u /dev/null src/etc/rc.d/resize_root:1.1
--- /dev/null	Mon Mar 30 10:58:37 2015
+++ src/etc/rc.d/resize_root	Mon Mar 30 10:58:37 2015
@@ -0,0 +1,95 @@
+#!/bin/sh
+#
+# $NetBSD: resize_root,v 1.1 2015/03/30 10:58:37 chopps Exp $
+#
+
+# PROVIDE: resize_root
+# REQUIRE: fsck_root
+
+$_rc_subr_loaded . /etc/rc.subr
+
+name="resize_root"
+rcvar=$name
+start_cmd="resize_root_start"
+stop_cmd=":"
+fstab_file=/etc/fstab
+rootmp="/"
+
+split_options()
+{
+	local IFS
+	IFS=,
+	OPTS=$1
+	for i in $OPTS; do
+		echo $i
+	done
+}
+
+resize_root_start()
+{
+	# if ! checkyesno $rcvar; then
+	# 	echo "Not resizing $rootmp: resize_root must be set to YES/yes/..."
+	# 	return
+	# fi
+
+	trap : 2 		# Ignore SIGINT, SIGQUIT, so we
+	trap : 3		# enter single-user mode on failure.
+
+	# Do nothing if root file system is not mentioned in /etc/fstab, or if
+	# root file system seems to be a network mount, or if root file system
+	# is not ffs or if logging is enabled.
+	rootdev=""
+	while read fs_spec fs_file fs_vfstype fs_mntops fs_freq fs_passno
+	do
+		# skip comment or blank line
+		case "${fs_spec}" in
+		\#*|'') continue ;;
+		esac
+
+		# skip non-root
+		if [ "${fs_file}" != "$rootmp" ]; then
+			continue
+		fi
+
+		if [ "${fs_vfstype}" != "ffs" ]; then
+			echo "Not resizing $rootmp: not an ffs file system"
+			return
+		fi
+
+		case "${fs_spec}" in
+		*:*)
+			echo "Not resizing $rootmp: network mount"
+			return
+			;;
+		esac
+
+		for opt in $(split_options "${fs_mntops}"); do
+			if [ "$opt" = "log" ];  then
+				echo "Not resizing $rootmp: logging unsupported"
+				return
+			fi
+		done
+
+		rootdev=${fs_spec%/*}/r${fs_spec##*/}
+		break
+	done < "${fstab_file}"
+
+	if [ -z "$rootdev" ]; then
+		echo "Not resizing $rootmp: not listed in ${fstab_file}"
+		return
+	fi
+
+	if resize_ffs -c $rootdev; then
+		echo "Resizing $rootmp"
+		if ! resize_ffs -y $rootdev; then
+		    echo "Error resizing root."
+		    stop_boot
+		fi
+	else
+		echo "Not resizing $rootmp: already correct size"
+	fi
+	return
+}
+
+load_rc_config $name
+run_rc_command "$1"

Reply via email to