如何使用 cfdisk 扇区结束值来计算分区大小?

如何使用 cfdisk 扇区结束值来计算分区大小?

cfdisk我能够获取有关磁盘的统计信息,即第一个到第三个分区中每个分区的结束扇区以及可用空间的末尾。我正在尝试计算分区大小,但出现了问题。当我调整某些分区的大小时,大小明显不正确cfdisk分析后。请帮助我了解出了什么问题!

#!/bin/bash
#This setsetcor script takes three arguments: setsector a b c d
#Both a, b, and c are integers

a=$1; #The end (in 512 byte sectors) of the sdx1 partition
b=$2; #The end (in 512 byte sectors) of the sdx2 partition
c=$3; #The end (in 512 byte sectors) of the sdx3 partition
d=$4; #The end (in 512 byte sectors) of the free space
e=$5; #The adjustment factor

#The result a-b-c-d

printf "The end (in 512 byte sectors) of the sdx1 partition is a=%d \n" $((a))
printf "The end (in 512 byte sectors) of the sdx2 partition is b=%d \n" $((b))
printf "The end (in 512 byte sectors) of the sdx3 partition is c=%d \n" $((c))
printf "The end (in 512 byte sectors) of the free space     is d=%d \n" $((d))
printf "The adjustment factor                               is e=%d \n" $((e))
printf "The number of sectors (512-Bytes erach) for parition 3 equals %dS .  \n" $(( $((c))-$((b))+$((e))))
printf "The number of sectors (512-Bytes erach) for parition 2 equals %dS .  \n" $(( $((b))-$((a))+$((e))))
printf "The number of sectors (512-Bytes erach) for the free space is %dS .  \n" $(( $((d))-$((c))+$((e))))
printf "The number of sectors (512-Bytes erach) for the drive size is %dS .  \n" $(( 0 ))
# printf "The initial size of sdx3 is d-c+e. \n"

相关内容