問題描述:html
Ubuntu 16.04系統,系統盤爲240G固態硬盤,還有1T機械硬盤,現要再添加一個4T硬盤。ubuntu
問題分析:vim
使用GTP對硬盤進行分區並掛載硬盤的方法,通常而言服務器上掛載的硬盤都是比較大的,傳統的對硬盤進行分區須要在終端敲sudo fdisk進行操做bash
可是,當掛載的硬盤的容量大於2T的時候,是沒法經過sudo fdisk進行分區的,這個時候必需要進行GPT進行分區,而且設置爲開機啓動。服務器
fdisk 分區,硬盤超過2T,只能生成2T分區。ide
$ sudo fdisk /dev/sda this
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).spa
Created a new DOS disklabel with disk identifier 0x721e33d2..net
解決方法:3d
一、使用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的格式,而後就能夠設置開機自動掛載了。
二、設置開機自動掛載
查看硬盤/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分區 操做詳解
一、顯示硬盤及所屬分區狀況。在終端窗口中輸入以下命令:
顯示當前的硬盤及所屬分區的狀況。以下圖所示:
系統提示: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 的分區。
2、硬盤格式化 | Format hard disk
一、顯示硬盤及所屬分區狀況。在終端窗口中輸入以下命令:
說明:
-t ext4 表示將分區格式化成ext4文件系統類型。