head	1.5;
access;
symbols
	netbsd-11-0-RC4:1.5
	netbsd-11-0-RC3:1.5
	netbsd-11-0-RC2:1.5
	netbsd-11-0-RC1:1.5
	perseant-exfatfs-base-20250801:1.5
	netbsd-11:1.5.0.4
	netbsd-11-base:1.5
	netbsd-10-1-RELEASE:1.3
	perseant-exfatfs-base-20240630:1.5
	perseant-exfatfs:1.5.0.2
	perseant-exfatfs-base:1.5
	netbsd-8-3-RELEASE:1.2
	netbsd-9-4-RELEASE:1.3
	netbsd-10-0-RELEASE:1.3
	netbsd-10-0-RC6:1.3
	netbsd-10-0-RC5:1.3
	netbsd-10-0-RC4:1.3
	netbsd-10-0-RC3:1.3
	netbsd-10-0-RC2:1.3
	netbsd-10-0-RC1:1.3
	netbsd-10:1.3.0.10
	netbsd-10-base:1.3
	netbsd-9-3-RELEASE:1.3
	cjep_sun2x-base1:1.3
	cjep_sun2x:1.3.0.8
	cjep_sun2x-base:1.3
	cjep_staticlib_x-base1:1.3
	netbsd-9-2-RELEASE:1.3
	cjep_staticlib_x:1.3.0.6
	cjep_staticlib_x-base:1.3
	netbsd-9-1-RELEASE:1.3
	phil-wifi-20200421:1.3
	phil-wifi-20200411:1.3
	is-mlppp:1.3.0.4
	is-mlppp-base:1.3
	phil-wifi-20200406:1.3
	netbsd-8-2-RELEASE:1.2
	netbsd-9-0-RELEASE:1.3
	netbsd-9-0-RC2:1.3
	netbsd-9-0-RC1:1.3
	phil-wifi-20191119:1.3
	netbsd-9:1.3.0.2
	netbsd-9-base:1.3
	phil-wifi-20190609:1.3
	netbsd-8-1-RELEASE:1.2
	netbsd-8-1-RC1:1.2
	pgoyette-compat-merge-20190127:1.2.10.1
	pgoyette-compat-20190127:1.3
	pgoyette-compat-20190118:1.3
	pgoyette-compat-1226:1.3
	pgoyette-compat-1126:1.3
	pgoyette-compat-1020:1.3
	pgoyette-compat-0930:1.2
	pgoyette-compat-0906:1.2
	netbsd-7-2-RELEASE:1.1.2.2
	pgoyette-compat-0728:1.2
	netbsd-8-0-RELEASE:1.2
	phil-wifi:1.2.0.12
	phil-wifi-base:1.2
	pgoyette-compat-0625:1.2
	netbsd-8-0-RC2:1.2
	pgoyette-compat-0521:1.2
	pgoyette-compat-0502:1.2
	pgoyette-compat-0422:1.2
	netbsd-8-0-RC1:1.2
	pgoyette-compat-0415:1.2
	pgoyette-compat-0407:1.2
	pgoyette-compat-0330:1.2
	pgoyette-compat-0322:1.2
	pgoyette-compat-0315:1.2
	netbsd-7-1-2-RELEASE:1.1.2.2
	pgoyette-compat:1.2.0.10
	pgoyette-compat-base:1.2
	netbsd-7-1-1-RELEASE:1.1.2.2
	matt-nb8-mediatek:1.2.0.8
	matt-nb8-mediatek-base:1.2
	perseant-stdc-iso10646:1.2.0.6
	perseant-stdc-iso10646-base:1.2
	netbsd-8:1.2.0.4
	netbsd-8-base:1.2
	prg-localcount2-base3:1.2
	prg-localcount2-base2:1.2
	prg-localcount2-base1:1.2
	prg-localcount2:1.2.0.2
	prg-localcount2-base:1.2
	pgoyette-localcount-20170426:1.2
	bouyer-socketcan-base1:1.2
	pgoyette-localcount-20170320:1.1
	netbsd-7-1:1.1.2.2.0.6
	netbsd-7-1-RELEASE:1.1.2.2
	netbsd-7-1-RC2:1.1.2.2
	netbsd-7-nhusb-base-20170116:1.1.2.2
	bouyer-socketcan:1.1.0.6
	bouyer-socketcan-base:1.1
	pgoyette-localcount-20170107:1.1
	netbsd-7-1-RC1:1.1.2.2
	pgoyette-localcount-20161104:1.1
	netbsd-7-0-2-RELEASE:1.1.2.2
	localcount-20160914:1.1
	netbsd-7-nhusb:1.1.2.2.0.4
	netbsd-7-nhusb-base:1.1.2.2
	pgoyette-localcount-20160806:1.1
	pgoyette-localcount-20160726:1.1
	pgoyette-localcount:1.1.0.4
	pgoyette-localcount-base:1.1
	netbsd-7-0-1-RELEASE:1.1.2.2
	netbsd-7-0:1.1.2.2.0.2
	netbsd-7-0-RELEASE:1.1.2.2
	netbsd-7-0-RC3:1.1.2.2
	netbsd-7:1.1.0.2;
locks; strict;
comment	@# @;


1.5
date	2023.03.18.11.36.23;	author mlelstv;	state Exp;
branches;
next	1.4;
commitid	7QcLrA5LFHLraBhE;

1.4
date	2023.02.18.07.58.34;	author mlelstv;	state Exp;
branches;
next	1.3;
commitid	wABwsDrnlN7hQYdE;

1.3
date	2018.10.06.09.58.55;	author jmcneill;	state Exp;
branches;
next	1.2;
commitid	kWS6yIjnNcWUPSUA;

1.2
date	2017.04.14.13.47.21;	author jmcneill;	state Exp;
branches
	1.2.10.1
	1.2.12.1;
next	1.1;
commitid	13Mmc2yCwYDUrvNz;

1.1
date	2015.04.06.20.19.28;	author jmcneill;	state Exp;
branches
	1.1.2.1
	1.1.4.1
	1.1.6.1;
next	;
commitid	tOifK7pY9bjAnzgy;

1.2.10.1
date	2018.10.20.06.58.18;	author pgoyette;	state Exp;
branches;
next	;
commitid	mTSoqZEZ4arHnFWA;

1.2.12.1
date	2019.06.10.21.42.37;	author christos;	state Exp;
branches;
next	;
commitid	jtc8rnCzWiEEHGqB;

1.1.2.1
date	2015.04.06.20.19.28;	author snj;	state dead;
branches;
next	1.1.2.2;
commitid	8DiUh5BbT1XZKfwy;

1.1.2.2
date	2015.08.06.21.13.43;	author snj;	state Exp;
branches;
next	;
commitid	8DiUh5BbT1XZKfwy;

1.1.4.1
date	2017.04.26.02.52.17;	author pgoyette;	state Exp;
branches;
next	;
commitid	ojV02aOSdzvBqZOz;

1.1.6.1
date	2017.04.21.16.51.15;	author bouyer;	state Exp;
branches;
next	;
commitid	dUG7nkTKALCadqOz;


desc
@@


1.5
log
@Can't use disklabel to find the real size of a disk since a fake disklabel
read from disk is trusted. Revert to use drvctl again.
@
text
@#!/bin/sh
#
# $NetBSD: resize_disklabel,v 1.4 2023/02/18 07:58:34 mlelstv Exp $
#

# PROVIDE: resize_disklabel
# REQUIRE: fsck_root
# BEFORE: resize_root

$_rc_subr_loaded . /etc/rc.subr

name="resize_disklabel"
rcvar=$name
start_cmd="resize_disklabel_start"
stop_cmd=":"

get_rawpart()
{
	local partno

	partno=$(/sbin/sysctl -n kern.rawpartition)
	printf "$(printf \\\\%o $((partno + 97)))"
}

get_total_sectors()
{
	local disk

	disk=$1
	/sbin/drvctl -p "$disk" disk-info/geometry/sectors-per-unit
}

get_rawpart_sectors()
{
	local disk rawpart

	disk=$1
	rawpart=$2
	/sbin/disklabel -t "$disk" \
	| sed -ne 's/.*:p'"$rawpart"'#\([0-9]*\):.*/\1/p'
}

grow_mbrpart()
{
	local disk rawpart ts rs oldsize newsize

	disk=$1
	rawpart=$(get_rawpart)

	eval $(/sbin/fdisk -S $disk)
	if [ ! "$PART1ID" = "169" ]; then
		warn "No NetBSD partition found in MBR partition #1"
		return
	fi

	ts=$((${DLSIZE} - ${PART1START}))
	rs=${PART1SIZE}

	if [ "$ts" = "$rs" ]; then
		return
	fi

	oldsize=$(($rs / 2048))
	newsize=$(($ts / 2048))
	echo "Growing $disk MBR partition #1 (${oldsize}MB -> ${newsize}MB)"
	/sbin/fdisk -f -u -1 -s 169/${PART1START}/${ts} ${disk}
}

grow_disklabel()
{
	local disk part rawpart ts rs oldsize newsize

	disk=$1
	part=$2
	rawpart=$(get_rawpart)

	ts=$(get_total_sectors $disk)
	rs=$(get_rawpart_sectors $disk $rawpart)

	if [ "$ts" = "$rs" ]; then
		return
	fi

	oldsize=$(($rs / 2048))
	newsize=$(($ts / 2048))
	echo "Growing $disk disklabel (${oldsize}MB -> ${newsize}MB)"
	printf "A\ny\n$part\n\n\n\$\nc\n\n\n\$\nd\n\n\n\$\nW\ny\nQ\n" | \
	    disklabel -i $disk >/dev/null
}

resize_disklabel_start()
{
	if [ x"${resize_disklabel_disk}" = "x" ]; then
		resize_disklabel_disk="$(/sbin/sysctl -n kern.root_device)"
	fi
	if [ x"${resize_disklabel_part}" = "x" ]; then
		resize_disklabel_part=$(printf \\$(printf '%03o' $(( 97 + $(sysctl -n kern.root_partition) ))))
	fi

	grow_mbrpart "${resize_disklabel_disk}"
	grow_disklabel "${resize_disklabel_disk}" "${resize_disklabel_part}"
}

load_rc_config $name
run_rc_command "$1"
@


1.4
log
@Handle arbitrary raw partitions.
Fetch geometry from disklabel to be consistent.
Use disktab format instead of the normal human-readable output for parsing
the disklabel.
Avoid overflows in size computation.
@
text
@d3 1
a3 1
# $NetBSD: resize_disklabel,v 1.3 2018/10/06 09:58:55 jmcneill Exp $
d30 1
a30 2
	/sbin/disklabel -t "$disk" \
	| sed -ne 's/.*:su#\([0-9]*\):.*/\1/p'
@


1.3
log
@resize_disklabel: if disk and partition is not specified, use kern.root_device/kern.root_partition sysctls
@
text
@d3 1
a3 1
# $NetBSD: resize_disklabel,v 1.2 2017/04/14 13:47:21 jmcneill Exp $
d19 2
d22 1
a22 1
	test $partno = 2 && echo c || echo d
d27 2
d30 2
a31 1
	/sbin/drvctl -p $disk disk-info/geometry/sectors-per-unit
d36 2
d40 2
a41 1
	/sbin/disklabel $disk | grep "^ $rawpart:" | awk '{ print $2; }'
d46 2
d57 1
a57 1
	ts=$(($(get_total_sectors $disk) - ${PART1START}))
d64 2
a65 2
	oldsize=$(($rs * 512 / 1024 / 1024))
	newsize=$(($ts * 512 / 1024 / 1024))
d72 2
d85 2
a86 2
	oldsize=$(($rs * 512 / 1024 / 1024))
	newsize=$(($ts * 512 / 1024 / 1024))
@


1.2
log
@Grow the MBR partition table entry for the BSD partition before
growing the disklabel.
@
text
@d3 1
a3 1
# $NetBSD: resize_disklabel,v 1.1 2015/04/06 20:19:28 jmcneill Exp $
d83 1
a83 2
		warn "\${resize_disklabel_disk} is not set, not resizing disklabel"
		return
d86 1
a86 2
		warn "\${resize_disklabel_part} is not set, not resizing disklabel"
		return
@


1.2.12.1
log
@Sync with HEAD
@
text
@d3 1
a3 1
# $NetBSD: resize_disklabel,v 1.3 2018/10/06 09:58:55 jmcneill Exp $
d83 2
a84 1
		resize_disklabel_disk="$(/sbin/sysctl -n kern.root_device)"
d87 2
a88 1
		resize_disklabel_part=$(printf \\$(printf '%03o' $(( 97 + $(sysctl -n kern.root_partition) ))))
@


1.2.10.1
log
@Sync with head
@
text
@d3 1
a3 1
# $NetBSD: resize_disklabel,v 1.3 2018/10/06 09:58:55 jmcneill Exp $
d83 2
a84 1
		resize_disklabel_disk="$(/sbin/sysctl -n kern.root_device)"
d87 2
a88 1
		resize_disklabel_part=$(printf \\$(printf '%03o' $(( 97 + $(sysctl -n kern.root_partition) ))))
@


1.1
log
@Add support for auto-growing the root partition. Enable it for rpi.img.
@
text
@d3 1
a3 1
# $NetBSD$
d36 24
d91 1
@


1.1.4.1
log
@Sync with HEAD
@
text
@d3 1
a3 1
# $NetBSD: resize_disklabel,v 1.2 2017/04/14 13:47:21 jmcneill Exp $
a35 24
grow_mbrpart()
{
	disk=$1
	rawpart=$(get_rawpart)

	eval $(/sbin/fdisk -S $disk)
	if [ ! "$PART1ID" = "169" ]; then
		warn "No NetBSD partition found in MBR partition #1"
		return
	fi

	ts=$(($(get_total_sectors $disk) - ${PART1START}))
	rs=${PART1SIZE}

	if [ "$ts" = "$rs" ]; then
		return
	fi

	oldsize=$(($rs * 512 / 1024 / 1024))
	newsize=$(($ts * 512 / 1024 / 1024))
	echo "Growing $disk MBR partition #1 (${oldsize}MB -> ${newsize}MB)"
	/sbin/fdisk -f -u -1 -s 169/${PART1START}/${ts} ${disk}
}

a66 1
	grow_mbrpart "${resize_disklabel_disk}"
@


1.1.6.1
log
@Sync with HEAD
@
text
@d3 1
a3 1
# $NetBSD: resize_disklabel,v 1.2 2017/04/14 13:47:21 jmcneill Exp $
a35 24
grow_mbrpart()
{
	disk=$1
	rawpart=$(get_rawpart)

	eval $(/sbin/fdisk -S $disk)
	if [ ! "$PART1ID" = "169" ]; then
		warn "No NetBSD partition found in MBR partition #1"
		return
	fi

	ts=$(($(get_total_sectors $disk) - ${PART1START}))
	rs=${PART1SIZE}

	if [ "$ts" = "$rs" ]; then
		return
	fi

	oldsize=$(($rs * 512 / 1024 / 1024))
	newsize=$(($ts * 512 / 1024 / 1024))
	echo "Growing $disk MBR partition #1 (${oldsize}MB -> ${newsize}MB)"
	/sbin/fdisk -f -u -1 -s 169/${PART1START}/${ts} ${disk}
}

a66 1
	grow_mbrpart "${resize_disklabel_disk}"
@


1.1.2.1
log
@file resize_disklabel was added on branch netbsd-7 on 2015-08-06 21:13:43 +0000
@
text
@d1 71
@


1.1.2.2
log
@Pull up following revision(s) (requested by skrll in ticket #909):
	distrib/sets/lists/etc/mi: revision 1.237
	distrib/sets/lists/tests/mi: revision 1.613
	distrib/utils/embedded/conf/armv7.conf: revisions 1.1, 1.2
	distrib/utils/embedded/conf/beagleboard.conf: delete
	distrib/utils/embedded/conf/evbarm.conf: revisions 1.21, 1.22
	distrib/utils/embedded/conf/rpi.conf: revisions 1.28, 1.29
	distrib/utils/embedded/conf/rpi_inst.conf: revisions 1.7, 1.8
	distrib/utils/embedded/conf/usermode.conf: revision 1.5
	distrib/utils/embedded/conf/x86.conf: revision 1.5
	distrib/utils/embedded/files/resize_disklabel: revision 1.1
	distrib/utils/embedded/mkimage: revisions 1.49, 1.55-1.59
	etc/defaults/rc.conf: revision 1.133
	etc/etc.evbarm/Makefile.inc: revisions 1.72, 1.76
	etc/rc.d/Makefile: revision 1.93 via patch
	etc/rc.d/resize_root: revisions 1.1-1.3
	etc/rc.d/root: revision 1.5
	sbin/resize_ffs/Makefile: revision 1.5
	sbin/resize_ffs/resize_ffs.8: revisions 1.14-1.16
	sbin/resize_ffs/resize_ffs.c: revisions 1.39-1.44
	share/man/man5/rc.conf.5: revision 1.158, 1.159
	tests/sbin/resize_ffs/Makefile: revision 1.4
	tests/sbin/resize_ffs/common.sh: revision 1.14
	tests/sbin/resize_ffs/t_check.sh: revision 1.1
	tests/sbin/resize_ffs/t_grow.sh: revision 1.9
	tests/sbin/resize_ffs/t_grow_swapped.sh: revision 1.3
	tests/sbin/resize_ffs/t_shrink.sh: revision 1.8
	tests/sbin/resize_ffs/t_shrink_swapped.sh: revision 1.2
fix image building:
         - round up the total size of the disk image
         - fix fdisk offset for netbsd ffs images
--
Make get_dev_size work on regular files too.
--
Use `!= -1' instead of `== 0' out of paranoia.
--
- Add -c to check to see if grow/shrink is required
- Divide by DEV_BSIZE when returning size of file.
- Update manpage
--
New sentence, new line. Sort option descriptions.
--
Add resize_root boot operation. If resize_root=YES in rc.conf then
the system attempts to resize the root file system to fill it's
partition prior to mounting read-write. Useful for things like AMI
file system images. May eventually be used by arm images after
coming up with similar solution for increasing the parition size.
--
- Add new tests for -c check flag in resize_ffs
--
Bump date for previous.
it's -> its
--
Handle case in grow() where last cylinder group is too small for ufs2.
Align with code in shrink().
--
factor out geometry calculation and use this also in CheckOnly mode.
be a bit more verbose in Verbose mode.
--
Add support for auto-growing the root partition. Enable it for rpi.img.
--
initialize resize before pulling in board config
--
add KEYWORD: interactive, honour resize_root_flags and
resize_root_postcmd rc vars
--
if the -p flag is specified, display a progress bar while growing the
file-system
--
show resize_ffs progress bar when resizing root partition
--
fix typo in previous; pass -y unconditionally to resize_ffs, not -p
--
Rename beagleboard.img to armv7.img. The new image includes the same
kernels as beagleboard.img plus support for Raspberry Pi 2, ODROID-C1,
Cubieboard2, Cubietruck, Hummingbird A31, and Banana Pi.
--
Properly spell X' name. From X(7):
        The  X.Org  Foundation  requests  that the following names be
used when
        referring to this software:
                                           X
                                    X Window System
                                     X Version 11
                              X Window System, Version 11
                                          X11
--
Add some documentation:
Tell what this does, and what it expects from conf files
--
Cleanup: make_filesystems is not used any longer, purge remains
--
More cleanup:
Instead of first overwriting the *_evbarm functions with own code,
and then calling them from the regular functions, directly put the
code into the regular functions.
No more functions from evbarm.conf are used now.
Some variables are still used!
--
define TOOL_MKUBOOTIMAGE for mkimage
--
fix mkubootimage
@
text
@a0 71
#!/bin/sh
#
# $NetBSD: resize_disklabel,v 1.1 2015/04/06 20:19:28 jmcneill Exp $
#

# PROVIDE: resize_disklabel
# REQUIRE: fsck_root
# BEFORE: resize_root

$_rc_subr_loaded . /etc/rc.subr

name="resize_disklabel"
rcvar=$name
start_cmd="resize_disklabel_start"
stop_cmd=":"

get_rawpart()
{
	partno=$(/sbin/sysctl -n kern.rawpartition)
	test $partno = 2 && echo c || echo d
}

get_total_sectors()
{
	disk=$1
	/sbin/drvctl -p $disk disk-info/geometry/sectors-per-unit
}

get_rawpart_sectors()
{
	disk=$1
	rawpart=$2
	/sbin/disklabel $disk | grep "^ $rawpart:" | awk '{ print $2; }'
}

grow_disklabel()
{
	disk=$1
	part=$2
	rawpart=$(get_rawpart)

	ts=$(get_total_sectors $disk)
	rs=$(get_rawpart_sectors $disk $rawpart)

	if [ "$ts" = "$rs" ]; then
		return
	fi

	oldsize=$(($rs * 512 / 1024 / 1024))
	newsize=$(($ts * 512 / 1024 / 1024))
	echo "Growing $disk disklabel (${oldsize}MB -> ${newsize}MB)"
	printf "A\ny\n$part\n\n\n\$\nc\n\n\n\$\nd\n\n\n\$\nW\ny\nQ\n" | \
	    disklabel -i $disk >/dev/null
}

resize_disklabel_start()
{
	if [ x"${resize_disklabel_disk}" = "x" ]; then
		warn "\${resize_disklabel_disk} is not set, not resizing disklabel"
		return
	fi
	if [ x"${resize_disklabel_part}" = "x" ]; then
		warn "\${resize_disklabel_part} is not set, not resizing disklabel"
		return
	fi

	grow_disklabel "${resize_disklabel_disk}" "${resize_disklabel_part}"
}

load_rc_config $name
run_rc_command "$1"
@


