1. 程式人生 > 實用技巧 >第二十二章 磁碟管理,Fdisk分割槽,Gdisk分割槽

第二十二章 磁碟管理,Fdisk分割槽,Gdisk分割槽

磁碟管理

1. 磁碟的基本概念
2. 磁碟的基本結構
3. 磁碟的預備知識
4. 磁碟基本分割槽Fdisk
5. 磁碟基本分割槽Gdisk
6. 磁碟掛載方式Mount
7. 虛擬記憶體Swap介紹
8. 磁碟陣列RAID概述
9. 磁碟陣列RAID實戰
10. 邏輯卷LVM概述
11. 邏輯卷LVM實踐
12. 磁碟常見故障

磁碟的基本概念



磁碟的工作流程
當記錄資料時,硬碟的磁頭開始通電,形成強磁場,資料在磁場的作用下轉變成電流,使顆粒磁化,從而將資訊記錄在圓盤上。由海量顆粒組成的資訊,就是我們存在硬盤裡的資料。

什麼是軟盤、硬碟、磁碟?
軟盤 1.44MB 安裝軟體驅動 早期對磁碟的稱呼
磁碟開始指的是1.44MB的3.5英寸磁碟,這是很早時候的電腦儲存檔,也叫軟盤。

硬碟 隨著技術的發展產生的磁碟 固態盤 資料量大 企業的主流
硬碟就是一種最為常見的外儲存器,它好比是資料的外部倉庫一樣。電腦除了要有“工作間”,還要有專門儲存東西的倉庫。是計算機中的最大的儲存裝置了,我們會將磁碟的儲存片裝到硬質金屬盒子裡,這樣就可以得到更好的保護,而且在使用壽命上也比軟盤優越得多,只有低格的時候才會對硬碟有很大的傷害。

磁碟 就是一個統稱
磁碟是指利用磁記錄技術儲存資料的儲存器,是所有硬式儲存的統稱,如最早出現的軟盤,現在的硬碟,都是磁碟中的一部分。

磁碟與軟盤硬碟的關係?
磁碟是一種統稱,即是一開始的軟盤,又是現如今的硬碟,但是在現在,說起磁碟,都指的是硬碟。

磁碟的基本結構


碟片 分為兩面 硬碟中有幾個碟片 不超過5片
單片的大小 80G 160G
磁軌 同一個軌跡的同心圓
扇區 512B 業界的規定 低階格式化
柱面 減少磁頭的讀取速度 抽象的概念
磁頭 用來讀寫資料的

硬碟中一般會有多個碟片,每個碟片包含兩個面,每個盤面都對應地有一個讀/寫磁頭(Head,簡寫為H)。受到硬碟整體體積和生產成本的限制,碟片數量都受到限制,一般都在5片以內。碟片的編號自下向上從0開始,如最下邊的碟片有0面和1面,再上一個碟片就編號為2面和3面。

磁碟的預備知識


磁碟介面的型別

HDD
IDE SCSI 被淘汰
SATA III SAS 企業用的多
SSD (支援SATA、PCI-E)
M.2介面是一種新的主機介面方案,可以相容多種通訊協議,如sata、PCIe、USB、HSIC、UART、SMBus等。為超極本(Ultrabook)量身定做的新一代介面標準,以取代原來的mSATA介面。無論是更小巧的規格尺寸,還是更高的傳輸效能,M.2都遠勝於mSATA。
M2 超極本新一代的介面標準 早期筆記本使用的是mstat

socket 2 SATA III PCIE x2

socket 3 PCIE x4

機械和固態的對比
機械 HDD Hard disk driver 固態 SSD solid state driver

容量大,體積大 容量小,體積小
價格低 價格高
讀寫速度低 效能好
容易損壞 不容易損壞
資料恢復容易 資料恢復難
使用壽命無限 次數1-2W

資料單位

容量: B 位元組 KB MB GB TB PB EB 1024倍 以千去計算

轉速RPM: 轉/每分鐘 5400 7200 10k 15k

iops:每秒輸入和輸出 讀寫的效能單位

尺寸:2.5 3.5英寸

磁碟分割槽的名稱

[root@lxy ~]# ll /dev/sd*
brw-rw----. 1 root disk 8, 0 Dec 28 23:20 /dev/sda
brw-rw----. 1 root disk 8, 1 Dec 28 23:20 /dev/sda1
brw-rw----. 1 root disk 8, 2 Dec 28 23:20 /dev/sda2
brw-rw----. 1 root disk 8, 3 Dec 28 23:20 /dev/sda3


命名規範
/dev/ 是存放所有的裝置目錄
sd #物理磁碟
vd #虛擬磁碟
a #第一塊硬碟
b #第二塊硬碟 以此類推
1 #第一個主分割槽
/dev/sdd2 #第四塊硬碟的第二個主分割槽
/dev/vdc1 #第三塊虛擬磁碟的第一個主分割槽

磁碟在系統上的命名方式
裝置名稱 分割槽資訊 裝置型別
/dev/sda /dev/sda1 第一塊物理磁碟第一分割槽
/dev/sdb /dev/sdb2 第二塊磁碟第二個分割槽
/dev/vdd /dev/vdd4 第四塊虛擬磁碟的第四個分割槽

分割槽表
MBR分割槽表 DPT分割槽表 支援2TB以下的分割槽

磁碟基本分割槽Fdisk
適用於磁碟小於2TB的磁碟,分割槽型別MBR,主分割槽4或主分割槽3+擴充套件分割槽(邏輯分割槽+…),分割槽後需要儲存後才能生效

磁碟基本分割槽Gdisk
分割槽表為GPT,主分割槽128,分割槽後需要儲存後才能生效

主引導記錄 512位元組大小

位置: 0磁頭0磁軌1扇區

446位元組 主引導記錄 64個位元組作為主分割槽 4個主分割槽 2位元組 分割槽結束識別符號 55AA AA55

擴充套件分割槽是不能儲存資料的

邏輯分割槽才是儲存資料的,邏輯分割槽的編號一定是從5開始的

3個主分割槽+1擴充套件分割槽(多個邏輯分割槽)

GPT分割槽表 高格 扇區 4KB

支援128個主分割槽 支援2TB以上的分割槽 最大18EB


分割槽的型別

分割槽的工具:
fdisk MBR分割槽表
gdisk GPT分割槽表
parted 高階分割槽工具 瞭解


檢視磁碟相關的命令

[root@lxy ~]# ll /dev/sd*
brw-rw----. 1 root disk 8, 0 Dec 28 23:20 /dev/sda
brw-rw----. 1 root disk 8, 1 Dec 28 23:20 /dev/sda1
brw-rw----. 1 root disk 8, 2 Dec 28 23:20 /dev/sda2
brw-rw----. 1 root disk 8, 3 Dec 28 23:20 /dev/sda3

#檢視磁碟的使用情況
[root@lxy ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 48G 1.5G 47G 4% /
devtmpfs 476M 0 476M 0% /dev
tmpfs 487M 0 487M 0% /dev/shm
tmpfs 487M 7.6M 479M 2% /run
tmpfs 487M 0 487M 0% /sys/fs/cgroup
/dev/sda1 497M 120M 378M 25% /boot
tmpfs 98M 0 98M 0% /run/user/0

#顯示所有分割槽的情況
[root@lxy ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 50G 0 disk
├─sda1 8:1 0 500M 0 part /boot
├─sda2 8:2 0 2G 0 part [SWAP]
└─sda3 8:3 0 47.5G 0 part /
sr0 11:0 1 4.3G 0 rom

Fdisk分割槽

1. 準備環境,新增一塊磁碟

[root@lxy ~]# lsblk
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda      8:0    0   50G  0 disk 
├─sda1   8:1    0  500M  0 part /boot
├─sda2   8:2    0    2G  0 part [SWAP]
└─sda3   8:3    0 47.5G  0 part /
sdb      8:16   0  100G  0 disk 
sdc      8:32   0    3T  0 disk 
sr0     11:0    1  4.3G  0 rom  

2. 開始進行分割槽  

[root@lxy ~]# fdisk   -l		#顯示所有的分割槽資訊 

Disk /dev/sda: 53.7 GB, 53687091200 bytes, 104857600 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: 0x000cd652

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     1026047      512000   83  Linux
/dev/sda2         1026048     5220351     2097152   82  Linux swap / Solaris
/dev/sda3         5220352   104857599    49818624   83  Linux

Disk /dev/sdb: 107.4 GB, 107374182400 bytes, 209715200 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 /dev/sdc: 3298.5 GB, 3298534883328 bytes, 6442450944 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

#針對/dev/sdb  進行分割槽 

[root@lxy ~]# fdisk   /dev/sdb
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x431a98f5.

Command (m for help): m			#命令幫助
Command action
   a   toggle a bootable flag			
   b   edit bsd disklabel			
   c   toggle the dos compatibility flag		
   d   delete a partition							#刪除分割槽
   g   create a new empty GPT partition table
   G   create an IRIX (SGI) partition table
   l   list known partition types					#顯示已知的分割槽型別資訊  
   m   print this menu								#選單 
   n   add a new partition							#新增一個新的分割槽 
   o   create a new empty DOS partition table
   p   print the partition table					#顯示這個分割槽表資訊
   q   quit without saving changes					#退出不儲存 
   s   create a new empty Sun disklabel
   t   change a partition's system id
   u   change display/entry units
   v   verify the partition table
   w   write table to disk and exit					#儲存退出 
   x   extra functionality (experts only)
Command (m for help): n			#建立新的分割槽 
Partition type:
   p   primary (0 primary, 0 extended, 4 free)   #主分割槽
   e   extended				#擴充套件分割槽
Select (default p): p			#選擇建立主分割槽 
Partition number (1-4, default 1): 1		#分割槽的編號 
First sector (2048-209715199, default 2048): 			#分割槽的扇區的起始位置 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-209715199, default 209715199): +10G		#扇區的結束位置  
Partition 1 of type Linux and of size 10 GiB is set

Command (m for help): p			#列印這個分割槽資訊

Disk /dev/sdb: 107.4 GB, 107374182400 bytes, 209715200 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: 0x431a98f5

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048    20973567    10485760   83  Linux

Command (m for help): n
Partition type:
   p   primary (2 primary, 0 extended, 2 free)
   e   extended
Select (default p): e		#建立擴充套件分割槽 
Partition number (3,4, default 3): 4  
First sector (62916608-209715199, default 62916608): 
Using default value 62916608
Last sector, +sectors or +size{K,M,G} (62916608-209715199, default 209715199): +50G
Partition 4 of type Extended and of size 50 GiB is set

Command (m for help): p

Disk /dev/sdb: 107.4 GB, 107374182400 bytes, 209715200 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: 0x431a98f5

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048    20973567    10485760   83  Linux
/dev/sdb2        20973568    62916607    20971520   83  Linux
/dev/sdb4        62916608   167774207    52428800    5  Extended

Command (m for help): n
Partition type:
   p   primary (2 primary, 1 extended, 1 free)
   l   logical (numbered from 5)
Select (default p): l			#建立邏輯分割槽
Adding logical partition 5		 #邏輯分割槽編號從5開始  
First sector (62918656-167774207, default 62918656): 
Using default value 62918656
Last sector, +sectors or +size{K,M,G} (62918656-167774207, default 167774207): +10G
Partition 5 of type Linux and of size 10 GiB is set

Command (m for help): p

Disk /dev/sdb: 107.4 GB, 107374182400 bytes, 209715200 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: 0x431a98f5

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048    20973567    10485760   83  Linux
/dev/sdb2        20973568    62916607    20971520   83  Linux
/dev/sdb4        62916608   167774207    52428800    5  Extended
/dev/sdb5        62918656    83890175    10485760   83  Linux

Command (m for help): 

Command (m for help): d				#刪除分割槽  
Partition number (1,2,4,5, default 5): 2		#刪除指定分割槽編號 
Partition 2 is deleted

Command (m for help): p

Disk /dev/sdb: 107.4 GB, 107374182400 bytes, 209715200 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: 0x431a98f5

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048    20973567    10485760   83  Linux
/dev/sdb4        62916608   167774207    52428800    5  Extended
/dev/sdb5        62918656    83890175    10485760   83  Linux

Command (m for help): w			#儲存退出 
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

#檢查結果  
[root@lxy ~]# ll  /dev/sd*
brw-rw----. 1 root disk 8,  0 Dec 31 18:45 /dev/sda
brw-rw----. 1 root disk 8,  1 Dec 31 18:45 /dev/sda1
brw-rw----. 1 root disk 8,  2 Dec 31 18:45 /dev/sda2
brw-rw----. 1 root disk 8,  3 Dec 31 18:45 /dev/sda3
brw-rw----. 1 root disk 8, 16 Dec 31 19:27 /dev/sdb
brw-rw----. 1 root disk 8, 17 Dec 31 19:27 /dev/sdb1
brw-rw----. 1 root disk 8, 20 Dec 31 19:27 /dev/sdb4
brw-rw----. 1 root disk 8, 21 Dec 31 19:27 /dev/sdb5
brw-rw----. 1 root disk 8, 32 Dec 31 18:45 /dev/sdc

[root@lxy ~]# lsblk
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda      8:0    0   50G  0 disk 
├─sda1   8:1    0  500M  0 part /boot
├─sda2   8:2    0    2G  0 part [SWAP]
└─sda3   8:3    0 47.5G  0 part /
sdb      8:16   0  100G  0 disk 
├─sdb1   8:17   0   10G  0 part 
├─sdb4   8:20   0    1K  0 part 
└─sdb5   8:21   0   10G  0 part 
sdc      8:32   0    3T  0 disk 
sr0     11:0    1  4.3G  0 rom  


3. 格式化並建立檔案系統   

ext3  centos5     ext4   centos6       xfs   centos 7     nfs    網路檔案共享的檔案系統 

[root@lxy ~]# mkfs  -t  xfs  /dev/sdb1 ^C		#兩種寫法
[root@lxy ~]# mkfs.xfs  /dev/sdb1 
meta-data=/dev/sdb1              isize=512    agcount=4, agsize=655360 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=2621440, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal log           bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0

4. 建立掛載點,進行掛載使用,沒有掛載的裝置是不能用的

[root@lxy ~]# mkdir   /mbr
[root@lxy ~]# mount  /dev/sdb1   /mbr
[root@lxy ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda3        48G  1.5G   47G   4% /
devtmpfs        476M     0  476M   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/sda1       497M  120M  378M  25% /boot
tmpfs            98M     0   98M   0% /run/user/0
/dev/sdb1        10G   33M   10G   1% /mbr
[root@lxy ~]# cp  /etc/services   /mbr/
[root@lxy ~]# ll /mbr/
total 656
-rw-r--r--. 1 root root 670293 Dec 31 19:36 services

[root@lxy ~]# umount   /dev/sdb1		#解除安裝  
[root@lxy ~]# ll /mbr/
total 0
[root@lxy ~]# ll /opt/
total 436
-rw-r--r--. 1 root root  26927 Nov 26 20:31 kaoshi.zip
-rw-r--r--. 1 root root 413973 Nov 26 20:20 windows-提交作業程式碼.zip
[root@lxy ~]# mount  /dev/sdb1  /opt/
[root@lxy ~]# ll /opt/
total 656
-rw-r--r--. 1 root root 670293 Dec 31 19:36 services
[root@lxy ~]# umount   /dev/sdb1
[root@lxy ~]# ll /opt/
total 436
-rw-r--r--. 1 root root  26927 Nov 26 20:31 kaoshi.zip
-rw-r--r--. 1 root root 413973 Nov 26 20:20 windows-提交作業程式碼.zip

#重啟失效 


5. 實現永久掛載  

	1.把掛載的命令寫入開機自啟動的列表中 
	
[root@lxy ~]# ll  /etc/rc.local 		#開機自啟動的檔案列表 
lrwxrwxrwx. 1 root root 13 Nov 26 20:23 /etc/rc.local -> rc.d/rc.local
[root@lxy ~]# ll  /etc/rc.d/rc.local 
-rw-r--r--. 1 root root 473 Oct 31  2018 /etc/rc.d/rc.local

#寫完之後一定要加執行許可權  


	2. 將掛載資訊寫入到開機自啟動掛載列表 
	
[root@lxy ~]# ll  /etc/fstab 

[root@lxy ~]# vi  /etc/fstab 
[root@lxy ~]# tail  -1  /etc/fstab
/dev/sdb1                                 /mbr                    xfs     defaults        0 0
[root@lxy ~]# 

[root@lxy ~]# mount -a		#重新載入自啟動掛載列表 
[root@lxy ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda3        48G  1.5G   47G   4% /
devtmpfs        476M     0  476M   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/sda1       497M  120M  378M  25% /boot
tmpfs            98M     0   98M   0% /run/user/0
/dev/sdb1        10G   33M   10G   1% /mbr

[root@lxy ~]# reboot
[root@lxy ~]# df  -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda3        48G  1.5G   46G   4% /
devtmpfs        476M     0  476M   0% /dev
tmpfs           487M     0  487M   0% /dev/shm
tmpfs           487M  7.6M  479M   2% /run
tmpfs           487M     0  487M   0% /sys/fs/cgroup
/dev/sdb1        10G   33M   10G   1% /mbr
/dev/sda1       497M  120M  378M  25% /boot
tmpfs            98M     0   98M   0% /run/user/0

Gdisk分割槽

[root@lxy ~]# yum  install  -y  gdisk

支援128主分割槽,支援2TB以上的分割槽,使用GPT的分割槽  


1. 新增一塊硬碟  3TB

[root@lxy ~]# lsblk
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda      8:0    0   50G  0 disk 
├─sda1   8:1    0  500M  0 part /boot
├─sda2   8:2    0    2G  0 part [SWAP]
└─sda3   8:3    0 47.5G  0 part /
sdb      8:16   0  100G  0 disk 
├─sdb1   8:17   0   10G  0 part /mbr
├─sdb4   8:20   0    1K  0 part 
└─sdb5   8:21   0   10G  0 part 
sdc      8:32   0    3T  0 disk 
sr0     11:0    1  4.3G  0 rom  


2. 開始進行分割槽  

[root@lxy ~]# gdisk   /dev/sdc
GPT fdisk (gdisk) version 0.8.10

Partition table scan:
  MBR: not present
  BSD: not present
  APM: not present
  GPT: not present

Creating new GPT entries.

Command (? for help): m
b	back up GPT data to a file
c	change a partition's name
d	delete a partition						#刪除分割槽 
i	show detailed information on a partition
l	list known partition types				#顯示分割槽型別資訊
n	add a new partition						#新增一個新的分割槽
o	create a new empty GUID partition table (GPT)
p	print the partition table					#列印這個分割槽表 
q	quit without saving changes					#退出不儲存 
r	recovery and transformation options (experts only)
s	sort partitions
t	change a partition's type code
v	verify disk
w	write table to disk and exit				#儲存退出
x	extra functionality (experts only)
?	print this menu								#選單

Command (? for help): n			#建立新的主分割槽 
Partition number (1-128, default 1): 			#從1開始,編號  
First sector (34-6442450910, default = 2048) or {+-}size{KMGTP}:    #扇區的起始位置
Last sector (2048-6442450910, default = 6442450910) or {+-}size{KMGTP}:   #扇區結束位置 
Current type is 'Linux filesystem'
Hex code or GUID (L to show codes, Enter = 8300): L			#顯示分割槽型別 
0700 Microsoft basic data  0c01 Microsoft reserved    2700 Windows RE          
3000 ONIE boot             3001 ONIE config           4100 PowerPC PReP boot   
4200 Windows LDM data      4201 Windows LDM metadata  7501 IBM GPFS            
7f00 ChromeOS kernel       7f01 ChromeOS root         7f02 ChromeOS reserved   
8200 Linux swap            8300 Linux filesystem      8301 Linux reserved      
8302 Linux /home           8400 Intel Rapid Start     8e00 Linux LVM           
a500 FreeBSD disklabel     a501 FreeBSD boot          a502 FreeBSD swap        
a503 FreeBSD UFS           a504 FreeBSD ZFS           a505 FreeBSD Vinum/RAID  
a580 Midnight BSD data     a581 Midnight BSD boot     a582 Midnight BSD swap   
a583 Midnight BSD UFS      a584 Midnight BSD ZFS      a585 Midnight BSD Vinum  
a800 Apple UFS             a901 NetBSD swap           a902 NetBSD FFS          
a903 NetBSD LFS            a904 NetBSD concatenated   a905 NetBSD encrypted    
a906 NetBSD RAID           ab00 Apple boot            af00 Apple HFS/HFS+      
af01 Apple RAID            af02 Apple RAID offline    af03 Apple label         
af04 AppleTV recovery      af05 Apple Core Storage    be00 Solaris boot        
bf00 Solaris root          bf01 Solaris /usr & Mac Z  bf02 Solaris swap        
bf03 Solaris backup        bf04 Solaris /var          bf05 Solaris /home       
bf06 Solaris alternate se  bf07 Solaris Reserved 1    bf08 Solaris Reserved 2  
bf09 Solaris Reserved 3    bf0a Solaris Reserved 4    bf0b Solaris Reserved 5  
c001 HP-UX data            c002 HP-UX service         ea00 Freedesktop $BOOT   
eb00 Haiku BFS             ed00 Sony system partitio  ed01 Lenovo system partit
Press the <Enter> key to see more codes: 			#翻頁   回車翻頁 
ef00 EFI System            ef01 MBR partition scheme  ef02 BIOS boot partition 
fb00 VMWare VMFS           fb01 VMWare reserved       fc00 VMWare kcore crash p
fd00 Linux RAID            
Hex code or GUID (L to show codes, Enter = 8300): 
Changed type of partition to 'Linux filesystem'

Command (? for help): p			#列印這個分割槽表資訊
Disk /dev/sdc: 6442450944 sectors, 3.0 TiB
Logical sector size: 512 bytes
Disk identifier (GUID): FC5D373A-D55E-464F-AEB8-3F3AB214906D
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 6442450910
Partitions will be aligned on 2048-sector boundaries
Total free space is 2014 sectors (1007.0 KiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048      6442450910   3.0 TiB     8300  Linux filesystem

Command (? for help): w			#儲存退出 

Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!

Do you want to proceed? (Y/N): y		#是否向下繼續執行  
OK; writing new GUID partition table (GPT) to /dev/sdc.
The operation has completed successfully.


3. 格式化並建立檔案系統   

[root@lxy ~]# mkfs.xfs   /dev/sdc1  
meta-data=/dev/sdc1              isize=512    agcount=4, agsize=201326527 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=805306107, imaxpct=5
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal log           bsize=4096   blocks=393215, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0


4. 建立掛載點,並進行掛載使用 


[root@lxy ~]# mkdir  /gpt
[root@lxy ~]# mount  /dev/sdc1  /gpt

[root@lxy ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda3        48G  1.6G   46G   4% /
devtmpfs        476M     0  476M   0% /dev
tmpfs           487M     0  487M   0% /dev/shm
tmpfs           487M  7.6M  479M   2% /run
tmpfs           487M     0  487M   0% /sys/fs/cgroup
/dev/sdb1        10G   33M   10G   1% /mbr
/dev/sda1       497M  120M  378M  25% /boot
tmpfs            98M     0   98M   0% /run/user/0
/dev/sdc1       3.0T   33M  3.0T   1% /gpt
[root@lxy ~]# lsblk
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda      8:0    0   50G  0 disk 
├─sda1   8:1    0  500M  0 part /boot
├─sda2   8:2    0    2G  0 part [SWAP]
└─sda3   8:3    0 47.5G  0 part /
sdb      8:16   0  100G  0 disk 
├─sdb1   8:17   0   10G  0 part /mbr
├─sdb4   8:20   0    1K  0 part 
└─sdb5   8:21   0   10G  0 part 
sdc      8:32   0    3T  0 disk 
└─sdc1   8:33   0    3T  0 part /gpt
sr0     11:0    1  4.3G  0 rom  
[root@lxy ~]# dd  if=/dev/zero  of=/gpt/test.log  bs=100M  count=50

[root@lxy ~]# ll  /gpt/
total 5120000
-rw-r--r--. 1 root root 5242880000 Dec 31 20:16 test.log
[root@lxy ~]# umount   /gpt/
[root@lxy ~]# ll  /gpt/
total 0
[root@lxy ~]# mount  /dev/sdc1  /gpt
[root@lxy ~]# ll  /gpt/
total 5120000
-rw-r--r--. 1 root root 5242880000 Dec 31 20:16 test.log

5. 實現永久掛載  

[root@lxy ~]# tail  -1 /etc/fstab
/dev/sdc1				  /gpt			  xfs     defaults        0 0
[root@lxy ~]# mount  -a
[root@lxy ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda3        48G  1.6G   46G   4% /
devtmpfs        476M     0  476M   0% /dev
tmpfs           487M     0  487M   0% /dev/shm
tmpfs           487M  7.6M  479M   2% /run
tmpfs           487M     0  487M   0% /sys/fs/cgroup
/dev/sdb1        10G   33M   10G   1% /mbr
/dev/sda1       497M  120M  378M  25% /boot
tmpfs            98M     0   98M   0% /run/user/0
/dev/sdc1       3.0T  5.0G  3.0T   1% /gpt