歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> Linux文件系統管理

Linux文件系統管理

日期:2017/2/28 13:55:58   编辑: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 ,根據磁盤響應先後順序確定名稱。

Copyright © Linux教程網 All Rights Reserved