Skip to content

Commit

Permalink
Add XFS partition imaging support, thanks to @rluzuriaga
Browse files Browse the repository at this point in the history
  • Loading branch information
rluzuriaga authored Mar 31, 2023
1 parent 1dfc29d commit 86d3d27
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 2 deletions.
7 changes: 5 additions & 2 deletions Buildroot/board/FOG/FOS/rootfs_overlay/bin/fog.upload
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ beginUpload() {
fsTypeSetting "$part"
getPartitionNumber "$part"
case $fstype in
ntfs|extfs|btrfs|f2fs)
ntfs|extfs|btrfs|f2fs|xfs)
continue
;;
*)
Expand All @@ -61,8 +61,9 @@ beginUpload() {
countPartTypes "$hd" "extfs" "extfscnt"
countPartTypes "$hd" "btrfs" "btrfscnt"
countPartTypes "$hd" "f2fs" "f2fscnt"
countPartTypes "$hd" "xfs" "xfscnt"
countPartTypes "$hd" "*" "partscnt"
if [[ $ntfscnt -eq 0 && $extfscnt -eq 0 && $btrfscnt -eq 0 && $f2fscnt -eq 0 ]]; then
if [[ $ntfscnt -eq 0 && $extfscnt -eq 0 && $btrfscnt -eq 0 && $f2fscnt -eq 0 && $xfscnt -eq 0 ]]; then
echo "Failed"
debugPause
handleError "No resizable partitions found ($0)\n Args Passed: $*"
Expand All @@ -77,6 +78,8 @@ beginUpload() {
debugPause
echo " * F2FS Partition count of: $f2fscnt"
debugPause
echo " * XFS Partition count of: $xfscnt"
debugPause
echo " * Total Partition count of: $partscnt"
debugPause
case $osid in
Expand Down
50 changes: 50 additions & 0 deletions Buildroot/board/FOG/FOS/rootfs_overlay/usr/share/fog/lib/funcs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,53 @@ expandPartition() {
echo "Done"
fi
;;
xfs)
if [[ $type == "down" ]]; then
dots "Attempting to resize $fstype volume ($part)"

# XFS partitions can only be expanded when there is free space after that partition.
# Retrieving the partition number of a XFS partition that has free space after it.
local xfsPartitionNumberThatCanBeExpanded=$(parted -s -a opt $disk "print free" | grep -i "free space" -B 1 | grep -i "xfs" | cut -d ' ' -f2)
local currentPartitionNumber=$(echo $part | grep -o '[0-9]*$')
if [[ "$xfsPartitionNumberThatCanBeExpanded" == "$currentPartitionNumber"a ]]; then
parted -s -a opt $disk "resizepart $xfsPartitionNumberThatCanBeExpanded 100%" >>/tmp/xfslog.txt 2>&1
if [[ $? -gt 0 ]]; then
echo "Failed"
debugPause
handleError "Could not resize partition $part (${FUNCNAME[0]})\n Info: $(cat /tmp/xfslog.txt)\n Args Passed: $*"
fi
if [[ ! -d /tmp/xfs ]]; then
mkdir /tmp/xfs >>/tmp/xfslog.txt 2>&1
if [[ $? -gt 0 ]]; then
echo "Failed"
debugPause
handleError "Could not create /tmp/xfs (${FUNCNAME[0]})\n Info: $(cat /tmp/xfslog.txt)\n Args Passed: $*"
fi
fi
mount -t xfs $part /tmp/xfs >>/tmp/xfslog.txt 2>&1
if [[ $? -gt 0 ]]; then
echo "Failed"
debugPause
handleError "Could not mount $part to /tmp/xfs (${FUNCNAME[0]})\n Info: $(cat /tmp/xfslog.txt)\n Args Passed: $*"
fi
xfs_growfs $part >>/tmp/xfslog.txt 2>&1
if [[ $? -gt 0 ]]; then
echo "Failed"
debugPause
handleError "Could not grow XFS partition $part (${FUNCNAME[0]})\n Info: $(cat /tmp/xfslog.txt)\n Args Passed: $*"
fi
umount /tmp/xfs >>/tmp/xfslog.txt 2>&1
if [[ $? -gt 0 ]]; then
echo Failed
debugPause
handleError "Could not unmount $part from /tmp/xfs (${FUNCNAME[0]})\n Info: $(cat /tmp/xfslog.txt)\n Args Passed: $*"
fi
echo "Done"
else
echo "Failed, XFS partition cannot be expanded"
fi
fi
;;
*)
echo " * Not expanding ($part -- $fstype)"
debugPause
Expand Down Expand Up @@ -724,6 +771,9 @@ shrinkPartition() {
f2fs)
echo " * Cannot shrink F2FS partitions"
;;
xfs)
echo " * Cannot shrink XFS partitions"
;;
*)
echo " * Not shrinking ($part $fstype)"
;;
Expand Down

0 comments on commit 86d3d27

Please sign in to comment.