Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions backend-query/disk-info.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,19 @@ SECS="${VAL}"
KB="`diskinfo -v ${1} | grep 'bytes' | cut -d '#' -f 1 | tr -s '\t' ' ' | tr -d ' '`"
MB=$(convert_byte_to_megabyte ${KB})

# Now get the Controller Type
CTYPE="`dmesg | grep "^${1}:" | grep ": <" | cut -d '>' -f 2 | cut -d ' ' -f 3-10`"
# Now get the protocol family. The device name prefix is the CAM peripheral
# that attached, so it is the protocol itself rather than a guess at it, and
# unlike scraping dmesg it cannot come up empty once the boot messages have
# rolled out of the ring buffer.
case "${DISK}" in
ada*|ad*) CTYPE="ATA" ;;
da*) CTYPE="SCSI" ;;
nvd*|nda*) CTYPE="NVMe" ;;
mmcsd*) CTYPE="MMC" ;;
vtbd*) CTYPE="VirtIO" ;;
md*) CTYPE="Memory" ;;
*) CTYPE="Unknown" ;;
esac

echo "cylinders=${CYLS}"
echo "heads=${HEADS}"
Expand Down
33 changes: 29 additions & 4 deletions backend-query/disk-part.sh
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,36 @@ EXTENDED="0"
START="0"
SIZEB="0"

# Get a listing of partitions on this disk
get_disk_partitions "${DISK}"
PARTS="${VAL}"
for curpart in $PARTS
# Walk the disk in on-disk order. gpart lists entries sorted by start block,
# so reporting each one as it is read keeps free space in its true position
# between the partitions it separates. Front-ends rely on that ordering when
# they merge adjacent free space after a partition is deleted.
case "${TYPE}" in
MBR) PSEP="s" ;;
GPT) PSEP="p" ;;
*) PSEP="s" ;;
esac

FREENUM=1
gpart show ${DISK} | grep -v '^=>' | while read PSTART PSIZE PINDEX PLABEL PREST
do
# gpart prints a trailing blank line
if [ -z "${PINDEX}" ] ; then
continue
fi

# A gap rather than a partition. Every gap is reported so it keeps its place
# in the sequence. blocksize is exact; sizemb rounds down and reads 0 for a
# gap smaller than 2048 blocks.
if [ "${PINDEX}" = "-" ] ; then
echo "${DISK}-freespace${FREENUM}-blockstart: ${PSTART}"
echo "${DISK}-freespace${FREENUM}-blocksize: ${PSIZE}"
echo "${DISK}-freespace${FREENUM}-sizemb: $(convert_blocks_to_megabyte ${PSIZE})"
FREENUM=$((FREENUM + 1))
continue
fi

curpart="${DISK}${PSEP}${PINDEX}"

# First get the sysid / label for this partition
if [ "$TYPE" = "MBR" ] ; then
Expand Down
54 changes: 33 additions & 21 deletions backend-query/part-label.sh
Original file line number Diff line number Diff line change
Expand Up @@ -65,33 +65,45 @@ EXTENDED="0"
START="0"
SIZEB="0"

# Get a listing of partitions from the primary partition
get_partitions_lables "${SLICE_PART}"
LABELS="${VAL}"
for curpart in $LABELS
# Walk the slice in on-disk order. gpart lists entries sorted by start block,
# so reporting each one as it is read keeps free space in its true position
# between the labels it separates. Front-ends rely on that ordering when they
# merge adjacent free space after a label is deleted.
FREENUM=1
gpart show ${SLICE_PART} | grep -v '^=>' | while read PSTART PSIZE PINDEX PLABEL PREST
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})
# gpart prints a trailing blank line
if [ -z "${PINDEX}" ] ; then
continue
fi

# A gap rather than a label. Every gap is reported so it keeps its place in
# the sequence. blocksize is exact; sizemb rounds down and reads 0 for a gap
# smaller than 2048 blocks.
if [ "${PINDEX}" = "-" ] ; then
echo "${SLICE_PART}-freespace${FREENUM}-blockstart: ${PSTART}"
echo "${SLICE_PART}-freespace${FREENUM}-blocksize: ${PSIZE}"
echo "${SLICE_PART}-freespace${FREENUM}-sizemb: $(convert_blocks_to_megabyte ${PSIZE})"
FREENUM=$((FREENUM + 1))
continue
fi

# Labels are lettered from their index: 1 becomes a, 2 becomes b, and so on
LETTER=`awk -v char=$((96+${PINDEX})) 'BEGIN { printf "%c\n", char; exit }'`
curpart="${SLICE_PART}${LETTER}"

echo "${curpart}-sysid: ${PLABEL}"
echo "${curpart}-label: ${PLABEL}"
echo "${curpart}-blockstart: ${PSTART}"
echo "${curpart}-blocksize: ${PSIZE}"

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

done


# Now calculate any free space
# Now calculate the largest block of free space
FREEB=`gpart show ${SLICE_PART} | grep '\- free\ -' | awk '{print $2}' | sort -g | tail -1`
FREEMB="`expr ${FREEB} / 2048`"
echo "${1}-freemb: $FREEMB"
Expand Down
8 changes: 8 additions & 0 deletions backend/functions-cleanup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,14 @@ run_final_cleanup()
# Generate the fstab for the installed system
setup_fstab

# Address disks by their raw adaX/nvdX names on the installed system. With
# diskid and gptid labels enabled, an imported pool binds to
# diskid/DISK-<serial>, which withdraws the raw partition geom for the whole
# disk. gpart(8) then fails on that disk and the /dev/adaXpY entries written
# above, including swap and the EFI mount, stop resolving.
echo 'kern.geom.label.disk_ident.enable="0"' >> ${FSMNT}/boot/loader.conf
echo 'kern.geom.label.gptid.enable="0"' >> ${FSMNT}/boot/loader.conf

# Workaround to issue in FreeBSD pkg base
rc_nohalt "chroot ${FSMNT} chown root:operator /sbin/shutdown"
rc_nohalt "chroot ${FSMNT} chmod 4554 /sbin/shutdown"
Expand Down