ICode9

精准搜索请尝试: 精确搜索
首页 > 系统相关> 文章详细

Linux下数据盘挂载、分区、卸载

2021-06-21 12:32:43  阅读:236  来源: 互联网

标签:字节 centos Linux 卸载 扇区 磁盘 挂载 512 root


文章目录

一 、Linux下挂载数据盘

1、查看数据盘是否分配

[root@VM-0-17-centos ~]# fdisk -l

磁盘 /dev/vda:54.8 GB, 54760833024 字节,106954752 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x000d64b4

   设备 Boot      Start         End      Blocks   Id  System
/dev/vda1   *        2048   106954718    53476335+  83  Linux

磁盘 /dev/vdb:10.7 GB, 10737418240 字节,20971520 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节

在这里插入图片描述

2、使用fdisk命令进行建立分区

[root@VM-0-17-centos ~]# fdisk /dev/vdb
欢迎使用 fdisk (util-linux 2.23.2)。

更改将停留在内存中,直到您决定将更改写入磁盘。
使用写入命令前请三思。

Device does not contain a recognized partition table
使用磁盘标识符 0x40cc50c4 创建新的 DOS 磁盘标签。

命令(输入 m 获取帮助):

在这里插入图片描述

Device does not contain a recognized partition table
使用磁盘标识符 0x40cc50c4 创建新的 DOS 磁盘标签。

命令(输入 m 获取帮助):m
命令操作
   a   toggle a bootable flag
   b   edit bsd disklabel
   c   toggle the dos compatibility flag
   d   delete a partition
   g   create a new empty GPT partition table
   G   create an IRIX (SGI) partition table
   l   list known partition types
   m   print this menu
   n   add a new partition
   o   create a new empty DOS partition table
   p   print the partition table
   q   quit without saving changes
   s   create a new empty Sun disklabel
   t   change a partition's system id
   u   change display/entry units
   v   verify the partition table
   w   write table to disk and exit
   x   extra functionality (experts only)

命令(输入 m 获取帮助):

在这里插入图片描述

3、然后先新建分区

命令(输入 m 获取帮助):n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): 
Using default response p
分区号 (1-4,默认 1):
起始 扇区 (2048-20971519,默认为 2048):
将使用默认值 2048
Last 扇区, +扇区 or +size{K,M,G} (2048-20971519,默认为 20971519):
将使用默认值 20971519
分区 1 已设置为 Linux 类型,大小设为 10 GiB

在这里插入图片描述

4、最后保存分区

命令(输入 m 获取帮助):w
The partition table has been altered!

Calling ioctl() to re-read partition table.
正在同步磁盘。
[root@VM-0-17-centos ~]#

在这里插入图片描述

5、使用fdisk -l命令查看,已经有分区了

[root@VM-0-17-centos ~]# fdisk -l

磁盘 /dev/vda:54.8 GB, 54760833024 字节,106954752 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x000d64b4

   设备 Boot      Start         End      Blocks   Id  System
/dev/vda1   *        2048   106954718    53476335+  83  Linux

磁盘 /dev/vdb:10.7 GB, 10737418240 字节,20971520 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x40cc50c4

   设备 Boot      Start         End      Blocks   Id  System
/dev/vdb1            2048    20971519    10484736   83  Linux
[root@VM-0-17-centos ~]# 

在这里插入图片描述

6、格式化分区,建立文件系统

[root@VM-0-17-centos ~]# mkfs -t ext4 /dev/vdb1
mke2fs 1.42.9 (28-Dec-2013)
文件系统标签=
OS type: Linux
块大小=4096 (log=2)
分块大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
655360 inodes, 2621184 blocks
131059 blocks (5.00%) reserved for the super user
第一个数据块=0
Maximum filesystem blocks=2151677952
80 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

Allocating group tables: 完成                            
正在写入inode表: 完成                            
Creating journal (32768 blocks): 完成
Writing superblocks and filesystem accounting information: 完成 

[root@VM-0-17-centos ~]# 

在这里插入图片描述

7. 选择挂载点挂载

[root@VM-0-17-centos html]#  mount /dev/vdb1 /usr/local/nginx2/html/
[root@VM-0-17-centos html]# 

在这里插入图片描述

8. 查看是否挂载成功

[root@VM-0-17-centos html]# df -TH /usr/local/nginx2/html/
文件系统       类型  容量  已用  可用 已用% 挂载点
/dev/vdb1      ext4   11G   38M  9.9G    1% /usr/local/nginx2/html
[root@VM-0-17-centos html]# 

在这里插入图片描述

9、设置系统启动自动挂载

修改一下系统配置加入下列行到/etc/fstab,让系统启动后自动挂载,否则有可能会掉啊

a. 查看先挂载数据盘编号

[root@VM-0-17-centos ~]# sudo blkid /dev/vdb1
/dev/vdb1: UUID="76a1fac6-fed7-4469-8e96-4611eaab6704" TYPE="ext4" 
[root@VM-0-17-centos ~]# 

在这里插入图片描述

b. 修改/etc/fstab,增加数据盘开机扫描

vim fstab
### 将入数据按照如下格式加入 并保存
### UUID=76a1fac6-fed7-4469-8e96-4611eaab6704       /usr/local/nginx2/html  ext4    defaults 0 0

二、Linux系统下数据盘卸载

1. 查看磁盘挂载情况

[root@VM-0-17-centos html]# fdisk -l

磁盘 /dev/vda:54.8 GB, 54760833024 字节,106954752 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x000d64b4

   设备 Boot      Start         End      Blocks   Id  System
/dev/vda1   *        2048   106954718    53476335+  83  Linux

磁盘 /dev/vdb:10.7 GB, 10737418240 字节,20971520 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x40cc50c4

   设备 Boot      Start         End      Blocks   Id  System
/dev/vdb1            2048    20971519    10484736   83  Linux
[root@VM-0-17-centos html]# 

2. 卸载磁盘挂载

[root@VM-0-17-centos html]# umount /dev/vdb1
umount: /usr/local/nginx2/html:目标忙。
        (有些情况下通过 lsof(8) 或 fuser(1) 可以
         找到有关使用该设备的进程的有用信息)
[root@VM-0-17-centos html]# 

在这里插入图片描述

3. 卸载时,磁盘正忙

如过卸载挂载磁盘时出现正忙则参照如下进行解决;未出现则直接跳过

[root@VM-0-17-centos html]# fuser -mv /usr/local/nginx2/html/
                     用户     进程号 权限   命令
/usr/local/nginx2/html:
                     root     kernel mount /usr/local/nginx2/html
                     root      30047 ..c.. bash
[root@VM-0-17-centos html]# kill -9 30047

连接断开

在这里插入图片描述

4. 磁盘卸载成功

原本挂载磁盘对应目录下的文件没有 那么卸载成功

在这里插入图片描述

5.删除/etc/fstab配置

删除/etc/fstab中对该磁盘的挂在配置,不删除则会在服务器开机时报错

6.至此数据盘卸载完成

标签:字节,centos,Linux,卸载,扇区,磁盘,挂载,512,root
来源: https://blog.csdn.net/Mister_yang/article/details/118083700

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有