创建具有确切大小而不是特定距离的分区


11

一个人如何创建一个没有特定距离的精确大小的分区?

我努力了:

parted -a optimal /dev/sdd mkpart primary 0% 0%+1GB
# and...
parted -a optimal /dev/sdd mkpart primary 0% +1GB

无济于事。

如何使其接受尺寸而不是末端距离?


您收到什么错误消息?有parted -a optimal /dev/sdd mkpart primary 0GB 10GB工作吗?
terdon

Answers:


7

我认为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

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.