Linux文件系统管理

:RHEL6.4 – 64

操作系统(机)中增加30G磁盘

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

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

1.1.1  确认系统中磁盘设备

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

[root@rhel64 ~]# df -Th

udast

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

[root@rhel64 ~]# fdisk -cul

udast

1.1.2  增加30G SCSI磁盘

关闭

[root@rhel64 ~]# shutdown -h now

udast

存储中增加一个SCSI控制器

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

udast

磁盘添加完成,启动

1.1.3  查看磁盘设备情况

[root@rhel64 ~]# fdisk -cul

udast

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

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

1.1.4  分区 fdisk

查看新加磁盘分区情况

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

udast

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

udast

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

udast

重新使用 fdisk -cu 方式分区

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

udast

m查看命了帮助

udast

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

udast

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

udast

m查看帮助 w保存分区表

udast

再次查看新磁盘分区情况

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

udast

查看对应设备

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

udast

1.1.5  格式化 mkfs.ext4

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

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

udast

1.1.6  打卷标  e2label

[root@rhel64 ~]# e2label

udast

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

udast

查看卷标、UUID

[root@rhel64 ~]# blkid

udast

1.1.7  创建挂载点

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

[root@rhel64 ~]# mkdir /u01

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

udast

1.1.8  临时挂载

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

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

[root@rhel64 ~]# ll /u01

udast

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

[root@rhel64 ~]# df -Th

udast

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

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

[root@rhel64 ~]# df -Th

udast

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

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

[root@rhel64 ~]# ll /u01

udast

1.1.9  卸载文件系统

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

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

[root@rhel64 ~]# ll /u01

udast

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

[root@rhel64 ~]# umount /u01

[root@rhel64 ~]# df -Th

[root@rhel64 ~]# ll /u01

udast

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

查看配置文件/etc/fstab

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

udast

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

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

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

udast

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

LABEL=u01  /u01  ext4    defaults        0 0

udast

可以使用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

udast

[root@rhel64 ~]# ll /u01

udast

1.1.11 关闭,重新启动验证

[root@rhel64 ~]# shutdown -h now

udast

[root@rhel64 ~]# df -Th

udast

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

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

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

转载自:https://www.linuxidc.com/Linux/2015-12/126304.htm

声明: 除非转自他站(如有侵权,请联系处理)外,本文采用 BY-NC-SA 协议进行授权 | 智乐兔
转载请注明:转自《Linux文件系统管理
本文地址:https://www.zhiletu.com/archives-5377.html
关注公众号:智乐兔

赞赏

wechat pay微信赞赏alipay pay支付宝赞赏

上一篇
下一篇

相关文章

在线留言

你必须 登录后 才能留言!

在线客服
在线客服 X

售前: 点击这里给我发消息
售后: 点击这里给我发消息

智乐兔官微