命令简介

parted 命令用于创立,查看,删除和批改磁盘分区。它是一个磁盘分区和分区大小调整工具。这个命令算是对fdisk命令的一个补充,因为如果磁盘大小大于2TB就无奈应用fdisk命令进行分区操作了。

语法格局

parted [options] [device [command [options...]...]]

选项阐明

-a  #为新创建的分区设置对齐形式-h  #显示帮忙信息-i  #交互式模式-s  #脚本模式-v  #显示版本号-l  #列出所有块设施上的分区布局-m  #显示机器可解析的输入

利用举例

虚拟机上没有大于2TB的硬盘,所以用10GB来代替。

[root@centos7 ~]# fdisk -lDisk /dev/sda: 21.5 GB, 21474836480 bytes, 41943040 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk label type: dosDisk identifier: 0x0003116d   Device Boot      Start         End      Blocks   Id  System/dev/sda1   *        2048     2099199     1048576   83  Linux/dev/sda2         2099200    41943039    19921920   8e  Linux LVM#新加的10GB磁盘Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytes

分区举例

[root@centos7 ~]# parted /dev/sdbGNU Parted 3.1Using /dev/sdbWelcome to GNU Parted! Type 'help' to view a list of commands.(parted) help      #帮忙信息   align-check TYPE N                        check partition N for TYPE(min|opt) alignment  help [COMMAND]                           print general help, or help on COMMAND  mklabel,mktable LABEL-TYPE               create a new disklabel (partition table)  mkpart PART-TYPE [FS-TYPE] START END     make a partition  name NUMBER NAME                         name partition NUMBER as NAME  print [devices|free|list,all|NUMBER]     display the partition table, available devices, free space, all found partitions, or a particular partition  quit                                     exit program  rescue START END                         rescue a lost partition near START and END    resizepart NUMBER END                    resize partition NUMBER  rm NUMBER                                delete partition NUMBER  select DEVICE                            choose the device to edit  disk_set FLAG STATE                      change the FLAG on selected device  disk_toggle [FLAG]                       toggle the state of FLAG on selected device  set NUMBER FLAG STATE                    change the FLAG on partition NUMBER  toggle [NUMBER [FLAG]]                   toggle the state of FLAG on partition NUMBER  unit UNIT                                set the default unit to UNIT  version                                  display the version number and copyright information of GNU Parted(parted) mklabel gpt   #批改磁盘分区构造为gptWarning: 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                                                               (parted) mkpart   #执行分区 Partition name?  []? primary      #主分区 File system type?  [ext2]? ext4   #文件系统类型 Start? 1                                                                  End? 10000    (parted) p     #打印分区表 Model: VMware, VMware Virtual S (scsi)Disk /dev/sdb: 10.7GBSector size (logical/physical): 512B/512BPartition Table: gptDisk Flags: Number  Start   End     Size    File system  Name     Flags 1      1049kB  10.0GB  9999MB               primary(parted) q                                                                Information: You may need to update /etc/fstab.

格式化并挂载

[root@centos7 ~]# mkfs.ext4 /dev/sdbmke2fs 1.42.9 (28-Dec-2013)/dev/sdb is entire device, not just one partition!Proceed anyway? (y,n) yFilesystem label=OS type: LinuxBlock size=4096 (log=2)Fragment size=4096 (log=2)Stride=0 blocks, Stripe width=0 blocks655360 inodes, 2621440 blocks131072 blocks (5.00%) reserved for the super userFirst data block=0Maximum filesystem blocks=215167795280 block groups32768 blocks per group, 32768 fragments per group8192 inodes per groupSuperblock backups stored on blocks:  32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632Allocating group tables: done                            Writing inode tables: done                            Creating journal (32768 blocks): done[root@centos7 ~]# df -hFilesystem               Size  Used Avail Use% Mounted ondevtmpfs                 475M     0  475M   0% /devtmpfs                    487M     0  487M   0% /dev/shmtmpfs                    487M  7.7M  479M   2% /runtmpfs                    487M     0  487M   0% /sys/fs/cgroup/dev/mapper/centos-root   17G  2.0G   16G  12% //dev/sda1               1014M  167M  848M  17% /boottmpfs                     98M     0   98M   0% /run/user/0[root@centos7 ~]# mount /dev/sdb /opt/[root@centos7 ~]# df -hFilesystem               Size  Used Avail Use% Mounted ondevtmpfs                 475M     0  475M   0% /devtmpfs                    487M     0  487M   0% /dev/shmtmpfs                    487M  7.7M  479M   2% /runtmpfs                    487M     0  487M   0% /sys/fs/cgroup/dev/mapper/centos-root   17G  2.0G   16G  12% //dev/sda1               1014M  167M  848M  17% /boottmpfs                     98M     0   98M   0% /run/user/0/dev/sdb                 9.8G   37M  9.2G   1% /opt

所以,parted 命令个别用于磁盘空间大于2TB大小的磁盘分区。