resize_root revision 1.3
11.1Schopps#!/bin/sh 21.1Schopps# 31.3Sjmcneill# $NetBSD: resize_root,v 1.3 2015/04/07 18:02:11 jmcneill Exp $ 41.1Schopps# 51.1Schopps 61.1Schopps# PROVIDE: resize_root 71.1Schopps# REQUIRE: fsck_root 81.2Sjmcneill# KEYWORD: interactive 91.1Schopps 101.1Schopps$_rc_subr_loaded . /etc/rc.subr 111.1Schopps 121.1Schoppsname="resize_root" 131.1Schoppsrcvar=$name 141.1Schoppsstart_cmd="resize_root_start" 151.1Schoppsstop_cmd=":" 161.1Schoppsfstab_file=/etc/fstab 171.1Schoppsrootmp="/" 181.1Schopps 191.1Schoppssplit_options() 201.1Schopps{ 211.1Schopps local IFS 221.1Schopps IFS=, 231.1Schopps OPTS=$1 241.1Schopps for i in $OPTS; do 251.1Schopps echo $i 261.1Schopps done 271.1Schopps} 281.1Schopps 291.1Schoppsresize_root_start() 301.1Schopps{ 311.1Schopps # if ! checkyesno $rcvar; then 321.1Schopps # echo "Not resizing $rootmp: resize_root must be set to YES/yes/..." 331.1Schopps # return 341.1Schopps # fi 351.1Schopps 361.1Schopps trap : 2 # Ignore SIGINT, SIGQUIT, so we 371.1Schopps trap : 3 # enter single-user mode on failure. 381.1Schopps 391.1Schopps # Do nothing if root file system is not mentioned in /etc/fstab, or if 401.1Schopps # root file system seems to be a network mount, or if root file system 411.1Schopps # is not ffs or if logging is enabled. 421.1Schopps rootdev="" 431.1Schopps while read fs_spec fs_file fs_vfstype fs_mntops fs_freq fs_passno 441.1Schopps do 451.1Schopps # skip comment or blank line 461.1Schopps case "${fs_spec}" in 471.1Schopps \#*|'') continue ;; 481.1Schopps esac 491.1Schopps 501.1Schopps # skip non-root 511.1Schopps if [ "${fs_file}" != "$rootmp" ]; then 521.1Schopps continue 531.1Schopps fi 541.1Schopps 551.1Schopps if [ "${fs_vfstype}" != "ffs" ]; then 561.1Schopps echo "Not resizing $rootmp: not an ffs file system" 571.1Schopps return 581.1Schopps fi 591.1Schopps 601.1Schopps case "${fs_spec}" in 611.1Schopps *:*) 621.1Schopps echo "Not resizing $rootmp: network mount" 631.1Schopps return 641.1Schopps ;; 651.1Schopps esac 661.1Schopps 671.1Schopps for opt in $(split_options "${fs_mntops}"); do 681.1Schopps if [ "$opt" = "log" ]; then 691.1Schopps echo "Not resizing $rootmp: logging unsupported" 701.1Schopps return 711.1Schopps fi 721.1Schopps done 731.1Schopps 741.1Schopps rootdev=${fs_spec%/*}/r${fs_spec##*/} 751.1Schopps break 761.1Schopps done < "${fstab_file}" 771.1Schopps 781.1Schopps if [ -z "$rootdev" ]; then 791.1Schopps echo "Not resizing $rootmp: not listed in ${fstab_file}" 801.1Schopps return 811.1Schopps fi 821.1Schopps 831.1Schopps if resize_ffs -c $rootdev; then 841.1Schopps echo "Resizing $rootmp" 851.3Sjmcneill if ! resize_ffs -y $resize_root_flags $rootdev; then 861.1Schopps echo "Error resizing root." 871.1Schopps stop_boot 881.1Schopps fi 891.2Sjmcneill if [ ! -z "${resize_root_postcmd}" ]; then 901.2Sjmcneill ${resize_root_postcmd} 911.2Sjmcneill fi 921.1Schopps else 931.1Schopps echo "Not resizing $rootmp: already correct size" 941.1Schopps fi 951.1Schopps return 961.1Schopps} 971.1Schopps 981.1Schoppsload_rc_config $name 991.1Schoppsrun_rc_command "$1" 100