"Fossies" - the Fresh Open Source Software Archive

Member "buildah-1.23.1/contrib/cirrus/add_second_partition.sh" (28 Sep 2021, 2151 Bytes) of package /linux/misc/buildah-1.23.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Bash source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 #!/bin/bash
    2 
    3 # N/B: This script could mega f*!@up your disks if run by mistake.
    4 #      it is left without the execute-bit on purpose!
    5 
    6 # $SLASH_DEVICE is the disk device to be f*xtuP
    7 SLASH_DEVICE="/dev/sda"  # Always the case on GCP VM Images
    8 
    9 # The unallocated space results from the difference in disk-size between VM Image
   10 # and runtime request.  The check_image.sh test includes a minimum-space check,
   11 # with the Image size set initially lower by contrib/cirrus/packer/libpod_images.yml
   12 NEW_PART_START="50%"
   13 NEW_PART_END="100%"
   14 
   15 set -eo pipefail
   16 
   17 source $(dirname $0)/lib.sh
   18 
   19 # Protection against double-execution
   20 if [[ ! -r "/root" ]] || [[ -r "/root/second_partition_ready" ]]
   21 then
   22     echo "Warning: Ignoring attempted execution of $(basename $0)"
   23     exit 0
   24 fi
   25 
   26 [[ -x "$(type -P parted)" ]] || \
   27     die "The parted command is required."
   28 
   29 [[ ! -b ${SLASH_DEVICE}2 ]] || \
   30     die "Found unexpected block device ${SLASH_DEVICE}2"
   31 
   32 PPRINTCMD="parted --script ${SLASH_DEVICE} print"
   33 FINDMNTCMD="findmnt --source=${SLASH_DEVICE}1 --mountpoint=/ --canonicalize --evaluate --first-only --noheadings"
   34 TMPF=$(mktemp -p '' $(basename $0)_XXXX)
   35 trap "rm -f $TMPF" EXIT
   36 
   37 if $FINDMNTCMD | tee $TMPF | egrep -q "^/\s+${SLASH_DEVICE}1"
   38 then
   39     echo "Repartitioning original partition table:"
   40     $PPRINTCMD
   41 else
   42     die "Unexpected output from '$FINDMNTCMD': $(<$TMPF)"
   43 fi
   44 
   45 echo "Adding partition offset within unpartitioned space."
   46 parted --script --align optimal $SLASH_DEVICE unit % mkpart primary "" "" "$NEW_PART_START" "$NEW_PART_END"
   47 
   48 echo "New partition table:"
   49 $PPRINTCMD
   50 
   51 echo "Growing ${SLASH_DEVICE}1 meet start of ${SLASH_DEVICE}2"
   52 growpart ${SLASH_DEVICE} 1
   53 
   54 FSTYPE=$(findmnt --first-only --noheadings --output FSTYPE ${SLASH_DEVICE}1)
   55 echo "Expanding $FSTYPE filesystem on ${SLASH_DEVICE}1"
   56 case $FSTYPE in
   57     ext*) resize2fs ${SLASH_DEVICE}1 ;;
   58     *) die "Script $(basename $0) doesn't know how to resize a $FSTYPE filesystem." ;;
   59 esac
   60 
   61 # Must happen last - signals completion to other tooling
   62 echo "Recording newly available disk partition device into /root/second_partition_ready"
   63 echo "${SLASH_DEVICE}2" > /root/second_partition_ready