parted磁盘分区方式:通常我们用的比较多的一般都是fdisk工具来进行分区,但是现在由于磁盘越来越
廉价,而且磁盘空间越来越大;而fdisk工具他对分区是有大小限制的,它只能划分小于2T的磁盘。但是
现在的磁盘空间很多都已经是远远大于2T了,甚至达到2.5T和3T,就需要通过Parted工具来实现对GPT磁
盘进行分区操作。
GUID磁碟分割表(GUID Partition Table,缩写:GPT)其含义为“全局唯一标识磁盘分区表”,是一
个实体硬盘的分区表的结构布局的标准。它是可扩展固件接口标准(被Intel用于替代个人计算机的
BIOS)的一部分,被用于替代BIOS系统中的一32bits来存储逻辑块地址和大小信息的主开机纪录(MBR)
分区表。
GPT格式的磁盘相当于原来MBR磁盘中原来保留4个partition table的4*16个字节,只留第一个16个字
节,类似于扩展分区,真正的partitiontable在512字节之后,GPT磁盘没有四个主分区的限制。
parted命令详解
用法:parted [选项]... [设备 [命令 [参数]...]...]
将带有“参数”的命令应用于“设备”。如果没有给出“命令”,则以交互模式运行.
帮助选项:
-h, --help 显示此求助信息
-l, --list 列出所有设备的分区信息
-i, --interactive 在必要时,提示用户
-s, --script 从不提示用户
-v, --version 显示版本
help #打印通用求助信息,或关于 COMMAND 的信息
mklabel 标签类型 #创建新的磁盘标签 (分区表)
mkfs 创建文件系统类型 #在创建类型为“文件系统类型”的文件系统
mkpart 分区类型 [文件系统类型] #创建一个分区
mkpartfs 分区类型 文件系统类型 #创建一个带有文件系统的分区
move 起始点 终止点 #移动编号为的分区
name 名称 #将编号为的分区命名为“名称”
print #打印分区表,或者分区
quit #退出程序
rescue 起始点 终止点 #挽救临近“起始点”、“终止点”的遗失的分区
resize 起始点 终止点 #改变位于编号为的分区中文件系统的大小
rm #删除编号为 MINOR 的分区
select 设备 #选择要编辑的设备
set标志 状态 #改变编号为的分区的标志
操作:
1、使用方法
1.1 进入Parted的方法(在命令行输入Parted命令即可)
[root@localhost /]# parted GNU Parted 2.1 Using /dev/sda Welcome to GNU Parted! Type 'help' to view a list of commands. (parted)
1.2 获取parted工具帮助的方法:(只需输入help即可)
(parted) help align-check TYPE N check partition N for TYPE(min|opt) alignment check NUMBER do a simple check on the file system cp [FROM-DEVICE] FROM-NUMBER TO-NUMBER copy file system to another partition help [COMMAND] print general help, or help on COMMAND mklabel,mktable LABEL-TYPE create a new disklabel (partition table)
…………
OPTIONs: -h, --help displays this help message -i, --interactive where necessary, prompts for userintervention -l, --list lists partition tables ofall detected devices -s, --script never prompts for userintervention -v, --version displays the version
…………
-h, --help 显示此求助信息
-l, --list 列出所有设备的分区信息
-i, --interactive 在必要时,提示用户
-s, --script 从不提示用户
-v, --version 显示版本
此处与fdisk基本一致,都是在命令菜单内部,输入命令
1.3 退出parted工具(只需输入quit即可)
(parted) quit [root@localhost /]#
2、通过parted工具对磁盘进行操作
2.1查看单个磁盘状态 parted /dev/sdc(我用的是额外新增的一块硬盘c)
[root@localhost ~]# ll /dev ...... brw-rw---- 1 root disk 8, 0 Mar 13 21:13 sda brw-rw---- 1 root disk 8, 1 Mar 13 21:13 sda1 brw-rw---- 1 root disk 8, 2 Mar 13 21:13 sda2 brw-rw---- 1 root disk 8, 16 Mar 13 21:15 sdb brw-rw---- 1 root disk 8, 17 Mar 13 21:13 sdb1 brw-rw---- 1 root disk 8, 18 Mar 13 21:13 sdb2 brw-rw---- 1 root disk 8, 19 Mar 13 21:13 sdb3 brw-rw---- 1 root disk 8, 20 Mar 13 21:13 sdb4 brw-rw---- 1 root disk 8, 21 Mar 13 21:13 sdb5 brw-rw---- 1 root disk 8, 22 Mar 13 21:13 sdb6 brw-rw---- 1 root disk 8, 32 Mar 13 21:13 sdc ......
[root@localhost ~]# parted /dev/sdc GNU Parted 2.1 Using /dev/sdc Welcome to GNU Parted! Type 'help' to view a list of commands. (parted)
2.2退出再执行:parted -l,可列出所有磁盘的状态
[root@localhost ~]# parted -l Model: VMware, VMware Virtual S (scsi) Disk /dev/sda: 129GB Sector size (logical/physical): 512B/512B Partition Table: msdos Number Start End Size Type File system Flags 1 1049kB 211MB 210MB primary ext4 boot 2 211MB 64.6GB 64.4GB primary lvm Model: VMware, VMware Virtual S (scsi) Disk /dev/sdb: 53.7GB Sector size (logical/physical): 512B/512B Partition Table: msdos Number Start End Size Type File system Flags 1 32.3kB 10.7GB 10.7GB primary 2 10.7GB 21.5GB 10.7GB primary
2.3通过parted工具来创建大于2T的分区
[root@localhost ~]# parted /dev/sdc GNU Parted 2.1 Using /dev/sdc Welcome to GNU Parted! Type 'help' to view a list of commands. (parted)
接着创建磁盘标签
(parted) mklabel New disk label type? gpt #此处设置类型 (parted) p Model: VMware, VMware Virtual S (scsi) Disk /dev/sdc: 1095GB Sector size (logical/physical): 512B/512B Partition Table: gpt Number Start End Size File system Name Flags (parted)
使用mkpart命令进行分区和设置文件系统类型
(parted) mkpart Partition name? []? gpt2 #名字 File system type? [ext2]? ext3 #文件系统类型 Start? 1 #从哪开始 End? 300G 到哪结束,可以用大小 (parted) p #查看列表 Model: VMware, VMware Virtual S (scsi) Disk /dev/sdc: 1095GB Sector size (logical/physical): 512B/512B Partition Table: gpt Number Start End Size File system Name Flags 1 1049kB 300GB 300GB gpt2
(parted) Q #退出 Information: You may need to update /etc/fstab. #不要忘记更新/etc/fstab
通过mkpart命令可以创建多个分区,part1,part2,part3,……
(parted) mkpart Partition name? []? gpt2 File system type? [ext2]? ext4 Start? 300G End? 600G (parted) mkpart Partition name? []? gpt3 File system type? [ext2]? ext4 Start? ^C (parted) mkpart Partition name? []? gpt3 File system type? [ext2]? xfs Start? 600 End? -1 Warning: You requested a partition from 600MB to 1095GB. #仔细 The closest location we can manage is 600GB to 1095GB. Is this still acceptable to you? Yes/No? n (parted) mkpart Partition name? []? gpt3 File system type? [ext2]? xfs #创建了一个XFS Start? 600G End? -1 (parted) p Model: VMware, VMware Virtual S (scsi) Disk /dev/sdc: 1095GB Sector size (logical/physical): 512B/512B Partition Table: gpt Number Start End Size File system Name Flags 1 1049kB 300GB 300GB gpt2 2 300GB 600GB 300GB gpt2 3 600GB 1095GB 495GB gpt3 (parted) #多分区结束
通过parted删除分区命令:
Number Start End Size File system Name Flags 1 1049kB 300GB 300GB gpt2 2 300GB 600GB 300GB gpt2 3 600GB 1095GB 495GB gpt3 (parted) rm 3 (parted) p Model: VMware, VMware Virtual S (scsi) Disk /dev/sdc: 1095GB Sector size (logical/physical): 512B/512B Partition Table: gpt Number Start End Size File system Name Flags 1 1049kB 300GB 300GB gpt2 2 300GB 600GB 300GB gpt2 (parted)
通过parted工具来创建文件系统:
(parted) mkfs 2ext3 WARNING: you are attempting to use parted to operate on (mkfs) a file system. parted's file system manipulation code is not as robust as what you'll find in dedicated, file-system-specific packages like e2fsprogs. We recommend you use parted only to manipulate partition tables, whenever possible. Support for performing most operations on most types of file systems will be removed in an upcoming release. Warning: The existing file system will be destroyed and all data on the partition will be lost. Do you want to continue? parted: invalid token: 2ext3 Yes/No? y Partition number? 2 File system type? [ext2]? ext3 No Implementation: Support for creating ext3 file systems is not implemented yet. (parted) mkfs 2ext2 WARNING: you are attempting to use parted to operate on (mkfs) a file system. parted's file system manipulation code is not as robust as what you'll find in dedicated, file-system-specific packages like e2fsprogs. We recommend you use parted only to manipulate partition tables, whenever possible. Support for performing most operations on most types of file systems will be removed in an upcoming release. Warning: The existing file system will be destroyed and all data on the partition will be lost. Do you want to continue? parted: invalid token: 2ext2 Yes/No? y Partition number? 2 File system type? [ext2]?
上面有犯的几个错误,我也列在里面了,改正
关于挂载同fdisk,实在不愿意写了,用mount umount命令,需要注意的事:第一,需要事先存在的目
录,第二,此目录最好以后用不到,第三如果目录里面有文件,可能会被隐藏
注意:比fdisk多了个功能,就是可以恢复删除掉的分区
rm 2 rescue #可以用来对刚刚删除的分区进行恢复,并且可以把数据一同恢复出来
check命令的使用:
check 1 #对分区的检查
(parted) check 1 WARNING: you are attempting to use parted to operate on (check) a file system. parted's file system manipulation code is not as robust as what you'll find in dedicated, file-system-specific packages like e2fsprogs. We recommend you use parted only to manipulate partition tables, whenever possible. Support for performing most operations on most types of file systems will be removed in an upcoming release. Error: Could not detect file system. (parted)