本文僅適用于使用 fdisk 命令對一個不大于 2 TB 的數據盤執行分區操作。如果需要分區的數據盤大于 2 TB
服務器安裝centos的時候,通常linux系統分區默認為3個分區,主分區最多4個,其他可根據自己的需要掛載。
/ 根分區,通常10-100G左右(根據總磁盤大小情況)
/boot 系統操作分區(100-500MB 足矣)
/swap 虛擬內存暫存分區(通常是內存的2倍,根據自己裝系統的習慣會有所差異)
[root@huoshi-111 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/cl-root 44G 4.3G 40G 10% /
devtmpfs 7.8G 0 7.8G 0% /dev
tmpfs 7.8G 0 7.8G 0% /dev/shm
tmpfs 7.8G 8.9M 7.8G 1% /run
tmpfs 7.8G 0 7.8G 0% /sys/fs/cgroup
/dev/sda1 1014M 251M 764M 25% /boot
tmpfs 1.6G 0 1.6G 0% /run/user/0
[root@huoshi-111 ~]#
1、首先查看未指派的分區名稱,有的不一樣,我的分別是/dev/sda和/dev/sdb,sda是系統分區,sdb是存儲數據分區。
[root@huoshi-111 ~]# fdisk -l
這里這個盤是需要掛載的
Disk /dev/sdb: 214.7 GB, 214748364800 bytes, 419430400 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/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: 0x000b33c5
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 104857599 51379200 8e Linux LVM
Disk /dev/mapper/cl-root: 47.2 GB, 47240445952 bytes, 92266496 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/mapper/cl-swap: 5368 MB, 5368709120 bytes, 10485760 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
[root@huoshi-111 ~]#
- 創建硬盤分區
[root@huoshi-111 ~]# 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 0x774b38c4.
Command (m for help): #輸入n回車,添加新分區,如果需要更多,請輸入m回車看幫助
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): # 輸入p回車,P的意思是主分區
Partition number (1-4): # 輸入數字1回車,分區數量
First sector (2048-20971519, default 2048): #默認回車
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-419430399, default 419430399): # 默認回車
Using default value 419430399
Partition 1 of type Linux and of size 200GiB is set
Command (m for help): # 輸入w保存
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
3、分區完成。輸入fdisk -l查看信息
[root@huoshi-111 ~]# fdisk -l
Disk /dev/sdb: 214.7 GB, 214748364800 bytes, 419430400 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: 0xc10d16e7
# 可以查看/dev/sdb1已經被默認分區
Device Boot Start End Blocks Id System
/dev/sdb1 2048 419430399 209714176 83 Linux
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: 0x000b33c5
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 104857599 51379200 8e Linux LVM
Disk /dev/mapper/cl-root: 47.2 GB, 47240445952 bytes, 92266496 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/mapper/cl-swap: 5368 MB, 5368709120 bytes, 10485760 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
[root@huoshi-111 ~]#
- 格式化分區
[root@huoshi-111 ~]# mkfs.ext4 /dev/sdb1
- 建立掛載目錄
[root@huoshi-111 ~]# mkdir /data
6.掛載分區
[root@huoshi-111 ~]# mount /dev/sdb1 /data
7.設置開機自動掛載
[root@huoshi-111 ~]# echo /dev/sdb1 /data ext4 defaults 0 0 >> /etc/fstab
8.確認是否掛載成功
# 重啟系統
[root@huoshi-111 ~]# reboot
[root@huoshi-111 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/cl-root 44G 4.3G 40G 10% /
devtmpfs 7.8G 0 7.8G 0% /dev
tmpfs 7.8G 0 7.8G 0% /dev/shm
tmpfs 7.8G 8.9M 7.8G 1% /run
tmpfs 7.8G 0 7.8G 0% /sys/fs/cgroup
# 注意看這里,/dev/sdb1 掛載在/data,說明這次掛載成功了
/dev/sdb1 197G 201M 187G 1% /data
/dev/sda1 1014M 251M 764M 25% /boot
tmpfs 1.6G 0 1.6G 0% /run/user/0
[root@huoshi-111 ~]#