diff options
author | Robert Peichaer <rpe@cvs.openbsd.org> | 2015-12-27 18:42:12 +0000 |
---|---|---|
committer | Robert Peichaer <rpe@cvs.openbsd.org> | 2015-12-27 18:42:12 +0000 |
commit | c484cb25187625eab5e9ab2a4f873323883123bd (patch) | |
tree | cad4f68011a823029400cee05dbc5ef35f49c990 /distrib/miniroot | |
parent | fca961dab3abac3ac391ebe5f01eaaabb0be8fcf (diff) |
Refactor and move disk initialization code from install.sh to a separate
function configure_disk() in install.sub.
based on work from and OK halex@
Diffstat (limited to 'distrib/miniroot')
-rw-r--r-- | distrib/miniroot/install.sh | 68 | ||||
-rw-r--r-- | distrib/miniroot/install.sub | 64 |
2 files changed, 70 insertions, 62 deletions
diff --git a/distrib/miniroot/install.sh b/distrib/miniroot/install.sh index 7befac08fe0..9fd28c877fb 100644 --- a/distrib/miniroot/install.sh +++ b/distrib/miniroot/install.sh @@ -1,5 +1,5 @@ #!/bin/ksh -# $OpenBSD: install.sh,v 1.272 2015/12/23 18:06:32 rpe Exp $ +# $OpenBSD: install.sh,v 1.273 2015/12/27 18:42:11 rpe Exp $ # $NetBSD: install.sh,v 1.5.2.8 1996/08/27 18:15:05 gwr Exp $ # # Copyright (c) 1997-2015 Todd Miller, Theo de Raadt, Ken Westerback @@ -108,21 +108,16 @@ echo # Get information about ROOTDISK, etc. get_rootinfo -DISK= DISKS_DONE= -_DKDEVS=$(get_dkdevs) -_fsent= +FSENT= # Remove traces of previous install attempt. rm -f /tmp/fstab* # Configure the disk(s). while :; do - DISKS_DONE=$(addel "$DISK" $DISKS_DONE) - _DKDEVS=$(rmel "$DISK" $_DKDEVS) - # Always do ROOTDISK first, and repeat until it is configured. - if isin $ROOTDISK $_DKDEVS; then + if ! isin $ROOTDISK $DISKS_DONE; then resp=$ROOTDISK rm -f /tmp/fstab else @@ -132,63 +127,14 @@ while :; do '$(get_dkdevs_uninitialized)' done [[ $resp == done ]] && break fi - - DISK=$resp - makedev $DISK || continue - - # Deal with disklabels, including editing the root disklabel - # and labeling additional disks. This is machine-dependent since - # some platforms may not be able to provide this functionality. - # /tmp/fstab.$DISK is created here with 'disklabel -F'. - rm -f /tmp/*.$DISK - md_prep_disklabel $DISK || { DISK=; continue; } - - # Make sure there is a '/' mount point. - grep -qs " / ffs " /tmp/fstab.$ROOTDISK || - { DISK=; echo "'/' must be configured!"; continue; } - - if [[ -f /tmp/fstab.$DISK ]]; then - # Avoid duplicate mount points on different disks. - while read _pp _mp _rest; do - if [[ $_mp == none ]]; then - # Multiple swap partitions are ok. - echo "$_pp $_mp $_rest" >>/tmp/fstab - continue - fi - # Non-swap mountpoints must be in only one file. - [[ /tmp/fstab.$DISK == $(grep -l " $_mp " /tmp/fstab.*) ]] || - { _rest=$DISK; DISK=; break; } - done </tmp/fstab.$DISK - - if [[ -z $DISK ]]; then - # Duplicate mountpoint. - # Allow disklabel(8) to read back mountpoint info - # if it is immediately run against the same disk. - cat /tmp/fstab.$_rest >/etc/fstab - rm /tmp/fstab.$_rest - set -- $(grep -h " $_mp " /tmp/fstab.*[0-9]) - echo "$_pp and $1 can't both be mounted at $_mp." - continue - fi - - # Add ffs filesystems to list after newfs'ing them. Ignore - # other filesystems. - while read _pp _mp _fstype _rest; do - [[ $_fstype == ffs ]] || continue - _OPT= - [[ $_mp == / ]] && _OPT=$MDROOTFSOPT - newfs -q $_OPT ${_pp##/dev/} - # N.B.: '!' is lexically < '/'. That is - # required for correct sorting of - # mount points. - _fsent="$_fsent $_mp!$_pp" - done </tmp/fstab.$DISK - fi + _disk=$resp + configure_disk $_disk || continue + DISKS_DONE=$(addel $_disk $DISKS_DONE) done # Write fstab entries to fstab in mount point alphabetic order # to enforce a rational mount order. -for _mp in $(bsort $_fsent); do +for _mp in $(bsort $FSENT); do _pp=${_mp##*!} _mp=${_mp%!*} echo -n "$_pp $_mp ffs rw" diff --git a/distrib/miniroot/install.sub b/distrib/miniroot/install.sub index 7cf3bcc3f8c..67e9d92ad0b 100644 --- a/distrib/miniroot/install.sub +++ b/distrib/miniroot/install.sub @@ -1,4 +1,4 @@ -# $OpenBSD: install.sub,v 1.866 2015/12/23 18:06:32 rpe Exp $ +# $OpenBSD: install.sub,v 1.867 2015/12/27 18:42:11 rpe Exp $ # # Copyright (c) 1997-2015 Todd Miller, Theo de Raadt, Ken Westerback # Copyright (c) 2015, Robert Peichaer <rpe@openbsd.org> @@ -361,6 +361,68 @@ disklabel_autolayout() { done } +configure_disk() { + local _disk=$1 _fstab=/tmp/fstab.$1 + + makedev $_disk || return + + # Deal with disklabels, including editing the root disklabel + # and labeling additional disks. This is machine-dependent since + # some platforms may not be able to provide this functionality. + # /tmp/fstab.$_disk is created here with 'disklabel -F'. + rm -f /tmp/*.$_disk + md_prep_disklabel $_disk || return + + # Make sure there is a '/ mount point. + if ! grep -qs ' / ffs ' /tmp/fstab.$ROOTDISK; then + echo "'/' must be configured!" + return 1 + fi + + if [[ -f $_fstab ]]; then + # Avoid duplicate mount points on different disks. + while read _pp _mp _rest; do + if [[ $_mp == none ]]; then + # Multiple swap partitions are ok. + echo "$_pp $_mp $_rest" >>/tmp/fstab + continue + fi + # Non-swap mountpoints must be in only one file. + if [[ $_fstab != $(grep -l " $_mp " /tmp/fstab.*) ]]; then + _rest=$_disk + _disk= + break + fi + done <$_fstab + + if [[ -z $_disk ]]; then + # Duplicate mountpoint. + # Allow disklabel(8) to read back mountpoint info + # if it is immediately run against the same disk. + cat /tmp/fstab.$_rest >/etc/fstab + rm /tmp/fstab.$_rest + set -- $(grep -h " $_mp " /tmp/fstab.*[0-9]) + echo "$_pp and $1 can't both be mounted at $_mp." + return 1 + fi + + # Add ffs filesystems to list after newfs'ing them. Ignore + # other filesystems. + while read _pp _mp _fstype _rest; do + [[ $_fstype == ffs ]] || continue + _OPT= + [[ $_mp == / ]] && _OPT=$MDROOTFSOPT + newfs -q $_OPT ${_pp##/dev/} + # N.B.: '!' is lexically < '/'. That is + # required for correct sorting of + # mount points. + FSENT="$FSENT $_mp!$_pp" + done <$_fstab + fi + + return 0 +} + # ------------------------------------------------------------------------------ # Functions for the dmesg listener # ------------------------------------------------------------------------------ |