Linux运维练习--Linux文件系统管理

复习本次课程所讲的内容以及总结整理磁盘管理及文件系统管理中设计的各种命令的使用,并附注一

定的示例;

     创建文件系统:

             主要命令:mke2fs [OPTION]... DEVICE
                                           -t  {ext2|ext3|ext4}
                                           -b {1024|2048|4096},取决于内核管理内存页框大小的支持
                                           -L 'LABEL'
                                           -j: mke2fs -t ext3
                                           -i #:多大的空间预留一个inode
                                          -N #:为磁盘分区保留的inode数量
                                          -m #: 预留磁盘空间占据多大百分比的空间为后期管理使用;
                                          -O FEATURE[,...]默认开启某指定特性,
                                          -O ^FEATURE:关闭某特性
                                                has_journal:格式化为ext3文件系统

                                 如将/dev/sdb1格式化为ext4,且block大小为2048B,inode大小为128字节,卷

                                 标为TEST:

                            wKiom1X28FLzR1LvAAJTkHaj7gE695.jpg

                                 查看/dev/sdb1的块设备信息:               

                               wKioL1X283OyJH2OAABzs_N8OUg607.jpg

       文件系统属性查看及调整工具:

              e2label:卷标管理工具,e2lable DEVICE [LABEL]

              tune2fs:显示ext系列文件系统的属性,或调整其属性(block大小不能改变);

                              
                             -l:显示超级块中的信息;显示整个文件的属性及布局等相关信息

                               wKiom1X28tbzrTM_AAKnb7DChYQ749.jpg

                             -L 'LABEL':修改卷标;

                               wKioL1X29hSDkjK2AAH6lFcJeRo505.jpg

                             -m #: 调整预留给管理员的管理空间百分比(Reserved block count/Free

                                       blocks); 默认为5%,如

                              wKiom1X29QWQq4QlAAEPbSleHy4976.jpg

                               更改为10%后可以看到Reserved block count已经改变

                              wKioL1X2-BWTFbSzAAGA5aowgHU744.jpg
                            

                              -j: ext2 --> ext3,为ext2增加日志功能
                            -O: 文件系统属性的启动或关闭 (在属性前增加^表示关闭)

                                 如,当前文件系统属性存在has_journal,

wKioL1X29hSDkjK2AAH6lFcJeRo505.jpg

                                关闭其has_journal属性,可以看到已没有has-journal属性

                    wKioL1X2-lLQf0z2AAHatle3qfg285.jpg

                            -o:文件系统默认挂载选项的启用或关闭(在属性前增加^表示关闭):如

wKiom1X2-bLSU6L0AAFtV4i-o8U706.jpg

        dumpe2fs:显示整个文件系统的布局结构以及超级块信息
                          -h: 仅显示超级块信息

     文件系统检测:
                         fsck: Filesystem check
                                 fsck -t type:type必须和该分区文件系统一致,否则可能会对文件系统带来损坏
                                 fsck.type
                                        a: 自动修复错误
                                        r: 交互式修复错误
                                        f: 强制检测

wKioL1X2_lmy8ZWaAAIxMUHzpcc574.jpg

                        e2fsck:ext系列文件系统专用的检测修复工具;
                                    -y: 自动回答为“yes”自动修复
                                    -f:force,强制检测并修复
     文件系统的挂载和使用:

             kernel --> rootfs(分区)

                      rootfs分区:
                                 bin, sbin, etc, lib, lib64, dev, tmp, proc, sys

                                /sbin/init

             挂载方法:

                         mount:通过读取/etc/mtab文件来显示当前系统所有已经挂载的设备;
                         mount -a:挂载/etc/fstab文件中的所有支持自动挂载的文件系统;
                         mount [options] [-o options] DEVICE MOUNT_POINT
                                     [options]:命令选项
                                    [-o options]:挂载选项

                                    DEVICE: 要挂载的设备
                                                (1) 设备文件:/dev/sda5
                                                (2) 卷标:-L 'LABEL'
                                                (3) UUID:-U 'UUID'
                                                (4) 伪文件系统名称,如/proc等
                                    MOUNT_POINT: 挂载点

            常用选项:
                                   -t type:文件系统类型
                                   -r: 以“只读”方式挂载此文件系统
                                   -w: 以“读写”方式挂载此文件系统
                                   -n:每个文件系统在挂载时都会自动更新/etc/mtab文件,-n用于禁止此功能;
                                           此时,如果想查看挂载的所有文件系统:cat /proc/mounts
                                   -a: 自动挂载所有支持自动挂载的设备;
                                   -B:绑定目录至另一个目录上,通过绑定可以通过/my文件访问/test

 wKioL1X3A42QhC4qAAEvKfoR5_w966.jpg

                                    -o 挂载选项:
                                                       async:异步模式
                                                       sync: 同步模式
                                                       atime/noatime:是否更新访问时间戳;
                                                       diratime/nodiratime:是否更新目录的访问时间戳;
                                                       auto/noauto: 是否允许此设备被自动挂载;
                                                       exec/noexec:是否允许执行此文件系统上应用程序;
                                                       dev/nodev:是否支持在此设备上使用设备文件;
                                                       suid/nosuid:
                                                       remount:重新挂载
                                                       ro,只读
                                                       rw,读写
                                             user/nouser: 是否允许普通挂载此设备;
                                                           acl:是否支持此设备上使用facl;
                                                  defaults:rw, suid, dev, exec, auto, nouser, and async

                   umount:卸载命令
                                   # umount DEVICE
                                   # umount MOUNT_POINT

                   查看正在访问指定挂载点的进程:
                                  # fuser -v MOUNT_POINT

                   终止所有正在访问指定的挂载点的进程:
                                  # fuser -km MOUNT_POINT

                                      如:

wKiom1X3ArWyKLQyAAEmJYGYCw4919.jpg


                交换分区:

                               free命令:
                               查看memory和swap的使用状态
                                               -m: 以MB为单位
                                                -g: 以GB为单位

                               mkswap:创建交换分区

                                              mkswap [option] DEVICE
                                                            -L 'LABEL' 
    
                               swapon:启用交换分区
                                           swapon [option] [DEVICE]
                                                         -a: 激活所有交换分区
                                                         -p PRIORITY: 设定其优先级;

                              swapoff:禁用交换分区
                              swapoff [option] [DEVICE]


               文件系统等空间占用信息的查看工个:
                              df: disk free
                                   -h: human-readable
                                   -i: inode数量
                                   -P: 以Posix兼容的格式输出

                                   如:

  wKiom1X3BEuwIwrgAAER70fvleQ589.jpg  

                            du: disk usage
                                 -h: human-readable
                                 -s: summary,一般查看文件只会显示文件目录本身所占空间,如果想查看该目录

                                      下所有文件所占空间呢,需要加使用du -s,如/etc

wKioL1X3CC3yfEvSAACa4pAWEjM936.jpg

               文件系统相关挂载配置文件:/etc/fstab

                          要挂载的设备或伪文件系统   挂载点   文件系统类型  挂载选项  转储频率   自检次序

                          要挂载的设备:
                                       设备文件、LABEL=、UUID=、伪文件系统名称

                                 挂载选项:
                                                  defaults(rw, suid, dev, exec, auto, nouser, and async)

                                 转储频率:文件系统备份
                                               0: 不转储
                                               1: 每天转储
                                               2: 每隔一天转储

                                 自检次序:在开机时是否会自动使用fsck或者e2fsck检测文件系统,不建议对文件

                                                  系统进行开机自检,自检会进行自动修复,可能会导致数据丢失
                                                0:不自检
                                                1:首先自检,通常只有 /(根文件系统)才为1
                                                2:

             文件系统上的链接文件:
                    硬链接:两个路径指向同一个inode

                                 不能对目录进行;
                                 不能跨分区进行
                                 指向同一个inode的多个不同路径; 创建文件的硬链接会增加inode的引用计数;删

                                 除硬链接仅是删除其一个访问路径,只到最后一个路径被删除;    

wKiom1X3DZbRC0djAAGgeQuogUU434.jpg

                符号链接:
                         链接文件的数据指向另一个文件路径;

                         可以对目录进行;
                         可以跨分区;
                         指向的是另一个文件路径;而非inode;
                         对文件创建符号链接不会增加其引用计数;删除原文件,符号链接文件也将无法使用; 

          wKioL1X3EI6jtV1kAAKSXZg_zbU709.jpg

                ln [-s] SRC DEST
                     -s:symbolic link 
                     -v:verbose

创建一个10G的文件系统,类型为ext4,要求开机可自动挂载至/mydata目录

          wKiom1X3EE3zy9eCAAISRuaEBF0224.jpg

          wKioL1X3ErehRhBHAAIFZIPbSZ8720.jpg

          编辑/etc/fatable

                    wKiom1X3EYCz9L0YAAFlbLTOxMs515.jpg

          mount -a

          df -lh

wKioL1X3FDDg71oxAAF5sTHIRXw185.jpg

                         

你可能感兴趣的:(Linux文件系统管理)