Skip to content

Commit

Permalink
Доработал скрипт с учетом nvme
Browse files Browse the repository at this point in the history
  • Loading branch information
apor committed Apr 11, 2024
1 parent 0816d1f commit 716ffea
Showing 1 changed file with 23 additions and 18 deletions.
41 changes: 23 additions & 18 deletions src/Core/System/RootFS/etc/rc/resize_storage_part
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#

disk="${1}";
disk_name=$(basename $disk);
disk_name="$(basename "$disk")";

# Check if the block device exists
if [ ! -b "${disk}" ]; then
Expand All @@ -28,21 +28,26 @@ if [ ! -b "${disk}" ]; then
fi;

# Determine the partition number based on whether it's a system disk or a storage disk
if [ -b "${disk}4" ]; then
# System disk
part='4';
else
# Storage disk
part='1';
part=4;
storageDev="$(/bin/lsblk -r -p | /bin/busybox grep "$(/bin/busybox basename "$disk")" | /bin/busybox cut -d ' ' -f 1 | /bin/busybox grep "4$" | /bin/busybox sort -u)";
systemPart="$storageDev";
if [ ! -b "${storageDev}" ]; then
part=1;
storageDev="$(/bin/lsblk -r -p | /bin/busybox grep "$(/bin/busybox basename "$disk")" | /bin/busybox cut -d ' ' -f 1 | /bin/busybox grep "1$" | /bin/busybox sort -u)";
fi;

if [ ! -b "${storageDev}" ]; then
echo " - ERROR block devise ${disk} not found";
exit 4;
fi;

tmp_dir='/storage/usbdisk1';
mkdir -p "$tmp_dir";

# Mount the partition
mount "${disk}${part}" "$tmp_dir";
mount "${storageDev}" "$tmp_dir";
if [ "$?" != "0" ]; then
echo " - ERROR mount storage disk part ${part}...";
echo " - ERROR mount storage disk ${storageDev}...";
rm -rf "$tmp_dir";
exit 2;
fi;
Expand All @@ -52,20 +57,20 @@ total_byte=`busybox blockdev --getsize64 $disk`;
total=`expr $total_byte / 1024 / 1024`;

# Get the size of the partition in megabytes
disk_size=`/bin/busybox df -P -m | /bin/busybox grep "${disk}${part}" | busybox head -n 1 | /bin/busybox awk '{ print $2}'`;
disk_size=`/bin/busybox df -P -m | /bin/busybox grep "${storageDev}" | busybox head -n 1 | /bin/busybox awk '{ print $2}'`;

# Unmount the partition
umount "${disk}${part}";
umount "${storageDev}";

# Calculate the difference in size (delta) between the total size and partition size
delta=`expr $total - $disk_size`;

echo " - disk: '${disk}'";
echo " - disk: '${storageDev}'";
echo " - total_size: ${total}Mb";
echo " - partition_size: ${disk_size}Mb";

if [ -b "${disk}4" ]; then
echo " - is SYSTEM disk: '${disk}'";
if [ -b "${systemPart}" ]; then
echo " - is SYSTEM disk: '${storageDev}'";
system_size=600;
if [ "$delta" -le "$system_size" ]; then
delta=0;
Expand Down Expand Up @@ -93,7 +98,7 @@ if [ "${is_mounted}x" != "x" ]; then
/sbin/freestorage;
fi;

echo " - delete part ${part} / add new part ${part}...";
echo " - delete part ${storageDev} / add new part ${storageDev}...";

if [ -b "${disk}4" ]; then
# Clear existing configuration for system disk
Expand Down Expand Up @@ -126,13 +131,13 @@ fi;
sleep 2;

# Get the file system type for the partition
fs_type=$(/sbin/blkid -ofull "${disk}${part}");
fs_type=$(/sbin/blkid -ofull "${storageDev}");
if [ "${fs_type}x" != "x" ]; then
echo " - e2fsck ${disk} part ${part}...";
e2fsck -f -p "${disk}${part}";
e2fsck -f -p "${storageDev}";
sleep 2;
echo " - resize2fs ${disk} part ${part}..."
resize2fs "${disk}${part}";
resize2fs "${storageDev}";
sleep 2;
else
echo " - error blkid $?"
Expand Down

0 comments on commit 716ffea

Please sign in to comment.