11.1Schopps#!/bin/sh 21.1Schopps# 31.6Sgutterid# $NetBSD: resize_root,v 1.6 2023/10/04 00:04:42 gutteridge 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.4Sjmcneill ROOT\.*) fs_spec="/dev/$(sysctl -n kern.root_device)${fs_spec#ROOT.}" ;; 491.1Schopps esac 501.1Schopps 511.1Schopps # skip non-root 521.1Schopps if [ "${fs_file}" != "$rootmp" ]; then 531.1Schopps continue 541.1Schopps fi 551.1Schopps 561.1Schopps if [ "${fs_vfstype}" != "ffs" ]; then 571.1Schopps echo "Not resizing $rootmp: not an ffs file system" 581.1Schopps return 591.1Schopps fi 601.1Schopps 611.1Schopps case "${fs_spec}" in 621.1Schopps *:*) 631.1Schopps echo "Not resizing $rootmp: network mount" 641.1Schopps return 651.1Schopps ;; 661.1Schopps esac 671.1Schopps 681.1Schopps for opt in $(split_options "${fs_mntops}"); do 691.1Schopps if [ "$opt" = "log" ]; then 701.1Schopps echo "Not resizing $rootmp: logging unsupported" 711.1Schopps return 721.1Schopps fi 731.1Schopps done 741.1Schopps 751.5Sjmcneill rootdev=${fs_spec} 761.1Schopps break 771.1Schopps done < "${fstab_file}" 781.1Schopps 791.1Schopps if [ -z "$rootdev" ]; then 801.1Schopps echo "Not resizing $rootmp: not listed in ${fstab_file}" 811.1Schopps return 821.1Schopps fi 831.1Schopps 841.5Sjmcneill if resize_ffs -c "$rootdev"; then 851.5Sjmcneill echo "Resizing $rootmp ($rootdev)" 861.6Sgutterid if ! resize_ffs -y $resize_root_flags "$rootdev"; then 871.1Schopps echo "Error resizing root." 881.1Schopps stop_boot 891.1Schopps fi 901.2Sjmcneill if [ ! -z "${resize_root_postcmd}" ]; then 911.2Sjmcneill ${resize_root_postcmd} 921.2Sjmcneill fi 931.1Schopps else 941.5Sjmcneill echo "Not resizing $rootmp ($rootdev): already correct size" 951.1Schopps fi 961.1Schopps return 971.1Schopps} 981.1Schopps 991.1Schoppsload_rc_config $name 1001.1Schoppsrun_rc_command "$1" 101