天天看點

Linux中使用parted分區工具進行GPT分區示例

使用parted和gdisk工具對硬碟進行GPT分區的最後效果差不多。

如果是固态硬碟,使用parted對硬碟分區預設會進行4K對齊。

但是使用parted分區,是直接修改分區表,實際環境中配置容錯率很低。

基本配置舉例:

配置前,使用fdisk -l 确認你的linux系統有一塊空的硬碟

[[email protected] ~]# parted /dev/sdb
GNU Parted 3.1
Using /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) help  # 使用help可以檢視parted支援的指令參數
  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
  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分區,支援2T以上的硬碟
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  # 輸入yes

(parted) mkpart  # 該指令進行分區
Partition name?  []?  # 設定分區名字
File system type?  [ext2]? xfs  # 設定分區類型
Start? 1  # 1表示從最開始分區,也可以用百分比表示,比如Start? 0% , End? 50%
End? -1   # -1表示到磁盤末尾;也可以分成多個磁盤,寫要配置設定的大小

# 如果想分兩個分區,大小均分,可以這樣寫
# Start? 1
# End? 50%

# 另一個分區
# Start? 50%
# End? 100%

(parted) print  # 檢查
Model: VMware Virtual disk (scsi)
Disk /dev/sdb: 215GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:

Number  Start   End    Size   File system  Name  Flags
 1      1049kB  215GB  215GB  xfs

(parted) quit
Information: You may need to update /etc/fstab.

You have new mail in /var/spool/mail/root

# 下面是删除分區示例
(parted) rm 1              #rm後面使用分區的号碼,就是用print列印出來的Number
(parted) print
Model: VBOX HARDDISK (ide)
Disk /dev/vdb: 2147GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Number Start End Size File system Name Flags
           

使用parted分完區後,可以直接格式化

[[email protected] ~]# mkfs.xfs -f /dev/sdb1
meta-data=/dev/sdb1              isize=256    agcount=4, agsize=13107072 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=0        finobt=0
data     =                       bsize=4096   blocks=52428288, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=0
log      =internal log           bsize=4096   blocks=25599, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
           

然後/etc/fstab進行挂載

[[email protected] ~]# vim /etc/fstab
/dev/sdb1 /lewis xfs defaults 0 0
           

繼續閱讀