由於MBR分割槽表最大支援2T硬碟,而且主分割槽數量還有限制.
而GPT分割槽表就沒有上述問題,線上伺服器基本都是採用這個來格式化系統, 所以使用gpt進行分割槽.
方法如下:
1.進入parted工具,輸入help可檢視幫助
[root@amd ~]# sudo parted
GNU Parted 3.1
# 預設使用第一個硬碟
Using /dev/sda
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
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
2.選擇你要操作的裝置,一定要注意,不要把預設裝置誤操作了
(parted) select /dev/sdb
Using /dev/sdb
3.設定使用的分割槽型別, 如果要用MBR分割槽,輸入msdos即可。
(parted) mklabel 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
4.新增一個分割槽
(parted) mkpart
5.輸入分割槽名稱,可以不用輸入,直接回車
Partition name? []?
6.輸入使用哪種檔案系統,預設ext2,回車 (此處可以隨意選,之後可以使用mkfs重新格式化寫入檔案系統)
File system type? [ext2]? xfs
7.輸入分割槽從第幾MB的位置開始,輸入1,從第1MB開始(最好不要從0開始), 輸入為什麼位置結束,可以帶單位,如我這裡輸入的是2000GB,也可以直接輸3TB
Start? 1
End? 2000GB
8.此時已經分割槽成功,輸入print檢視當前分割槽/dev/sdb情況
(parted) print
Model: ATA ST2000DM006-2DM1 (scsi)
Disk /dev/sdb: 2000GB
Sector size (logical/physical): 512B/4096B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 1049kB 2000GB 2000GB ext4
(parted)
額, 我這個好像不給力啊, 怎麼File System還是ext4,不過沒關係, 後面可以強制格式化它來修改檔案系統
9.退出parted工具
(parted) quit
Information: You may need to update /etc/fstab.
10.格式化系統
[root@amd ~]# mkfs.xfs /dev/sdb1
mkfs.xfs: /dev/sdb1 appears to contain an existing filesystem (ext4).
mkfs.xfs: Use the -f option to force overwrite.
[root@amd ~]# mkfs.xfs -f /dev/sdb1
meta-data=/dev/sdb1 isize=512 agcount=4, agsize=122094592 blks
= sectsz=4096 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=488378368, imaxpct=5
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal log bsize=4096 blocks=238466, version=2
= sectsz=4096 sunit=1 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
11.建立目錄/mydata
[root@amd ~]# mkdir /mydata
12.修改/etc/fstab
[root@amd ~]# vim /etc/fstab
#
# /etc/fstab
# Created by anaconda on Sat Oct 20 01:23:55 2018
#
# Accessible filesystems, by reference, are maintained under `/dev/disk`
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/cl-root / xfs defaults 0 0
UUID=7f16402f-ec92-4a9d-bbe0-56ee0b509d83 /boot xfs defaults 0 0
UUID=32AA-91B7 /boot/efi vfat umask=0077,shortname=winnt 0 0
/dev/mapper/cl-home /home xfs defaults 0 0
/dev/mapper/cl-swap swap swap defaults 0 0
/dev/sdb1 /mydata xfs defaults 0 0
13.掛載
[root@amd ~]# mount -a
[root@amd ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/cl-root 50G 1.6G 49G 4% /
devtmpfs 3.7G 0 3.7G 0% /dev
tmpfs 3.7G 0 3.7G 0% /dev/shm
tmpfs 3.7G 8.7M 3.7G 1% /run
tmpfs 3.7G 0 3.7G 0% /sys/fs/cgroup
/dev/mapper/cl-home 873G 33M 873G 1% /home
/dev/sda2 1014M 151M 864M 15% /boot
/dev/sda1 200M 12M 189M 6% /boot/efi
tmpfs 744M 0 744M 0% /run/user/0
/dev/sdb1 1.9T 33M 1.9T 1% /mydata
14.獲取UUID方法
[root@amd ~]# blkid /dev/sdb1
/dev/sdb1: UUID="a8b15d78-e144-40e4-8f0e-c68b9749affd" TYPE="xfs" PARTUUID="142a3cd8-f2a2-4c83-987d-be3811eca4fc"