从未分配的磁盘空间创建未格式化的分区

msc*_*woj 6 partition centos

parted输出是如下:

$> parted /dev/sda print free
Model: ATA Hitachi HUA72302 (scsi)
Disk /dev/sda: 2000GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags: 

Number  Start   End     Size    Type     File system  Flags
        32.3kB  1049kB  1016kB           Free Space
 1      1049kB  33.6GB  33.6GB  primary               raid
 2      33.6GB  67.1GB  33.6GB  primary               raid
 3      67.1GB  67.7GB  524MB   primary  ext4         boot, raid
        67.7GB  2000GB  1933GB           Free Space
Run Code Online (Sandbox Code Playgroud)

在 CentOS 7.1 上,在那些免费的 1933GB 上创建一个空的、未格式化的分区的步骤是什么?(仅使用终端工具)

msc*_*woj 8

既然我已经弄清楚了,我会在这里给出答案。

首先,我使用类似于上面的命令查询磁盘布局,但请求扇区一个单位:

> parted /dev/sda unit s print free
Model: ATA Hitachi HUA72302 (scsi)
Disk /dev/sda: 3907029168s
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags: 

Number  Start       End          Size         Type     File system  Flags
        63s         2047s        1985s                 Free Space
 1      2048s       65570815s    65568768s    primary               raid
 2      65570816s   66594815s    1024000s     primary  ext4         boot, raid
 3      66594816s   132163583s   65568768s    primary               raid
 4      132163584s  3907029167s  3774865584s  primary
Run Code Online (Sandbox Code Playgroud)

注意132163584s,空闲空间的起始扇区(前一个分区结束+1,如果你不使用free开关)。那么剩下的就很简单了:

parted /dev/sda mkpart primary ext4 132163584s -- -1s
Run Code Online (Sandbox Code Playgroud)

-1s是结束扇区是磁盘的结尾。---1s在批处理模式下使用并防止parted: invalid option -- '1'错误(parted在交互模式下运行不需要这个)。