本文仅适用于使用 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 ~]#