手机版
你好,游客 登录 注册
背景:
阅读新闻

Linux文件系统管理

磁盘分区、格式化、挂载-卷标挂载

[日期:2015-12-15] 来源:Linux社区  作者:吕星昊 [字体: ]

操作系统:RHEL6.4 - 64

在Linux操作系统(虚拟机)中增加30G磁盘

分区,第一个主分区18G  ,格式化为ext4文件系统, 挂在到 /u01 

要实现系统重启依然有效(开机自动挂载)使用LABEL进行挂载

1.1.1  确认系统中磁盘设备

df -Th 查看当前文件系统使用情况

[root@rhel64 ~]# df -Th

查看当前磁盘设备及分区情况

[root@rhel64 ~]# fdisk -cul

1.1.2  增加30G SCSI磁盘

关闭操作系统

[root@rhel64 ~]# shutdown -h now

存储中增加一个SCSI控制器

在SCSI控制器上增加一个30G磁盘

磁盘添加完成,启动虚拟机操作系统。

1.1.3  查看磁盘设备情况

[root@rhel64 ~]# fdisk -cul

每次重启后,磁盘的命名可能会发生变化。

此次重启后,新添加磁盘名称为/dev/sda 

1.1.4  分区 fdisk

查看新加磁盘分区情况

[root@rhel64 ~]# fdisk -cul /dev/sda

[root@rhel64 ~]# fdisk /dev/sda

提示推荐使用cu ,按m帮助,q退出

重新使用 fdisk -cu 方式分区

[root@rhel64 ~]# fdisk -cu /dev/sda

m查看命了帮助

n添加新分区  p 主分区  1  first sector 默认回车      laster sector 输入分区大小 +18G

m查看帮助  p打印当前分区表

m查看帮助 w保存分区表

再次查看新磁盘分区情况

[root@rhel64 ~]# fdisk -cul /dev/sda

查看对应设备

[root@rhel64 ~]# ll /dev/sda*

1.1.5  格式化 mkfs.ext4

企业版6默认使用ext4文件系统

[root@rhel64 ~]# mkfs.ext4 /dev/sda1

1.1.6  打卷标  e2label

[root@rhel64 ~]# e2label

[root@rhel64 ~]# e2label /dev/sda1 u01

查看卷标、UUID

[root@rhel64 ~]# blkid

1.1.7  创建挂载点

挂载点本质就是一个目录,是访问磁盘分区的入口

[root@rhel64 ~]# mkdir /u01

[root@rhel64 ~]# ls -ld /u01

1.1.8  临时挂载

挂载前 在/u01中创建文件 file1

[root@rhel64 ~]# touch /u01/file1

[root@rhel64 ~]# ll /u01

查看文件系统,此时/u01只是一个普通目录,占用 / 文件系统空间

[root@rhel64 ~]# df -Th

使用mount命令 挂载/dev/sda1  到  /u01

[root@rhel64 ~]# mount /dev/sda1 /u01

[root@rhel64 ~]# df -Th

挂载后  /u01是一个单独的文件系统,对应一个硬盘分区,有自己独立的磁盘空间大小

查看/u01,file1文件已经不显示

[root@rhel64 ~]# ll /u01

1.1.9  卸载文件系统

卸载前,在/u01中新建文件file2

[root@rhel64 ~]# touch /u01/file2

[root@rhel64 ~]# ll /u01

卸载/u01文件系统 查看/u01中文件,显示之前的file1  file2不显示

[root@rhel64 ~]# umount /u01

[root@rhel64 ~]# df -Th

[root@rhel64 ~]# ll /u01

1.1.10 写入/etc/fstab 实现系统启动自动挂载

查看配置文件/etc/fstab

[root@rhel64 ~]# cat /etc/fstab

备份配置文件,在配置文件中增加新条目

[root@rhel64 ~]# cp /etc/fstab /etc/fstab.bak

[root@rhel64 ~]# vi /etc/fstab

G快速移动光标到最后一行  o下一行开始插入,可以使用Tab键分隔对齐

LABEL=u01  /u01  ext4    defaults        0 0

可以使用LABEL挂载,也可以使用UUID挂载。

不要使用如下挂载方法!!! 

当前状态没有问题,重启后,磁盘名称可能会发生变化,30G的新加磁盘重启后可能变为/dev/sdb!!!

/dev/sda1  /u01  ext4  defaults  0 0

查看文件系统情况,使用mount /u01挂载,如果/etc/fstab配置正确,可以正常挂载

[root@rhel64 ~]# df -Th

[root@rhel64 ~]# mount /u01

[root@rhel64 ~]# df -Th

[root@rhel64 ~]# ll /u01

1.1.11 关闭操作系统,重新启动验证

[root@rhel64 ~]# shutdown -h now

[root@rhel64 ~]# df -Th

/u01文件系统能够显示,说明重启自动挂载成功。

注意:此时/u01对应的磁盘分区显示为/dev/sdb1,说明这次关机重启后,30G磁盘名称是/dev/sdb!

也有可能还是/dev/sda ,根据磁盘响应先后顺序确定名称。

更多详情见请继续阅读下一页的精彩内容http://www.linuxidc.com/Linux/2015-12/126304p2.htm

linux
【内容导航】
第1页:磁盘分区、格式化、挂载-卷标挂载 第2页:磁盘分区、格式化、挂载-UUID挂载
第3页:卸载正在被访问的文件系统 - fuser命令
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款