![如何使用 cfdisk 扇区结束值来计算分区大小?](https://linux22.com/image/220197/%E5%A6%82%E4%BD%95%E4%BD%BF%E7%94%A8%20cfdisk%20%E6%89%87%E5%8C%BA%E7%BB%93%E6%9D%9F%E5%80%BC%E6%9D%A5%E8%AE%A1%E7%AE%97%E5%88%86%E5%8C%BA%E5%A4%A7%E5%B0%8F%EF%BC%9F.png)
从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"