# Copyright (c) 2019-2020, NVIDIA CORPORATION. All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # * Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # * 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. # * Neither the name of NVIDIA CORPORATION nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``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 COPYRIGHT OWNER 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.
# This is a script to resize partition and filesystem on the root partition # This will consume all un-allocated sapce on SD card after boot.
set -e
functionusage() { if [ -n "${1}" ]; then echo"${1}" fi
echo"Usage:" echo"${script_name} [options]" echo"" echo"Available options are:" echo"" echo" -h | --help" echo" Show this usage" echo"" echo" -c | --check" echo" Check whether ${script_name} can be used on current platform" echo"" echo" -g | --get" echo" Show APP partition size in MB" echo"" echo" -m | --max" echo" Show APP partition maximum available size in MB" echo"" echo" -s <app_size> | --size <app_size>" echo" Set APP partition size in MB" echo"" echo"Without any option means consume all unallocated" echo"space on SD card." echo"" echo"Example:" echo"${script_name}" echo"${script_name} -s 16384" }
if [[ "${root_dev}" == *UUID* ]]; then root_dev="$(/sbin/findfs ${root_dev})" fi
if [[ "${root_dev}" == /dev/mmcblk* ]] || [[ "${root_dev}" == /dev/sd* ]]; then block_dev="$(/bin/lsblk -no pkname ${root_dev})" root_dev="$(echo $root_dev | sed 's/^.....//g')" fi
if [ "${block_dev}" != "" ]; then # Check whether APP partition is located at the end of the disk root_start_sector="$(cat /sys/block/${block_dev}/${root_dev}/start)" all_start_sectors="$(cat /sys/block/${block_dev}/*/start)"
is_last="true" for start_sector in${all_start_sectors}; do if [[ "${start_sector}" -gt "${root_start_sector}" ]]; then is_last="false" break fi done support_resizefs="${is_last}" fi }