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