当前位置: 首页 > news >正文

通过fdisk初始化Linux数据盘

1.查看新增数据盘

fdisk -l

[root@ecs-test-0001 ~]# fdisk -lDisk /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: 0x000bcb4eDevice Boot      Start         End      Blocks   Id  System
/dev/vda1   *        2048    83886079    41942016   83  LinuxDisk /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 setCommand (m for help):

8.查看新建分区信息

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

Command (m for help): pDisk /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: 0x38717fc1Device Boot      Start         End      Blocks   Id  System
/dev/vdb1            2048   209715199   104856576   83  LinuxCommand (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, 23887872Allocating 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)

相关文章:

  • Xcode16适配
  • 机器学习(1):机器学习的概念
  • android 系统默认apn数据库
  • Vue 3 魔法揭秘:CSS 解析与 scoped 背后的奇幻之旅
  • 长沙某公司.Net高级开发面试题
  • 实战C++手写线程池
  • 【自用软件】IDM下载器 Internet Download Manager v6.42 Build 10
  • 黑马头条day5- 延迟任务精准发布文章
  • 前端框架对比与选择
  • Flink 性能优化的高频面试题及答案
  • Android 简单实现联系人列表+字母索引效果
  • py-mmcif包pdbx_struct_oper_list对象介绍
  • Windows安装启动apache httpd 2.4 web服务器
  • 机械键盘驱动调光DIY--【DAREU】
  • C++手动实现栈、和队列
  • 【编码】-360实习笔试编程题(二)-2016.03.29
  • Apache的基本使用
  • Bootstrap JS插件Alert源码分析
  • Brief introduction of how to 'Call, Apply and Bind'
  • C++回声服务器_9-epoll边缘触发模式版本服务器
  • Docker下部署自己的LNMP工作环境
  • IDEA 插件开发入门教程
  • Laravel深入学习6 - 应用体系结构:解耦事件处理器
  • linux学习笔记
  • Shadow DOM 内部构造及如何构建独立组件
  • vue--为什么data属性必须是一个函数
  • Windows Containers 大冒险: 容器网络
  • 创建一种深思熟虑的文化
  • 从0实现一个tiny react(三)生命周期
  • 十年未变!安全,谁之责?(下)
  • 手机app有了短信验证码还有没必要有图片验证码?
  • 手写一个CommonJS打包工具(一)
  • 算法-图和图算法
  • 学习JavaScript数据结构与算法 — 树
  • 2017年360最后一道编程题
  • const的用法,特别是用在函数前面与后面的区别
  • RDS-Mysql 物理备份恢复到本地数据库上
  • 格斗健身潮牌24KiCK获近千万Pre-A轮融资,用户留存高达9个月 ...
  • #include到底该写在哪
  • (2)空速传感器
  • (8)STL算法之替换
  • (JSP)EL——优化登录界面,获取对象,获取数据
  • (NO.00004)iOS实现打砖块游戏(九):游戏中小球与反弹棒的碰撞
  • (python)数据结构---字典
  • (SpringBoot)第七章:SpringBoot日志文件
  • (附源码)apringboot计算机专业大学生就业指南 毕业设计061355
  • (三)终结任务
  • (算法)Travel Information Center
  • (一)pytest自动化测试框架之生成测试报告(mac系统)
  • (转)http-server应用
  • (转)Linux NTP配置详解 (Network Time Protocol)
  • (转)ObjectiveC 深浅拷贝学习
  • * 论文笔记 【Wide Deep Learning for Recommender Systems】
  • .NET MVC第五章、模型绑定获取表单数据
  • .NET Remoting学习笔记(三)信道