Answers:
我认为parted
只接受绝对值,不接受x+y
。
您可以这样做:(+
由shell解释)
# start=1
# size=512
# parted /dev/loop0 unit mib mkpart primary $start $(($start+$size))
# parted /dev/loop0 unit mib print free
Model: Loopback device (loopback)
Disk /dev/loop0: 1000MiB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
0.02MiB 1.00MiB 0.98MiB Free Space
1 1.00MiB 513MiB 512MiB primary
513MiB 1000MiB 487MiB Free Space
...如果您想追加更多,那么
# start=$(($start+$size+1))
# size=128
# parted /dev/loop0 unit mib mkpart primary $start $(($start+$size))
# parted /dev/loop0 unit mib print free
Model: Loopback device (loopback)
Disk /dev/loop0: 1000MiB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
0.02MiB 1.00MiB 0.98MiB Free Space
1 1.00MiB 513MiB 512MiB primary
513MiB 514MiB 1.00MiB Free Space
2 514MiB 642MiB 128MiB primary
642MiB 1000MiB 358MiB Free Space
该+1
完全是可选的,我只是想离开1MiB免费的“保险杠”分区之间,出于某种原因。
如果要处理百分比,还可以使用来从Shell获取设备大小blockdev --getsize64 /dev/device
,因此可以将所有数学运算从parted中移出到Shell脚本中。我这样做是为了保证与MiB对齐的分区,因为我永远不太清楚的parted
确切含义-a optimal
。
parted -a optimal /dev/sdd mkpart primary 0GB 10GB
工作吗?