Skip to content

Commit

Permalink
bsp: Bugfix: handle over-mounted mountpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
hzyitc committed Jan 12, 2023
1 parent a3feee9 commit 06dda19
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 27 deletions.
2 changes: 1 addition & 1 deletion packages/blobs/desktop/chromium.conf
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ CHROMIUM_FLAGS="--disable-smooth-scrolling \
--profiler-timing=0 \
--disable-composited-antialiasing \
--disk-cache-dir=/tmp/${USER}-cache \
--disk-cache-size=$(findmnt --target /tmp -n -o AVAIL -b | awk '{printf ("%0.0f",$1*0.3); }') \
--disk-cache-size=$(findmnt --noheadings --output AVAIL --bytes --target "/tmp" --uniq | awk '{printf ("%0.0f",$1*0.3); }') \
--no-sandbox \
--test-type"
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ for f in $files; do
done

check_boot_dev (){
available_size_boot_device=$(df -h | awk '/boot$/{print $4}')
available_size_boot_device=$(df --output="avail" -h "/boot" | awk 'END{print $1}')
echo "Free space after deleting the package $DPKG_MAINTSCRIPT_PACKAGE in /boot: $available_size_boot_device" >&2
}
mountpoint -q /boot && check_boot_dev
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ for f in $files; do
done

check_boot_dev (){
available_size_boot_device=$(df -h | awk '/boot$/{print $4}')
available_size_boot_device=$(df --output="avail" -h "/boot" | awk 'END{print $1}')
echo "Free space after deleting the package $DPKG_MAINTSCRIPT_PACKAGE in /boot: $available_size_boot_device" >&2
}
mountpoint -q /boot && check_boot_dev
Expand Down
17 changes: 9 additions & 8 deletions packages/bsp/common/etc/update-motd.d/30-armbian-sysinfo
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,16 @@ function get_ip_addresses() {

function storage_info() {
# storage info
RootInfo=$(df -h /)
root_usage=$(awk '/\// {print $(NF-1)}' <<<${RootInfo} | sed 's/%//g')
root_total=$(awk '/\// {print $(NF-4)}' <<<${RootInfo})
StorageInfo=$(df -h $STORAGE 2>/dev/null | grep $STORAGE)
if [[ -n "${StorageInfo}" && ${RootInfo} != *$STORAGE* ]]; then
storage_usage=$(awk '/\// {print $(NF-1)}' <<<${StorageInfo} | sed 's/%//g')
storage_total=$(awk '/\// {print $(NF-4)}' <<<${StorageInfo})
local RootInfo=$(df --output=source,size,pcent --human-readable "/" | tail -n1)
local root_device="$(awk '{print $1}' <<<${RootInfo})"
root_total=$(awk '{print $2}' <<<${RootInfo})
root_usage=$(awk '{print $3}' <<<${RootInfo} | sed 's/%//g')
if [[ "${root_device}" != "${STORAGE}" && -b "${STORAGE}" ]]; then
local StorageInfo=$(df --output=size,pcent --human-readable "${STORAGE}" | tail -n1)
storage_total=$(awk '{print $1}' <<<${StorageInfo})
storage_usage=$(awk '{print $2}' <<<${StorageInfo} | sed 's/%//g')
if [[ -n "$(command -v smartctl)" ]]; then
DISK="${STORAGE::-1}"
DISK="/dev/$(lsblk --noheadings --nodeps --output PKNAME "${STORAGE}")"
storage_temp+=$(smartctl -l scttempsts $DISK 2> /dev/null | grep -i 'Current Temperature:' | awk '{print $(NF-1)}')
fi
fi
Expand Down
10 changes: 5 additions & 5 deletions packages/bsp/common/usr/bin/armbianmonitor
Original file line number Diff line number Diff line change
Expand Up @@ -1039,11 +1039,11 @@ ShowDeviceWarning() {
} # ShowDeviceWarning

GetDevice() {
TestPath=$(findmnt "$1" | awk -F" " '/\/dev\// {print $2"\t"$3}')
if [[ -z ${TestPath} && -n "${1%/*}" ]]; then
GetDevice "${1%/*}"
elif [[ -z ${TestPath} && -z "${1%/*}" ]]; then
findmnt / | awk -F" " '/\/dev\// {print $2"\t"$3}'
TestPath=$(findmnt --noheadings --output SOURCE,FSTYPE "$1" --uniq)
if [[ -z ${TestPath} ]]; then
[[ -n "${1%/*}" ]] \
&& GetDevice "${1%/*}" \
|| GetDevice "/"
else
echo "${TestPath}"
fi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ set_io_scheduler() {

prepare_board() {

CheckDevice=$(for i in /var/log /var /; do findmnt -n -o SOURCE $i && break; done)
CheckDevice=$(for i in /var/log /var /; do findmnt --noheadings --output SOURCE --target "$i" --uniq && break; done)
# adjust logrotate configs
if [[ "${CheckDevice}" == *"/dev/zram"* || "${CheckDevice}" == "armbian-ramlog" ]]; then
for ConfigFile in /etc/logrotate.d/*; do sed -i -e "s/\/var\/log\//\/var\/log.hdd\//g" "${ConfigFile}"; done
Expand Down
8 changes: 4 additions & 4 deletions packages/bsp/common/usr/lib/armbian/armbian-resize-filesystem
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ do_expand_filesystem()
local partdev=$1
local mountpoint=$2

local fstype=$(findmnt -n -o FSTYPE $mountpoint) # i.e. ext4 or btrfs
local fstype=$(findmnt --noheadings --output FSTYPE --target "$mountpoint" --uniq) # i.e. ext4 or btrfs

echo -e "\n### [resize2fs] Trying to resize $fstype filesystem on $partdev:\n"

Expand All @@ -231,7 +231,7 @@ do_expand_filesystem()

# 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)
local fssize=$(findmnt --noheadings --output SIZE --bytes --target "$mountpoint" --uniq)
if [[ $(( 100 * $fssize / $devsize )) -lt 90 ]]; then
echo -e "\n### [resize2fs] Automated reboot needed to finish the resize procedure"
touch /var/run/resize2fs-reboot
Expand All @@ -254,8 +254,8 @@ main()
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
# Use `--nofsroot` to trim any btrfs subvolume identifier given in square brackets (e.g. /dev/mapper/armbian-root[/@])
local rootdev=$(findmnt --noheadings --output SOURCE --nofsroot --target "/" --uniq) # i.e. /dev/mmcblk0p1, /dev/sda1 or /dev/mapper/armbian-root

# check for crypt
local cryptname=""
Expand Down
2 changes: 1 addition & 1 deletion packages/bsp/common/usr/lib/armbian/armbian-truncate-logs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ if [ -z "`grep ^Storage=volatile /etc/systemd/journald.conf`" -a -z "$(ls -A /ru
journalctl --relinquish-var # make sure to do volatile logging until the next flush
fi

logusage=$(df /var/log/ --output=pcent | tail -1 |cut -d "%" -f 1)
logusage=$(df --output=pcent "/var/log/" | awk 'END{print $1}' | sed 's/%//')
if [ $logusage -ge $treshold ]; then
# remove journal backup files created by armbian-ramdisk in case of duplicate journals directories
rm -rf /var/log.hdd/journal-*
Expand Down
6 changes: 3 additions & 3 deletions packages/bsp/common/usr/sbin/armbian-install
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ create_armbian()
echo "Root: \$2 $2 $FilesystemChoosen" >> $logfile

# calculate usage and see if it fits on destination
USAGE=$(df -BM | grep ^/dev | head -1 | awk '{print $3}' | tr -cd '[0-9]. \n')
DEST=$(df -BM | grep ^/dev | grep "${TempDir}"/rootfs | awk '{print $4}' | tr -cd '[0-9]. \n')
USAGE=$(df --output="used" --block-size=1M "/" | awk 'END{print $1}')
DEST=$(df --output="avail" --block-size=1M "${TempDir}/rootfs" | awk 'END{print $1}')
if [[ $USAGE -gt $DEST ]]; then
dialog --title "$title" --backtitle "$backtitle" --colors --infobox\
"\n\Z1Partition too small.\Zn Needed: $USAGE MB Avaliable: $DEST MB" 5 60
Expand Down Expand Up @@ -391,7 +391,7 @@ create_armbian()
dd if=/dev/zero of="${TempDir}"/rootfs/swapfile bs=$(cat /proc/meminfo | awk '/MemTotal/ {print $2}') count=1024 conv=notrunc
mkswap "${TempDir}"/rootfs/swapfile
chmod 0600 "${TempDir}"/rootfs/swapfile
sed -i "/^GRUB_CMDLINE_LINUX_DEFAULT=/ s/\"$/ resume=UUID=$(findmnt -no UUID -T "${TempDir}"/rootfs/swapfile) resume_offset=$(filefrag -v "${TempDir}"/rootfs/swapfile |grep " 0:"| awk '{print $4}' | cut -d"." -f1)\"/" "${TempDir}"/rootfs/etc/default/grub.d/98-armbian.cfg
sed -i "/^GRUB_CMDLINE_LINUX_DEFAULT=/ s/\"$/ resume=UUID=$(findmnt --noheadings --output UUID --target "${TempDir}/rootfs/swapfile" --uniq) resume_offset=$(filefrag -v "${TempDir}"/rootfs/swapfile |grep " 0:"| awk '{print $4}' | cut -d"." -f1)\"/" "${TempDir}"/rootfs/etc/default/grub.d/98-armbian.cfg

echo "GRUB_DISABLE_OS_PROBER=false" >> "${TempDir}"/rootfs/etc/default/grub.d/98-armbian.cfg

Expand Down
2 changes: 1 addition & 1 deletion packages/bsp/common/usr/sbin/ddbr
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ image=BACKUP-arm-64-emmc.img

if [ "$wantsbackup" = true ]
then
rootfree=$(df | grep /$ | awk '{print $4}')
rootfree=$(df --output="avail" "/" | awk 'END{print $1}')
[ $rootfree -le $intsize ] && echo -e "$_r NOT ENOUGH FREE SPACE! \n FORCING COMPRESSION MODE $_x" && compress=true
else
echo "$_b AVAILABLE DEVICES: "$_g"$(echo $avail)""$_x"
Expand Down
2 changes: 1 addition & 1 deletion packages/bsp/h3disp
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ PatchScriptBin() {
# try to find location of script.bin
Path2ScriptBin=/boot
if [ ! -f "${Path2ScriptBin}/script.bin" ]; then
Path2ScriptBin="$(df | awk -F" " '/^\/dev\/mmcblk0p1/ {print $6}')"
Path2ScriptBin="$(findmnt --noheadings --output TARGET --source "/dev/mmcblk0p1" --uniq)"
if [ ! -f "${Path2ScriptBin}/script.bin" ]; then
echo -e "Aborted\nCan not find script.bin. Ensure boot partition is mounted" >&2
logger "Can not find script.bin. Ensure boot partition is mounted"
Expand Down

0 comments on commit 06dda19

Please sign in to comment.