問題描述:
Ubuntu 16.04系統,系統盤為240G固態硬盤,還有1T機械硬盤,現要再添加一個4T硬盤。
問題分析:
使用GTP對硬盤進行分區並掛載硬盤的方法,一般而言服務器上掛載的硬盤都是比較大的,傳統的對硬盤進行分區需要在終端敲sudo fdisk進行操作
但是,當掛載的硬盤的容量大於2T的時候,是無法通過sudo fdisk進行分區的,這個時候必須要進行GPT進行分區,並且設置為開機啟動。
fdisk 分區,硬盤超過2T,只能生成2T分區。
$ sudo fdisk /dev/sda
Device does not contain a recognized partition table.
The size of this disk is 3.7 TiB (4000787030016 bytes). DOS partition table format can not be used on drives for volumes larger than 2199023255040 bytes for 512-byte sectors. Use GUID partition table format (GPT).
Created a new DOS disklabel with disk identifier 0x721e33d2.
解決方法:
1、使用GTP對硬盤進行分區
終端輸入 sudo fdisk -l 查看機器上都插了哪些安裝盤,看到/dev/sda,並且沒有進行分區且大小為3.7T,是要掛載的硬盤。
$ sudo fdisk -l
Disk /dev/nvme0n1: 238.5 GiB, 256060514304 bytes, 500118192 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
Disklabel type: dos
Disk identifier: 0xb091dbe9
Device Boot Start End Sectors Size Id Type
/dev/nvme0n1p1 * 2048 498116607 498114560 237.5G 83 Linux
/dev/nvme0n1p2 498118654 500117503 1998850 976M 5 Extended
/dev/nvme0n1p5 498118656 500117503 1998848 976M 82 Linux swap / Solaris
Disk /dev/sda: 3.7 TiB, 4000787030016 bytes, 7814037168 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk /dev/sdb: 1.8 TiB, 2000398934016 bytes, 3907029168 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: dos
Disk identifier: 0x2ef87b1f
Device Boot Start End Sectors Size Id Type
/dev/sdb1 * 2048 1126399 1124352 549M 7 HPFS/NTFS/exFAT
/dev/sdb2 1128446 3907028991 3905900546 1.8T 5 Extended
/dev/sdb5 1128448 3874134015 3873005568 1.8T 83 Linux
/dev/sdb6 3874136064 3907028991 32892928 15.7G 82 Linux swap / Solaris
Partition 2 does not start on physical sector boundary.
然后運行如下命令:
sudo parted /dev/sda #進入parted
mklabel gpt #將磁盤設置為gpt格式,
mkpart logical 0 -1 #將磁盤所有的容量設置為GPT格式
print #查看分區結果
這個時候應該是默認進行分了一個/dev/sda1這個分區
然后退出parted,在終端輸入 sudo mkfs.ext4 -F /dev/sda1
將剛剛分出來的sda1格式化為ext4的格式,然后就可以設置開機自動掛載了。
2、設置開機自動掛載
查看硬盤/dev/sda1 對應的UUID
sudo blkid
注意: 唯一的sda1的UUID號。
再事先准備好一個地方來做掛載點,比如我這里是/DATA4T然后再用命令打開配置文件:
終端輸入 sudo vim /etc/fstab
然后在文件末尾添加
UUID=7941f2c5-d582-4414-85c5-6d199a701795 /DATA4T ext4 defaults 0 0
最后重啟電腦。
由於/DATA4T 是在根目錄下,為便於操作,需將其用戶屬性從 root改成 普通用戶。
附錄:
常用相關命令:
lsblk -f
可以查看硬盤UUIDfdisk -l
查看硬盤mkfs.ext4 /dev/vdb
格式化硬盤blkid
查看磁盤的UUID
參考:
在Ubuntu 16.04下使用GPT分區並掛載硬盤(主要)
Ubuntu16.04 掛載硬盤(簡單實用)(掛載參考)
ubuntu16.04 掛載硬盤
Ubuntu環境下掛載新硬盤
sudo fdisk /dev/sdb分區 操作詳解
1、顯示硬盤及所屬分區情況。在終端窗口中輸入如下命令:
顯示當前的硬盤及所屬分區的情況。如下圖所示:
系統提示:DIsk /dev/sdb doesn't contain a valid partition table。
2、對硬盤進行分區。在終端窗口中輸入如下命令:
如下圖所示:
在Command (m for help)提示符后面輸入m顯示一個幫助菜單。
在Command (m for help)提示符后面輸入n,執行 add a new partition 指令給硬盤增加一個新分區。
出現Command action時,輸入e,指定分區為擴展分區(extended)。
出現Partition number(1-4)時,輸入1表示只分一個區。
后續指定起啟柱面(cylinder)號完成分區。
在Command (m for help)提示符后面輸入p,顯示分區表。
系統提示如下:
Device Boot Start End Blocks Id System
/dev/sdb1 1 26108 209712478+ 5 Extended
在Command (m for help)提示符后面輸入w,保存分區表。
系統提示:The partition table has been altered!
在終端窗口中輸入如下命令:
如下圖所示:
系統已經識別了硬盤 /dev/sdb 的分區。
二、硬盤格式化 | Format hard disk
1、顯示硬盤及所屬分區情況。在終端窗口中輸入如下命令:
說明:
-t ext4 表示將分區格式化成ext4文件系統類型。