parted 命令用於建立,查看,刪除和修改磁盤分區。它是一個磁盤分區和分區大小調整工具。這個命令算是對fdisk命令的一個補充,由於若是磁盤大小大於2TB就沒法使用fdisk命令進行分區操做了。node
parted [options] [device [command [options...]...]]
-a #爲新建立的分區設置對齊方式 -h #顯示幫助信息 -i #交互式模式 -s #腳本模式 -v #顯示版本號 -l #列出全部塊設備上的分區佈局 -m #顯示機器可解析的輸出
虛擬機上沒有大於2TB的硬盤,因此用10GB來替代。centos
[root@centos7 ~]# fdisk -l Disk /dev/sda: 21.5 GB, 21474836480 bytes, 41943040 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk label type: dos Disk 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 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes
分區舉例app
[root@centos7 ~]# parted /dev/sdb GNU Parted 3.1 Using /dev/sdb Welcome 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 #修改磁盤分區結構爲gpt 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 (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.7GB Sector size (logical/physical): 512B/512B Partition Table: gpt Disk 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.
格式化並掛載ide
[root@centos7 ~]# mkfs.ext4 /dev/sdb mke2fs 1.42.9 (28-Dec-2013) /dev/sdb is entire device, not just one partition! Proceed anyway? (y,n) y Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 655360 inodes, 2621440 blocks 131072 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=2151677952 80 block groups 32768 blocks per group, 32768 fragments per group 8192 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632 Allocating group tables: done Writing inode tables: done Creating journal (32768 blocks): done [root@centos7 ~]# df -h Filesystem Size Used Avail Use% Mounted on devtmpfs 475M 0 475M 0% /dev tmpfs 487M 0 487M 0% /dev/shm tmpfs 487M 7.7M 479M 2% /run tmpfs 487M 0 487M 0% /sys/fs/cgroup /dev/mapper/centos-root 17G 2.0G 16G 12% / /dev/sda1 1014M 167M 848M 17% /boot tmpfs 98M 0 98M 0% /run/user/0 [root@centos7 ~]# mount /dev/sdb /opt/ [root@centos7 ~]# df -h Filesystem Size Used Avail Use% Mounted on devtmpfs 475M 0 475M 0% /dev tmpfs 487M 0 487M 0% /dev/shm tmpfs 487M 7.7M 479M 2% /run tmpfs 487M 0 487M 0% /sys/fs/cgroup /dev/mapper/centos-root 17G 2.0G 16G 12% / /dev/sda1 1014M 167M 848M 17% /boot tmpfs 98M 0 98M 0% /run/user/0 /dev/sdb 9.8G 37M 9.2G 1% /opt
因此,parted 命令通常用於磁盤空間大於2TB大小的磁盤分區。工具