8.4 parted:磁盘分区工具

parted

    对于小于2TB的磁盘可以用fdisk和parted命令进行分区,这种情况一般采用flisk命令,但对于大于2TB的磁盘则只能用parted分区,且需要将磁盘转换为GPT格式。
parted [选项] [设备名]
 
-l    显示所有磁盘分区的信息
-h    查看帮助
 
[root@cs6 ~]# parted
GNU Parted 2.1
使用 /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) h                                                                
  align-check TYPE N                       #<==检查磁盘分区,TYPE分为min/opt两个选择,N为磁盘分区号。
  check NUMBER                             #<==简单检查文件系统。
  cp [FROM-DEVICE] FROM-NUMBER TO-NUMBER   #<==将文件系统复制到另一个分区。
  help [COMMAND]                           #<=查看帮助,简写h,还可以类似于help check 查看其他指令帮助。
  mklabel,mktable LABEL-TYPE               #<==创建分区表*
  mkfs NUMBER FS-TYPE                      #<==创建文件系统。
  mkpart PART-TYPE [FS-TYPE] START END     #<==创建分区*。
  mkpartfs PART-TYPE FS-TYPE START END     #<==创建带有文件系统的分区*。
  move NUMBER START END                    #<==移动分区。
  name NUMBER NAME                         #<==为分区命名
  print [devices|free|list,all|NUMBER]     #<==显示分区表信息,简写p*。
        partitions, or a particular partition
  quit                                     #<==退出程序。
  rescue START END                         #<==挽救临近“起始点”、”终止点”的 失的分区。
  resize NUMBER START END                  #<==重设分区大小。
  rm NUMBER                                #<==删除编号 NUMBER的分区*。
  select DEVICE                            #<==选择要编辑的设备。
  set NUMBER FLAG STATE                    #<==改变分区的标志。
  toggle [NUMBER [FLAG]]                   #<==设置分区标志。
  unit UNIT                                #<==设置默认单位。
  version                                  #<==显示版本号。
(parted)                                                          

显示分区情况的例子

[root@cs6 ~]# parted -l    #<==显示所有磁盘分区的信息。
Model: VMware, VMware Virtual S (scsi)    #<=磁盘型号,这里采用VMware虚拟化演示。
Disk /dev/sda: 32.2GB                     #<==磁盘大小。
Sector size (logical/physical): 512B/512B #<==扇区大小,为msdos,这是适合disk分区的类型。
 
Partition Table: msdos                    #<==分区表类型。
 
Number  Start   End     Size    Type     File system  标志
1      1049kB  525MB   524MB   primary  ext4         启动
2      525MB   32.2GB  31.7GB  primary               lvm
 
 
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 1074MB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
 
Number  Start   End     Size   Type      File system  标志
1      32.3kB  115MB   115MB  primary   ext4
2      115MB   1069MB  954MB  extended
5      115MB   543MB   428MB  logical
6      543MB   1069MB  526MB  logical
 
 
上述内容每列说明具体如下:
Number:分区编号。
Start:分区开始位置。
End:分区结束位置。
Size:分区大小。
Type:分区类型。
primary:为主分区。
File system:文件系统,例如ext4、swap等。
Flags:标志位,boot为启动分区。
 

在虚拟机(VMware Workstation Pro)中模拟2TB以上的磁盘分区

步骤1:在虚拟机中添加一块1GB的硬盘,如图8-2所示。
步骤2:交互式分区。
 
[root@cs6 ~]# parted /dev/sdb
GNU Parted 2.1
Using /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) mklabel gpt
Warning: Partition(s) on /dev/sdb are being used.                         
Ignore/Cancel? Ignore
Warning: The existing disk label on /dev/sdb will be destroyed and all data on this disk will be lost. Do you want to
continue?
Yes/No? Yes                                                               
Warning: WARNING: the kernel failed to re-read the partition table on /dev/sdb (Device or resource busy).  As a
result, it may not reflect all of your changes until after reboot.
(parted) mkpart primary 0 500                                             
Warning: The resulting partition is not properly aligned for best performance.
Ignore/Cancel? Ignore                                                     
Warning: WARNING: the kernel failed to re-read the partition table on /dev/sdb (Device or resource busy).  As a
result, it may not reflect all of your changes until after reboot.
(parted) p                                                                
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 1074MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
 
Number  Start   End    Size   File system  Name     Flags
1      17.4kB  500MB  500MB               primary
 
(parted) mkpart logical 501 1000                                          
Warning: WARNING: the kernel failed to re-read the partition table on /dev/sdb (Device or resource busy).  As a
result, it may not reflect all of your changes until after reboot.
(parted) p                                                                
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 1074MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
 
Number  Start   End     Size   File system  Name     Flags
1      17.4kB  500MB   500MB               primary
2      501MB   1000MB  499MB               logical      #<-第一个逻辑分区已创建完毕。
 
(parted) quit                                                             
[root@cs6 ~]# ls /dev/sdb*    #<==查看己分的分区,parted分区是即时生效的,没有保存的步骤。
/dev/sdb  /dev/sdb1  /dev/sdb2 

 

后续格式化分区、分区挂载、开机自动挂载等步骤和fdisk分区实践的范例8-2完全相同,读者可前往参考。

非交互式分区(批量分区)案例

步骤1:先删除前面分的区。
[root@cs6 ~]# parted /dev/sdb
GNU Parted 2.1
Using /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) p                                                                
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 1074MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
 
Number  Start   End     Size   File system  Name     Flags
1      17.4kB  500MB   500MB               primary
2      501MB   1000MB  499MB               logical
 
(parted) rm 1                                                             
(parted) rm 2                                                             
(parted) p                                                                
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 1074MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
 
Number  Start  End  Size  File system  Name  Flags
 
(parted) quit                                                             
Information: You may need to update /etc/fstab.                           
 
[root@cs6 ~]# ls /dev/sd*
/dev/sda  /dev/sda1  /dev/sda2  /dev/sdb
 
步骤2:非交互创建分区命令。
 
[root@cs6 ~]# parted /dev/sdb mklabel gpt Yes    #<=非交互创建分区的实质上就是将在交互窗口执行的命令作为参数。
Warning: The existing disk label on /dev/sdb will be destroyed and all data on this disk will be lost. Do you want to
continue?
Information: You may need to update /etc/fstab.                           
 
[root@cs6 ~]# parted /dev/sdb mkpart primary 0 500
Warning: The resulting partition is not properly aligned for best performance.
Information: You may need to update /etc/fstab.                           
 
[root@cs6 ~]# parted /dev/sdb mkpart primary  500 1000
Information: You may need to update /etc/fstab.                           
 
[root@cs6 ~]# parted /dev/sdb p    #<==查看分区结果。
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 1074MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
 
Number  Start   End     Size   File system  Name     Flags
1      17.4kB  500MB   500MB               primary
2      500MB   1000MB  500MB               primary

 

 
posted @ 2020-01-19 15:40  前海渔文乐  阅读(197)  评论(0编辑  收藏  举报