通过fdisk初始化Linux数据盘

1.查看新增数据盘

fdisk -l

[root@ecs-test-0001 ~]# fdisk -l

Disk /dev/vda: 42.9 GB, 42949672960 bytes, 83886080 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: 0x000bcb4e

Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *        2048    83886079    41942016   83  Linux

Disk /dev/vdb: 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

表示当前系统有两块磁盘,"/dev/vda"是系统盘,"/dev/vdb"是新增数据盘。

2.新增数据盘分区

fdisk 新增数据盘 如fdisk /dev/vdb

[root@ecs-test-0001 ~]# fdisk /dev/vdb
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 0x38717fc1.

Command (m for help):

3.开始新建分区

输入"n",按"Enter",开始新建分区

Command (m for help): n
Partition type:
p   primary (0 primary, 0 extended, 4 free)
e   extended

"p"表示主分区,"e"表示扩展分区
● 磁盘使用MBR分区形式,最多可以创建4个主分区,或者3个主分区加1个扩展分区,扩展分区不可以直接使用,需要划分成若干个逻辑分区才可以使用。

● 磁盘使用GPT分区形式时,没有主分区、扩展分区以及逻辑分区之分。

4.创建主分区

输入"p",按"Enter",创建主分区

Select (default p): p
Partition number (1-4, default 1):

5.输入分区编号

以分区编号选择"1"为例,输入主分区编号"1",按"Enter"。

Partition number (1-4, default 1): 1
First sector (2048-209715199, default 2048):

6.选择起始磁柱值

以分区编号选择"1"为例,输入主分区编号"1",按"Enter"。

First sector (2048-209715199, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-209715199, default 209715199):

7.选择截止磁柱值

以选择默认截止磁柱值209715199为例,按"Enter"。

Last sector, +sectors or +size{K,M,G} (2048-209715199, default 209715199):
Using default value 209715199
Partition 1 of type Linux and of size 100 GiB is set

Command (m for help):

8.查看新建分区信息

输入"p",按"Enter",查看新建分区的详细信息。

Command (m for help): p

Disk /dev/vdb: 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: 0x38717fc1

Device Boot      Start         End      Blocks   Id  System
/dev/vdb1            2048   209715199   104856576   83  Linux

Command (m for help):

9.将分区结果写入分区表

输入"w",按"Enter",将分区结果写入分区表中。

Command (m for help): w
The partition table has been altered!

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

10.新的分区表变更同步至操作系统

输入 partprobe将新的分区表变更同步至操作系统。

11.格式化新建分区文件系统

mkfs -t 文件系统格式 /dev/vdb1

以设置文件系统为"ext4"为例:

mkfs -t ext4 /dev/vdb1

[root@ecs-test-0001 ~]# mkfs -t ext4 /dev/vdb1
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
6553600 inodes, 26214144 blocks
1310707 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2174746624
800 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624, 11239424, 20480000, 23887872

Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

12.新建挂载目录

mkdir 挂载目录

以新建挂载目录"/data"为例:

mkdir /data

13.将新建分区挂载到新创建的目录下

mount 磁盘分区 挂载目录

以挂载新建分区"/dev/vdb1"至"/data"为例:

mount /dev/vdb1 /data

14.查看挂载结果

df -TH

[root@ecs-test-0001 ~]# df -TH
Filesystem     Type      Size  Used Avail Use% Mounted on
/dev/vda1      ext4       43G  1.9G   39G   5% /
devtmpfs       devtmpfs  2.0G     0  2.0G   0% /dev
tmpfs          tmpfs     2.0G     0  2.0G   0% /dev/shm
tmpfs          tmpfs     2.0G  9.1M  2.0G   1% /run
tmpfs          tmpfs     2.0G     0  2.0G   0% /sys/fs/cgroup
tmpfs          tmpfs     398M     0  398M   0% /run/user/0
/dev/vdb1      ext4      106G   63M  101G   1% /data

15.查询磁盘分区UUID

blkid 磁盘分区

以查询磁盘分区"/dev/vdb1"的UUID为例:

blkid /dev/vdb1

[root@ecs-test-0001 ~]# blkid /dev/vdb1
/dev/vdb1: UUID="0b3040e2-1367-4abb-841d-ddb0b92693df" TYPE="ext4"

16.编辑fstab文件

vi /etc/fstab

按"i",进入编辑模式。

将光标移至文件末尾,按"Enter",添加如下内容。

UUID=0b3040e2-1367-4abb-841d-ddb0b92693df /mnt/sdc ext4 defaults 0 2

按"ESC"后,输入":wq",按"Enter"。

17.验证自动挂载功能

umount 磁盘分区 卸载已挂载的分区 umount /dev/vdb1

mount -a 重新加载/etc/fstab文件

mount | grep 挂载目录 查询文件系统挂载信息 mount | grep /data

回显类似如下信息,说明自动挂载功能生效

root@ecs-test-0001 ~]# mount | grep /data
/dev/vdb1 on /data type ext4 (rw,relatime,data=ordered)
相关推荐
原机小子28 分钟前
Spring Boot框架下的新闻推荐技术
服务器·spring boot·php
卓琢1 小时前
(九)Shell 脚本(四):正则表达式、sed 和 awk 详解
linux·mysql·正则表达式
iangyu1 小时前
docker常用命令
运维·docker·容器
一切皆是定数2 小时前
Linux驱动开发——LED驱动开发
linux·驱动开发·b树
小小不董2 小时前
图文深入理解Oracle DB Scheduler
linux·运维·服务器·数据库·oracle
繁依Fanyi2 小时前
旅游心动盲盒:开启个性化旅行新体验
java·服务器·python·算法·eclipse·tomcat·旅游
不烦下雨c3 小时前
[网络]抓包工具介绍 tcpdump
linux·tcpdump
秋风起,再归来~3 小时前
【Linux庖丁解牛】—Linux基本指令(中)!
linux·指令
Eternal-Student3 小时前
预处理、编译、汇编、链接
linux·汇编·windows