Skip to content

Commit

Permalink
fix change new_gpart_partitions gpt CURPART
Browse files Browse the repository at this point in the history
  • Loading branch information
ericbsd committed Feb 4, 2019
1 parent db9a5b9 commit ecd8fec
Show file tree
Hide file tree
Showing 4 changed files with 267 additions and 77 deletions.
98 changes: 98 additions & 0 deletions backend-query/part-label.sh
@@ -0,0 +1,98 @@
#!/bin/sh
#-
# Copyright (c) 2018 iXsystems, Inc. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
# $FreeBSD: $

# Query mbr partitions label and display them
##############################

. ${PROGDIR}/backend/functions.sh
. ${PROGDIR}/backend/functions-disk.sh


if [ -z "${1}" ]
then
echo "Error: No partition specified!"
exit 1
fi

if [ ! -e "/dev/${1}" ]
then
echo "Error: Partition /dev/${1} does not exist!"
exit 1
fi


gpart show ${1} >/dev/null 2>/dev/null
if [ "$?" != "0" ] ; then
# No partitions on this disk, display entire disk size and exit
echo "${1} is not a primary partition"
exit
fi


SLICE_PART="${1}"
TMPDIR=${TMPDIR:-"/tmp"}

TYPE=`gpart show ${1} | awk '/^=>/ { printf("%s",$5); }'`
echo "${1}-format: $TYPE"

# Set some search flags
PART="0"
EXTENDED="0"
START="0"
SIZEB="0"

# Get a listing of partitions on this disk
get_partitions_lables "${SLICE_PART}"
LABELS="${VAL}"
for curpart in $LABELS
do

# First get the sysid / label for this partition
get_partition_label "${SLICE_PART}" "${curpart}"
echo "${curpart}-sysid: ${VAL}"
echo "${curpart}-label: ${VAL}"

# Now get the startblock, blocksize and MB size of this partition
get_label_startblock "${SLICE_PART}" "${curpart}"
START="${VAL}"
echo "${curpart}-blockstart: ${START}"

get_label_blocksize "${SLICE_PART}" "${curpart}"
SIZEB="${VAL}"
echo "${curpart}-blocksize: ${SIZEB}"

SIZEMB=$(convert_blocks_to_megabyte ${SIZEB})
echo "${curpart}-sizemb: ${SIZEMB}"

done


# Now calculate any free space
FREEB=`gpart show ${SLICE_PART} | grep '\- free\ -' | awk '{print $2}' | sort -g | tail -1`
FREEMB="`expr ${FREEB} / 2048`"
echo "${1}-freemb: $FREEMB"
echo "${1}-freeblocks: $FREEB"
74 changes: 37 additions & 37 deletions backend/functions-bsdlabel.sh
Expand Up @@ -31,8 +31,8 @@
check_for_enc_pass()
{
CURLINE="${1}"
get_next_cfg_line "${CFGF}" "${CURLINE}"

get_next_cfg_line "${CFGF}" "${CURLINE}"
echo ${VAL} | grep -q "^encpass=" 2>/dev/null
if [ $? -eq 0 ] ; then
# Found a password, return it
Expand Down Expand Up @@ -162,7 +162,7 @@ setup_zfs_mirror_parts()
fi
else
_nZFS="$_nZFS ${_zvars}"
fi
fi

done

Expand Down Expand Up @@ -214,10 +214,10 @@ gen_glabel_name()
exit_err "Cannot allocate additional glabel name for $NAME"
break
fi
done

done

export VAL="${NAME}${NUM}"

export VAL="${NAME}${NUM}"
};

# Function to determine the GPT size we can safely use when 0 is specified
Expand Down Expand Up @@ -341,7 +341,7 @@ new_gpart_partitions()

# Lets read in the config file now and setup our partitions
if [ "${_pType}" = "gpt" ] ; then
CURPART="2"
CURPART="${_sNum}"
elif [ "${_pType}" = "apm" ] ; then
CURPART="3"
elif [ "${_pType}" = "freembr" ] ; then
Expand Down Expand Up @@ -411,9 +411,9 @@ new_gpart_partitions()
dpart=`expr $dpart + 1`

# We need to split up the string now, and pick out the variables
FS=`echo $STRING | tr -s '\t' ' ' | cut -d ' ' -f 1`
SIZE=`echo $STRING | tr -s '\t' ' ' | cut -d ' ' -f 2`
MNT=`echo $STRING | tr -s '\t' ' ' | cut -d ' ' -f 3`
FS=`echo $STRING | tr -s '\t' ' ' | cut -d ' ' -f 1`
SIZE=`echo $STRING | tr -s '\t' ' ' | cut -d ' ' -f 2`
MNT=`echo $STRING | tr -s '\t' ' ' | cut -d ' ' -f 3`

# Check if we have a .eli extension on this FS
echo ${FS} | grep -q ".eli" 2>/dev/null
Expand All @@ -424,7 +424,7 @@ new_gpart_partitions()
check_for_enc_pass "${line}"
if [ "${VAL}" != "" ] ; then
# We have a user supplied password, save it for later
ENCPASS="${VAL}"
ENCPASS="${VAL}"
fi
else
ENC="OFF"
Expand All @@ -436,7 +436,7 @@ new_gpart_partitions()
then
export USINGENCROOT="0"
fi

# Now check that these values are sane
case $FS in
UFS|UFS+S|UFS+J|UFS+SUJ|ZFS|SWAP) ;;
Expand Down Expand Up @@ -474,7 +474,7 @@ new_gpart_partitions()
check_for_mount "${MNT}" "/"
if [ $? -eq 0 ] ; then
export FOUNDROOT="1"
if [ "${CURPART}" = "2" -a "$_pType" = "gpt" ] ; then
if [ "$_pType" = "gpt" ] ; then
export FOUNDROOT="0"
fi
if [ "${CURPART}" = "3" -a "$_pType" = "apm" ] ; then
Expand Down Expand Up @@ -565,7 +565,7 @@ new_gpart_partitions()
sleep 2
# MBR type
if [ "${INSTALLTYPE}" = "GhostBSD" ] ; then
# From research the first label be aligned with the disk
# From research the first label be aligned with the disk
aCmd="gpart add -a 4k ${SOUT} -t ${PARTYPE} ${_wSlice}"
elif [ "$PARTLETTER" = "a" ] ; then
# The BOOT/ROOT partition must NOT be aligned
Expand Down Expand Up @@ -604,12 +604,12 @@ new_gpart_partitions()
for TESTMNT in `echo ${MNT} | sed 's|,| |g' | cut -d '(' -f 1`
do
if [ "${TESTMNT}" = "/" -a -z "${BOOTTYPE}" ] ; then
BOOTTYPE="${PARTYPE}"
fi
BOOTTYPE="${PARTYPE}"
fi
if [ "${TESTMNT}" = "/boot" ] ; then
BOOTTYPE="${PARTYPE}"
fi
done
BOOTTYPE="${PARTYPE}"
fi
done

# Save this data to our partition config dir
if [ "${_pType}" = "gpt" ] ; then
Expand Down Expand Up @@ -680,7 +680,7 @@ new_gpart_partitions()
case ${BOOTTYPE} in
freebsd-ufs) rc_halt "gpart bootcode -b /boot/pmbr -p /boot/gptboot -i 1 ${_pDisk}" ;;
freebsd-zfs) rc_halt "gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 1 ${_pDisk}" ;;
esac
esac
fi

# Make sure to stamp the MBR on NON-ZFS loader
Expand Down Expand Up @@ -763,7 +763,7 @@ modify_gpart_partitions()
if [ $? -eq 0 -a "${ENC}" = "ON" ]; then
export USINGENCROOT="0"
fi

# Now check that these values are sane
case $FS in
UFS|UFS+S|UFS+J|UFS+SUJ|ZFS|SWAP) ;;
Expand Down Expand Up @@ -846,18 +846,18 @@ populate_disk_label()
fi

# Set some vars from the given working slice
diskid="`echo $1 | cut -d ':' -f 1`"
disk="`echo $1 | cut -d ':' -f 1 | sed 's|-|/|g'`"
slicenum="`echo $1 | cut -d ':' -f 2`"
type="`echo $1 | cut -d ':' -f 3`"
diskid="`echo $1 | cut -d ':' -f 1`"
disk="`echo $1 | cut -d ':' -f 1 | sed 's|-|/|g'`"
slicenum="`echo $1 | cut -d ':' -f 2`"
type="`echo $1 | cut -d ':' -f 3`"
mod="`echo $1 | cut -d ':' -f 4`"

# Check if we are only modifying an existing GPT partition
MODONLY="NO"
if [ "$mod" = "mod" ] ; then
MODONLY="YES"
fi

# Set WRKSLICE based upon format we are using
if [ "$type" = "mbr" -o "$type" = "freembr" ] ; then
wrkslice="${diskid}s${slicenum}"
Expand All @@ -875,7 +875,7 @@ populate_disk_label()

disktag="`cat ${SLICECFGDIR}/${wrkslice}`"
slicedev="`echo $wrkslice | sed 's|-|/|g'`"

if [ "$MODONLY" = "YES" ] ; then
# We are doing a modification of GPT partitions
modify_gpart_partitions "${disktag}" "${disk}" "${slicedev}" "${slicenum}" "${type}"
Expand Down Expand Up @@ -904,10 +904,10 @@ setup_disk_label()

# Check if we are using a /boot partition
export USINGBOOTPART="1"

# Set encryption on root check
export USINGENCROOT="1"

# Make the tmp directory where we'll store FS info & mount-points
rm -rf ${PARTDIR} >/dev/null 2>/dev/null
mkdir -p ${PARTDIR} >/dev/null 2>/dev/null
Expand Down Expand Up @@ -972,9 +972,9 @@ check_fstab_mbr()
if [ "${PARTLETTER}" = "a" ]
then
USINGBOOTPART="0"
else
else
exit_err "/boot partition must be first partition"
fi
fi
export USINGBOOTPART
fi

Expand Down Expand Up @@ -1027,9 +1027,9 @@ check_fstab_gpt()
if [ "${PARTNUMBER}" = "2" ]
then
USINGBOOTPART="0"
else
else
exit_err "/boot partition must be first partition"
fi
fi
export USINGBOOTPART
fi

Expand Down Expand Up @@ -1078,15 +1078,15 @@ check_disk_layout()
TYPE="MBR"
RES=0
fi

for slice in ${SLICES}
do
F=1
mount ${slice} /mnt 2>/dev/null
if [ $? -ne 0 ]
then
continue
fi
fi

if [ "${TYPE}" = "MBR" ]
then
Expand All @@ -1097,12 +1097,12 @@ check_disk_layout()
then
check_fstab_gpt "${slice}" "/mnt"
F="$?"
fi
fi

if [ ${F} -eq 0 ]
then
umount /mnt
break
break
fi

umount /mnt
Expand Down

1 comment on commit ecd8fec

@allentiak
Copy link

@allentiak allentiak commented on ecd8fec Mar 11, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, @ericbsd,

Great contribution!

I've had problems* this change may solve...
However, I don't see this commit in master...
Has this already been integrated into the latest GhostBSD build?

*See trueos/trueos-core#1541

Please sign in to comment.