Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 4 May 2014 17:42:37 -0700
From:      John-Mark Gurney <jmg@funkthat.com>
To:        freebsd-rc@FreeBSD.org
Subject:   growfs rc script...
Message-ID:  <20140505004237.GP43976@funkthat.com>

next in thread | raw e-mail | index | archive | help

--pwWdILMQNxDD/Cps
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

Crochet uses a script to grow the FS so that images can be smaller and
used with different sizes of SD cards...

Crochet hard coded the devices to resize, so I have taken the script
and made it such that it will work on any set of partitions to resize
the root fs...

I think it'd be useful to integrate this into base...  Though it
probably does need some tweeks before committing..

Comments?

Thanks.

-- 
  John-Mark Gurney				Voice: +1 415 225 5579

     "All that I will do, has been done, All that I have, has not."

--pwWdILMQNxDD/Cps
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename=growfs

#!/bin/sh

# PROVIDE: growfs
# BEFORE: sysctl
# KEYWORD: firstbootonly

# Automatically grow / to fill the entire disk.
#
# This allows us to distribute a single image
# and have it work on essentially any sized disk.
#
# TODO: Figure out a clean way to have this run
# only on first boot.  (We can't write anything to
# disk here since the root disk is still mounted
# read-only at this point.)  Fortunately, it completes
# very quickly if it can't actually grow the partition.
#
# TODO: Figure out where this should really be ordered.
# I suspect it should go just after fsck but before mountcritlocal
# but it's hard to tell for sure because of the bug described
# below.
# 

. /etc/rc.subr

name="growfs"
start_cmd="growfs_start"
stop_cmd=":"
rcvar="growfs_enable"

growfs_start ()
{
    echo "Growing root partition to fill device"
    rootdev=$(df / | tail -n 1 | awk '{ sub("/dev/", "", $1); print $1 }')
    if [ x"$rootdev" = x"${rootdev%/*}" ]; then
        # raw device
        rawdev="$rootdev"
    else
        rawdev=$(glabel status | awk '$1 == "'"$rootdev"'" { print $3 }')
        if [ x"$rawdev" = x"" ]; then
            echo "Can't figure out device for: $rootdev"
            return
        fi
    fi

    sysctl -b kern.geom.conftxt | awk '
{
        lvl=$1
        device[lvl] = $3
        type[lvl] = $2
        idx[lvl] = $7
        if (dev == $3) {
                for (i = 1; i <= lvl; i++) {
                        # resize
                        if (type[i] == "PART") {
                                pdev = device[i - 1]
				cmd[i] = "gpart resize -i " idx[i] " " pdev
                        } else if (type[i] == "LABEL") {
                                continue
                        } else {
                                print "unhandled type: " type[i]
                                exit 1
                        }
                }
		for (i = 1; i <= lvl; i++) {
			if (cmd[i])
				system(cmd[i])
		}
                exit 0
        }
}' dev="$rawdev"
    growfs -y /dev/"$rootdev"
}

load_rc_config $name
run_rc_command "$1"

--pwWdILMQNxDD/Cps--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20140505004237.GP43976>