1 1.1 chopps #!/bin/sh 2 1.1 chopps # 3 1.2 jmcneill # $NetBSD: resize_root,v 1.2 2015/04/06 22:40:09 jmcneill 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.1 chopps esac 49 1.1 chopps 50 1.1 chopps # skip non-root 51 1.1 chopps if [ "${fs_file}" != "$rootmp" ]; then 52 1.1 chopps continue 53 1.1 chopps fi 54 1.1 chopps 55 1.1 chopps if [ "${fs_vfstype}" != "ffs" ]; then 56 1.1 chopps echo "Not resizing $rootmp: not an ffs file system" 57 1.1 chopps return 58 1.1 chopps fi 59 1.1 chopps 60 1.1 chopps case "${fs_spec}" in 61 1.1 chopps *:*) 62 1.1 chopps echo "Not resizing $rootmp: network mount" 63 1.1 chopps return 64 1.1 chopps ;; 65 1.1 chopps esac 66 1.1 chopps 67 1.1 chopps for opt in $(split_options "${fs_mntops}"); do 68 1.1 chopps if [ "$opt" = "log" ]; then 69 1.1 chopps echo "Not resizing $rootmp: logging unsupported" 70 1.1 chopps return 71 1.1 chopps fi 72 1.1 chopps done 73 1.1 chopps 74 1.1 chopps rootdev=${fs_spec%/*}/r${fs_spec##*/} 75 1.1 chopps break 76 1.1 chopps done < "${fstab_file}" 77 1.1 chopps 78 1.1 chopps if [ -z "$rootdev" ]; then 79 1.1 chopps echo "Not resizing $rootmp: not listed in ${fstab_file}" 80 1.1 chopps return 81 1.1 chopps fi 82 1.1 chopps 83 1.1 chopps if resize_ffs -c $rootdev; then 84 1.1 chopps echo "Resizing $rootmp" 85 1.2 jmcneill if ! resize_ffs -p $resize_root_flags $rootdev; then 86 1.1 chopps echo "Error resizing root." 87 1.1 chopps stop_boot 88 1.1 chopps fi 89 1.2 jmcneill if [ ! -z "${resize_root_postcmd}" ]; then 90 1.2 jmcneill ${resize_root_postcmd} 91 1.2 jmcneill fi 92 1.1 chopps else 93 1.1 chopps echo "Not resizing $rootmp: already correct size" 94 1.1 chopps fi 95 1.1 chopps return 96 1.1 chopps } 97 1.1 chopps 98 1.1 chopps load_rc_config $name 99 1.1 chopps run_rc_command "$1" 100