【Linux】分区工具parted

转载:点击打开链接(http://blog.itpub.net/12129601/viewspace-735520/)

昨天准备安装一套新的rac数据库,需要对阵列上的存储做分区,一开始采用常用的fdisk工具来分区,出现告警信息:

WARNING: The size of this disk is 6.8 TB (6784974585856 bytes).

DOS partition table format can not be used on drives for volumes
larger than 2.2 TB (2199023255040 bytes). Use parted(1) and GUID 
partition table format (GPT).


一、parted的命令方式

Parted 命令分为两种模式:命令行模式和交互模式。
1、命令行模式: parted [option] device [command] ,该模式可以直接在命令行下对磁盘进行分区操作,比较适合编程应用。如:
# parted /dev/sdb print --显示磁盘/dev/sdb分区。
2、交互模式:parted [option] device
# parted /dev/sdb      --进入交互模式,建议使用交互模式,尤其是对parted命令不是很熟悉的情况下。
 

 二、常用的2种分区表:MBR与GPT区别。

 MBR:MBR分区表(即主引导记录)大家都很熟悉,是过去我们使用windows时常用的。 所支持的最大卷:2T,而且对分区有限制:最多4个主分区或3个主分区加一个扩展分区

GPT: GPT(即GUID分区表)是源自EFI标准的一种较新的磁盘分区表结构的标准,是未来磁盘分区的主要形式。与MBR分区方式相比,具有如下优点。突破MBR 4个主分区限制,每个磁盘最多支持128个分区。支持大于2T的分区,最大卷可达18EB。


             

三、parted命令常用选项。

当在命令行输入parted后,进入parted命令的交互模式。输入help会显示帮助信息。下面就简单介绍一下常用的功能

1、Check     简单检查文件系统。建议用其他命令检查文件系统,比如fsck

2、Help      显示帮助信息

3、mklabel   创建分区表, 即是使用msdos(MBR)还是使用gpt,或者是其他方式分区表

4、 mkfs     创建文件系统。该命令不支持ext3 格式,因此建议不使用,最好是用parted分好区,然后退出parted交互模式,用其他命令进行分区,比如:mkfs.ext3

5、mkpart   创建新分区。

         格式:mkpart PART-TYPE  [FS-TYPE]  START  END

                PART-TYPE 类型主要有primary(主分区), extended(扩展分区), logical(逻辑区). 扩展分区和逻辑分区只对msdos。

                fs-type   文件系统类型,主要有fs32,NTFS,ext2,ext3等

                start end 分区的起始和结束位置。

6、mkpartfs 建立分区及其文件系统。目前还不支持ext3文件系统,因此不建议使用该功能。最后是分好区后,退出parted,然后用其他命令建立文件系统。

7、print    输出分区信息。该功能有3个选项,

        free 显示该盘的所有信息,并显示磁盘剩余空间

        number 显示指定的分区的信息

        all 显示所有磁盘信息

8、resize   调整指定的分区的大小。目前对ext3格式支持不是很好,所以不建议使用该功能。

9、resuce  恢复不小心删除的分区。如果不消息用parted的rm命令删除了一个分区,那么可以通过rescue功能进行回复。恢复时需要给出分区的起始和结束未知。然后parted就会在给定的范围内去寻找,并提示恢复分区。

10、rm    删除分区。命令格式 rm  number 。如:rm 3 就是将编号为3的分区删除

11、select  选择设备。当输入parted命令后直接回车进入交互模式是,如果有多块硬盘,需要用select 选择要操作的硬盘。如:select /dev/sdb

12、set     设置标记。更改指定分区编号的标志。标志通常有如下几种:boot  hidden   raid   lvm 等。

        boot 为引导分区,hidden 为隐藏分区,raid 软raid,lvm 为逻辑分区。

        如:set 3  boot  on   设置分区号3 为启动分区

注:以上内容为parted常用的功能,由于该工具目前对ext3支持得不是很好,因此有些功能无法应用,比如move(移动分区)resize等。


四、parted分区实例

GNU Parted 1.8.1
使用 /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) help                                                             
  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]                           prints general help, or help on COMMAND
  mklabel,mktable LABEL-TYPE               create a new disklabel (partition table)
  mkfs NUMBER FS-TYPE                      make a FS-TYPE file system on partititon NUMBER
  mkpart PART-TYPE [FS-TYPE] START END     make a partition
  mkpartfs PART-TYPE FS-TYPE START END     make a partition with a file system
  move NUMBER START END                    move partition NUMBER
  name NUMBER NAME                         name partition NUMBER as NAME
  print [free|NUMBER|all]                  display the partition table, a partition, or all devices
  quit                                     exit program
  rescue START END                         rescue a lost partition near START and END
  resize NUMBER START END                  resize partition NUMBER and its file system
  rm NUMBER                                delete partition NUMBER
  select DEVICE                            choose the device to edit
  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                                  displays the current version of GNU Parted and copyright information
(parted) p                                                                
错误: msdos labels do not support devices that have more than 4294967295 sectors.
(parted) mklabel
新的磁盘标签类型?  [msdos]? gpt                                          
(parted) p                                                               
Disk /dev/sda: 6785GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
分区名称?  []?                                                           
文件系统类型?  [ext2]?                                                   
起始点? 0                                                                
结束点? 1024G                                                            
(parted) p                                                               
Disk /dev/sda: 6785GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
 1      17.4kB  1024GB  1024GB                        
分区名称?  []?                                                           
文件系统类型?  [ext2]?                                                   
起始点? 1024G                                                            
结束点? 1536G                                                            
(parted) mkpart                                                           
分区名称?  []?                                                           
文件系统类型?  [ext2]?                                                   
起始点? 1536G                                                            
结束点? 2048G                                                            
(parted) p                                                               
Disk /dev/sda: 6785GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
 1      17.4kB  1024GB  1024GB                         
 2      1024GB  1536GB  512GB                          
 3      1536GB  2048GB  512GB                         
Disk /dev/sda: 6785GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
 1      17.4kB  1024GB  1024GB                         
 2      1024GB  1536GB  512GB                          
 3      1536GB  2048GB  512GB                          
        2048GB  6785GB  4737GB  Free Space            
分区名称?  []?                                                           
文件系统类型?  [ext2]?                                                   
起始点? 2560G                                                            
结束点? 3072G                                                            
(parted) p                                                               
Disk /dev/sda: 6785GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
 1      17.4kB  1024GB  1024GB                         
 2      1024GB  1536GB  512GB                          
 3      1536GB  2048GB  512GB                          
 4      2560GB  3072GB  512GB                         
分区名称?  []?                                                           
文件系统类型?  [ext2]?                                                   
起始点? 2048G
结束点? 2560G                                                            
(parted) p                                                               
Disk /dev/sda: 6785GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
 1      17.4kB  1024GB  1024GB                         
 2      1024GB  1536GB  512GB                          
 3      1536GB  2048GB  512GB                          
 5      2048GB  2560GB  512GB                          
 4      2560GB  3072GB  512GB                         
分区名称?  []?                                                           
文件系统类型?  [ext2]?                                                   
起始点? 3072G                                                            
结束点? 3584G                                                            
(parted) p                                                               
Disk /dev/sda: 6785GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
 1      17.4kB  1024GB  1024GB                         
 2      1024GB  1536GB  512GB                          
 3      1536GB  2048GB  512GB                          
 5      2048GB  2560GB  512GB                          
 4      2560GB  3072GB  512GB                          
 6      3072GB  3584GB  512GB                         
分区名称?  []?                                                           
文件系统类型?  [ext2]?                                                   
起始点? 3584G                                                            
结束点? 4096G                                                            
(parted) mkpart                                                           
分区名称?  []?                                                           
文件系统类型?  [ext2]?                                                   
起始点? 4096G                                                            
结束点? 4608G                                                            
(parted) p                                                               
Disk /dev/sda: 6785GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
 1      17.4kB  1024GB  1024GB                         
 2      1024GB  1536GB  512GB                          
 3      1536GB  2048GB  512GB                          
 5      2048GB  2560GB  512GB                          
 4      2560GB  3072GB  512GB                          
 6      3072GB  3584GB  512GB                          
 7      3584GB  4096GB  512GB                          
 8      4096GB  4608GB  512GB                         
分区名称?  []?                                                           
文件系统类型?  [ext2]?                                                   
起始点? 4608G
结束点? 5120G                                                            
(parted) p                                                               
Disk /dev/sda: 6785GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
 1      17.4kB  1024GB  1024GB                         
 2      1024GB  1536GB  512GB                          
 3      1536GB  2048GB  512GB                          
 5      2048GB  2560GB  512GB                          
 4      2560GB  3072GB  512GB                          
 6      3072GB  3584GB  512GB                          
 7      3584GB  4096GB  512GB                          
 8      4096GB  4608GB  512GB                          
 9      4608GB  5120GB  512GB                         
分区名称?  []?                                                           
文件系统类型?  [ext2]?                                                   
起始点? 5120G                                                            
结束点? 5632G
(parted) P                                                               
Disk /dev/sda: 6785GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
 1      17.4kB  1024GB  1024GB                         
 2      1024GB  1536GB  512GB                          
 3      1536GB  2048GB  512GB                          
 5      2048GB  2560GB  512GB                          
 4      2560GB  3072GB  512GB                          
 6      3072GB  3584GB  512GB                          
 7      3584GB  4096GB  512GB                          
 8      4096GB  4608GB  512GB                          
 9      4608GB  5120GB  512GB                          
10      5120GB  5632GB  512GB                         
Disk /dev/sda: 6785GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
 1      17.4kB  1024GB  1024GB                         
 2      1024GB  1536GB  512GB                          
 3      1536GB  2048GB  512GB                          
 5      2048GB  2560GB  512GB                          
 4      2560GB  3072GB  512GB                          
 6      3072GB  3584GB  512GB                          
 7      3584GB  4096GB  512GB                          
 8      4096GB  4608GB  512GB                          
 9      4608GB  5120GB  512GB                          
10      5120GB  5632GB  512GB                          
        5632GB  6785GB  1153GB  Free Space            
分区名称?  []?                                                           
文件系统类型?  [ext2]?                                                   
起始点? 5632G                                                            
结束点? 6144G                                                            
(parted) p                                                               
Disk /dev/sda: 6785GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
 1      17.4kB  1024GB  1024GB                         
 2      1024GB  1536GB  512GB                          
 3      1536GB  2048GB  512GB                          
 5      2048GB  2560GB  512GB                          
 4      2560GB  3072GB  512GB                          
 6      3072GB  3584GB  512GB                          
 7      3584GB  4096GB  512GB                          
 8      4096GB  4608GB  512GB                          
 9      4608GB  5120GB  512GB                          
10      5120GB  5632GB  512GB                          
11      5632GB  6144GB  512GB                         
Disk /dev/sda: 6785GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
 1      17.4kB  1024GB  1024GB                         
 2      1024GB  1536GB  512GB                          
 3      1536GB  2048GB  512GB                          
 5      2048GB  2560GB  512GB                          
 4      2560GB  3072GB  512GB                          
 6      3072GB  3584GB  512GB                          
 7      3584GB  4096GB  512GB                          
 8      4096GB  4608GB  512GB                          
 9      4608GB  5120GB  512GB                          
10      5120GB  5632GB  512GB                          
11      5632GB  6144GB  512GB                          
        6144GB  6785GB  641GB   Free Space            
分区名称?  []?                                                           
文件系统类型?  [ext2]?                                                   
起始点? 6144G                                                            
结束点? 6785G                                                            
(parted) p                                                               
Disk /dev/sda: 6785GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
 1      17.4kB  1024GB  1024GB                         
 2      1024GB  1536GB  512GB                          
 3      1536GB  2048GB  512GB                          
 5      2048GB  2560GB  512GB                          
 4      2560GB  3072GB  512GB                          
 6      3072GB  3584GB  512GB                          
 7      3584GB  4096GB  512GB                          
 8      4096GB  4608GB  512GB                          
 9      4608GB  5120GB  512GB                          
10      5120GB  5632GB  512GB                          
11      5632GB  6144GB  512GB                          
12      6144GB  6785GB  641GB                         
Disk /dev/sda: 6785GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
 1      17.4kB  1024GB  1024GB                         
 2      1024GB  1536GB  512GB                          
 3      1536GB  2048GB  512GB                          
 5      2048GB  2560GB  512GB                          
 4      2560GB  3072GB  512GB                          
 6      3072GB  3584GB  512GB                          
 7      3584GB  4096GB  512GB                          
 8      4096GB  4608GB  512GB                          
 9      4608GB  5120GB  512GB                          
10      5120GB  5632GB  512GB                          
11      5632GB  6144GB  512GB                          
12      6144GB  6785GB  641GB                         
[root@bj-db-01 dev]# ll sda*
brw-r----- 1 root disk 8,  0 08-22 20:27 sda
brw-r----- 1 root disk 8,  1 08-22 20:27 sda1
brw-r----- 1 root disk 8, 10 08-22 20:27 sda10
brw-r----- 1 root disk 8, 11 08-22 20:27 sda11
brw-r----- 1 root disk 8, 12 08-22 20:27 sda12
brw-r----- 1 root disk 8,  2 08-22 20:27 sda2
brw-r----- 1 root disk 8,  3 08-22 20:27 sda3
brw-r----- 1 root disk 8,  4 08-22 20:27 sda4
brw-r----- 1 root disk 8,  5 08-22 20:27 sda5
brw-r----- 1 root disk 8,  6 08-22 20:27 sda6
brw-r----- 1 root disk 8,  7 08-22 20:27 sda7
brw-r----- 1 root disk 8,  8 08-22 20:27 sda8
brw-r----- 1 root disk 8,  9 08-22 20:27 sda9
brw-r----- 1 root disk 8,  0 08-20 03:34 sda
存储是共享的,但没有分区设备的信息,需要在第二个节点上partprobe命令读取分区信息:
[root@bj-db-02 ~]# partprobe
[root@bj-db-02 dev]# ll sda*
brw-r----- 1 root disk 8,  0 08-20 03:34 sda
brw-r----- 1 root disk 8,  1 08-22 20:31 sda1
brw-r----- 1 root disk 8, 10 08-22 20:31 sda10
brw-r----- 1 root disk 8, 11 08-22 20:31 sda11
brw-r----- 1 root disk 8, 12 08-22 20:31 sda12
brw-r----- 1 root disk 8,  2 08-22 20:31 sda2
brw-r----- 1 root disk 8,  3 08-22 20:31 sda3
brw-r----- 1 root disk 8,  4 08-22 20:31 sda4
brw-r----- 1 root disk 8,  5 08-22 20:31 sda5
brw-r----- 1 root disk 8,  6 08-22 20:31 sda6
brw-r----- 1 root disk 8,  7 08-22 20:31 sda7
brw-r----- 1 root disk 8,  8 08-22 20:31 sda8
brw-r----- 1 root disk 8,  9 08-22 20:31 sda9
看来分区信息在第二个节点上生成了,在其他节点上再用partprobe来读取分区信息即可。

看来大于2.2TB的存储空间用fdisk不支持,需要采用parted来分区,看到网上写parted分区的帖子特别多,但是比较乱,我就系统的整理下,以方便后面使用.


当在命令行输入parted后,进入parted命令的交互模式。输入help会显示帮助信息。下面就简单介绍一下常用的功能1、Check     简单检查文件系统。建议用其他命令检查文件系统,比如fsck

[root@bj-db-01 ~]# parted /dev/sda

Model: HP HSV300 (scsi)

Number  Start  End  Size  File system  Name  标志

(parted) mkpart                                                           

Model: HP HSV300 (scsi)

Number  Start   End     Size    File system  Name  标志

(parted) mkpart                                                           

Model: HP HSV300 (scsi)

Number  Start   End     Size    File system  Name  标志

(parted) print free                                                      

Model: HP HSV300 (scsi)

Number  Start   End     Size    File system  Name  标志

(parted) mkpart                                                           

Model: HP HSV300 (scsi)

Number  Start   End     Size    File system  Name  标志

(parted) mkpart                                                           

Model: HP HSV300 (scsi)

Number  Start   End     Size    File system  Name  标志

(parted) mkpart                                                           

Model: HP HSV300 (scsi)

Number  Start   End     Size    File system  Name  标志

(parted) mkpart                                                           

Model: HP HSV300 (scsi)

Number  Start   End     Size    File system  Name  标志

(parted) mkpart                                                           

Model: HP HSV300 (scsi)

Number  Start   End     Size    File system  Name  标志

(parted) mkpart                                                           

Model: HP HSV300 (scsi)

Number  Start   End     Size    File system  Name  标志

(parted) print free

Model: HP HSV300 (scsi)

Number  Start   End     Size    File system  Name  标志

(parted) mkpart                                                           

Model: HP HSV300 (scsi)

Number  Start   End     Size    File system  Name  标志

(parted) print free

Model: HP HSV300 (scsi)

Number  Start   End     Size    File system  Name  标志

(parted) mkpart                                                           

Model: HP HSV300 (scsi)

Number  Start   End     Size    File system  Name  标志

(parted) print free

Model: HP HSV300 (scsi)

Number  Start   End     Size    File system  Name  标志

(parted) quit                                 

去/dev/先查看:

在第二个上查看:

root@bj-db-02 dev]# ll sda*


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值