2015-12-02 19:33:32 +00:00
|
|
|
#!/bin/bash
|
2018-06-16 17:41:16 +00:00
|
|
|
#
|
2021-06-10 09:27:51 +00:00
|
|
|
# Copyright (c) Authors: https://www.armbian.com/authors
|
2018-06-16 17:41:16 +00:00
|
|
|
#
|
|
|
|
|
# This file is licensed under the terms of the GNU General Public
|
|
|
|
|
# License version 2. This program is licensed "as is" without any
|
|
|
|
|
# warranty of any kind, whether express or implied.
|
2014-10-08 05:39:24 +00:00
|
|
|
|
2017-09-17 14:06:32 +00:00
|
|
|
. /etc/armbian-release
|
2017-01-16 18:53:36 +00:00
|
|
|
. /lib/init/vars.sh
|
|
|
|
|
. /lib/lsb/init-functions
|
2018-06-16 17:41:16 +00:00
|
|
|
. /usr/lib/armbian/armbian-common
|
2017-01-16 18:53:36 +00:00
|
|
|
|
|
|
|
|
do_expand_partition()
|
|
|
|
|
{
|
2022-08-13 19:17:33 +00:00
|
|
|
local partdev=$1
|
|
|
|
|
echo -e "\n### [resize2fs] Trying to resize partition $partdev:\n"
|
|
|
|
|
|
|
|
|
|
# make sure the target is a partition
|
|
|
|
|
local parttype=$(lsblk -n -o TYPE $partdev | head -1)
|
|
|
|
|
if [[ "$parttype" != "part" ]]; then
|
|
|
|
|
echo -e "\n$partdev isn't a partition: $parttype" >&2
|
|
|
|
|
return 1
|
extensions framework + UEFI aarch64/x86 + rpi4b + core changes/fixes (#3300)
* extensions framework (née "fragments")
- this should actually change nothing at this point, just add capabilities
- the framework is implemented in lib/extensions.sh
- the "if function x exists then call x" replaced with call_extension_method()
- +inline documentation
- +compatibility names
Signed-off-by: Ricardo Pardini <ricardo@pardini.net>
* extensions framework; meta-extensions: auto-docs and sample extension gen
- 2 extensions dealing with extensibility itself
- detect-unused-extensions: shows which extensions are enabled, but never called.
- gen-sample-extension-docs: generates a sample empty extension & Markdown documentation for extensions
Signed-off-by: Ricardo Pardini <ricardo@pardini.net>
* new extension methods and features via config variables in core Armbian
- `SKIP_EXTERNAL_TOOLCHAINS=yes` - does not download or use any linaro toolchains, only build host-installed ones
- `SKIP_BOOTSPLASH=yes` - does not patch kernel for splash file
- `EXTRA_BSP_NAME=xyz` - allows for BSP variants, useful for when extensions modify the BSP
- `EXTRA_ROOTFS_MIB_SIZE=x` - add x mib's to rootfs size, for use with very small images
- `KERNEL_EXTRA_TARGETS` - what extra targets to make kernel for, default to "modules dtbs"
- `BOOTCONFIG=none` - does not build nor install u-boot; also doesn't handle bootscripts et al
- `unset KERNELSOURCE` - does not build nor install kernel, nor build initrd, nor build nor install firmware
- `ARMHF_ARCH=skip` - does not add armhf to apt/dpkg, thus pure arm64
- `SKIP_ARMBIAN_REPO=yes` - results in armbian.list.disabled in the final image
- define `APT_EXTRA_DIST_PARAMS` with apt-cacher-ng options and use it for `PACKAGE_LIST_INSTALL/REMOVE` et al
- initial support for targeting x86/amd64 UEFI and BIOS
- some do's/don'ts for x86/amd64, like a different `UBUNTU_MIRROR` default
- GPT/EFI(ESP) partitions (fat, `UEFISIZE=256` to enable, mount `UEFI_MOUNT_POINT=/boot/efi`, first on disk but ends
up at `$uefipart`=15)
- GPT/BIOS partitions (fat, `BIOSSIZE=1` to enable, second on disk but ends up at partition 14)
- `UEFI_FS_LABEL="armbiefi"` - to set the FAT label for the EFI partition, visible in Win/Mac
- hard-requires gdisk package host-side
- add add_host_dependencies() extension method; fill `EXTRA_BUILD_DEPS="pkg pkg2"` to install to host before toolchains
download
- add pre_prepare_partitions() extension method, for custom partition size calculations
- add create_partition_table() extension method, used to do full-custom partitioning if `USE_HOOK_FOR_PARTITION=yes`
- add post_create_partitions() extension method, mostly for easy debugging
- add post_write_sdcard() extension method, where you can also set `SKIP_VERIFY=yes` to skip sdcard verification
- add post_install_kernel_debs() extension method.
- multiple fixes to bsp to avoid spurious errors when files are not where it expects
- v4: detect `update-initramfs` failure and abort build with useful message if it does
- v4: show useful stacktrace in `exit_with_error`
- if `ERROR_DEBUG_SHELL=yes`, drop into a shell before unmounting/deleting everything, so we can inspect what went wrong
- v4: display a message before `apt-get remove PACKAGE_LIST_BOARD_REMOVE` packages, so any errors while removing are easy to understand
- v4: preserve kernel .config's dates when copying
Signed-off-by: Ricardo Pardini <ricardo@pardini.net>
* extensions framework; refactor tool fetching/building into extensions
- a few examples of core refactoring using extensions
- sunxi-tools extension, enabled by 2 different sunxi family includes ("reuse" example)
- marvel-tools extension, enabled by 2 different mvebu family includes
- rkbin-tools extension, enabled by rockship64_common family include
- amlogic-fip/c2-blobs stuff refactored directly into meson64_common.inc ("single-use" example)
- removed the 'testings' fetch_from_repo completely since not used anywhere.
Signed-off-by: Ricardo Pardini <ricardo@pardini.net>
* .wip's for UEFI arm64 and UEFI/BIOS x86 via new GRUB extension
- v3: added `growroot`-awareness to `armbian-resize-filesystem`
- the partition-growing part of `armbian-resize-filesystem` does not deal correctly with the UEFI layout
- `growroot` is installed on UEFI images by default, that handles growing partition during initramfs
- now `armbian-resize-filesystem` handles `resize2fs` only, and works.
- v4: reworked UEFI board/family/include structure:
- use Distro's `linux-generic` kernel only for `current`
- `edge` now builds it's own pure-mainline `5.15.y` kernel, for both x86 and arm64
- `.config` taken from Ubuntu, probably needs tuning for EXTRAWIFI=yes et al
- v4: introduce `SKIP_KERNEL_SYMLINK=yes`, tested in `builddeb`
- to avoid symlinking kernel; u-boot likes it, but grub and flash-kernel hates it
- v5: many fixes
- v7: more small fixes.
Signed-off-by: Ricardo Pardini <ricardo@pardini.net>
* .wip for the RaspberryPi 4B via new flash-kernel extension
- this does not build it's own kernel "yet", but uses default linux-raspi kernel from Ubuntu
- flash-kernel is not really a bootloader
- it just prepares kernel et al a FAT partition for booting by the RPi4b bootloader
- flash-kernel is standard Debian package, but has only been tested on Ubuntu releases
- it is really only known-working since Hirsute release.
- Debian's rpi kernel is armhf only, so out of scope here, at least until we add source-built kernels.
- v3: fixed focal rootfs build. untested.
- v3: better variable names, preparing for source-built kernel.
- v5: new edge build with pure mainline kernel.
- v6: many fixes and some hacks for packaging and layout, also firmware (using Ubuntu's)
Signed-off-by: Ricardo Pardini <ricardo@pardini.net>
* Added first patch to edge x86 related to wifi drivers
* extensions: leave hostapd alone; remove hackish ext; block reentrancy
- package-list-utils does not belong in this PR
- grub or bcm2711 is not the place to remove hostapd
- block recursive enable_extension() calls, for now.
Signed-off-by: Ricardo Pardini <ricardo@pardini.net>
* gen-sample-extension-docs: fix: avoid counter in generated sample
Signed-off-by: Ricardo Pardini <ricardo@pardini.net>
* extensions: dependencies: enable_extension() in extensions with a stack
- and better stacktraces, I hope
Signed-off-by: Ricardo Pardini <ricardo@pardini.net>
* Remove code from package list since we don't have it in repository
Adjust kernel config to disable driver that needs further polishing.
* Allow amd64 to build the same desktops as aarch64. We only have this limit for armhf, where some desktops don't work
* amd64: allow building amd64 on aarch64 with system toolchain
- conditionally add gcc-x86-64-linux-gnu to hostdeps
Signed-off-by: Ricardo Pardini <ricardo@pardini.net>
* add libelf-dev directly to hostdeps (and Dockerfile), remove extension
Signed-off-by: Ricardo Pardini <ricardo@pardini.net>
* packaging: remove SKIP_KERNEL_SYMLINK hack, fix the root cause
- which was the missing $image_name for non-arm64 & non-arm, so: x86 for example
Signed-off-by: Ricardo Pardini <ricardo@pardini.net>
* grub: really obliterate u-boot stuff from BSP
- for now. soon we'll refactor u-boot so not have to do this
Signed-off-by: Ricardo Pardini <ricardo@pardini.net>
* flash-kernel: really obliterate u-boot stuff from BSP
- for now. soon we'll refactor u-boot so not have to do this
Signed-off-by: Ricardo Pardini <ricardo@pardini.net>
* extensions: add host_dependencies_ready() hook
- this passes FINAL_HOST_DEPS containing all hostdeps for the run after they're installed
Signed-off-by: Ricardo Pardini <ricardo@pardini.net>
* Add verification functions for correct selection.
* If UEFI Skip symlink creation
* Do not create dtb package for amd64
* Skip scripts folder cleaning if build process native.
Skip creating postinst prerm scripts for headers.
* Skip applying headers-debian-byteshift.patch if build native
* Fix architecture syntax as x86_64
* Revert "amd64: allow building amd64 on aarch64 with system toolchain"
This reverts commit 0c5ee20bb1b33a133e6e359476082d43d5ad457c.
* Compare architectures before starting compilation.
Signed-off-by: The-going <48602507+The-going@users.noreply.github.com>
* extensions: cleanups after fixes by the-Going
- packaging:
- there is _no need_ anymore for the symlink hack, CONFIG_EFI or no. But check is great, see below
- it's not `amd64` that has no DTB's, it's all UEFI, thus: `is_enabled CONFIG_EFI`, thanks!
- Explicitly disallow "reverse cross compile" in amd64.conf.
- whitespace-only-deletions: revert. we shall shellfmt the whole thing one day, but not today.
- fix a few syntax warnings in newly introduced code (floating `$ARCH` vs `"${ARCH}`) - blame shellcheck
Signed-off-by: Ricardo Pardini <ricardo@pardini.net>
* packaging: fix: turns out a lot of boards have CONFIG_EFI=y, can't use that for dtb/no-dtb decision.
Signed-off-by: Ricardo Pardini <ricardo@pardini.net>
* grub: remove debug
Signed-off-by: Ricardo Pardini <ricardo@pardini.net>
* firmware: allow installing `armbian-firmware-full`; make it really full
- can now use `BOARD_FIRMWARE_INSTALL="-full"` to install full firmware for the board. enable for UEFI.
- don't rely on KERNELSOURCE for firmware-related decisions. introduce `INSTALL_ARMBIAN_FIRMWARE` which defaults to `yes`
- rpi4b/flash-kernel: disable Armbian firmware; we need linux-firmware-raspi2, which conflicts.
Signed-off-by: Ricardo Pardini <ricardo@pardini.net>
* extensions: log to /${LOG_SUBPATH}/ instead of fixed /debug/
Signed-off-by: Ricardo Pardini <ricardo@pardini.net>
* extensions: introduce cleanup_extension_manager() called by build-all-ng's unset_all()
- to reset/unset everything done by the the initializer, so build can run again
Signed-off-by: Ricardo Pardini <ricardo@pardini.net>
* extensions: remove 'global' logging, for use with build_all_ng
- enable_extensions() will have to live on without logging to file. it's just too early.
- now init EXTENSION_MANAGER_TMP_DIR in initialize_extension_manager()
- now init EXTENSION_MANAGER_LOG_FILE in initialize_extension_manager()
Signed-off-by: Ricardo Pardini <ricardo@pardini.net>
* extensions: build-all-ng.sh bugfix due to extension's debug to stdout
- extensions (among other things) can produce output to stdout when activated
- fix: check_hash() produced "idential" (sic, now changed to IDENTICAL) to stdout as a trigger
- debugging output got mixed with "idential", rendering hash cache void for families that used extensions
- eg: sunxi, others
- fix is to send stdout to the bitbucket when sourcing the board & arch config files
- proper fix would be stop using stdout in this case and use return code for check_hash()
- one day soon
Signed-off-by: Ricardo Pardini <ricardo@pardini.net>
* Add CI build targets
Co-authored-by: Igor Pecovnik <igor.pecovnik@gmail.com>
Co-authored-by: The-going <48602507+The-going@users.noreply.github.com>
2021-12-06 08:49:49 +00:00
|
|
|
fi
|
2022-08-13 19:17:33 +00:00
|
|
|
|
|
|
|
|
local diskdevname=$(lsblk -n -o PKNAME $partdev | head -1) # i.e. mmcblk0 or sda
|
2019-11-19 22:25:39 +00:00
|
|
|
# due to the bug in util-linux 2.34 which fails to show device, let's use this failover:
|
2022-08-13 19:17:33 +00:00
|
|
|
[[ -z $diskdevname ]] && diskdevname=$(echo $partdev | sed -e "s/^\/dev\///" | sed "s/p.*//")
|
|
|
|
|
local diskdev="/dev/$diskdevname" # i.e. /dev/mmcblk0, /dev/sda
|
|
|
|
|
echo "diskdevname: $diskdevname"
|
|
|
|
|
echo "diskdev: $diskdev"
|
|
|
|
|
|
|
|
|
|
# detect partindex
|
|
|
|
|
local partindex="$(echo $partdev | sed "s|^$diskdev||" | sed 's/^p//')" # i.e. 1
|
|
|
|
|
if [[ -n "$(echo "$partindex" | tr -d '[:digit:]')" ]]; then
|
|
|
|
|
echo -e "\nFail to detect partindex: $partindex" >&2
|
|
|
|
|
return 1
|
|
|
|
|
fi
|
|
|
|
|
echo "partindex: $partindex"
|
|
|
|
|
|
|
|
|
|
# find the target part's boundaries
|
|
|
|
|
local partstart=$(parted $diskdev unit s print -sm | awk -F':' "NR>=3{if(\$1 == $partindex){print \$2}}" | sed 's/s//')
|
|
|
|
|
local partend=$(parted $diskdev unit s print -sm | awk -F':' "NR>=3{if(\$1 == $partindex){print \$3}}" | sed 's/s//')
|
|
|
|
|
if [[ -z "$partstart" ]] || [[ -z "$partend" ]]; then
|
|
|
|
|
echo -e "\nFail to find the target partition" >&2
|
|
|
|
|
return 1
|
|
|
|
|
fi
|
|
|
|
|
echo "partstart: ${partstart}s"
|
|
|
|
|
echo "partend: ${partend}s"
|
|
|
|
|
|
|
|
|
|
# check if it's the last partition in logical layout
|
|
|
|
|
# Note: the order may be different between partition table and logical layout
|
|
|
|
|
local list=$(parted $diskdev unit s print -sm | awk -F':' "NR>=3{if(\$2 - $partstart > 0){print \$1}}")
|
|
|
|
|
if [[ -n "$list" ]]; then
|
|
|
|
|
echo -e "\nThe target partition isn't the last partition in logical layout" >&2
|
|
|
|
|
echo "Partition ${list[*]} behind it" >&2
|
|
|
|
|
return 1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
local capacity=$(parted $diskdev unit s print -sm | awk -F':' 'NR==2{print $2}' | sed 's/s//')
|
|
|
|
|
local sectorsize=$(parted $diskdev unit s print -sm | awk -F':' 'NR==2{print $4}')
|
|
|
|
|
echo "capacity: ${capacity}s"
|
|
|
|
|
echo "sectorsize: ${sectorsize}B"
|
2017-01-16 18:53:36 +00:00
|
|
|
|
|
|
|
|
# check whether a resizing rule is defined. We will take this value if it's not too low. In
|
|
|
|
|
# this case the value will be ignored and resizing to the whole card size happens.
|
|
|
|
|
if [[ -f /root/.rootfs_resize ]]; then
|
|
|
|
|
read RESIZE_VALUE </root/.rootfs_resize
|
2022-08-13 19:17:33 +00:00
|
|
|
echo "Resize rule $RESIZE_VALUE defined for root partition"
|
2017-01-16 18:53:36 +00:00
|
|
|
case $RESIZE_VALUE in
|
|
|
|
|
*%)
|
2022-08-13 19:17:33 +00:00
|
|
|
# percentage value
|
2017-01-16 18:53:36 +00:00
|
|
|
local percentage=$(echo $RESIZE_VALUE | tr -c -d '[:digit:]')
|
2022-08-13 19:17:33 +00:00
|
|
|
local lastsector=$(( $capacity * $percentage / 100 ))
|
2017-01-16 18:53:36 +00:00
|
|
|
;;
|
|
|
|
|
*s)
|
|
|
|
|
# sector value, we use it directly
|
|
|
|
|
local lastsector=$(echo $RESIZE_VALUE | tr -c -d '[:digit:]')
|
2022-08-13 19:17:33 +00:00
|
|
|
;;
|
|
|
|
|
*B)
|
|
|
|
|
# byte value
|
|
|
|
|
local byte=$(echo $RESIZE_VALUE | tr -c -d '[:digit:]')
|
|
|
|
|
local lastsector=$(( $byte / $sectorsize ))
|
|
|
|
|
;;
|
|
|
|
|
*)
|
|
|
|
|
echo -e "\nUnknown rule: $RESIZE_VALUE" >&2
|
|
|
|
|
return 1;
|
2017-01-16 18:53:36 +00:00
|
|
|
;;
|
|
|
|
|
esac
|
2022-08-13 19:17:33 +00:00
|
|
|
|
|
|
|
|
# if remain more than 1GiB then create another partition
|
|
|
|
|
if [[ $(( $sectorsize * ($capacity - $lastsector) )) -ge $(( 1 * 1024 * 1024 * 1024 )) ]]; then
|
|
|
|
|
local newpartition=$(( $capacity * 99 / 100 ))
|
2017-04-12 13:04:21 +00:00
|
|
|
fi
|
2017-01-16 18:53:36 +00:00
|
|
|
else
|
2020-06-27 12:13:33 +00:00
|
|
|
# check device capacity. If 4GiB or below do not use whole card but leave a 5% spare area
|
2017-01-16 18:53:36 +00:00
|
|
|
# to help older cards with wear leveling and garbage collection. In case this reduced card
|
|
|
|
|
# capacity is less than the actual image capacity this is a clear sign that someone wants
|
|
|
|
|
# to use Armbian on a card of inappropriate size so he gets what he deserves (at least he
|
|
|
|
|
# should know what he's doing)
|
2022-08-13 19:17:33 +00:00
|
|
|
if [[ $(( $sectorsize * $capacity )) -lt $(( 4 * 1024 * 1024 * 1024 )) ]]; then # 4 GiB or less
|
|
|
|
|
# Leave 5 percent unpartitioned
|
|
|
|
|
local lastsector=$(( $capacity * 95 / 100 ))
|
|
|
|
|
echo "4GiB or smaller media - leaving 5% spare area"
|
|
|
|
|
elif [[ $(( $sectorsize * $capacity )) -lt $(( 8 * 1024 * 1024 * 1024 )) ]]; then # 8 GiB or less
|
2017-01-16 18:53:36 +00:00
|
|
|
# Leave 2 percent unpartitioned
|
2022-08-13 19:17:33 +00:00
|
|
|
local lastsector=$(( $capacity * 98 / 100 ))
|
|
|
|
|
echo "8GiB or smaller media - leaving 2% spare area"
|
2017-01-16 18:53:36 +00:00
|
|
|
else
|
|
|
|
|
# Leave 1 percent unpartitioned
|
2022-08-13 19:17:33 +00:00
|
|
|
local lastsector=$(( $capacity * 99 / 100 ))
|
|
|
|
|
echo "Leaving 1% spare area"
|
2017-01-16 18:53:36 +00:00
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
|
2022-08-13 19:17:33 +00:00
|
|
|
# use 16MiB to align partitions since this is the erase block size of more recent SD cards
|
2024-02-28 01:50:43 +00:00
|
|
|
local lastsector=$(( $lastsector - ($lastsector % (16 * 1024 * 1024 / $sectorsize)) - 1 ))
|
2022-08-13 19:17:33 +00:00
|
|
|
[[ -n "$newpartition" ]] && local newpartition=$(( $newpartition - ($newpartition % (16 * 1024 * 1024 / $sectorsize)) ))
|
|
|
|
|
|
|
|
|
|
if [[ $lastsector -lt $partend ]]; then
|
|
|
|
|
echo -e "\n${partend} is larger than ${lastsector}s, that means you trying to shrink filesystem. Sorry, this tool designed for expanding only." >&2
|
|
|
|
|
return 1
|
|
|
|
|
elif [[ $lastsector -eq $partend ]]; then
|
|
|
|
|
echo -e "\nSame size. Skip" >&2
|
|
|
|
|
return 0
|
|
|
|
|
fi
|
|
|
|
|
if [[ $newpartition -le $(( $lastsector + 1 )) ]]; then
|
|
|
|
|
unset newpartition
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
echo -e "Old partition table:\n"
|
|
|
|
|
cat /proc/partitions
|
|
|
|
|
|
2017-01-16 18:53:36 +00:00
|
|
|
# Start resizing
|
2022-08-13 19:17:33 +00:00
|
|
|
echo -e "\nExecuting fdisk:"
|
|
|
|
|
local partnum=$(parted $diskdev unit s print -sm | awk 'END{print NR-2}')
|
2017-08-19 14:16:09 +00:00
|
|
|
local fdisk_version=$(fdisk --version | awk '{print $NF}' | grep -oE "^[[:digit:]]\.[[:digit:]]+")
|
2022-08-13 19:17:33 +00:00
|
|
|
if [[ $partnum == 1 ]] && awk "BEGIN{exit ! ($fdisk_version >= 2.27 )}"; then
|
2017-01-16 18:53:36 +00:00
|
|
|
# if dealing with fdisk from util-linux 2.27+ we need a workaround for just 1 partition
|
|
|
|
|
# though it does not break anything - just prevents an "unexpected command" to fdisk
|
|
|
|
|
# https://github.com/igorpecovnik/lib/issues/353#issuecomment-224728506
|
2022-08-13 19:17:33 +00:00
|
|
|
{
|
|
|
|
|
echo d
|
|
|
|
|
echo n; echo p; echo $partindex; echo $partstart; echo $lastsector
|
|
|
|
|
echo w
|
|
|
|
|
} | fdisk $diskdev
|
2017-01-16 18:53:36 +00:00
|
|
|
else
|
2022-08-13 19:17:33 +00:00
|
|
|
{
|
|
|
|
|
echo d; echo $partindex
|
|
|
|
|
echo n; echo p; echo $partindex; echo $partstart; echo $lastsector
|
|
|
|
|
echo w
|
|
|
|
|
} | fdisk $diskdev
|
|
|
|
|
fi
|
|
|
|
|
if [[ -n $newpartition ]]; then
|
|
|
|
|
{
|
|
|
|
|
echo n; echo p; echo ; echo $(( $lastsector + 1 )); echo $newpartition
|
|
|
|
|
echo w
|
|
|
|
|
} | fdisk $diskdev
|
2017-01-16 18:53:36 +00:00
|
|
|
fi
|
2020-09-13 17:45:07 +00:00
|
|
|
|
2022-08-13 19:17:33 +00:00
|
|
|
echo -e "\nExecuting partprobe:"
|
2020-09-13 17:45:07 +00:00
|
|
|
# Workaround for Kernel bug in 5.8.y and up. Ignore partprobe returning error and inticating that fs is not expended while it is
|
|
|
|
|
KERNELID=$(uname -r | awk -F'.' '{print ($1 * 100) + $2}')
|
2022-08-13 19:17:33 +00:00
|
|
|
if ! partprobe $rootdev && [[ ${KERNELID} -le 507 ]]; then
|
|
|
|
|
echo -e "\n### [resize2fs] Automated reboot needed to finish the resize procedure"
|
|
|
|
|
touch /var/run/resize2fs-reboot
|
2018-07-31 21:02:26 +00:00
|
|
|
fi
|
2022-08-13 19:17:33 +00:00
|
|
|
|
|
|
|
|
local partsize=$(lsblk -n -b -o SIZE $partdev | head -1)
|
|
|
|
|
local actualsize=$(( $sectorsize * ($lastsector - $partstart + 1) ))
|
|
|
|
|
if [[ $actualsize -ne $partsize ]]; then
|
|
|
|
|
echo -e "\n### [resize2fs] Automated reboot needed to finish the resize procedure"
|
|
|
|
|
touch /var/run/resize2fs-reboot
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
echo -e "New partition table:\n"
|
|
|
|
|
cat /proc/partitions
|
|
|
|
|
|
|
|
|
|
return 0
|
2017-01-16 18:53:36 +00:00
|
|
|
}
|
|
|
|
|
|
2018-07-31 21:02:26 +00:00
|
|
|
do_resize_crypt()
|
|
|
|
|
{
|
2022-08-13 19:17:33 +00:00
|
|
|
local dev=$1
|
|
|
|
|
local parentdev=$2
|
|
|
|
|
local name=$(lsblk -n -o NAME $dev | head -1) # i.e. armbian-root
|
|
|
|
|
|
|
|
|
|
echo -e "\n### [resize2fs] Start resizing LUKS container now\n"
|
|
|
|
|
# It's probably no need to run 'cryptsetup resize'.
|
|
|
|
|
# After reboot, it will auto resize to adapte the partition
|
|
|
|
|
# 'cryptsetup resize' requires passphrase, so it will fail.
|
|
|
|
|
cryptsetup resize $name
|
|
|
|
|
|
|
|
|
|
local parentsize=$(lsblk -n -b -o SIZE $parentdev | head -1)
|
|
|
|
|
|
|
|
|
|
local sectorsize=$(cryptsetup status $name | awk -F':' '/^ *sector size/ {print $2}' | tr -c -d '[:digit:]')
|
|
|
|
|
local offset=$(cryptsetup status $name | awk -F':' '/^ *offset/ {print $2}' | tr -c -d '[:digit:]')
|
|
|
|
|
local size=$(cryptsetup status $name | awk -F':' '/^ *size/ {print $2}' | tr -c -d '[:digit:]')
|
|
|
|
|
local actualsize=$(( $sectorsize * ($offset + $size) ))
|
|
|
|
|
if [[ $actualsize -ne $parentsize ]]; then
|
|
|
|
|
echo -e "\n### [resize2fs] Automated reboot needed to finish the resize procedure"
|
|
|
|
|
touch /var/run/resize2fs-reboot
|
|
|
|
|
fi
|
2018-07-31 21:02:26 +00:00
|
|
|
}
|
|
|
|
|
|
2022-08-13 19:17:33 +00:00
|
|
|
do_expand_filesystem()
|
2017-01-16 18:53:36 +00:00
|
|
|
{
|
2022-08-13 19:17:33 +00:00
|
|
|
local partdev=$1
|
|
|
|
|
local mountpoint=$2
|
|
|
|
|
|
|
|
|
|
local fstype=$(findmnt -n -o FSTYPE $mountpoint) # i.e. ext4 or btrfs
|
|
|
|
|
|
|
|
|
|
echo -e "\n### [resize2fs] Trying to resize $fstype filesystem on $partdev:\n"
|
|
|
|
|
|
|
|
|
|
case $fstype in
|
|
|
|
|
ext4)
|
|
|
|
|
echo "Running 'resize2fs $partdev' now..."
|
|
|
|
|
resize2fs $partdev
|
|
|
|
|
;;
|
2024-06-30 17:33:33 +00:00
|
|
|
xfs)
|
|
|
|
|
echo "Running 'xfs_growfs $mountpoint' now..."
|
|
|
|
|
xfs_growfs $mountpoint
|
|
|
|
|
;;
|
2022-08-13 19:17:33 +00:00
|
|
|
btrfs)
|
|
|
|
|
echo "Running 'btrfs filesystem resize max $mountpoint' now..."
|
|
|
|
|
btrfs filesystem resize max $mountpoint
|
|
|
|
|
;;
|
2023-05-14 23:17:00 +00:00
|
|
|
nilfs2)
|
2024-06-30 17:33:33 +00:00
|
|
|
echo "Running 'nilfs-resize -v -y $partdev' now..."
|
2023-05-14 23:17:00 +00:00
|
|
|
nilfs-resize -v -y $partdev
|
|
|
|
|
;;
|
2022-08-13 19:17:33 +00:00
|
|
|
*)
|
|
|
|
|
echo "Unsupported filesystem: $fstype"
|
|
|
|
|
echo "Trying to run 'resize2fs $partdev' now..."
|
|
|
|
|
resize2fs $partdev
|
|
|
|
|
return
|
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
|
|
|
|
|
# check whether reboot is necessary for resize2fs to take effect
|
|
|
|
|
local devsize=$(lsblk -n -b -o SIZE $partdev | head -1)
|
|
|
|
|
local fssize=$(findmnt -n -b -o SIZE --target $mountpoint)
|
|
|
|
|
if [[ $(( 100 * $fssize / $devsize )) -lt 90 ]]; then
|
|
|
|
|
echo -e "\n### [resize2fs] Automated reboot needed to finish the resize procedure"
|
|
|
|
|
touch /var/run/resize2fs-reboot
|
|
|
|
|
fi
|
2017-08-28 16:19:57 +00:00
|
|
|
}
|
2017-01-16 18:53:36 +00:00
|
|
|
|
2022-08-13 19:17:33 +00:00
|
|
|
main()
|
2017-08-28 16:19:57 +00:00
|
|
|
{
|
2022-08-13 19:17:33 +00:00
|
|
|
rm /var/run/resize2fs-reboot 2>/dev/null
|
2017-01-16 18:53:36 +00:00
|
|
|
|
2022-08-13 19:17:33 +00:00
|
|
|
# skip resizing if explicitly disabled
|
|
|
|
|
if [[ -f /root/.no_rootfs_resize ]]; then
|
|
|
|
|
systemctl disable armbian-resize-filesystem
|
|
|
|
|
exit 0
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# Logging header
|
|
|
|
|
CPU_ARCH=$(lscpu | awk '/Architecture/ {print $2}')
|
|
|
|
|
DISTRO_ARCH=$(dpkg --print-architecture)
|
|
|
|
|
KERNELID=$(uname -r)
|
|
|
|
|
echo "$(date) | ${BOARD_NAME} | ${VERSION} | ${DISTRO_ARCH} | ${CPU_ARCH} | ${KERNELID}"
|
|
|
|
|
|
|
|
|
|
# trim any btrfs subvolume identifier given in square brackets (e.g. /dev/mapper/armbian-root[/@])
|
|
|
|
|
local rootdev=$(findmnt -n -o SOURCE / | sed 's~\[.*\]~~') # i.e. /dev/mmcblk0p1, /dev/sda1 or /dev/mapper/armbian-root
|
|
|
|
|
|
|
|
|
|
# check for crypt
|
|
|
|
|
local cryptname=""
|
|
|
|
|
if [[ "$(lsblk -n -o TYPE $rootdev | head -1)" == "crypt" ]]; then
|
|
|
|
|
local cryptname=$(lsblk -n -o NAME $rootdev | head -1) # i.e. armbian-root
|
|
|
|
|
local parent_uuid=$(cat /etc/crypttab | awk "{if(\$1 == \"$cryptname\"){print \$2}}" | sed 's/UUID=//')
|
|
|
|
|
local parentdev=$(blkid -U $parent_uuid) # i.e. /dev/mmcblk0p1 or /dev/sda1
|
|
|
|
|
|
|
|
|
|
do_expand_partition "$parentdev"
|
|
|
|
|
|
|
|
|
|
# resize LUKS container
|
|
|
|
|
do_resize_crypt "$rootdev" "$parentdev"
|
|
|
|
|
else
|
|
|
|
|
# check if growroot (from cloud-initramfs-growroot package) is installed.
|
|
|
|
|
# despite it's name, that package does NOT require cloud-init.
|
|
|
|
|
# it will resize the *partition* which root filesystem on during initramfs.
|
|
|
|
|
# in this case do nothing here, just run resize2fs (growroot does not handle that).
|
|
|
|
|
# Note: it can't handle crypt device
|
|
|
|
|
if [[ -f /usr/share/initramfs-tools/hooks/growroot ]] || [[ -f /usr/share/initramfs-tools/scripts/local-bottom/growroot ]]; then
|
|
|
|
|
echo "partition resize skipped: growroot detected."
|
|
|
|
|
else
|
|
|
|
|
do_expand_partition "$rootdev"
|
2017-08-28 16:19:57 +00:00
|
|
|
fi
|
2022-08-13 19:17:33 +00:00
|
|
|
fi
|
2017-01-16 18:53:36 +00:00
|
|
|
|
2022-08-13 19:17:33 +00:00
|
|
|
do_expand_filesystem "$rootdev" "/"
|
2017-09-17 14:06:32 +00:00
|
|
|
|
2022-08-13 19:17:33 +00:00
|
|
|
# disable itself
|
|
|
|
|
[[ ! -f /var/run/resize2fs-reboot ]] && systemctl disable armbian-resize-filesystem
|
|
|
|
|
exit 0
|
|
|
|
|
}
|
2017-01-16 18:53:36 +00:00
|
|
|
|
2022-08-13 19:17:33 +00:00
|
|
|
case "$1" in
|
|
|
|
|
start)
|
|
|
|
|
touch ${Log}
|
|
|
|
|
chmod 644 ${Log}
|
|
|
|
|
main |& tee -a ${Log}
|
2017-08-28 16:19:57 +00:00
|
|
|
;;
|
2017-01-16 18:53:36 +00:00
|
|
|
*)
|
2017-08-28 16:19:57 +00:00
|
|
|
echo "Usage: $0 start"
|
|
|
|
|
exit 0
|
2017-01-16 18:53:36 +00:00
|
|
|
;;
|
2018-07-31 21:02:26 +00:00
|
|
|
esac
|