Home | History | Annotate | Line # | Download | only in rc.d
resize_root revision 1.3.16.1
      1       1.1    chopps #!/bin/sh
      2       1.1    chopps #
      3  1.3.16.1  pgoyette # $NetBSD: resize_root,v 1.3.16.1 2018/10/20 06:58:19 pgoyette Exp $
      4       1.1    chopps #
      5       1.1    chopps 
      6       1.1    chopps # PROVIDE: resize_root
      7       1.1    chopps # REQUIRE: fsck_root
      8       1.2  jmcneill # KEYWORD: interactive
      9       1.1    chopps 
     10       1.1    chopps $_rc_subr_loaded . /etc/rc.subr
     11       1.1    chopps 
     12       1.1    chopps name="resize_root"
     13       1.1    chopps rcvar=$name
     14       1.1    chopps start_cmd="resize_root_start"
     15       1.1    chopps stop_cmd=":"
     16       1.1    chopps fstab_file=/etc/fstab
     17       1.1    chopps rootmp="/"
     18       1.1    chopps 
     19       1.1    chopps split_options()
     20       1.1    chopps {
     21       1.1    chopps 	local IFS
     22       1.1    chopps 	IFS=,
     23       1.1    chopps 	OPTS=$1
     24       1.1    chopps 	for i in $OPTS; do
     25       1.1    chopps 		echo $i
     26       1.1    chopps 	done
     27       1.1    chopps }
     28       1.1    chopps 
     29       1.1    chopps resize_root_start()
     30       1.1    chopps {
     31       1.1    chopps 	# if ! checkyesno $rcvar; then
     32       1.1    chopps 	# 	echo "Not resizing $rootmp: resize_root must be set to YES/yes/..."
     33       1.1    chopps 	# 	return
     34       1.1    chopps 	# fi
     35       1.1    chopps 
     36       1.1    chopps 	trap : 2 		# Ignore SIGINT, SIGQUIT, so we
     37       1.1    chopps 	trap : 3		# enter single-user mode on failure.
     38       1.1    chopps 
     39       1.1    chopps 	# Do nothing if root file system is not mentioned in /etc/fstab, or if
     40       1.1    chopps 	# root file system seems to be a network mount, or if root file system
     41       1.1    chopps 	# is not ffs or if logging is enabled.
     42       1.1    chopps 	rootdev=""
     43       1.1    chopps 	while read fs_spec fs_file fs_vfstype fs_mntops fs_freq fs_passno
     44       1.1    chopps 	do
     45       1.1    chopps 		# skip comment or blank line
     46       1.1    chopps 		case "${fs_spec}" in
     47       1.1    chopps 		\#*|'') continue ;;
     48  1.3.16.1  pgoyette 		ROOT\.*) fs_spec="/dev/$(sysctl -n kern.root_device)${fs_spec#ROOT.}" ;;
     49       1.1    chopps 		esac
     50       1.1    chopps 
     51       1.1    chopps 		# skip non-root
     52       1.1    chopps 		if [ "${fs_file}" != "$rootmp" ]; then
     53       1.1    chopps 			continue
     54       1.1    chopps 		fi
     55       1.1    chopps 
     56       1.1    chopps 		if [ "${fs_vfstype}" != "ffs" ]; then
     57       1.1    chopps 			echo "Not resizing $rootmp: not an ffs file system"
     58       1.1    chopps 			return
     59       1.1    chopps 		fi
     60       1.1    chopps 
     61       1.1    chopps 		case "${fs_spec}" in
     62       1.1    chopps 		*:*)
     63       1.1    chopps 			echo "Not resizing $rootmp: network mount"
     64       1.1    chopps 			return
     65       1.1    chopps 			;;
     66       1.1    chopps 		esac
     67       1.1    chopps 
     68       1.1    chopps 		for opt in $(split_options "${fs_mntops}"); do
     69       1.1    chopps 			if [ "$opt" = "log" ];  then
     70       1.1    chopps 				echo "Not resizing $rootmp: logging unsupported"
     71       1.1    chopps 				return
     72       1.1    chopps 			fi
     73       1.1    chopps 		done
     74       1.1    chopps 
     75       1.1    chopps 		rootdev=${fs_spec%/*}/r${fs_spec##*/}
     76       1.1    chopps 		break
     77       1.1    chopps 	done < "${fstab_file}"
     78       1.1    chopps 
     79       1.1    chopps 	if [ -z "$rootdev" ]; then
     80       1.1    chopps 		echo "Not resizing $rootmp: not listed in ${fstab_file}"
     81       1.1    chopps 		return
     82       1.1    chopps 	fi
     83       1.1    chopps 
     84       1.1    chopps 	if resize_ffs -c $rootdev; then
     85       1.1    chopps 		echo "Resizing $rootmp"
     86       1.3  jmcneill 		if ! resize_ffs -y $resize_root_flags $rootdev; then
     87       1.1    chopps 		    echo "Error resizing root."
     88       1.1    chopps 		    stop_boot
     89       1.1    chopps 		fi
     90       1.2  jmcneill 		if [ ! -z "${resize_root_postcmd}" ]; then
     91       1.2  jmcneill 			${resize_root_postcmd}
     92       1.2  jmcneill 		fi
     93       1.1    chopps 	else
     94       1.1    chopps 		echo "Not resizing $rootmp: already correct size"
     95       1.1    chopps 	fi
     96       1.1    chopps 	return
     97       1.1    chopps }
     98       1.1    chopps 
     99       1.1    chopps load_rc_config $name
    100       1.1    chopps run_rc_command "$1"
    101