Skip to content

Commit

Permalink
#837 Поправил преобразование из MBR в GPT разметки диска. Доработал д…
Browse files Browse the repository at this point in the history
…обавление 4ого раздела для системного диска
  • Loading branch information
boffart committed Nov 20, 2024
1 parent 9e7cf14 commit f1f254e
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 6 deletions.
39 changes: 39 additions & 0 deletions src/Core/System/PBXInstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ private function proceedInstallation(): void
// Start the installation process
echo Util::translate("Installing PBX...").PHP_EOL;
$this->unmountPartitions();
$this->convertDiscLayout();
$this->unpackImage();
$this->mountStorage();
$this->copyConfiguration();
Expand All @@ -214,6 +215,44 @@ private function proceedInstallation(): void
System::reboot();
}

/**
* Converting the disk layout
* @param $disk
* @return void
*/
private function convertDiscLayout($disk):void
{
if (!file_exists($disk)) {
$disk = "/dev/$disk";
}
if (!file_exists($disk)) {
return;
}
$gDiskPath = Util::which('gdisk');
if (empty($gDiskPath)) {
return;
}
$partedPath = Util::which('parted');
$command = "$partedPath $disk print | grep 'Partition Table' | awk '{print $3}'";
exec($command, $partitionTypeOutput, $partedStatus);
if ($partedStatus !== 0 || empty($partitionTypeOutput)) {
return;
}
$partitionType = trim($partitionTypeOutput[0]);
if ($partitionType === "msdos") {
echo " - Converting from MBR to GPT...\n";
$echoPath = Util::which('echo');
$gDiskCommand = "$echoPath -e \"w\\nY\\n\" | $gDiskPath $disk > /dev/null 2>&1";
exec($gDiskCommand, $gDiskOutput, $gDiskStatus);
if ($gDiskStatus === 0) {
echo " - The conversion to GPT has been completed successfully.\n";
} else {
echo " - Error converting to GPT.\n";
}
}
}


/**
* Unmount the partitions of the selected disk.
*/
Expand Down
12 changes: 6 additions & 6 deletions src/Core/System/RootFS/sbin/initial_storage_part_four
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,17 @@ if [ "$totalMb" -le "600" ]; then
exit 0;
fi

# Looking for a way to the fourth section
partitionFour=$(/bin/lsblk -r "$dev" -p -o NAME,TYPE| grep "part$" | /bin/busybox cut -d ' ' -f 1 | /bin/busybox grep "4$");
# Get partition info for the device
count=$(/sbin/sfdisk -l "${dev}" | /bin/busybox grep "^/dev" | /bin/busybox wc -l);
if [ "$count" -eq "4" ]; then
if [ -n "$partitionFour" ]; then
# The fourth partition already exists, format it and resize
partitionName=$(/bin/lsblk -r | /bin/busybox grep "$(/bin/busybox basename "$dev")" | /bin/busybox cut -d ' ' -f 1 | /bin/busybox grep "4$" | /bin/sort -u);
partitionFour="/dev/${partitionName}";
echo "Formatting and resizing the existing fourth partition ${partitionFour}..."
/sbin/parted --script "${dev}" resizepart 4 100%
elif [ "$count" -eq "3" ]; then
elif [ "$count" -eq 3 ] || [ "$count" -eq 4 ]; then
# There are only 3 partitions, add a new one
echo "Adding a new partition..."
echo "Adding a new partition №4..."
# Use parted to create a new partition on the device.
# The new partition is primary, has ext4 filesystem, starts from 600MiB, and occupies the rest of the disk.
/sbin/parted --script --align optimal "${dev}" 'mkpart primary ext4 600MiB 100%';
Expand Down Expand Up @@ -97,7 +97,7 @@ done

# If the partition was successfully created
if [ "$resultParted" = "0" ];then
if [ "$action" == "create" ]; then
if [ "$action" = "create" ]; then
/sbin/mkfs.ext4 -qF "${partitionFour}"
sleep 5;
resize2fs ${partitionFour}
Expand Down
14 changes: 14 additions & 0 deletions src/Core/System/RootFS/sbin/pbx_firmware
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,20 @@ fi

# Inform the user of the installation process
if [ -r "${img_file}" ]; then
if command -v gdisk > /dev/null 2>&1; then
PARTITION_TYPE=$(/sbin/parted "$DISK" print | grep "Partition Table" | awk '{print $3}')
echo " - Performing an action for the msdos section"
if [ "$PARTITION_TYPE" == "msdos" ]; then
echo -e "w\nY\n" | gdisk "/dev/${systemDevice}" > /dev/null 2>&1;
resultGDisk="$?";
if [ "$resultGDisk" -eq 0 ]; then
echo " - The conversion to GPT has been completed successfully."
else
echo " - Error converting to GPT."
fi
fi
fi

echo " - Installing new image on /dev/${systemDevice}"
# Use pv to monitor the progress of the data being piped to the dd command
if test -w /dev/ttyS0 && ! /bin/busybox setserial -g /dev/ttyS0 | /bin/grep -q unknown; then
Expand Down

0 comments on commit f1f254e

Please sign in to comment.