• Linux磁盘挂载


     

    Linux的磁盘挂载mount

    一磁盘挂载介绍

    挂载:将额外文件系统与根文件系统某现存的目录建立起关联关系,进而使得此目录做为其它文件访问入口的行为。

    卸载:为解除此关联关系的过程


    把设备关联挂载点:mount Point

    卸载时:可使用设备,也可以使用挂载点

    挂载点下原有文件在挂载完成后会被临时隐藏


    挂载点目录一般为空

    用mount命令挂载文件系统


    挂载方法:mount DEVICE MOUNT_POINT


    mount:通过查看/etc/mtab文件显示当前已挂载的所有设备


    mount [-fnrsvw] [-t vfstype] [-o options] device dir


    device:指明要挂载的设备;


    (1) 设备文件:例如/dev/sda5


    (2) 卷标:-L 'LABEL', 例如 -L 'MYDATA'


    (3) UUID, -U 'UUID':例如 -U '0c50523c-43f1-45e7-85c0-a126711d406e'


    (4) 伪文件系统名称:proc, sysfs, devtmpfs, configfs


    dir:挂载点


    事先存在;建议使用空目录


    进程正在使用中的设备无法被卸载

    安装操作系统时就提到了挂载了。

    分完分区了并且做完了文件系统的创建了,要使用这个分区就必须挂载。

    访问数据是基于文件方式访问,而文件是放到目录里面的,所以分区存储数据要和目录关联。

    只要在目录存储数据,那么数据的内容也会存放到对应分区里面。

    如果不和其他目录关联,就相当于在windows里面创建了文件系统但是没有分配盘符

    创建目录才可以进入到使用的分区,因为访问数据就是访问目录的方式访问的。

    计算机管理里面把分区的盘符删除了就没有访问文件的入口了。

    假如磁盘上有4个分区sda1到sda4

    其中sda1是挂载到/下,当在/下创建子目录app,也就是在sda1分区创建app目录了

    如果app目录下创建子目录dir1。如果sda2挂载到/app/dir1下面,那么在dir1下存放数据就是存放到sda2下

    如果在dir1下创建子目录dir2,那么数据就存放在sda2下。

    假如在dir2下创建文件file1,sda3挂载到dir2,那么就进入到dir2里面看不到file1,因为file1是在原来的分区里面,被隐藏起来了。

    如果持续这种状态被隐藏的文件将永久不能访问了

    在/下创建test目录,并且把sda2挂载到test下,那么sda2的数据就会出现了。

    一个分区是可以挂载到多个目录上的。就好比一个人可以有很多名字的,现用名和曾用名。

    把分区挂载到已经挂载了数据的目录,原来的目录下的数据就会被隐藏

    [root@centos65 ~]# lsblk 
    NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
    sr0     11:0    1  3.7G  0 rom  
    sda      8:0    0  200G  0 disk 
    ├─sda1   8:1    0    1G  0 part /boot
    ├─sda2   8:2    0 48.8G  0 part /
    ├─sda3   8:3    0 19.5G  0 part /app
    ├─sda4   8:4    0    1K  0 part 
    ├─sda5   8:5    0    2G  0 part [SWAP]
    └─sda6   8:6    0    1G  0 part 
    sdb      8:16   0  100G  0 disk 
    ├─sdb1   8:17   0    1K  0 part 
    ├─sdb2   8:18   0    5G  0 part 
    ├─sdb3   8:19   0    2G  0 part 
    └─sdb5   8:21   0   10G  0 part 
    sdc      8:32   0   80G  0 disk 
    ├─sdc1   8:33   0   10G  0 part 
    └─sdc2   8:34   0    6G  0 part 
    sdd      8:48   0   60G  0 disk 
    [root@centos65 ~]# blkid
    /dev/sda1: UUID="6bbd9da4-0c3d-4496-a4b1-44bf79912740" TYPE="ext4" 
    /dev/sda2: UUID="10d2b40d-dcd8-4c16-aa81-511c520213f6" TYPE="ext4" 
    /dev/sda3: UUID="e432b350-a9a6-429b-8f07-592058efc6e2" TYPE="ext4" 
    /dev/sda5: UUID="b25a8a7e-40d8-485b-a5af-1b583698864d" TYPE="swap" 
    /dev/sdb2: UUID="b5e3fb3c-48be-49ff-b610-2b244d18639c" TYPE="ext4" 
    /dev/sdd: UUID="c4a0e490-aa52-4c8b-bcad-b20dd895971d" TYPE="ext4" 
    /dev/sdb3: UUID="bef91525-93b8-48a8-a2af-4ba463dc48ce" SEC_TYPE="ext2" TYPE="ext3" LABEL="/mnt/sdb3" 
    /dev/sdb5: UUID="53bc9bdb-6256-4ad9-bddb-12343a4728fd" SEC_TYPE="ext2" TYPE="ext3" 
    [root@centos65 ~]# mount  /dev/sdb5  /app 
    [root@centos65 ~]# ls  /app/
    lost+found
    [root@centos65 ~]# df
    Filesystem     1K-blocks    Used Available Use% Mounted on
    /dev/sda2       50264772 1548160  46156612   4% /
    tmpfs             502068       0    502068   0% /dev/shm
    /dev/sda3       10325716  154256   9646944   2% /app
    /dev/sda1         999320   30488    916404   4% /boot
    /dev/sdb5       10325716  154256   9646944   2% /app
    [root@centos65 ~]# umount  /dev/sdb5
    [root@centos65 ~]# ls /app/
    fstab  lost+found  MBR
    [root@centos65 ~]# df
    Filesystem     1K-blocks    Used Available Use% Mounted on
    /dev/sda2       50264772 1548160  46156612   4% /
    tmpfs             502068       0    502068   0% /dev/shm
    /dev/sda3       20027260   45000  18958260   1% /app
    /dev/sda1         999320   30488    916404   4% /boot

    一个挂载点同一时间只能挂载一个设备,如果同时挂载了多个设备只能有一个有效

    [root@centos65 ~]# ls  /boot/
    config-2.6.32-642.el6.x86_64  grub                                 lost+found                        System.map-2.6.32-642.el6.x86_64
    efi                           initramfs-2.6.32-642.el6.x86_64.img  symvers-2.6.32-642.el6.x86_64.gz  vmlinuz-2.6.32-642.el6.x86_64
    [root@centos65 ~]# df
    Filesystem     1K-blocks    Used Available Use% Mounted on
    /dev/sda2       50264772 1548160  46156612   4% /
    tmpfs             502068       0    502068   0% /dev/shm
    /dev/sda3       20027260   45000  18958260   1% /app
    /dev/sda1         999320   30488    916404   4% /boot
    [root@centos65 ~]# mount  /dev/sdb3  /boot 
    [root@centos65 ~]# df
    Filesystem     1K-blocks    Used Available Use% Mounted on
    /dev/sda2       50264772 1548160  46156612   4% /
    tmpfs             502068       0    502068   0% /dev/shm
    /dev/sda3       20027260   45000  18958260   1% /app
    /dev/sda1        2071416   68700   1897492   4% /boot
    /dev/sdb3        2071416   68700   1897492   4% /boot
    [root@centos65 ~]# ls /boot/
    lost+found

    取消挂载是最迟挂载的分区

    [root@centos65 ~]# df
    Filesystem     1K-blocks    Used Available Use% Mounted on
    /dev/sda2       50264772 1548160  46156612   4% /
    tmpfs             502068       0    502068   0% /dev/shm
    /dev/sda3       20027260   45000  18958260   1% /app
    /dev/sda1        2071416   68700   1897492   4% /boot
    /dev/sdb3        2071416   68700   1897492   4% /boot
    [root@centos65 ~]# ls /boot/
    lost+found
    [root@centos65 ~]# umount  /boot 
    [root@centos65 ~]# df
    Filesystem     1K-blocks    Used Available Use% Mounted on
    /dev/sda2       50264772 1548164  46156608   4% /
    tmpfs             502068       0    502068   0% /dev/shm
    /dev/sda3       20027260   45000  18958260   1% /app
    /dev/sda1         999320   30488    916404   4% /boot

    最先挂载的分区内容就会出现了

    [root@centos65 ~]# ls  /boot/
    config-2.6.32-642.el6.x86_64  grub                                 lost+found                        System.map-2.6.32-642.el6.x86_64
    efi                           initramfs-2.6.32-642.el6.x86_64.img  symvers-2.6.32-642.el6.x86_64.gz  vmlinuz-2.6.32-642.el6.x86_64

    再取消,目录里面就没文件了

    [root@centos65 ~]# umount  /boot 
    [root@centos65 ~]# ls  /boot/
    [root@centos65 ~]# df
    Filesystem     1K-blocks    Used Available Use% Mounted on
    /dev/sda2       50264772 1548164  46156608   4% /
    tmpfs             502068       0    502068   0% /dev/shm
    /dev/sda3       20027260   45000  18958260   1% /app

    一个设备可以挂载到多个目录下,而且多个目录的数据显示的是一样的内容。

    [root@centos65 ~]# df
    Filesystem     1K-blocks    Used Available Use% Mounted on
    /dev/sda2       50264772 1548164  46156608   4% /
    tmpfs             502068       0    502068   0% /dev/shm
    /dev/sda3       20027260   45000  18958260   1% /app
    [root@centos65 ~]# mount  /dev/sda1  /boot 
    [root@centos65 ~]# df
    Filesystem     1K-blocks    Used Available Use% Mounted on
    /dev/sda2       50264772 1548164  46156608   4% /
    tmpfs             502068       0    502068   0% /dev/shm
    /dev/sda3       20027260   45000  18958260   1% /app
    /dev/sda1         999320   30488    916404   4% /boot
    [root@centos65 ~]# ls  /boot/
    config-2.6.32-642.el6.x86_64  grub                                 lost+found                        System.map-2.6.32-642.el6.x86_64
    efi                           initramfs-2.6.32-642.el6.x86_64.img  symvers-2.6.32-642.el6.x86_64.gz  vmlinuz-2.6.32-642.el6.x86_64
    [root@centos65 ~]# mount  /dev/sda1    /mnt/
    [root@centos65 ~]# df
    Filesystem     1K-blocks    Used Available Use% Mounted on
    /dev/sda2       50264772 1548164  46156608   4% /
    tmpfs             502068       0    502068   0% /dev/shm
    /dev/sda3       20027260   45000  18958260   1% /app
    /dev/sda1         999320   30488    916404   4% /boot
    /dev/sda1         999320   30488    916404   4% /mnt
    [root@centos65 ~]# ls  /mnt/
    config-2.6.32-642.el6.x86_64  grub                                 lost+found                        System.map-2.6.32-642.el6.x86_64
    efi                           initramfs-2.6.32-642.el6.x86_64.img  symvers-2.6.32-642.el6.x86_64.gz  vmlinuz-2.6.32-642.el6.x86_64
    [root@centos65 ~]# ls  /boot/
    config-2.6.32-642.el6.x86_64  grub                                 lost+found                        System.map-2.6.32-642.el6.x86_64
    efi                           initramfs-2.6.32-642.el6.x86_64.img  symvers-2.6.32-642.el6.x86_64.gz  vmlinuz-2.6.32-642.el6.x86_64
    [root@centos65 ~]# df
    Filesystem     1K-blocks    Used Available Use% Mounted on
    /dev/sda2       50264772 1548164  46156608   4% /
    tmpfs             502068       0    502068   0% /dev/shm
    /dev/sda3       20027260   45000  18958260   1% /app
    /dev/sda1         999320   30488    916404   4% /boot
    /dev/sda1         999320   30488    916404   4% /mnt

    在mnt下创建目录boot

    分区不仅挂载到mnt下,也挂载到mnt的boot下,子目录boot的数据和父目录mnt的数据是一样的。

    但是只是一次这样,避免循环挂载。

    而在windows下允许10个

    [root@centos65 ~]# mkdir  /mnt/boot
    [root@centos65 ~]#  mount  /dev/sda1  /mnt/boot/
    [root@centos65 ~]# df
    Filesystem     1K-blocks    Used Available Use% Mounted on
    /dev/sda2       50264772 1548172  46156600   4% /
    tmpfs             502068       0    502068   0% /dev/shm
    /dev/sda3       20027260   45000  18958260   1% /app
    /dev/sda1         999320   30492    916400   4% /boot
    /dev/sda1         999320   30492    916400   4% /mnt
    /dev/sda1         999320   30492    916400   4% /mnt/boot
    [root@centos65 ~]# ls  /mnt/
    boot                          grub                                 symvers-2.6.32-642.el6.x86_64.gz
    config-2.6.32-642.el6.x86_64  initramfs-2.6.32-642.el6.x86_64.img  System.map-2.6.32-642.el6.x86_64
    efi                           lost+found                           vmlinuz-2.6.32-642.el6.x86_64
    [root@centos65 ~]# ls /mnt/boot/
    boot                          grub                                 symvers-2.6.32-642.el6.x86_64.gz
    config-2.6.32-642.el6.x86_64  initramfs-2.6.32-642.el6.x86_64.img  System.map-2.6.32-642.el6.x86_64
    efi                           lost+found                           vmlinuz-2.6.32-642.el6.x86_64

    mount:通过查看/etc/mtab文件显示当前已挂载的所有设备

    [root@centos65 ~]# cat  /etc/mtab 
    /dev/sda2 / ext4 rw 0 0
    proc /proc proc rw 0 0
    sysfs /sys sysfs rw 0 0
    devpts /dev/pts devpts rw,gid=5,mode=620 0 0
    tmpfs /dev/shm tmpfs rw,rootcontext="system_u:object_r:tmpfs_t:s0" 0 0
    /dev/sda3 /app ext4 rw 0 0
    none /proc/sys/fs/binfmt_misc binfmt_misc rw 0 0
    /dev/sda1 /boot ext4 rw 0 0
    /dev/sda1 /mnt ext4 rw 0 0
    /dev/sda1 /mnt/boot ext4 rw 0 0
    [root@centos65 ~]# df
    Filesystem     1K-blocks    Used Available Use% Mounted on
    /dev/sda2       50264772 1548184  46156588   4% /
    tmpfs             502068       0    502068   0% /dev/shm
    /dev/sda3       20027260   45000  18958260   1% /app
    /dev/sda1         999320   30492    916400   4% /boot
    /dev/sda1         999320   30492    916400   4% /mnt
    /dev/sda1         999320   30492    916400   4% /mnt/boot
    [root@centos65 ~]# lsblk 
    NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
    sr0     11:0    1  3.7G  0 rom  
    sda      8:0    0  200G  0 disk 
    ├─sda1   8:1    0    1G  0 part /boot
    ├─sda2   8:2    0 48.8G  0 part /
    ├─sda3   8:3    0 19.5G  0 part /app
    ├─sda4   8:4    0    1K  0 part 
    ├─sda5   8:5    0    2G  0 part [SWAP]
    └─sda6   8:6    0    1G  0 part 
    sdb      8:16   0  100G  0 disk 
    ├─sdb1   8:17   0    1K  0 part 
    ├─sdb2   8:18   0    5G  0 part 
    ├─sdb3   8:19   0    2G  0 part 
    └─sdb5   8:21   0   10G  0 part 
    sdc      8:32   0   80G  0 disk 
    ├─sdc1   8:33   0   10G  0 part 
    └─sdc2   8:34   0    6G  0 part 
    sdd      8:48   0   60G  0 disk 

    扩展分区是不能创建文件系统的

    [root@centos65 ~]# lsblk 
    NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
    sr0     11:0    1  3.7G  0 rom  
    sda      8:0    0  200G  0 disk 
    ├─sda1   8:1    0    1G  0 part /boot
    ├─sda2   8:2    0 48.8G  0 part /
    ├─sda3   8:3    0 19.5G  0 part /app
    ├─sda4   8:4    0    1K  0 part 
    ├─sda5   8:5    0    2G  0 part [SWAP]
    └─sda6   8:6    0    1G  0 part 
    sdb      8:16   0  100G  0 disk 
    ├─sdb1   8:17   0    1K  0 part 
    ├─sdb2   8:18   0    5G  0 part 
    ├─sdb3   8:19   0    2G  0 part 
    └─sdb5   8:21   0   10G  0 part 
    sdc      8:32   0   80G  0 disk 
    ├─sdc1   8:33   0   10G  0 part 
    └─sdc2   8:34   0    6G  0 part 
    sdd      8:48   0   60G  0 disk 
    [root@centos65 ~]# blkid
    /dev/sda1: UUID="6bbd9da4-0c3d-4496-a4b1-44bf79912740" TYPE="ext4" 
    /dev/sda2: UUID="10d2b40d-dcd8-4c16-aa81-511c520213f6" TYPE="ext4" 
    /dev/sda3: UUID="e432b350-a9a6-429b-8f07-592058efc6e2" TYPE="ext4" 
    /dev/sda5: UUID="b25a8a7e-40d8-485b-a5af-1b583698864d" TYPE="swap" 
    /dev/sdb2: UUID="b5e3fb3c-48be-49ff-b610-2b244d18639c" TYPE="ext4" 
    /dev/sdd: UUID="c4a0e490-aa52-4c8b-bcad-b20dd895971d" TYPE="ext4" 
    /dev/sdb3: UUID="bef91525-93b8-48a8-a2af-4ba463dc48ce" SEC_TYPE="ext2" TYPE="ext3" LABEL="/mnt/sdb3" 
    /dev/sdb5: UUID="53bc9bdb-6256-4ad9-bddb-12343a4728fd" SEC_TYPE="ext2" TYPE="ext3" 
    [root@centos65 ~]# df
    Filesystem     1K-blocks    Used Available Use% Mounted on
    /dev/sda2       50264772 1548204  46156568   4% /
    tmpfs             502068       0    502068   0% /dev/shm
    /dev/sda3       20027260   45000  18958260   1% /app
    /dev/sda1         999320   30492    916400   4% /boot
    /dev/sda1         999320   30492    916400   4% /mnt
    /dev/sda1         999320   30492    916400   4% /mnt/boot
    [root@centos65 ~]# umount  /mnt
    umount: /mnt: device is busy.
            (In some cases useful info about processes that use
             the device is found by lsof(8) or fuser(1))
    [root@centos65 ~]# umount  /mnt/boot 
    [root@centos65 ~]# umount  /mnt
    [root@centos65 ~]# df
    Filesystem     1K-blocks    Used Available Use% Mounted on
    /dev/sda2       50264772 1548212  46156560   4% /
    tmpfs             502068       0    502068   0% /dev/shm
    /dev/sda3       20027260   45000  18958260   1% /app
    /dev/sda1         999320   30492    916400   4% /boot
    

    创建测试的目录

    [root@centos65 ~]# mkdir   /mnt/sdb2
    [root@centos65 ~]# mount  /dev/sdb2  /mnt/sdb2
    [root@centos65 ~]# cat /etc/mtab 
    /dev/sda2 / ext4 rw 0 0
    proc /proc proc rw 0 0
    sysfs /sys sysfs rw 0 0
    devpts /dev/pts devpts rw,gid=5,mode=620 0 0
    tmpfs /dev/shm tmpfs rw,rootcontext="system_u:object_r:tmpfs_t:s0" 0 0
    /dev/sda3 /app ext4 rw 0 0
    none /proc/sys/fs/binfmt_misc binfmt_misc rw 0 0
    /dev/sda1 /boot ext4 rw 0 0
    /dev/sdb2 /mnt/sdb2 ext4 rw 0 0
    [root@centos65 ~]# mount
    /dev/sda2 on / type ext4 (rw)
    proc on /proc type proc (rw)
    sysfs on /sys type sysfs (rw)
    devpts on /dev/pts type devpts (rw,gid=5,mode=620)
    tmpfs on /dev/shm type tmpfs (rw,rootcontext="system_u:object_r:tmpfs_t:s0")
    /dev/sda3 on /app type ext4 (rw)
    none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
    /dev/sda1 on /boot type ext4 (rw)/dev/sdb2 on /mnt/sdb2 type ext4 (rw)

    取消挂载的时候可以写设备名或者挂载点

    但是挂载和取消挂载都是临时有效的。重启机器就没用了,要想永久有效就要存储到文件里面。

    [root@centos65 ~]# umount  /dev/sdb2
    [root@centos65 ~]# mount  /dev/sr0  /media 
    mount: block device /dev/sr0 is write-protected, mounting read-only
    [root@centos65 ~]# df
    Filesystem     1K-blocks    Used Available Use% Mounted on
    /dev/sda2       50264772 1548220  46156552   4% /
    tmpfs             502068       0    502068   0% /dev/shm
    /dev/sda3       20027260   45000  18958260   1% /app
    /dev/sda1         999320   30492    916400   4% /boot
    /dev/sr0         3824484 3824484         0 100% /media

    在挂载的时候可以指定挂载设备的文件系统,但是和之前创建的类型不符合就会失去原来文件系统的功能,只有指定文件系统的功能

    比如创建的文件系统是ext3,但是指定是ext2,那么就会失去ext3的日志功能

     -t vsftype:指定要挂载的设备上的文件系统类型

    所以一般不指定类型,因为系统就自动识别出正确的文件系统

    [root@centos65 ~]# blkid
    /dev/sda1: UUID="6bbd9da4-0c3d-4496-a4b1-44bf79912740" TYPE="ext4" 
    /dev/sda2: UUID="10d2b40d-dcd8-4c16-aa81-511c520213f6" TYPE="ext4" 
    /dev/sda3: UUID="e432b350-a9a6-429b-8f07-592058efc6e2" TYPE="ext4" 
    /dev/sda5: UUID="b25a8a7e-40d8-485b-a5af-1b583698864d" TYPE="swap" 
    /dev/sdb2: UUID="b5e3fb3c-48be-49ff-b610-2b244d18639c" TYPE="ext4" 
    /dev/sdd: UUID="c4a0e490-aa52-4c8b-bcad-b20dd895971d" TYPE="ext4" 
    /dev/sdb3: UUID="bef91525-93b8-48a8-a2af-4ba463dc48ce" SEC_TYPE="ext2" TYPE="ext3" LABEL="/mnt/sdb3" 
    /dev/sdb5: UUID="53bc9bdb-6256-4ad9-bddb-12343a4728fd" SEC_TYPE="ext2" TYPE="ext3" 
    [root@centos65 ~]# mount  -t    ext2        /dev/sdb5   /mnt/sdb2

     -L 'LABEL': 以卷标指定挂载设备

    卷标名是挂载点,但是只是习惯,不是必须的

    创建标签,标签利用标签挂载

    [root@centos65 ~]# e2label    /dev/sdb2    /mnt/sdb2
    [root@centos65 ~]# blkid
    /dev/sda1: UUID="6bbd9da4-0c3d-4496-a4b1-44bf79912740" TYPE="ext4" 
    /dev/sda2: UUID="10d2b40d-dcd8-4c16-aa81-511c520213f6" TYPE="ext4" 
    /dev/sda3: UUID="e432b350-a9a6-429b-8f07-592058efc6e2" TYPE="ext4" 
    /dev/sda5: UUID="b25a8a7e-40d8-485b-a5af-1b583698864d" TYPE="swap" 
    /dev/sdb2: UUID="b5e3fb3c-48be-49ff-b610-2b244d18639c" TYPE="ext4" LABEL="/mnt/sdb2" 
    /dev/sdd: UUID="c4a0e490-aa52-4c8b-bcad-b20dd895971d" TYPE="ext4" 
    /dev/sdb3: UUID="bef91525-93b8-48a8-a2af-4ba463dc48ce" SEC_TYPE="ext2" TYPE="ext3" LABEL="/mnt/sdb3" 
    /dev/sdb5: UUID="53bc9bdb-6256-4ad9-bddb-12343a4728fd" SEC_TYPE="ext2" TYPE="ext3" 
    [root@centos65 ~]# df
    Filesystem     1K-blocks    Used Available Use% Mounted on
    /dev/sda2       50264772 1548232  46156540   4% /
    tmpfs             502068       0    502068   0% /dev/shm
    /dev/sda3       20027260   45000  18958260   1% /app
    /dev/sda1         999320   30492    916400   4% /boot
    /dev/sr0         3824484 3824484         0 100% /media
    
    [root@centos65 ~]# mount  -L   "/mnt/sdb2"    /mnt/sdb2
    mount: no such partition found
    [root@centos65 ~]# mount  -L   "/mnt/sbd2"    /mnt/sdb2
    [root@centos65 ~]# df
    Filesystem     1K-blocks    Used Available Use% Mounted on
    /dev/sda2       50264772 1548236  46156536   4% /
    tmpfs             502068       0    502068   0% /dev/shm
    /dev/sda3       20027260   45000  18958260   1% /app
    /dev/sda1         999320   30492    916400   4% /boot
    /dev/sr0         3824484 3824484         0 100% /media
    /dev/sdb2        5039624   10264   4766700   1% /mnt/sdb2

    -U 'UUID': 以UUID指定要挂载的设备

    [root@centos65 ~]# blkid
    /dev/sda1: UUID="6bbd9da4-0c3d-4496-a4b1-44bf79912740" TYPE="ext4" 
    /dev/sda2: UUID="10d2b40d-dcd8-4c16-aa81-511c520213f6" TYPE="ext4" 
    /dev/sda3: UUID="e432b350-a9a6-429b-8f07-592058efc6e2" TYPE="ext4" 
    /dev/sda5: UUID="b25a8a7e-40d8-485b-a5af-1b583698864d" TYPE="swap" 
    /dev/sdb2: UUID="b5e3fb3c-48be-49ff-b610-2b244d18639c" TYPE="ext4" LABEL="/mnt/sbd2" 
    /dev/sdd: UUID="c4a0e490-aa52-4c8b-bcad-b20dd895971d" TYPE="ext4" 
    /dev/sdb3: UUID="bef91525-93b8-48a8-a2af-4ba463dc48ce" SEC_TYPE="ext2" TYPE="ext3" LABEL="/mnt/sdb3" 
    /dev/sdb5: UUID="53bc9bdb-6256-4ad9-bddb-12343a4728fd" SEC_TYPE="ext2" TYPE="ext3"
    [root@centos65 ~]# df
    Filesystem     1K-blocks    Used Available Use% Mounted on
    /dev/sda2       50264772 1548244  46156528   4% /
    tmpfs             502068       0    502068   0% /dev/shm
    /dev/sda3       20027260   45000  18958260   1% /app
    /dev/sda1         999320   30492    916400   4% /boot
    /dev/sr0         3824484 3824484         0 100% /media
    [root@centos65 ~]# mount  -U   "c4a0e490-aa52-4c8b-bcad-b20dd895971d"    /mnt/sdb2
    
    [root@centos65 ~]# df
    Filesystem     1K-blocks    Used Available Use% Mounted on
    /dev/sda2       50264772 1548244  46156528   4% /
    tmpfs             502068       0    502068   0% /dev/shm
    /dev/sda3       20027260   45000  18958260   1% /app
    /dev/sda1         999320   30492    916400   4% /boot
    /dev/sr0         3824484 3824484         0 100% /media
    /dev/sdd        61796348   53064  58597556   1% /mnt/sdb2

    下面3个在前面出现了

    mount [-fnrsvw] [-t vfstype] [-o options] device dir


    device:指明要挂载的设备;


    (1) 设备文件:例如/dev/sda5


    (2) 卷标:-L 'LABEL', 例如 -L 'MYDATA'


    (3) UUID, -U 'UUID':例如 -U '0c50523c-43f1-45e7-85c0-a126711d406e'


    (4) 伪文件系统名称:proc, sysfs, devtmpfs, configfs也就是不是真实的磁盘,为了实现内存管理自动加载的

    [root@centos65 ~]# df
    Filesystem     1K-blocks    Used Available Use% Mounted on
    /dev/sda2       50264772 1548244  46156528   4% /
    tmpfs             502068       0    502068   0% /dev/shm
    /dev/sda3       20027260   45000  18958260   1% /app
    /dev/sda1         999320   30492    916400   4% /boot
    /dev/sr0         3824484 3824484         0 100% /media
    /dev/sdd        61796348   53064  58597556   1% /mnt/sdb2

    一个设备是可以挂载到多个目录下的,但是一个目录不能挂载多个设备

    原因就是进入到了目录到底是看到哪个设备上的数据。

    取消挂载的问题

    因为是在要挂载的目录里面,相当于占用了这个目录,退出这个目录就可以卸载了

    [root@centos65 ~]# mount  /dev/sdb2  /mnt/sdb2
    [root@centos65 ~]# df
    Filesystem     1K-blocks    Used Available Use% Mounted on
    /dev/sda2       50264772 1549080  46155692   4% /
    tmpfs             502068       0    502068   0% /dev/shm
    /dev/sda3       20027260   45000  18958260   1% /app
    /dev/sda1         999320   30492    916400   4% /boot
    /dev/sr0         3824484 3824484         0 100% /media
    /dev/sdb2        5039624   10264   4766700   1% /mnt/sdb2
    [root@centos65 ~]# cd  /mnt/sdb2
    [root@centos65 sdb2]# ls
    lost+found
    [root@centos65 sdb2]# umount  /mnt/sdb2 
    umount: /mnt/sdb2: device is busy.
            (In some cases useful info about processes that use
             the device is found by lsof(8) or fuser(1))
    [root@centos65 sdb2]# cd
    [root@centos65 ~]# umount  /mnt/sdb2 
    [root@centos65 ~]# df
    Filesystem     1K-blocks    Used Available Use% Mounted on
    /dev/sda2       50264772 1549080  46155692   4% /
    tmpfs             502068       0    502068   0% /dev/shm
    /dev/sda3       20027260   45000  18958260   1% /app
    /dev/sda1         999320   30492    916400   4% /boot
    /dev/sr0         3824484 3824484         0 100% /media

    如果是网络用户在访问要卸载的目录里面的资源时上面的卸载是不成功的

    打开新终端进入到要挂载的目录里面,模拟生产环境中的用户正在访问的情况

    [root@centos65 ~]# cd  /mnt/sdb2
    [root@centos65 sdb2]# ls
    lost+found
    [root@centos65 sdb2]# df
    Filesystem     1K-blocks    Used Available Use% Mounted on
    /dev/sda2       50264772 1549084  46155688   4% /
    tmpfs             502068       0    502068   0% /dev/shm
    /dev/sda3       20027260   45000  18958260   1% /app
    /dev/sda1         999320   30492    916400   4% /boot
    /dev/sr0         3824484 3824484         0 100% /media
    /dev/sdb2        5039624   10264   4766700   1% /mnt/sdb2

    在原来的终端是不能卸载的

    [root@centos65 ~]# df
    Filesystem     1K-blocks    Used Available Use% Mounted on
    /dev/sda2       50264772 1549080  46155692   4% /
    tmpfs             502068       0    502068   0% /dev/shm
    /dev/sda3       20027260   45000  18958260   1% /app
    /dev/sda1         999320   30492    916400   4% /boot
    /dev/sr0         3824484 3824484         0 100% /media
    /dev/sdb2        5039624   10264   4766700   1% /mnt/sdb2
    [root@centos65 ~]# umount  /mnt/sdb2 
    umount: /mnt/sdb2: device is busy.
            (In some cases useful info about processes that use
             the device is found by lsof(8) or fuser(1))

    在原来的终端查看进程号

    [root@centos65 ~]# lsof    /mnt/sdb2
    COMMAND  PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
    bash    2307 root  cwd    DIR   8,18     4096    2 /mnt/sdb2

    新的终端显示的进程号

    [root@centos65 sdb2]# df
    Filesystem     1K-blocks    Used Available Use% Mounted on
    /dev/sda2       50264772 1549084  46155688   4% /
    tmpfs             502068       0    502068   0% /dev/shm
    /dev/sda3       20027260   45000  18958260   1% /app
    /dev/sda1         999320   30492    916400   4% /boot
    /dev/sr0         3824484 3824484         0 100% /media
    /dev/sdb2        5039624   10264   4766700   1% /mnt/sdb2
    [root@centos65 sdb2]# echo   $$
    2307

    fuser也可以查看到目前是哪些用户正在使用卸载不了的目录

    [root@centos65 ~]# fuser  /mnt/sdb2  -v
                         USER        PID ACCESS COMMAND
    /mnt/sdb2:           root       2307 ..c.. bash

    使用w也可以查看已经登录系统的用户

    [root@centos65 ~]# w
     11:41:01 up 28 min,  2 users,  load average: 0.00, 0.01, 0.05
    USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT
    root     pts/0    192.168.137.1    11:14    0.00s  0.23s  0.01s w
    root     pts/1    192.168.137.1    11:22   13:23   0.08s  0.08s -bash

    要卸载用户正在使用的目录可以事先发通知

    [root@centos65 ~]# w
     11:41:01 up 28 min,  2 users,  load average: 0.00, 0.01, 0.05
    USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT
    root     pts/0    192.168.137.1    11:14    0.00s  0.23s  0.01s w
    root     pts/1    192.168.137.1    11:22   13:23   0.08s  0.08s -bash
    [root@centos65 ~]# echo   please  exit  !   >    /dev/pts/
    0     1     ptmx  
    [root@centos65 ~]# echo   please  exit  !   >    /dev/pts/1
    [root@centos65 ~]# fuser  -km    /mnt/sdb2
    /mnt/sdb2:            2307c

    现在在此终端用户被踢了,说明fuser起作用了

    [root@centos65 sdb2]# echo   $$
    2307
    [root@centos65 sdb2]# please exit !
    
    Connection closed by foreign host.
    
    Disconnected from remote host(192.168.137.65:22) at 12:01:59.
    
    Type `help' to learn how to use Xshell prompt.
    [c:~]$ 

    查看某个文件是否是挂载点

    [root@centos65 ~]# df
    Filesystem     1K-blocks    Used Available Use% Mounted on
    /dev/sda2       50264772 1549344  46155428   4% /
    tmpfs             502068       0    502068   0% /dev/shm
    /dev/sda3       20027260   45000  18958260   1% /app
    /dev/sda1         999320   30492    916400   4% /boot
    /dev/sr0         3824484 3824484         0 100% /media
    [root@centos65 ~]# findmnt   /mnt/sdb2
    [root@centos65 ~]# findmnt   /media/
    TARGET SOURCE   FSTYPE  OPTIONS
    /media /dev/sr0 iso9660 ro,relatime
    [root@centos65 ~]# mount  /dev/sdb2  /mnt/sdb2
    [root@centos65 ~]# findmnt   /mnt/sdb2
    TARGET    SOURCE    FSTYPE OPTIONS
    /mnt/sdb2 /dev/sdb2 ext4   rw,relatime,seclabel,barrier=1,data=ordered

    二mount常用命令选项

    -t vsftype:指定要挂载的设备上的文件系统类型


    -r: readonly,只读挂载


    -w: read and write, 读写挂载


    -n: 不更新/etc/mtab,mount不可见


    -a:自动挂载所有支持自动挂载的设备(定义在了/etc/fstab文件中,且挂载选项中有auto功能)


    -L 'LABEL': 以卷标指定挂载设备


    -U 'UUID': 以UUID指定要挂载的设备


    -B, --bind: 绑定目录到另一个目录上


    查看内核追踪到的已挂载的所有设备cat /proc/mounts

    -o options:(挂载文件系统的选项),多个选项使用逗号分隔


    async:异步模式


    sync:同步模式,内存更改时,同时写磁盘


    atime/noatime:包含目录和文件


    diratime/nodiratime:目录的访问时间戳


    auto/noauto:是否支持自动挂载,是否支持-a选项


    exec/noexec:是否支持将文件系统上运行应用程序


    dev/nodev:是否支持在此文件系统上使用设备文件


    suid/nosuid:是否支持suid和sgid权限


    remount:重新挂载


    ro:只读


    rw:读写


    user/nouser:是否允许普通用户挂载此设备,/etc/fstab使用


    acl:启用此文件系统上的acl功能


    loop: 使用loop设备


    defaults:相当于rw, suid, dev, exec, auto, nouser, async

     -r: readonly,只读挂载

    [root@centos65 ~]# df
    Filesystem     1K-blocks    Used Available Use% Mounted on
    /dev/sda2       50264772 1549508  46155264   4% /
    tmpfs             502068       0    502068   0% /dev/shm
    /dev/sda3       20027260   45000  18958260   1% /app
    /dev/sda1         999320   30492    916400   4% /boot
    /dev/sr0         3824484 3824484         0 100% /media
    /dev/sdb2        5039624   10264   4766700   1% /mnt/sdb2
    [root@centos65 ~]# mount
    /dev/sda2 on / type ext4 (rw)
    proc on /proc type proc (rw)
    sysfs on /sys type sysfs (rw)
    devpts on /dev/pts type devpts (rw,gid=5,mode=620)
    tmpfs on /dev/shm type tmpfs (rw,rootcontext="system_u:object_r:tmpfs_t:s0")
    /dev/sda3 on /app type ext4 (rw)
    /dev/sda1 on /boot type ext4 (rw)
    /dev/sr0 on /media type iso9660 (ro)
    none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
    /dev/sdb2 on /mnt/sdb2 type ext4 (rw)
    [root@centos65 ~]# mount    -r   /dev/sdb2     /mnt/sdb2
    mount: /dev/sdb2 already mounted or /mnt/sdb2 busy
    mount: according to mtab, /dev/sdb2 is already mounted on /mnt/sdb2
    [root@centos65 ~]# df
    Filesystem     1K-blocks    Used Available Use% Mounted on
    /dev/sda2       50264772 1549508  46155264   4% /
    tmpfs             502068       0    502068   0% /dev/shm
    /dev/sda3       20027260   45000  18958260   1% /app
    /dev/sda1         999320   30492    916400   4% /boot
    /dev/sr0         3824484 3824484         0 100% /media
    /dev/sdb2        5039624   10264   4766700   1% /mnt/sdb2
    [root@centos65 ~]# umount  /dev/sdb2  
    [root@centos65 ~]# mount    -r   /dev/sdb2     /mnt/sdb2
    [root@centos65 ~]# mount
    /dev/sda2 on / type ext4 (rw)
    proc on /proc type proc (rw)
    sysfs on /sys type sysfs (rw)
    devpts on /dev/pts type devpts (rw,gid=5,mode=620)
    tmpfs on /dev/shm type tmpfs (rw,rootcontext="system_u:object_r:tmpfs_t:s0")
    /dev/sda3 on /app type ext4 (rw)
    /dev/sda1 on /boot type ext4 (rw)
    /dev/sr0 on /media type iso9660 (ro)
    none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
    /dev/sdb2 on /mnt/sdb2 type ext4 (ro)

    设置为只读就不能在此目录下创建文件或者目录了,包括root用户也不能写入

    [root@centos65 ~]# cd    /mnt/sdb2
    [root@centos65 sdb2]# mkdir  aaa
    mkdir: cannot create directory `aaa': Read-only file system
    [root@centos65 sdb2]# vim    aaa
    [root@centos65 sdb2]# ls
    lost+found
    [root@centos65 sdb2]# touch   aaaa
    touch: cannot touch `aaaa': Read-only file system

    要想改回原来的可读可写可以卸载后再挂载。

    文件是自动更新的

    [root@centos65 ~]# umount  /dev/sdb2
    [root@centos65 ~]# df
    Filesystem     1K-blocks    Used Available Use% Mounted on
    /dev/sda2       50264772 1549512  46155260   4% /
    tmpfs             502068       0    502068   0% /dev/shm
    /dev/sda3       20027260   45000  18958260   1% /app
    /dev/sda1         999320   30492    916400   4% /boot
    /dev/sr0         3824484 3824484         0 100% /media
    [root@centos65 ~]# cat  /etc/mtab 
    /dev/sda2 / ext4 rw 0 0
    proc /proc proc rw 0 0
    sysfs /sys sysfs rw 0 0
    devpts /dev/pts devpts rw,gid=5,mode=620 0 0
    tmpfs /dev/shm tmpfs rw,rootcontext="system_u:object_r:tmpfs_t:s0" 0 0
    /dev/sda3 /app ext4 rw 0 0
    /dev/sda1 /boot ext4 rw 0 0
    /dev/sr0 /media iso9660 ro 0 0
    none /proc/sys/fs/binfmt_misc binfmt_misc rw 0 0
    [root@centos65 ~]# ll  /etc/mtab 
    -rw-r--r--. 1 root root 322 Mar  1 22:18 /etc/mtab

    挂载上去了之后就自动更新了

    [root@centos65 ~]# mount  /dev/sdb2  /mnt/sdb2
    [root@centos65 ~]# df
    Filesystem     1K-blocks    Used Available Use% Mounted on
    /dev/sda2       50264772 1549520  46155252   4% /
    tmpfs             502068       0    502068   0% /dev/shm
    /dev/sda3       20027260   45000  18958260   1% /app
    /dev/sda1         999320   30492    916400   4% /boot
    /dev/sr0         3824484 3824484         0 100% /media
    /dev/sdb2        5039624   10264   4766700   1% /mnt/sdb2
    [root@centos65 ~]# cat  /etc/mtab 
    /dev/sda2 / ext4 rw 0 0
    proc /proc proc rw 0 0
    sysfs /sys sysfs rw 0 0
    devpts /dev/pts devpts rw,gid=5,mode=620 0 0
    tmpfs /dev/shm tmpfs rw,rootcontext="system_u:object_r:tmpfs_t:s0" 0 0
    /dev/sda3 /app ext4 rw 0 0
    /dev/sda1 /boot ext4 rw 0 0
    /dev/sr0 /media iso9660 ro 0 0
    none /proc/sys/fs/binfmt_misc binfmt_misc rw 0 0
    /dev/sdb2 /mnt/sdb2 ext4 rw 0 0

     -n: 不更新/etc/mtab,mount不可见

    只有使用findmnt /mnt/sdb2才知道是已经挂载了。

    [root@centos65 ~]# mount  /dev/sdb2   /mnt/sdb2  -n
    [root@centos65 ~]# findmnt    /mnt/sdb2
    TARGET    SOURCE    FSTYPE OPTIONS
    /mnt/sdb2 /dev/sdb2 ext4   rw,relatime,seclabel,barrier=1,data=ordered
    [root@centos65 ~]# mount
    /dev/sda2 on / type ext4 (rw)
    proc on /proc type proc (rw)
    sysfs on /sys type sysfs (rw)
    devpts on /dev/pts type devpts (rw,gid=5,mode=620)
    tmpfs on /dev/shm type tmpfs (rw,rootcontext="system_u:object_r:tmpfs_t:s0")
    /dev/sda3 on /app type ext4 (rw)
    /dev/sda1 on /boot type ext4 (rw)
    /dev/sr0 on /media type iso9660 (ro)
    none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
    [root@centos65 ~]# cat  /etc/mtab 
    /dev/sda2 / ext4 rw 0 0
    proc /proc proc rw 0 0
    sysfs /sys sysfs rw 0 0
    devpts /dev/pts devpts rw,gid=5,mode=620 0 0
    tmpfs /dev/shm tmpfs rw,rootcontext="system_u:object_r:tmpfs_t:s0" 0 0
    /dev/sda3 /app ext4 rw 0 0
    /dev/sda1 /boot ext4 rw 0 0
    /dev/sr0 /media iso9660 ro 0 0
    none /proc/sys/fs/binfmt_misc binfmt_misc rw 0 0
    [root@centos65 ~]# df
    Filesystem     1K-blocks    Used Available Use% Mounted on
    /dev/sda2       50264772 1549520  46155252   4% /
    tmpfs             502068       0    502068   0% /dev/shm
    /dev/sda3       20027260   45000  18958260   1% /app
    /dev/sda1         999320   30492    916400   4% /boot
    /dev/sr0         3824484 3824484         0 100% /media
    [root@centos65 ~]# ls  /mnt/sdb2
    lost+found
    [root@centos65 ~]# ll  /mnt/sdb2
    total 16
    drwx------. 2 root root 16384 Feb 26 11:25 lost+found

    只要创建ext系列文件系统就会在分区下自动创建lost+found这个目录,xfs文件系统就没有

    [root@centos65 ~]# cd  /mnt/sdb2/lost+found/
    [root@centos65 lost+found]# ls
    [root@centos65 lost+found]# ls
    [root@centos65 ~]# df
    Filesystem     1K-blocks    Used Available Use% Mounted on
    /dev/sda2       50264772 1549528  46155244   4% /
    tmpfs             502068       0    502068   0% /dev/shm
    /dev/sda3       20027260   45000  18958260   1% /app
    /dev/sda1         999320   30492    916400   4% /boot
    /dev/sr0         3824484 3824484         0 100% /media
    [root@centos65 ~]# ls  /boot/
    boot                          grub                                 symvers-2.6.32-642.el6.x86_64.gz
    config-2.6.32-642.el6.x86_64  initramfs-2.6.32-642.el6.x86_64.img  System.map-2.6.32-642.el6.x86_64
    efi                           lost+found                           vmlinuz-2.6.32-642.el6.x86_64

    或者是使用cat /proc/mounts

    [root@centos65 ~]# cat  /proc/mounts
    rootfs / rootfs rw 0 0
    proc /proc proc rw,relatime 0 0
    sysfs /sys sysfs rw,seclabel,relatime 0 0
    devtmpfs /dev devtmpfs rw,seclabel,relatime,size=489492k,nr_inodes=122373,mode=755 0 0
    devpts /dev/pts devpts rw,seclabel,relatime,gid=5,mode=620,ptmxmode=000 0 0
    tmpfs /dev/shm tmpfs rw,seclabel,relatime 0 0
    /dev/sda2 / ext4 rw,seclabel,relatime,barrier=1,data=ordered 0 0
    none /selinux selinuxfs rw,relatime 0 0
    devtmpfs /dev devtmpfs rw,seclabel,relatime,size=489492k,nr_inodes=122373,mode=755 0 0
    /proc/bus/usb /proc/bus/usb usbfs rw,relatime 0 0
    /dev/sda3 /app ext4 rw,seclabel,relatime,barrier=1,data=ordered 0 0
    /dev/sda1 /boot ext4 rw,seclabel,relatime,barrier=1,data=ordered 0 0
    /dev/sr0 /media iso9660 ro,relatime 0 0
    none /proc/sys/fs/binfmt_misc binfmt_misc rw,relatime 0 0
    cgroup /cgroup/cpuset cgroup rw,relatime,cpuset 0 0
    cgroup /cgroup/cpu cgroup rw,relatime,cpu 0 0
    cgroup /cgroup/cpuacct cgroup rw,relatime,cpuacct 0 0
    cgroup /cgroup/memory cgroup rw,relatime,memory 0 0
    cgroup /cgroup/devices cgroup rw,relatime,devices 0 0
    cgroup /cgroup/freezer cgroup rw,relatime,freezer 0 0
    cgroup /cgroup/net_cls cgroup rw,relatime,net_cls 0 0
    cgroup /cgroup/blkio cgroup rw,relatime,blkio 0 0
    /dev/sdb2 /mnt/sdb2 ext4 rw,seclabel,relatime,barrier=1,data=ordered 0 0

    lost+found这个目录相当于收容所。

    因为特殊原因,比如不正常关机,有些数据原来是在某个目录里面存放的,后来因为数据出现了问题,不知道放到哪个目录里面就放到lost+found这个目录

    [root@centos65 ~]# cd  /
    [root@centos65 /]# ls
    app  bin  boot  cgroup  dev  etc  home  lib  lib64  lost+found  media  mnt  opt  proc  root  sbin  selinux  srv  sys  tmp  usr  var
    [root@centos72 ~]# df
    Filesystem     1K-blocks    Used Available Use% Mounted on
    /dev/sda2       52403200 1121672  51281528   3% /
    devtmpfs          487952       0    487952   0% /dev
    tmpfs             498976       0    498976   0% /dev/shm
    tmpfs             498976    7828    491148   2% /run
    tmpfs             498976       0    498976   0% /sys/fs/cgroup
    /dev/sr0         4364408 4364408         0 100% /mnt
    /dev/sda3       20961280   32944  20928336   1% /app
    /dev/sda1        1038336  126596    911740  13% /boot
    tmpfs              99796       0     99796   0% /run/user/0
    [root@centos72 ~]# ls  /app/

    -B, --bind: 绑定目录到另一个目录上

    这样两个目录里面的文件是一样的

    注意下面的设备/dev/sdb2已经挂载到了/mnt/sdb2下了

    [root@centos65 ~]# cat  /proc/mounts
    rootfs / rootfs rw 0 0
    proc /proc proc rw,relatime 0 0
    sysfs /sys sysfs rw,seclabel,relatime 0 0
    devtmpfs /dev devtmpfs rw,seclabel,relatime,size=489492k,nr_inodes=122373,mode=755 0 0
    devpts /dev/pts devpts rw,seclabel,relatime,gid=5,mode=620,ptmxmode=000 0 0
    tmpfs /dev/shm tmpfs rw,seclabel,relatime 0 0
    /dev/sda2 / ext4 rw,seclabel,relatime,barrier=1,data=ordered 0 0
    none /selinux selinuxfs rw,relatime 0 0
    devtmpfs /dev devtmpfs rw,seclabel,relatime,size=489492k,nr_inodes=122373,mode=755 0 0
    /proc/bus/usb /proc/bus/usb usbfs rw,relatime 0 0
    /dev/sda3 /app ext4 rw,seclabel,relatime,barrier=1,data=ordered 0 0
    /dev/sda1 /boot ext4 rw,seclabel,relatime,barrier=1,data=ordered 0 0
    /dev/sr0 /media iso9660 ro,relatime 0 0
    none /proc/sys/fs/binfmt_misc binfmt_misc rw,relatime 0 0
    cgroup /cgroup/cpuset cgroup rw,relatime,cpuset 0 0
    cgroup /cgroup/cpu cgroup rw,relatime,cpu 0 0
    cgroup /cgroup/cpuacct cgroup rw,relatime,cpuacct 0 0
    cgroup /cgroup/memory cgroup rw,relatime,memory 0 0
    cgroup /cgroup/devices cgroup rw,relatime,devices 0 0
    cgroup /cgroup/freezer cgroup rw,relatime,freezer 0 0
    cgroup /cgroup/net_cls cgroup rw,relatime,net_cls 0 0
    cgroup /cgroup/blkio cgroup rw,relatime,blkio 0 0
    /dev/sdb2 /mnt/sdb2 ext4 rw,seclabel,relatime,barrier=1,data=ordered 0 0
    [root@centos65 ~]# ls  /app/
    lost+found
    [root@centos65 ~]# mkdir    /app/sdb2
    [root@centos65 ~]# ls  /app/
    lost+found  sdb2
    [root@centos65 ~]# mount  /mnt/sdb2  /app/sdb2/
    mount: you must specify the filesystem type
    [root@centos65 ~]# mount  /mnt/sdb2  /app/sdb2/   -B
    [root@centos65 ~]# df
    Filesystem     1K-blocks    Used Available Use% Mounted on
    /dev/sda2       50264772 1549532  46155240   4% /
    tmpfs             502068       0    502068   0% /dev/shm
    /dev/sda3       20027260   44996  18958264   1% /app
    /dev/sda1         999320   30492    916400   4% /boot
    /dev/sr0         3824484 3824484         0 100% /media
    [root@centos65 ~]# mount
    /dev/sda2 on / type ext4 (rw)
    proc on /proc type proc (rw)
    sysfs on /sys type sysfs (rw)
    devpts on /dev/pts type devpts (rw,gid=5,mode=620)
    tmpfs on /dev/shm type tmpfs (rw,rootcontext="system_u:object_r:tmpfs_t:s0")
    /dev/sda3 on /app type ext4 (rw)
    /dev/sda1 on /boot type ext4 (rw)
    /dev/sr0 on /media type iso9660 (ro)
    none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
    /mnt/sdb2 on /app/sdb2 type none (rw,bind)
    [root@centos65 ~]# cd  /app/sdb2
    [root@centos65 sdb2]# ls
    lost+found
    [root@centos65 sdb2]# touch   /mnt/sdb2/sdb2file
    [root@centos65 sdb2]# ls
    lost+found  sdb2file
    [root@centos65 sdb2]# pwd
    /app/sdb2
    [root@centos65 sdb2]# ls  /app/sdb2
    lost+found  sdb2file
    [root@centos65 sdb2]# ls  /mnt/sdb2
    lost+found  sdb2file
    [root@centos65 sdb2]# ls  /dev/sdb2
    /dev/sdb2

    虽然是在不同的目录,但是节点编号是一样的。

    [root@centos65 sdb2]# ls  /app/sdb2/  -i  -l
    total 16
    11 drwx------. 2 root root 16384 Feb 26 11:25 lost+found
    12 -rw-r--r--. 1 root root     0 Mar  1 23:20 sdb2file
    [root@centos65 sdb2]# ls  /mnt/sdb2/  -i  -l
    total 16
    11 drwx------. 2 root root 16384 Feb 26 11:25 lost+found
    12 -rw-r--r--. 1 root root     0 Mar  1 23:20 sdb2file

    问题上面的挂载和软链接有什么区别,软链接是可以跨设备,硬链接不能。

    上面是挂载关系,访问哪个的是同一个文件。用起来像硬链接,而且可以跨设备的,但是又不是硬链接。

    [root@centos65 ~]# ls  /app/sdb2/
    lost+found  sdb2file
    [root@centos65 ~]# pwd
    /root
    [root@centos65 ~]# cd  /app/sdb2
    [root@centos65 sdb2]# pwd
    /app/sdb2
    [root@centos65 sdb2]# cd
    [root@centos65 ~]# cd  /mnt/sdb2
    [root@centos65 sdb2]# ls
    lost+found  sdb2file
    [root@centos65 sdb2]# pwd
    /mnt/sdb2

    -o options:(挂载文件系统的选项),多个选项使用逗号分隔
    async:异步模式
    sync:同步模式,内存更改时,同时写磁盘

    [root@centos65 sdb2]# pwd
    /mnt/sdb2
    [root@centos65 sdb2]# cd
    [root@centos65 ~]# mount
    /dev/sda2 on / type ext4 (rw)
    proc on /proc type proc (rw)
    sysfs on /sys type sysfs (rw)
    devpts on /dev/pts type devpts (rw,gid=5,mode=620)
    tmpfs on /dev/shm type tmpfs (rw,rootcontext="system_u:object_r:tmpfs_t:s0")
    /dev/sda3 on /app type ext4 (rw)
    /dev/sda1 on /boot type ext4 (rw)
    /dev/sr0 on /media type iso9660 (ro)
    none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
    /mnt/sdb2 on /app/sdb2 type none (rw,bind)
    [root@centos65 ~]# echo   aaaa  >>   /app/sdb2/sdb2file 
    [root@centos65 ~]# ls  /app/sdb2/sdb2file 
    /app/sdb2/sdb2file
    [root@centos65 ~]# cat    /app/sdb2/sdb2file 
    aaaa

    修改文件是在内存里面修改并且写入到磁盘的缓存里面,在系统不是很忙时再写入到磁盘上。

    因为内存和磁盘的速度差异大,无法同步,写入到高速缓冲区,这样就不会占用内存。

    但是缺点就是容易造成数据的丢失,比如突然断电了,缓冲区的数据来不及写入到磁盘里面。

    注意高速缓冲区就相当于内存。默认是异步模式,效率更高。

    问题缓冲区和缓存的区别?

    缓冲区buffer:写数据,临时存放写到磁盘的空间

    atime/noatime:是否刷新读时间,包含目录和文件

    diratime/nodiratime:目录的访问时间戳

    访问时间也就是读数据的时间

    如果有大量用户访问,那么修改访问时间是没有意义的。

    [root@centos65 ~]# cat  /proc/mounts 
    rootfs / rootfs rw 0 0
    proc /proc proc rw,relatime 0 0
    sysfs /sys sysfs rw,seclabel,relatime 0 0
    devtmpfs /dev devtmpfs rw,seclabel,relatime,size=489492k,nr_inodes=122373,mode=755 0 0
    devpts /dev/pts devpts rw,seclabel,relatime,gid=5,mode=620,ptmxmode=000 0 0
    tmpfs /dev/shm tmpfs rw,seclabel,relatime 0 0
    /dev/sda2 / ext4 rw,seclabel,relatime,barrier=1,data=ordered 0 0
    none /selinux selinuxfs rw,relatime 0 0
    devtmpfs /dev devtmpfs rw,seclabel,relatime,size=489492k,nr_inodes=122373,mode=755 0 0
    /proc/bus/usb /proc/bus/usb usbfs rw,relatime 0 0
    /dev/sda3 /app ext4 rw,seclabel,relatime,barrier=1,data=ordered 0 0
    /dev/sda1 /boot ext4 rw,seclabel,relatime,barrier=1,data=ordered 0 0
    /dev/sr0 /media iso9660 ro,relatime 0 0
    none /proc/sys/fs/binfmt_misc binfmt_misc rw,relatime 0 0
    cgroup /cgroup/cpuset cgroup rw,relatime,cpuset 0 0
    cgroup /cgroup/cpu cgroup rw,relatime,cpu 0 0
    cgroup /cgroup/cpuacct cgroup rw,relatime,cpuacct 0 0
    cgroup /cgroup/memory cgroup rw,relatime,memory 0 0
    cgroup /cgroup/devices cgroup rw,relatime,devices 0 0
    cgroup /cgroup/freezer cgroup rw,relatime,freezer 0 0
    cgroup /cgroup/net_cls cgroup rw,relatime,net_cls 0 0
    cgroup /cgroup/blkio cgroup rw,relatime,blkio 0 0
    /dev/sdb2 /mnt/sdb2 ext4 rw,seclabel,relatime,barrier=1,data=ordered 0 0
    /dev/sdb2 /app/sdb2 ext4 rw,seclabel,relatime,barrier=1,data=ordered 0 0

    对于网页文件可以采用取消访问文件和目录时间的功能,因为有大量的用户访问,刷新访问时间是没有意义的,而且取消之后可以提高性能。

    [root@centos65 ~]# umount  /app/sdb2 
    [root@centos65 ~]# umount  /mnt/sdb2 
    [root@centos65 ~]# w
     10:52:33 up 14:56,  1 user,  load average: 0.00, 0.01, 0.05
    USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT
    root     pts/0    192.168.137.34   10:51    0.00s  0.17s  0.06s w
    [root@centos65 ~]# cat  /proc/mounts 
    rootfs / rootfs rw 0 0
    proc /proc proc rw,relatime 0 0
    sysfs /sys sysfs rw,seclabel,relatime 0 0
    devtmpfs /dev devtmpfs rw,seclabel,relatime,size=489492k,nr_inodes=122373,mode=755 0 0
    devpts /dev/pts devpts rw,seclabel,relatime,gid=5,mode=620,ptmxmode=000 0 0
    tmpfs /dev/shm tmpfs rw,seclabel,relatime 0 0
    /dev/sda2 / ext4 rw,seclabel,relatime,barrier=1,data=ordered 0 0
    none /selinux selinuxfs rw,relatime 0 0
    devtmpfs /dev devtmpfs rw,seclabel,relatime,size=489492k,nr_inodes=122373,mode=755 0 0
    /proc/bus/usb /proc/bus/usb usbfs rw,relatime 0 0
    /dev/sda3 /app ext4 rw,seclabel,relatime,barrier=1,data=ordered 0 0
    /dev/sda1 /boot ext4 rw,seclabel,relatime,barrier=1,data=ordered 0 0
    /dev/sr0 /media iso9660 ro,relatime 0 0
    none /proc/sys/fs/binfmt_misc binfmt_misc rw,relatime 0 0
    cgroup /cgroup/cpuset cgroup rw,relatime,cpuset 0 0
    cgroup /cgroup/cpu cgroup rw,relatime,cpu 0 0
    cgroup /cgroup/cpuacct cgroup rw,relatime,cpuacct 0 0
    cgroup /cgroup/memory cgroup rw,relatime,memory 0 0
    cgroup /cgroup/devices cgroup rw,relatime,devices 0 0
    cgroup /cgroup/freezer cgroup rw,relatime,freezer 0 0
    cgroup /cgroup/net_cls cgroup rw,relatime,net_cls 0 0
    cgroup /cgroup/blkio cgroup rw,relatime,blkio 0 0
    [root@centos65 ~]# mount  -o  noatime    /dev/sdb2  /mnt/sdb2
    [root@centos65 ~]# df
    Filesystem     1K-blocks    Used Available Use% Mounted on
    /dev/sda2       50264772 1549888  46154884   4% /
    tmpfs             502068       0    502068   0% /dev/shm
    /dev/sda3       20027260   44996  18958264   1% /app
    /dev/sda1         999320   30492    916400   4% /boot
    /dev/sr0         3824484 3824484         0 100% /media
    /dev/sdb2        5039624   10268   4766696   1% /mnt/sdb2
    [root@centos65 ~]# cd  /mnt/sdb2
    [root@centos65 sdb2]# ls
    lost+found  sdb2file
    [root@centos65 sdb2]# ll
    total 20
    drwx------. 2 root root 16384 Feb 26 11:25 lost+found
    -rw-r--r--. 1 root root     5 Mar  2 10:30 sdb2file
    [root@centos65 sdb2]# stat  sdb2file 
      File: `sdb2file'
      Size: 5             Blocks: 8          IO Block: 4096   regular file
    Device: 812h/2066d    Inode: 12          Links: 1
    Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
    Access: 2019-03-02 10:32:30.268722639 +0800
    Modify: 2019-03-02 10:30:43.536219363 +0800
    Change: 2019-03-02 10:30:43.536219363 +0800
    [root@centos65 sdb2]# pwd
    /mnt/sdb2
    [root@centos65 sdb2]# cat  /mnt/sdb2/sdb2file 
    aaaa
    [root@centos65 sdb2]# stat  sdb2file 
      File: `sdb2file'
      Size: 5             Blocks: 8          IO Block: 4096   regular file
    Device: 812h/2066d    Inode: 12          Links: 1
    Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
    Access: 2019-03-02 10:32:30.268722639 +0800
    Modify: 2019-03-02 10:30:43.536219363 +0800
    Change: 2019-03-02 10:30:43.536219363 +0800

    exec/noexec:是否支持将文件系统上运行应用程序

    现在是可以执行脚本的

    [root@centos65 sdb2]# echo   hostname  >  f1.sh
    [root@centos65 sdb2]# ls
    f1.sh  lost+found  sdb2file
    [root@centos65 sdb2]# chmod   +x   f1.sh 
    [root@centos65 sdb2]# bash f1.sh 
    centos65.jd.com
    [root@centos65 sdb2]# ll
    total 24
    -rwxr-xr-x. 1 root root     9 Mar  2 11:16 f1.sh
    drwx------. 2 root root 16384 Feb 26 11:25 lost+found
    -rw-r--r--. 1 root root     5 Mar  2 10:30 sdb2file
    [root@centos65 sdb2]# pwd
    /mnt/sdb2

    禁止设备上的文件具有可执行的功能

    [root@centos65 sdb2]# mount  -o    remount,noexec     /mnt/sdb2
    [root@centos65 sdb2]# mount
    /dev/sda2 on / type ext4 (rw)
    proc on /proc type proc (rw)
    sysfs on /sys type sysfs (rw)
    devpts on /dev/pts type devpts (rw,gid=5,mode=620)
    tmpfs on /dev/shm type tmpfs (rw,rootcontext="system_u:object_r:tmpfs_t:s0")
    /dev/sda3 on /app type ext4 (rw)
    /dev/sda1 on /boot type ext4 (rw)
    /dev/sr0 on /media type iso9660 (ro)
    none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
    /dev/sdb2 on /mnt/sdb2 type ext4 (rw,noexec,noatime)
    [root@centos65 sdb2]# ls  /mnt/sdb2
    f1.sh  lost+found  sdb2file
    [root@centos65 sdb2]# bash    /mnt/sdb2/f1.sh 
    centos65.jd.com
    [root@centos65 sdb2]# cd
    [root@centos65 ~]# bash    /mnt/sdb2/f1.sh 
    centos65.jd.com
    [root@centos65 ~]# bash    /mnt/sdb2/f1.sh 
    centos65.jd.com
    [root@centos65 ~]# /mnt/sdb2/f1.sh 
    -bash: /mnt/sdb2/f1.sh: Permission denied
    [root@centos65 ~]# ll  /mnt/sdb2/f1.sh
    -rwxr-xr-x. 1 root root 9 Mar  2 11:16 /mnt/sdb2/f1.sh
    [root@centos65 ~]# mount  -o    remount,exec     /mnt/sdb2
    [root@centos65 ~]# /mnt/sdb2/f1.sh 
    centos65.jd.com
    [root@centos65 ~]# mount
    /dev/sda2 on / type ext4 (rw)
    proc on /proc type proc (rw)
    sysfs on /sys type sysfs (rw)
    devpts on /dev/pts type devpts (rw,gid=5,mode=620)
    tmpfs on /dev/shm type tmpfs (rw,rootcontext="system_u:object_r:tmpfs_t:s0")
    /dev/sda3 on /app type ext4 (rw)
    /dev/sda1 on /boot type ext4 (rw)
    /dev/sr0 on /media type iso9660 (ro)
    none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
    /dev/sdb2 on /mnt/sdb2 type ext4 (rw,noatime)

    设备文件

    dev/nodev:是否支持在此文件系统上使用设备文件

    创建设备文件

    [root@centos65 ~]# ll   /mnt/sdb2
    total 24
    -rwxr-xr-x. 1 root root     9 Mar  2 11:16 f1.sh
    drwx------. 2 root root 16384 Feb 26 11:25 lost+found
    -rw-r--r--. 1 root root     5 Mar  2 10:30 sdb2file
    [root@centos65 ~]# ll  /dev/zero 
    crw-rw-rw-. 1 root root 1, 5 Feb  1 19:55 /dev/zero
    [root@centos65 ~]# cp    /dev/zero   /mnt/sdb2  -p
    ^C
    [root@centos65 ~]# ll  /dev/zero 
    crw-rw-rw-. 1 root root 1, 5 Feb  1 19:55 /dev/zero
    [root@centos65 ~]# ll   /mnt/sdb2
    total 203204
    -rwxr-xr-x. 1 root root         9 Mar  2 11:16 f1.sh
    drwx------. 2 root root     16384 Feb 26 11:25 lost+found
    -rw-r--r--. 1 root root         5 Mar  2 10:30 sdb2file
    -rw-------. 1 root root 208056320 Mar  2 11:27 zero
    [root@centos65 ~]# cp    /dev/zero   /mnt/sdb2  -a
    cp: overwrite `/mnt/sdb2/zero'? y
    [root@centos65 ~]# ll   /mnt/sdb2
    total 24
    -rwxr-xr-x. 1 root root     9 Mar  2 11:16 f1.sh
    drwx------. 2 root root 16384 Feb 26 11:25 lost+found
    -rw-r--r--. 1 root root     5 Mar  2 10:30 sdb2file
    crw-rw-rw-. 1 root root  1, 5 Feb  1 19:55 zero

    使用设备文件

    [root@centos65 ~]# dd  if=/mnt/sdb2/zero  of=/app/f1  bs=1M  count=10
    10+0 records in
    10+0 records out
    10485760 bytes (10 MB) copied, 0.00955517 s, 1.1 GB/s
    [root@centos65 ~]# ll  /app/f1 
    -rw-r--r--. 1 root root 10485760 Mar  2 11:29 /app/f1
    [root@centos65 ~]# file  /mnt/sdb2/zero   /dev/zero 
    /mnt/sdb2/zero: character special
    /dev/zero:      character special

    禁用设备文件的使用

    注意最好是复制前面内容的最后部分,这样不容易出错。而如果不是使用同一个终端就更要注意了。

    [root@centos65 ~]# file  /mnt/sdb2/zero   /dev/zero 
    /mnt/sdb2/zero: character special
    /dev/zero:      character special
    [root@centos65 ~]# mount   -o    remount,nodev    /mnt/sdb2
    [root@centos65 ~]# mount
    /dev/sda2 on / type ext4 (rw)
    proc on /proc type proc (rw)
    sysfs on /sys type sysfs (rw)
    devpts on /dev/pts type devpts (rw,gid=5,mode=620)
    tmpfs on /dev/shm type tmpfs (rw,rootcontext="system_u:object_r:tmpfs_t:s0")
    /dev/sda3 on /app type ext4 (rw)
    /dev/sda1 on /boot type ext4 (rw)
    /dev/sr0 on /media type iso9660 (ro)
    none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
    /dev/sdb2 on /mnt/sdb2 type ext4 (rw,nodev,noatime)
    [root@centos65 ~]# df
    Filesystem     1K-blocks    Used Available Use% Mounted on
    /dev/sda2       50264772 1549904  46154868   4% /
    tmpfs             502068       0    502068   0% /dev/shm
    /dev/sda3       20027260   55236  18948024   1% /app
    /dev/sda1         999320   30492    916400   4% /boot
    /dev/sr0         3824484 3824484         0 100% /media
    /dev/sdb2        5039624   10272   4766692   1% /mnt/sdb2
    [root@centos65 ~]# dd  if=/mnt/sdb2/zero  of=/app/f2  bs=1M  count=10
    dd: opening `/mnt/sdb2/zero': Permission denied
    [root@centos65 ~]# ll  /mnt/sdb2/zero 
    crw-rw-rw-. 1 root root 1, 5 Feb  1 19:55 /mnt/sdb2/zero

    suid/nosuid:是否支持suid和sgid权限

    [root@centos65 ~]# ll  /mnt/sdb2/zero 
    crw-rw-rw-. 1 root root 1, 5 Feb  1 19:55 /mnt/sdb2/zero
    [root@centos65 ~]# cp   -p  /bin/vi    /mnt/sdb2
    [root@centos65 ~]# ll  /mnt/sdb2
    total 916
    -rwxr-xr-x. 1 root root      9 Mar  2 11:16 f1.sh
    drwx------. 2 root root  16384 Feb 26 11:25 lost+found
    -rw-r--r--. 1 root root      5 Mar  2 10:30 sdb2file
    -rwxr-xr-x. 1 root root 913080 Jul 24  2015 vi
    crw-rw-rw-. 1 root root   1, 5 Feb  1 19:55 zero
    [root@centos65 ~]# chmod   u+s    /mnt/sdb2/vi 
    [root@centos65 ~]# ll  /mnt/sdb2
    total 916
    -rwxr-xr-x. 1 root root      9 Mar  2 11:16 f1.sh
    drwx------. 2 root root  16384 Feb 26 11:25 lost+found
    -rw-r--r--. 1 root root      5 Mar  2 10:30 sdb2file
    -rwsr-xr-x. 1 root root 913080 Jul 24  2015 vi
    crw-rw-rw-. 1 root root   1, 5 Feb  1 19:55 zero
    [root@centos65 ~]# su  -  wang
    [wang@centos65 ~]$ /mnt/sdb2/vi   /etc/shadow
    [wang@centos65 ~]$ pwd
    /home/wang
    [wang@centos65 ~]$ exit 
    logout

    为了安全可以禁止普通用户具有s权限

    [wang@centos65 ~]$ pwd
    /home/wang
    [wang@centos65 ~]$ exit 
    logout
    [root@centos65 ~]# mount
    /dev/sda2 on / type ext4 (rw)
    proc on /proc type proc (rw)
    sysfs on /sys type sysfs (rw)
    devpts on /dev/pts type devpts (rw,gid=5,mode=620)
    tmpfs on /dev/shm type tmpfs (rw,rootcontext="system_u:object_r:tmpfs_t:s0")
    /dev/sda3 on /app type ext4 (rw)
    /dev/sda1 on /boot type ext4 (rw)
    /dev/sr0 on /media type iso9660 (ro)
    none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
    /dev/sdb2 on /mnt/sdb2 type ext4 (rw,nodev,noatime)
    [root@centos65 ~]# mount  -o   remount,nosuid     /mnt/sdb2
    [root@centos65 ~]# mount
    /dev/sda2 on / type ext4 (rw)
    proc on /proc type proc (rw)
    sysfs on /sys type sysfs (rw)
    devpts on /dev/pts type devpts (rw,gid=5,mode=620)
    tmpfs on /dev/shm type tmpfs (rw,rootcontext="system_u:object_r:tmpfs_t:s0")
    /dev/sda3 on /app type ext4 (rw)
    /dev/sda1 on /boot type ext4 (rw)
    /dev/sr0 on /media type iso9660 (ro)
    none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
    /dev/sdb2 on /mnt/sdb2 type ext4 (rw,nosuid,nodev,noatime)
    [root@centos65 ~]# id  wang
    uid=500(wang) gid=500(wang) groups=500(wang)
    [root@centos65 ~]# su  -  wang
    [wang@centos65 ~]$ /mnt/sdb2/vi   /etc/shadow
    [wang@centos65 ~]$ ll  /etc/shadow
    ----------. 1 root root 1204 Feb 22 23:17 /etc/shadow
    [wang@centos65 ~]$ ll  /mnt/sdb2/vi 
    -rwsr-xr-x. 1 root root 913080 Jul 24  2015 /mnt/sdb2/vi
    "/etc/shadow" [Permission Denied]

     rw:读写

    [wang@centos65 ~]$ exit 
    logout
    [root@centos65 ~]# mount
    /dev/sda2 on / type ext4 (rw)
    proc on /proc type proc (rw)
    sysfs on /sys type sysfs (rw)
    devpts on /dev/pts type devpts (rw,gid=5,mode=620)
    tmpfs on /dev/shm type tmpfs (rw,rootcontext="system_u:object_r:tmpfs_t:s0")
    /dev/sda3 on /app type ext4 (rw)
    /dev/sda1 on /boot type ext4 (rw)
    /dev/sr0 on /media type iso9660 (ro)
    none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
    /dev/sdb2 on /mnt/sdb2 type ext4 (rw,nosuid,nodev,noatime)
    [root@centos65 ~]# touch    /mnt/sdb2/f3
    [root@centos65 ~]# ll  /mnt/sdb2
    total 916
    -rwxr-xr-x. 1 root root      9 Mar  2 11:16 f1.sh
    -rw-r--r--. 1 root root      0 Mar  2 11:48 f3
    drwx------. 2 root root  16384 Feb 26 11:25 lost+found
    -rw-r--r--. 1 root root      5 Mar  2 10:30 sdb2file
    -rwsr-xr-x. 1 root root 913080 Jul 24  2015 vi
    crw-rw-rw-. 1 root root   1, 5 Feb  1 19:55 zero

    修改成ro:只读,那么在挂载的目录下就无法创建文件了

    注意在很多情况下是不适合取消挂载再挂载的,使用remount会更好

    [root@centos65 ~]# ll  /mnt/sdb2
    total 916
    -rwxr-xr-x. 1 root root      9 Mar  2 11:16 f1.sh
    -rw-r--r--. 1 root root      0 Mar  2 11:48 f3
    drwx------. 2 root root  16384 Feb 26 11:25 lost+found
    -rw-r--r--. 1 root root      5 Mar  2 10:30 sdb2file
    -rwsr-xr-x. 1 root root 913080 Jul 24  2015 vi
    crw-rw-rw-. 1 root root   1, 5 Feb  1 19:55 zero
    [root@centos65 ~]# mount
    /dev/sda2 on / type ext4 (rw)
    proc on /proc type proc (rw)
    sysfs on /sys type sysfs (rw)
    devpts on /dev/pts type devpts (rw,gid=5,mode=620)
    tmpfs on /dev/shm type tmpfs (rw,rootcontext="system_u:object_r:tmpfs_t:s0")
    /dev/sda3 on /app type ext4 (rw)
    /dev/sda1 on /boot type ext4 (rw)
    /dev/sr0 on /media type iso9660 (ro)
    none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
    /dev/sdb2 on /mnt/sdb2 type ext4 (rw,nosuid,nodev,noatime)
    [root@centos65 ~]# mount   -o     remount,ro   /mnt/sdb2
    [root@centos65 ~]# mount
    /dev/sda2 on / type ext4 (rw)
    proc on /proc type proc (rw)
    sysfs on /sys type sysfs (rw)
    devpts on /dev/pts type devpts (rw,gid=5,mode=620)
    tmpfs on /dev/shm type tmpfs (rw,rootcontext="system_u:object_r:tmpfs_t:s0")
    /dev/sda3 on /app type ext4 (rw)
    /dev/sda1 on /boot type ext4 (rw)
    /dev/sr0 on /media type iso9660 (ro)
    none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
    /dev/sdb2 on /mnt/sdb2 type ext4 (ro,nosuid,nodev,noatime)
    [root@centos65 ~]# touch    /mnt/sdb2/aaaaaa
    touch: cannot touch `/mnt/sdb2/aaaaaa': Read-only file system
    [root@centos65 ~]# ls  /mnt/sdb2
    f1.sh  f3  lost+found  sdb2file  vi  zero
    [root@centos65 ~]# mount   -o     remount,rw   /mnt/sdb2
    [root@centos65 ~]# mount
    /dev/sda2 on / type ext4 (rw)
    proc on /proc type proc (rw)
    sysfs on /sys type sysfs (rw)
    devpts on /dev/pts type devpts (rw,gid=5,mode=620)
    tmpfs on /dev/shm type tmpfs (rw,rootcontext="system_u:object_r:tmpfs_t:s0")
    /dev/sda3 on /app type ext4 (rw)
    /dev/sda1 on /boot type ext4 (rw)
    /dev/sr0 on /media type iso9660 (ro)
    none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
    /dev/sdb2 on /mnt/sdb2 type ext4 (rw,nosuid,nodev,noatime)
    [root@centos65 ~]# touch    /mnt/sdb2/aaaaaa
    [root@centos65 ~]# ls  /mnt/sdb2
    aaaaaa  f1.sh  f3  lost+found  sdb2file  vi  zero

    修改成只读的即时生效。注意看进程号就是在不同的终端了。

    而使用umount就不能卸载了

    [root@centos65 ~]# ls  /mnt/sdb2
    aaaaaa  f1.sh  f3  lost+found  sdb2file  vi  zero
    [root@centos65 ~]# umount  /app 
    umount: /app: device is busy.
            (In some cases useful info about processes that use
             the device is found by lsof(8) or fuser(1))
    [root@centos65 ~]# mount
    /dev/sda2 on / type ext4 (rw)
    proc on /proc type proc (rw)
    sysfs on /sys type sysfs (rw)
    devpts on /dev/pts type devpts (rw,gid=5,mode=620)
    tmpfs on /dev/shm type tmpfs (rw,rootcontext="system_u:object_r:tmpfs_t:s0")
    /dev/sda3 on /app type ext4 (rw)
    /dev/sda1 on /boot type ext4 (rw)
    /dev/sr0 on /media type iso9660 (ro)
    none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
    /dev/sdb2 on /mnt/sdb2 type ext4 (rw,nosuid,nodev,noatime)
    [root@centos65 ~]# mount  -o  remount,ro   /app 
    [root@centos65 ~]# mount
    /dev/sda2 on / type ext4 (rw)
    proc on /proc type proc (rw)
    sysfs on /sys type sysfs (rw)
    devpts on /dev/pts type devpts (rw,gid=5,mode=620)
    tmpfs on /dev/shm type tmpfs (rw,rootcontext="system_u:object_r:tmpfs_t:s0")
    /dev/sda3 on /app type ext4 (ro)
    /dev/sda1 on /boot type ext4 (rw)
    /dev/sr0 on /media type iso9660 (ro)
    none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
    /dev/sdb2 on /mnt/sdb2 type ext4 (rw,nosuid,nodev,noatime)
    [root@centos65 ~]# echo $$
    11279

    修改成只读的就不能创建文件了

    [root@centos65 ~]# cd   /app/
    [root@centos65 app]# w
     12:44:39 up 16:49,  2 users,  load average: 0.30, 0.10, 0.07
    USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT
    root     pts/0    192.168.137.34   10:51    3:02   0.44s  0.44s -bash
    root     pts/1    192.168.137.34   12:44    0.00s  0.15s  0.06s w
    [root@centos65 app]# touch   xxxxxxx
    [root@centos65 app]# ll
    total 10260
    -rw-r--r--. 1 root root 10485760 Mar  2 11:29 f1
    drwx------. 2 root root    16384 Jan 23 16:50 lost+found
    drwxr-xr-x. 2 root root     4096 Mar  1 23:18 sdb2
    -rw-r--r--. 1 root root        0 Mar  2 12:46 xxxxxxx
    [root@centos65 app]# touch   yyyyyyy
    touch: cannot touch `yyyyyyy': Read-only file system
    [root@centos65 app]# ll
    total 10260
    -rw-r--r--. 1 root root 10485760 Mar  2 11:29 f1
    drwx------. 2 root root    16384 Jan 23 16:50 lost+found
    drwxr-xr-x. 2 root root     4096 Mar  1 23:18 sdb2
    -rw-r--r--. 1 root root        0 Mar  2 12:46 xxxxxxx
    [root@centos65 app]# echo $$
    13124

    注意/是不能卸载的,因为已经登录到了/下面了

    问题/和进程的关系?

    [root@centos65 ~]# umount  /
    umount: /: device is busy.
            (In some cases useful info about processes that use
             the device is found by lsof(8) or fuser(1))
    [root@centos65 ~]# pwd
    /root

    acl:启用此文件系统上的acl功能

     Default mount options: (none) 就是在挂载设备的时候什么选项都没有加。

    Filesystem state: clean

    [root@centos65 ~]# tune2fs   -l  /dev/sdb2
    tune2fs 1.41.12 (17-May-2010)
    Filesystem volume name:   /mnt/sdb2
    Last mounted on:          /mnt/sdb2
    Filesystem UUID:          b5e3fb3c-48be-49ff-b610-2b244d18639c
    Filesystem magic number:  0xEF53
    Filesystem revision #:    1 (dynamic)
    Filesystem features:      has_journal ext_attr resize_inode dir_index filetype needs_recovery extent flex_bg sparse_super large_file huge_file uninit_bg dir_nlink extra_isize
    Filesystem flags:         signed_directory_hash 
    Default mount options:    (none)  就是在挂载设备的时候什么选项都没有加。
    Filesystem state:         clean
    Errors behavior:          Continue
    Filesystem OS type:       Linux
    Inode count:              328656
    Block count:              1313313
    Reserved block count:     65665
    Free blocks:              1257115
    Free inodes:              328640
    First block:              0
    Block size:               4096
    Fragment size:            4096
    Reserved GDT blocks:      320
    Blocks per group:         32768
    Fragments per group:      32768
    Inodes per group:         8016
    Inode blocks per group:   501
    Flex block group size:    16
    Filesystem created:       Tue Feb 26 11:25:47 2019
    Last mount time:          Sat Mar  2 12:41:22 2019
    Last write time:          Sat Mar  2 10:54:18 2019
    Mount count:              13
    Maximum mount count:      22
    Last checked:             Tue Feb 26 11:25:47 2019
    Check interval:           15552000 (6 months)
    Next check after:         Sun Aug 25 11:25:47 2019
    Lifetime writes:          410 MB
    Reserved blocks uid:      0 (user root)
    Reserved blocks gid:      0 (group root)
    First inode:              11
    Inode size:              256
    Required extra isize:     28
    Desired extra isize:      28
    Journal inode:            8
    Default directory hash:   half_md4
    Directory Hash Seed:      924e4b78-8f91-46e4-850e-55996338052f
    Journal backup:           inode blocks

    现在不支持acl功能

    [root@centos65 ~]# mount
    /dev/sda2 on / type ext4 (rw)
    proc on /proc type proc (rw)
    sysfs on /sys type sysfs (rw)
    devpts on /dev/pts type devpts (rw,gid=5,mode=620)
    tmpfs on /dev/shm type tmpfs (rw,rootcontext="system_u:object_r:tmpfs_t:s0")
    /dev/sda3 on /app type ext4 (ro)
    /dev/sda1 on /boot type ext4 (rw)
    /dev/sr0 on /media type iso9660 (ro)
    none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
    /dev/sdb2 on /mnt/sdb2 type ext4 (rw,nosuid,nodev,noatime)
    [root@centos65 ~]# cd  /mnt/sdb2
    [root@centos65 sdb2]# ls
    aaaaaa  f1.sh  f3  lost+found  sdb2file  vi  zero
    [root@centos65 sdb2]# setfa  -m   u:wang:w  f3
    setfacl   setfattr  
    [root@centos65 sdb2]# setfacl    -m   u:wang:w  f3
    setfacl: f3: Operation not supported
    [root@centos65 sdb2]# getfacl   f3
    # file: f3
    # owner: root
    # group: root
    user::rw-
    group::r--
    other::r--

    设置acl功能,方法有2

    法1:

    不能使用remount,只能先卸载再挂载

    [root@centos65 sdb2]# tune2fs    -o  acl     /dev/sdb2
    tune2fs 1.41.12 (17-May-2010)
    [root@centos65 sdb2]# tune2fs   /dev/sdb2   -l
    tune2fs 1.41.12 (17-May-2010)
    Filesystem volume name:   /mnt/sdb2
    Last mounted on:          /mnt/sdb2
    Filesystem UUID:          b5e3fb3c-48be-49ff-b610-2b244d18639c
    Filesystem magic number:  0xEF53
    Filesystem revision #:    1 (dynamic)
    Filesystem features:      has_journal ext_attr resize_inode dir_index filetype needs_recovery extent flex_bg sparse_super large_file huge_file uninit_bg dir_nlink extra_isize
    Filesystem flags:         signed_directory_hash 
    Default mount options:    acl
    Filesystem state:         clean
    Errors behavior:          Continue
    Filesystem OS type:       Linux
    Inode count:              328656
    Block count:              1313313
    Reserved block count:     65665
    Free blocks:              1257115
    Free inodes:              328640
    First block:              0
    Block size:               4096
    Fragment size:            4096
    Reserved GDT blocks:      320
    Blocks per group:         32768
    Fragments per group:      32768
    Inodes per group:         8016
    Inode blocks per group:   501
    Flex block group size:    16
    Filesystem created:       Tue Feb 26 11:25:47 2019
    Last mount time:          Sat Mar  2 12:41:22 2019
    Last write time:          Sat Mar  2 15:09:38 2019
    Mount count:              13
    Maximum mount count:      22
    Last checked:             Tue Feb 26 11:25:47 2019
    Check interval:           15552000 (6 months)
    Next check after:         Sun Aug 25 11:25:47 2019
    Lifetime writes:          410 MB
    Reserved blocks uid:      0 (user root)
    Reserved blocks gid:      0 (group root)
    First inode:              11
    Inode size:              256
    Required extra isize:     28
    Desired extra isize:      28
    Journal inode:            8
    Default directory hash:   half_md4
    Directory Hash Seed:      924e4b78-8f91-46e4-850e-55996338052f
    Journal backup:           inode blocks
    [root@centos65 sdb2]# pwd
    /mnt/sdb2
    [root@centos65 sdb2]# !set
    setfacl    -m   u:wang:w  f3
    setfacl: f3: Operation not supported
    [root@centos65 sdb2]# mount   -o     remount   /dev/sdb2   /mnt/sdb2
    [root@centos65 sdb2]# mount
    /dev/sda2 on / type ext4 (rw)
    proc on /proc type proc (rw)
    sysfs on /sys type sysfs (rw)
    devpts on /dev/pts type devpts (rw,gid=5,mode=620)
    tmpfs on /dev/shm type tmpfs (rw,rootcontext="system_u:object_r:tmpfs_t:s0")
    /dev/sda3 on /app type ext4 (ro)
    /dev/sda1 on /boot type ext4 (rw)
    /dev/sr0 on /media type iso9660 (ro)
    none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
    /dev/sdb2 on /mnt/sdb2 type ext4 (rw)
    [root@centos65 sdb2]# !se
    setfacl    -m   u:wang:w  f3
    setfacl: f3: Operation not supported
    [root@centos65 sdb2]# cd
    [root@centos65 ~]# umount   /mnt/sdb2 
    [root@centos65 ~]# mount  /dev/sdb2   /mnt/sdb2
    [root@centos65 ~]# cd    /mnt/sdb2
    [root@centos65 sdb2]# ls
    aaaaaa  f1.sh  f3  lost+found  sdb2file  vi  zero
    [root@centos65 sdb2]# !se
    setfacl    -m   u:wang:w  f3
    [root@centos65 sdb2]# !get
    getfacl   f3
    # file: f3
    # owner: root
    # group: root
    user::rw-
    user:wang:-w-
    group::r--
    mask::rw-
    other::r--

    法2:

    取消acl功能必须要卸载挂载点,现在还是可以支持的,因为之前挂载就支持

    [root@centos65 ~]# tune2fs   -o     ^acl   /dev/sdb2
    tune2fs 1.41.12 (17-May-2010)
    [root@centos65 ~]# tune2fs   -l   /dev/sdb2
    tune2fs 1.41.12 (17-May-2010)
    Filesystem volume name:   /mnt/sdb2
    Last mounted on:          /mnt/sdb2
    Filesystem UUID:          b5e3fb3c-48be-49ff-b610-2b244d18639c
    Filesystem magic number:  0xEF53
    Filesystem revision #:    1 (dynamic)
    Filesystem features:      has_journal ext_attr resize_inode dir_index filetype needs_recovery extent flex_bg sparse_super large_file huge_file uninit_bg dir_nlink extra_isize
    Filesystem flags:         signed_directory_hash 
    Default mount options:    (none)
    Filesystem state:         clean
    Errors behavior:          Continue
    Filesystem OS type:       Linux
    Inode count:              328656
    Block count:              1313313
    Reserved block count:     65665
    Free blocks:              1257115
    Free inodes:              328639
    First block:              0
    Block size:               4096
    Fragment size:            4096
    Reserved GDT blocks:      320
    Blocks per group:         32768
    Fragments per group:      32768
    Inodes per group:         8016
    Inode blocks per group:   501
    Flex block group size:    16
    Filesystem created:       Tue Feb 26 11:25:47 2019
    Last mount time:          Sat Mar  2 15:13:32 2019
    Last write time:          Sat Mar  2 15:16:54 2019
    Mount count:              14
    Maximum mount count:      22
    Last checked:             Tue Feb 26 11:25:47 2019
    Check interval:           15552000 (6 months)
    Next check after:         Sun Aug 25 11:25:47 2019
    Lifetime writes:          410 MB
    Reserved blocks uid:      0 (user root)
    Reserved blocks gid:      0 (group root)
    First inode:              11
    Inode size:              256
    Required extra isize:     28
    Desired extra isize:      28
    Journal inode:            8
    Default directory hash:   half_md4
    Directory Hash Seed:      924e4b78-8f91-46e4-850e-55996338052f
    Journal backup:           inode blocks

    完成这步才完全取消acl功能了

    [root@centos65 ~]# setfacl   -m  u:wang:w   /mnt/sdb2/f
    f1.sh  f3     
    [root@centos65 ~]# setfacl   -m  u:wang:w   /mnt/sdb2/f3
    [root@centos65 ~]# umount  /mnt/sdb2 
    [root@centos65 ~]# mount  /dev/sdb2  /mnt/sdb2
    [root@centos65 ~]# setfacl   -m  u:wang:w   /mnt/sdb2/f3
    setfacl: /mnt/sdb2/f3: Operation not supported

    现在又具有acl功能了。和tune2fs是有区别的,法2acl功能可在mount命令里面显示

    tune2fs的设置是保存在磁盘上面的超级块的,永久生效,重启机器也不会变化,而remount是临时生效。

    就和设置selinux和主机名一样,有临时和永久两种。

    [root@centos65 ~]# setfacl   -m  u:wang:w   /mnt/sdb2/f3
    setfacl: /mnt/sdb2/f3: Operation not supported
    [root@centos65 ~]# mount    -o   remount,acl     /mnt/sdb2
    [root@centos65 ~]# setfacl   -m  u:wang:w   /mnt/sdb2/f3
    [root@centos65 ~]# mount
    /dev/sda2 on / type ext4 (rw)
    proc on /proc type proc (rw)
    sysfs on /sys type sysfs (rw)
    devpts on /dev/pts type devpts (rw,gid=5,mode=620)
    tmpfs on /dev/shm type tmpfs (rw,rootcontext="system_u:object_r:tmpfs_t:s0")
    /dev/sda3 on /app type ext4 (ro)
    /dev/sda1 on /boot type ext4 (rw)
    /dev/sr0 on /media type iso9660 (ro)
    none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
    /dev/sdb2 on /mnt/sdb2 type ext4 (rw,acl)

    取消acl功能

    注意当acl和noacl并存时排在最后面的有效

    /dev/sdb2 on /mnt/sdb2 type ext4 (rw,acl,noacl)

    [root@centos65 ~]# mount    -o   remount,noacl     /mnt/sdb2
    [root@centos65 ~]# mount
    /dev/sda2 on / type ext4 (rw)
    proc on /proc type proc (rw)
    sysfs on /sys type sysfs (rw)
    devpts on /dev/pts type devpts (rw,gid=5,mode=620)
    tmpfs on /dev/shm type tmpfs (rw,rootcontext="system_u:object_r:tmpfs_t:s0")
    /dev/sda3 on /app type ext4 (ro)
    /dev/sda1 on /boot type ext4 (rw)
    /dev/sr0 on /media type iso9660 (ro)
    none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
    /dev/sdb2 on /mnt/sdb2 type ext4 (rw,acl,noacl)
    [root@centos65 ~]#  setfacl   -m  u:wang:w   /mnt/sdb2/f3
    setfacl: /mnt/sdb2/f3: Operation not supported

    注意这个命令的remount设置是临时有效的

    [root@centos65 ~]#  setfacl   -m  u:wang:w   /mnt/sdb2/f3
    setfacl: /mnt/sdb2/f3: Operation not supported
    [root@centos65 ~]# MKE2FS
    -bash: MKE2FS: command not found
    [root@centos65 ~]# man  mount
    [root@centos65 ~]# mount    -o   remount,acl     /mnt/sdb2
    [root@centos65 ~]# mount
    /dev/sda2 on / type ext4 (rw)
    proc on /proc type proc (rw)
    sysfs on /sys type sysfs (rw)
    devpts on /dev/pts type devpts (rw,gid=5,mode=620)
    tmpfs on /dev/shm type tmpfs (rw,rootcontext="system_u:object_r:tmpfs_t:s0")
    /dev/sda3 on /app type ext4 (ro)
    /dev/sda1 on /boot type ext4 (rw)
    /dev/sr0 on /media type iso9660 (ro)
    none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
    /dev/sdb2 on /mnt/sdb2 type ext4 (rw,acl,noacl,acl)
    [root@centos65 ~]#  setfacl   -m  u:wang:w   /mnt/sdb2/f3

    loop: 使用loop设备

    对设备创建分区,创建文件系统并且挂载设备三部曲最终使分区可以使用了。

    在生产中要创建一个分区并且是特殊的文件系统,但是分区都分完了。

    那么可以使用文件来模拟分区

    只要磁盘上还有剩余空间

    [root@centos65 ~]#  setfacl   -m  u:wang:w   /mnt/sdb2/f3
    [root@centos65 ~]# lsblk 
    NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
    sr0     11:0    1  3.7G  0 rom  /media
    sdb      8:16   0  100G  0 disk 
    ├─sdb1   8:17   0    1K  0 part 
    ├─sdb2   8:18   0    5G  0 part /mnt/sdb2
    ├─sdb3   8:19   0    2G  0 part 
    └─sdb5   8:21   0   10G  0 part 
    sdc      8:32   0   80G  0 disk 
    ├─sdc1   8:33   0   10G  0 part 
    └─sdc2   8:34   0    6G  0 part 
    sdd      8:48   0   60G  0 disk 
    sda      8:0    0  200G  0 disk 
    ├─sda1   8:1    0    1G  0 part /boot
    ├─sda2   8:2    0 48.8G  0 part /
    ├─sda3   8:3    0 19.5G  0 part /app
    ├─sda4   8:4    0    1K  0 part 
    ├─sda5   8:5    0    2G  0 part [SWAP]
    └─sda6   8:6    0    1G  0 part 
    [root@centos65 ~]# df
    Filesystem     1K-blocks    Used Available Use% Mounted on
    /dev/sda2       50264772 1550024  46154748   4% /
    tmpfs             502068       0    502068   0% /dev/shm
    /dev/sda3       20027260   55236  18948024   1% /app
    /dev/sda1         999320   30492    916400   4% /boot
    /dev/sr0         3824484 3824484         0 100% /media
    /dev/sdb2        5039624   11168   4765796   1% /mnt/sdb2
    [root@centos65 ~]# cd  /app/
    [root@centos65 app]# ls
    f1  lost+found  sdb2  xxxxxxx
    [root@centos65 app]# mount
    /dev/sda2 on / type ext4 (rw)
    proc on /proc type proc (rw)
    sysfs on /sys type sysfs (rw)
    devpts on /dev/pts type devpts (rw,gid=5,mode=620)
    tmpfs on /dev/shm type tmpfs (rw,rootcontext="system_u:object_r:tmpfs_t:s0")
    /dev/sda3 on /app type ext4 (ro)
    /dev/sda1 on /boot type ext4 (rw)
    /dev/sr0 on /media type iso9660 (ro)
    none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
    /dev/sdb2 on /mnt/sdb2 type ext4 (rw,acl,noacl,acl)
    [root@centos65 app]# pwd
    /app
    [root@centos65 app]# rm   -rf  *
    rm: cannot remove `f1': Read-only file system
    rm: cannot remove `lost+found': Read-only file system
    rm: cannot remove `sdb2': Read-only file system
    rm: cannot remove `xxxxxxx': Read-only file system
    [root@centos65 app]# mount  -o   remount,rw    /app 
    [root@centos65 app]# mount
    /dev/sda2 on / type ext4 (rw)
    proc on /proc type proc (rw)
    sysfs on /sys type sysfs (rw)
    devpts on /dev/pts type devpts (rw,gid=5,mode=620)
    tmpfs on /dev/shm type tmpfs (rw,rootcontext="system_u:object_r:tmpfs_t:s0")
    /dev/sda3 on /app type ext4 (rw)
    /dev/sda1 on /boot type ext4 (rw)
    /dev/sr0 on /media type iso9660 (ro)
    none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
    /dev/sdb2 on /mnt/sdb2 type ext4 (rw,acl,noacl,acl)
    [root@centos65 app]#  rm   -rf  *
    [root@centos65 app]# ls

    使用文件创建分区

    为什么设置的大小不同,创建的时间也会不同

    dd if=/dev/zero of=partfile bs=1G count=1

    dd if=/dev/zero of=partfile bs=1M count=1024

    如果bs是1G,那么dd就会在内存里面开辟1G的内存空间。

    [root@centos65 app]# ls
    [root@centos65 app]# dd   if=/dev/zero  of=partfile    bs=1G  count=1
    1+0 records in
    1+0 records out
    1073741824 bytes (1.1 GB) copied, 140.781 s, 7.6 MB/s
    [root@centos65 app]# dd   if=/dev/zero  of=partfile    bs=1M   count=1024
    1024+0 records in
    1024+0 records out
    1073741824 bytes (1.1 GB) copied, 35.8925 s, 29.9 MB/s
    [root@centos65 app]# ls
    partfile
    [root@centos65 app]# ll
    total 1048580
    -rw-r--r--. 1 root root 1073741824 Mar  2 15:58 partfile
    [root@centos65 app]# ll  -h
    total 1.1G
    -rw-r--r--. 1 root root 1.0G Mar  2 15:58 partfile
    [root@centos65 app]# pwd
    /app

    如果内存里面没有1G的内存空间就要使用到swap

    那么就要在内存和swap之间倒腾,再写到磁盘上。

    [root@centos65 app]# free
                 total       used       free     shared    buffers     cached
    Mem:       1004136     941300      62836          0       2948     788704
    -/+ buffers/cache:     149648     854488
    Swap:      2097148      23884    2073264
    [root@centos65 app]# free  -h
                 total       used       free     shared    buffers     cached
    Mem:          980M       919M        61M         0B       2.9M       770M
    -/+ buffers/cache:       146M       834M
    Swap:         2.0G        23M       2.0G

    而在内存上开辟1M的空间更容易,每次在内存里面占用1M并且直接写入到磁盘,不需要交换分区。

    如果创建几G的空间会报错,因为内存和swap合起来都没有那么大的空间

    注意操作系统也是需要空间的,即使内存有1G也不能全部分配给新的分区?

    [root@centos65 app]# dd   if=/dev/zero  of=partfile    bs=3G  count=1
    dd: memory exhausted
    [root@centos65 app]# df  -h
    Filesystem      Size  Used Avail Use% Mounted on
    /dev/sda2        48G  1.5G   45G   4% /
    tmpfs           491M     0  491M   0% /dev/shm
    /dev/sda3        20G   44M   19G   1% /app
    /dev/sda1       976M   30M  895M   4% /boot
    /dev/sr0        3.7G  3.7G     0 100% /media
    /dev/sdb2       4.9G   11M  4.6G   1% /mnt/sdb2
    [root@centos65 app]# free  -h
                 total       used       free     shared    buffers     cached
    Mem:          980M       140M       840M         0B       2.9M        12M
    -/+ buffers/cache:       124M       855M
    Swap:         2.0G        23M       2.0G

    如果创建几G的空间会报错,因为内存和swap合起来都没有那么大的空间

    注意操作系统也是需要空间的,即使内存有1G也不能全部分配给新的分区?

    [root@centos65 app]# dd   if=/dev/zero  of=partfile    bs=3G  count=1
    dd: memory exhausted
    [root@centos65 app]# df  -h
    Filesystem      Size  Used Avail Use% Mounted on
    /dev/sda2        48G  1.5G   45G   4% /
    tmpfs           491M     0  491M   0% /dev/shm
    /dev/sda3        20G   44M   19G   1% /app
    /dev/sda1       976M   30M  895M   4% /boot
    /dev/sr0        3.7G  3.7G     0 100% /media
    /dev/sdb2       4.9G   11M  4.6G   1% /mnt/sdb2
    [root@centos65 app]# free  -h
                 total       used       free     shared    buffers     cached
    Mem:          980M       140M       840M         0B       2.9M        12M
    -/+ buffers/cache:       124M       855M
    Swap:         2.0G        23M       2.0G

    每次只需要内存3M的空间,写完3M马上写入磁盘,这样就不会占用内存空间了。

    最终我又创建1G的空间了。注意每次创建同名文件时,最后一次创建的生效,和remount,acl是一样的。

    [root@centos65 app]# dd   if=/dev/zero  of=partfile    bs=3M    count=1024
    ^C199+0 records in
    199+0 records out
    625999872 bytes (626 MB) copied, 18.6972 s, 33.5 MB/s
    
    [root@centos65 app]# ll  -h  partfile 
    -rw-r--r--. 1 root root 597M Mar  2 16:21 partfile
    [root@centos65 app]# dd   if=/dev/zero  of=partfile    bs=1.3M    count=1024
    dd: invalid number `1.3M'
    [root@centos65 app]# dd   if=/dev/zero  of=partfile    bs=1M    count=1024
    1024+0 records in
    1024+0 records out
    1073741824 bytes (1.1 GB) copied, 36.4765 s, 29.4 MB/s
    [root@centos65 app]# ll  -h  partfile 
    -rw-r--r--. 1 root root 1.0G Mar  2 16:24 partfile

    创建文件系统

    注意现在是对文件创建文件系统

    [root@centos65 app]# mkfs.ext4     partfile 
    mke2fs 1.41.12 (17-May-2010)
    partfile is not a block special device.
    Proceed anyway? (y,n) y
    Filesystem label=
    OS type: Linux
    Block size=4096 (log=2)
    Fragment size=4096 (log=2)
    Stride=0 blocks, Stripe width=0 blocks
    65536 inodes, 262144 blocks
    13107 blocks (5.00%) reserved for the super user
    First data block=0
    Maximum filesystem blocks=268435456
    8 block groups
    32768 blocks per group, 32768 fragments per group
    8192 inodes per group
    Superblock backups stored on blocks: 
        32768, 98304, 163840, 229376
    
    Writing inode tables: done                            
    Creating journal (8192 blocks): done
    Writing superblocks and filesystem accounting information: done
    
    This filesystem will be automatically checked every 27 mounts or
    180 days, whichever comes first.  Use tune2fs -c or -i to override.

    但是不能设置分区

    [root@centos65 app]# fdisk   partfile 
    Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
    Building a new DOS disklabel with disk identifier 0xbfa49da4.
    Changes will remain in memory only, until you decide to write them.
    After that, of course, the previous content won't be recoverable.
    
    Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
    You must set cylinders.
    You can do this from the extra functions menu.
    
    WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
             switch off the mode (command 'c') and change display units to
             sectors (command 'u').
    
    Command (m for help): n
    You must set cylinders.
    You can do this from the extra functions menu.

    查看创建的文件系统

    [root@centos65 app]# blkid
    /dev/sda1: UUID="6bbd9da4-0c3d-4496-a4b1-44bf79912740" TYPE="ext4" 
    /dev/sda2: UUID="10d2b40d-dcd8-4c16-aa81-511c520213f6" TYPE="ext4" 
    /dev/sda3: UUID="e432b350-a9a6-429b-8f07-592058efc6e2" TYPE="ext4" 
    /dev/sda5: UUID="b25a8a7e-40d8-485b-a5af-1b583698864d" TYPE="swap" 
    /dev/sdb2: UUID="b5e3fb3c-48be-49ff-b610-2b244d18639c" TYPE="ext4" LABEL="/mnt/sdb2" 
    /dev/sdd: UUID="c4a0e490-aa52-4c8b-bcad-b20dd895971d" TYPE="ext4" 
    /dev/sdb3: UUID="bef91525-93b8-48a8-a2af-4ba463dc48ce" SEC_TYPE="ext2" TYPE="ext3" LABEL="/mnt/sdb3" 
    /dev/sdb5: UUID="53bc9bdb-6256-4ad9-bddb-12343a4728fd" SEC_TYPE="ext2" TYPE="ext3" 
    [root@centos65 app]# blkid  partfile 
    partfile: UUID="0aecde22-9f3d-4afc-ac1e-c70153426ec6" TYPE="ext4" 

    可以把创建的文件当做分区使用了,注意没加回环会报错

    因为一般是设备挂载到目录下,而现在是文件挂载到目录下,也就是文件挂载到文件下

    好处就是目录的数据是放到创建的文件里面的,还可以把文件里面的数据拷贝到其他机器上,相当于硬盘。

    [root@centos65 app]# blkid  partfile 
    partfile: UUID="0aecde22-9f3d-4afc-ac1e-c70153426ec6" TYPE="ext4" 
    [root@centos65 app]# mkdir    /mnt/part
    [root@centos65 app]# mount   /app/partfile   /mnt/part/
    mount: /app/partfile is not a block device (maybe try `-o loop'?)
    [root@centos65 app]# mount   /app/partfile   /mnt/part/   -o  loop
    [root@centos65 app]# df  -h
    Filesystem      Size  Used Avail Use% Mounted on
    /dev/sda2        48G  1.5G   45G   4% /
    tmpfs           491M     0  491M   0% /dev/shm
    /dev/sda3        20G  1.1G   18G   6% /app
    /dev/sda1       976M   30M  895M   4% /boot
    /dev/sr0        3.7G  3.7G     0 100% /media
    /dev/sdb2       4.9G   11M  4.6G   1% /mnt/sdb2
    /app/partfile   976M  1.3M  924M   1% /mnt/part
    [root@centos65 app]# cd    /mnt/part/
    [root@centos65 part]# ls
    lost+found
    [root@centos65 part]# cp  /etc/fstab   f1
    [root@centos65 part]# cp  /etc/fstab   f2
    [root@centos65 part]# ls
    f1  f2  lost+found

    复制文件数据到其他机器72

    确保机器里面的目录是空目录

    [root@centos72 ~]# ls  /app/
    [root@centos72 ~]# pwd
    /root
    [root@centos72 ~]# ifconfig 
    ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
            inet 192.168.137.72  netmask 255.255.255.0  broadcast 192.168.137.255
            inet6 fe80::b029:2522:876f:5456  prefixlen 64  scopeid 0x20<link>
            ether 00:0c:29:fc:69:f8  txqueuelen 1000  (Ethernet)
            RX packets 5723  bytes 526787 (514.4 KiB)
            RX errors 0  dropped 0  overruns 0  frame 0
            TX packets 933  bytes 61422 (59.9 KiB)
            TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
    
    lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
            inet 127.0.0.1  netmask 255.0.0.0
            inet6 ::1  prefixlen 128  scopeid 0x10<host>
            loop  txqueuelen 1000  (Local Loopback)
            RX packets 0  bytes 0 (0.0 B)
            RX errors 0  dropped 0  overruns 0  frame 0
            TX packets 0  bytes 0 (0.0 B)
            TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
    [root@centos65 part]# ll    -h
    total 24K
    -rw-r--r--. 1 root root 944 Mar  2 16:46 f1
    -rw-r--r--. 1 root root 944 Mar  2 16:47 f2
    drwx------. 2 root root 16K Mar  2 16:37 lost+found
    [root@centos65 part]# ll  /app/partfile 
    -rw-r--r--. 1 root root 1073741824 Mar  2 16:48 /app/partfile
    [root@centos65 part]# ll  /app/partfile   -h
    -rw-r--r--. 1 root root 1.0G Mar  2 16:48 /app/partfile
    [root@centos65 part]# scp  /app/partfile   192.168.137.72:/app
    The authenticity of host '192.168.137.72 (192.168.137.72)' can't be established.
    RSA key fingerprint is 4f:e5:d1:05:5b:d2:ed:f6:12:f3:96:80:1c:cc:e9:d8.
    Are you sure you want to continue connecting (yes/no)? y
    Please type 'yes' or 'no': yes
    Warning: Permanently added '192.168.137.72' (RSA) to the list of known hosts.
    root@192.168.137.72's password: 
    partfile                                                                                            100% 1024MB   8.7MB/s   01:58    

    拷贝到另外一台主机上了

    [root@centos72 ~]# ll  /app/  -h
    total 1.0G
    -rw-r--r--. 1 root root 1.0G Mar  2 17:12 partfile
    [root@centos72 ~]# blkid   /app/partfile
    /app/partfile: UUID="0aecde22-9f3d-4afc-ac1e-c70153426ec6" TYPE="ext4" 
    [root@centos72 ~]# blkid
    /app/partfile: UUID="0aecde22-9f3d-4afc-ac1e-c70153426ec6" TYPE="ext4" 
    /dev/sdb1: UUID="7462ebb5-e37a-4b4e-a0d3-17253ce91ec2" TYPE="ext4" 
    /dev/sdb2: UUID="f20ffdda-3b71-4b27-8cca-4f049549fa6a" TYPE="xfs" 
    /dev/sda1: UUID="92886c3f-42a3-40f4-8cf7-c6890ca3a52e" TYPE="xfs" 
    /dev/sda2: UUID="5998ead0-b370-4859-9153-ecf4e2b9dd84" TYPE="xfs" 
    /dev/sda3: UUID="ac6bb7e3-fa78-4eb2-b00d-e85c421c1bb0" TYPE="xfs" 
    /dev/sda5: UUID="104520e1-0e97-4248-8fd0-a21e7d88a881" TYPE="swap" 
    /dev/sr0: UUID="2018-05-03-20-55-23-00" LABEL="CentOS 7 x86_64" TYPE="iso9660" PTTYPE="dos" 

    把文件挂载到72的空目录下

    注意在7上挂载是不需要指定-o

    [root@centos72 ~]# df
    Filesystem     1K-blocks    Used Available Use% Mounted on
    /dev/sda2       52403200 1122128  51281072   3% /
    devtmpfs          487952       0    487952   0% /dev
    tmpfs             498976       0    498976   0% /dev/shm
    tmpfs             498976    7836    491140   2% /run
    tmpfs             498976       0    498976   0% /sys/fs/cgroup
    /dev/sr0         4364408 4364408         0 100% /mnt
    /dev/sda3       20961280 1081520  19879760   6% /app
    /dev/sda1        1038336  126596    911740  13% /boot
    tmpfs              99796       0     99796   0% /run/user/0
    [root@centos72 ~]# ls  /media/
    [root@centos72 ~]# mount  /app/partfile    /media/
    [root@centos72 ~]# df
    Filesystem     1K-blocks    Used Available Use% Mounted on
    /dev/sda2       52403200 1122128  51281072   3% /
    devtmpfs          487952       0    487952   0% /dev
    tmpfs             498976       0    498976   0% /dev/shm
    tmpfs             498976    7840    491136   2% /run
    tmpfs             498976       0    498976   0% /sys/fs/cgroup
    /dev/sr0         4364408 4364408         0 100% /mnt
    /dev/sda3       20961280 1081520  19879760   6% /app
    /dev/sda1        1038336  126596    911740  13% /boot
    tmpfs              99796       0     99796   0% /run/user/0
    /dev/loop0        999320    1292    929216   1% /media
    [root@centos72 ~]# cd  /media/
    [root@centos72 media]# ls
    f1  f2  lost+found
    [root@centos72 media]# mount
    sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime,seclabel)
    proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
    devtmpfs on /dev type devtmpfs (rw,nosuid,seclabel,size=487952k,nr_inodes=121988,mode=755)
    securityfs on /sys/kernel/security type securityfs (rw,nosuid,nodev,noexec,relatime)
    tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev,seclabel)
    devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,seclabel,gid=5,mode=620,ptmxmode=000)
    tmpfs on /run type tmpfs (rw,nosuid,nodev,seclabel,mode=755)
    tmpfs on /sys/fs/cgroup type tmpfs (ro,nosuid,nodev,noexec,seclabel,mode=755)
    cgroup on /sys/fs/cgroup/systemd type cgroup (rw,nosuid,nodev,noexec,relatime,seclabel,xattr,release_agent=/usr/lib/systemd/systemd-cgroups-agent,name=systemd)
    pstore on /sys/fs/pstore type pstore (rw,nosuid,nodev,noexec,relatime)
    cgroup on /sys/fs/cgroup/hugetlb type cgroup (rw,nosuid,nodev,noexec,relatime,seclabel,hugetlb)
    cgroup on /sys/fs/cgroup/pids type cgroup (rw,nosuid,nodev,noexec,relatime,seclabel,pids)
    cgroup on /sys/fs/cgroup/memory type cgroup (rw,nosuid,nodev,noexec,relatime,seclabel,memory)
    cgroup on /sys/fs/cgroup/blkio type cgroup (rw,nosuid,nodev,noexec,relatime,seclabel,blkio)
    cgroup on /sys/fs/cgroup/freezer type cgroup (rw,nosuid,nodev,noexec,relatime,seclabel,freezer)
    cgroup on /sys/fs/cgroup/cpuset type cgroup (rw,nosuid,nodev,noexec,relatime,seclabel,cpuset)
    cgroup on /sys/fs/cgroup/devices type cgroup (rw,nosuid,nodev,noexec,relatime,seclabel,devices)
    cgroup on /sys/fs/cgroup/net_cls,net_prio type cgroup (rw,nosuid,nodev,noexec,relatime,seclabel,net_prio,net_cls)
    cgroup on /sys/fs/cgroup/perf_event type cgroup (rw,nosuid,nodev,noexec,relatime,seclabel,perf_event)
    cgroup on /sys/fs/cgroup/cpu,cpuacct type cgroup (rw,nosuid,nodev,noexec,relatime,seclabel,cpuacct,cpu)
    configfs on /sys/kernel/config type configfs (rw,relatime)
    /dev/sda2 on / type xfs (rw,relatime,seclabel,attr2,inode64,noquota)
    selinuxfs on /sys/fs/selinux type selinuxfs (rw,relatime)
    systemd-1 on /proc/sys/fs/binfmt_misc type autofs (rw,relatime,fd=30,pgrp=1,timeout=0,minproto=5,maxproto=5,direct,pipe_ino=13167)
    hugetlbfs on /dev/hugepages type hugetlbfs (rw,relatime,seclabel)
    mqueue on /dev/mqueue type mqueue (rw,relatime,seclabel)
    debugfs on /sys/kernel/debug type debugfs (rw,relatime)
    /dev/sr0 on /mnt type iso9660 (ro,relatime)
    /dev/sda3 on /app type xfs (rw,relatime,seclabel,attr2,inode64,noquota)
    /dev/sda1 on /boot type xfs (rw,relatime,seclabel,attr2,inode64,noquota)
    tmpfs on /run/user/0 type tmpfs (rw,nosuid,nodev,relatime,seclabel,size=99796k,mode=700)
    /app/partfile on /media type ext4 (rw,relatime,seclabel,data=ordered)

    同样的文件挂载到目录下之后显示的内容是有区别的

    把文件挂载到目录下时是变相的使用设备/dev/loop0实现的

    相当于把文件和设备/dev/loop0关联起来了。因为一般是设置挂载到目录下的,关联的设备就好比是桥梁,实现了文件挂载到目录的作用。

    如果是多个文件也使用同样的方法,那么就显示loop1,loop2....,和6上显示的网卡名是一样的。

    [root@centos65 part]# mount
    /dev/sda2 on / type ext4 (rw)
    proc on /proc type proc (rw)
    sysfs on /sys type sysfs (rw)
    devpts on /dev/pts type devpts (rw,gid=5,mode=620)
    tmpfs on /dev/shm type tmpfs (rw,rootcontext="system_u:object_r:tmpfs_t:s0")
    /dev/sda3 on /app type ext4 (rw)
    /dev/sda1 on /boot type ext4 (rw)
    /dev/sr0 on /media type iso9660 (ro)
    none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
    /dev/sdb2 on /mnt/sdb2 type ext4 (rw,acl,noacl,acl)
    /app/partfile on /mnt/part type ext4 (rw,loop=/dev/loop0)

    在6上最多可以挂载8个文件,简称8挂

    [root@centos65 part]# ls    /dev/loop*
    /dev/loop0  /dev/loop1  /dev/loop2  /dev/loop3  /dev/loop4  /dev/loop5  /dev/loop6  /dev/loop7

    在7上也用了,不过现在的是两个loop设备,但是不限制个数,挂载几个就显示几个。

    [root@centos72 media]# df
    Filesystem     1K-blocks    Used Available Use% Mounted on
    /dev/sda2       52403200 1122128  51281072   3% /
    devtmpfs          487952       0    487952   0% /dev
    tmpfs             498976       0    498976   0% /dev/shm
    tmpfs             498976    7840    491136   2% /run
    tmpfs             498976       0    498976   0% /sys/fs/cgroup
    /dev/sr0         4364408 4364408         0 100% /mnt
    /dev/sda3       20961280 1081520  19879760   6% /app
    /dev/sda1        1038336  126596    911740  13% /boot
    tmpfs              99796       0     99796   0% /run/user/0
    /dev/loop0        999320    1292    929216   1% /media
    [root@centos72 media]#  ls    /dev/loop*
    /dev/loop0  /dev/loop-control
    [root@centos72 media]#  ll    /dev/loop*
    brw-rw----. 1 root disk  7,   0 Mar  2 17:33 /dev/loop0
    crw-rw----. 1 root disk 10, 237 Mar  2 17:33 /dev/loop-control

    参考原有的设备创建新的loop设备并且要注意和修改权限和所属组和所有者

    7类型第8个

    [root@centos65 part]# ls    /dev/loop*
    /dev/loop0  /dev/loop1  /dev/loop2  /dev/loop3  /dev/loop4  /dev/loop5  /dev/loop6  /dev/loop7
    [root@centos65 part]#  ll    /dev/loop*
    brw-rw----. 1 root disk 7, 0 Feb  1 19:55 /dev/loop0
    brw-rw----. 1 root disk 7, 1 Feb  1 19:55 /dev/loop1
    brw-rw----. 1 root disk 7, 2 Feb  1 19:55 /dev/loop2
    brw-rw----. 1 root disk 7, 3 Feb  1 19:55 /dev/loop3
    brw-rw----. 1 root disk 7, 4 Feb  1 19:55 /dev/loop4
    brw-rw----. 1 root disk 7, 5 Feb  1 19:55 /dev/loop5
    brw-rw----. 1 root disk 7, 6 Feb  1 19:55 /dev/loop6
    brw-rw----. 1 root disk 7, 7 Feb  1 19:55 /dev/loop7
    [root@centos65 part]# mknod    /dev/lo
    log    loop0  loop1  loop2  loop3  loop4  loop5  loop6  loop7  
    [root@centos65 part]# mknod    /dev/loop8    b  7   8
    [root@centos65 part]#  ll    /dev/loop*
    brw-rw----. 1 root disk 7, 0 Feb  1 19:55 /dev/loop0
    brw-rw----. 1 root disk 7, 1 Feb  1 19:55 /dev/loop1
    brw-rw----. 1 root disk 7, 2 Feb  1 19:55 /dev/loop2
    brw-rw----. 1 root disk 7, 3 Feb  1 19:55 /dev/loop3
    brw-rw----. 1 root disk 7, 4 Feb  1 19:55 /dev/loop4
    brw-rw----. 1 root disk 7, 5 Feb  1 19:55 /dev/loop5
    brw-rw----. 1 root disk 7, 6 Feb  1 19:55 /dev/loop6
    brw-rw----. 1 root disk 7, 7 Feb  1 19:55 /dev/loop7
    brw-r--r--. 1 root root 7, 8 Mar  2 17:31 /dev/loop8
    [root@centos65 part]# chmod   660   /dev/loop8
    [root@centos65 part]#  ll    /dev/loop*
    brw-rw----. 1 root disk 7, 0 Feb  1 19:55 /dev/loop0
    brw-rw----. 1 root disk 7, 1 Feb  1 19:55 /dev/loop1
    brw-rw----. 1 root disk 7, 2 Feb  1 19:55 /dev/loop2
    brw-rw----. 1 root disk 7, 3 Feb  1 19:55 /dev/loop3
    brw-rw----. 1 root disk 7, 4 Feb  1 19:55 /dev/loop4
    brw-rw----. 1 root disk 7, 5 Feb  1 19:55 /dev/loop5
    brw-rw----. 1 root disk 7, 6 Feb  1 19:55 /dev/loop6
    brw-rw----. 1 root disk 7, 7 Feb  1 19:55 /dev/loop7
    brw-rw----. 1 root root 7, 8 Mar  2 17:31 /dev/loop8

    再创建一个文件

    [root@centos65 part]# ls  /app/
    partfile
    [root@centos65 part]# dd  if=/dev/zero  of=/app/partfile2     bs=1M  count=100
    100+0 records in
    100+0 records out
    104857600 bytes (105 MB) copied, 0.341661 s, 307 MB/s
    [root@centos65 part]# mkfs.ext4  /app/partfile2
    mke2fs 1.41.12 (17-May-2010)
    /app/partfile2 is not a block special device.
    Proceed anyway? (y,n) y
    Filesystem label=
    OS type: Linux
    Block size=1024 (log=0)
    Fragment size=1024 (log=0)
    Stride=0 blocks, Stripe width=0 blocks
    25688 inodes, 102400 blocks
    5120 blocks (5.00%) reserved for the super user
    First data block=1
    Maximum filesystem blocks=67371008
    13 block groups
    8192 blocks per group, 8192 fragments per group
    1976 inodes per group
    Superblock backups stored on blocks: 
        8193, 24577, 40961, 57345, 73729
    
    Writing inode tables: done                            
    Creating journal (4096 blocks): done
    Writing superblocks and filesystem accounting information: done
    
    This filesystem will be automatically checked every 24 mounts or
    180 days, whichever comes first.  Use tune2fs -c or -i to override.
    [root@centos65 part]# blkid
    /dev/sda1: UUID="6bbd9da4-0c3d-4496-a4b1-44bf79912740" TYPE="ext4" 
    /dev/sda2: UUID="10d2b40d-dcd8-4c16-aa81-511c520213f6" TYPE="ext4" 
    /dev/sda3: UUID="e432b350-a9a6-429b-8f07-592058efc6e2" TYPE="ext4" 
    /dev/sda5: UUID="b25a8a7e-40d8-485b-a5af-1b583698864d" TYPE="swap" 
    /dev/sdb2: UUID="b5e3fb3c-48be-49ff-b610-2b244d18639c" TYPE="ext4" LABEL="/mnt/sdb2" 
    /dev/sdd: UUID="c4a0e490-aa52-4c8b-bcad-b20dd895971d" TYPE="ext4" 
    /dev/sdb3: UUID="bef91525-93b8-48a8-a2af-4ba463dc48ce" SEC_TYPE="ext2" TYPE="ext3" LABEL="/mnt/sdb3" 
    /dev/sdb5: UUID="53bc9bdb-6256-4ad9-bddb-12343a4728fd" SEC_TYPE="ext2" TYPE="ext3" 
    /dev/loop0: UUID="0aecde22-9f3d-4afc-ac1e-c70153426ec6" TYPE="ext4" 
    [root@centos65 part]# blkid  /app/partfile2
    /app/partfile2: UUID="ea8b7466-ef6c-4a21-88d6-dc48b07297ec" TYPE="ext4" 
    [root@centos65 part]# blkid
    /dev/sda1: UUID="6bbd9da4-0c3d-4496-a4b1-44bf79912740" TYPE="ext4" 
    /dev/sda2: UUID="10d2b40d-dcd8-4c16-aa81-511c520213f6" TYPE="ext4" 
    /dev/sda3: UUID="e432b350-a9a6-429b-8f07-592058efc6e2" TYPE="ext4" 
    /dev/sda5: UUID="b25a8a7e-40d8-485b-a5af-1b583698864d" TYPE="swap" 
    /dev/sdb2: UUID="b5e3fb3c-48be-49ff-b610-2b244d18639c" TYPE="ext4" LABEL="/mnt/sdb2" 
    /dev/sdd: UUID="c4a0e490-aa52-4c8b-bcad-b20dd895971d" TYPE="ext4" 
    /dev/sdb3: UUID="bef91525-93b8-48a8-a2af-4ba463dc48ce" SEC_TYPE="ext2" TYPE="ext3" LABEL="/mnt/sdb3" 
    /dev/sdb5: UUID="53bc9bdb-6256-4ad9-bddb-12343a4728fd" SEC_TYPE="ext2" TYPE="ext3" 
    /dev/loop0: UUID="0aecde22-9f3d-4afc-ac1e-c70153426ec6" TYPE="ext4" 
    /app/partfile2: UUID="ea8b7466-ef6c-4a21-88d6-dc48b07297ec" TYPE="ext4" 

    不可能是磁盘上挨个查找文件系统,要先使用blikid  指定特定的文件系统再次查看才会出现

    [root@centos65 part]# blkid
    /dev/sda1: UUID="6bbd9da4-0c3d-4496-a4b1-44bf79912740" TYPE="ext4" 
    /dev/sda2: UUID="10d2b40d-dcd8-4c16-aa81-511c520213f6" TYPE="ext4" 
    /dev/sda3: UUID="e432b350-a9a6-429b-8f07-592058efc6e2" TYPE="ext4" 
    /dev/sda5: UUID="b25a8a7e-40d8-485b-a5af-1b583698864d" TYPE="swap" 
    /dev/sdb2: UUID="b5e3fb3c-48be-49ff-b610-2b244d18639c" TYPE="ext4" LABEL="/mnt/sdb2" 
    /dev/sdd: UUID="c4a0e490-aa52-4c8b-bcad-b20dd895971d" TYPE="ext4" 
    /dev/sdb3: UUID="bef91525-93b8-48a8-a2af-4ba463dc48ce" SEC_TYPE="ext2" TYPE="ext3" LABEL="/mnt/sdb3" 
    /dev/sdb5: UUID="53bc9bdb-6256-4ad9-bddb-12343a4728fd" SEC_TYPE="ext2" TYPE="ext3" 
    /dev/loop0: UUID="0aecde22-9f3d-4afc-ac1e-c70153426ec6" TYPE="ext4" 

    把新创建的文件挂载到目录下

    [root@centos65 part]# df
    Filesystem     1K-blocks    Used Available Use% Mounted on
    /dev/sda2       50264772 1550060  46154712   4% /
    tmpfs             502068       0    502068   0% /dev/shm
    /dev/sda3       20027260 1195956  17807304   7% /app
    /dev/sda1         999320   30492    916400   4% /boot
    /dev/sr0         3824484 3824484         0 100% /media
    /dev/sdb2        5039624   11168   4765796   1% /mnt/sdb2
    /app/partfile     999320    1292    945600   1% /mnt/part
    [root@centos65 part]# mkdir  /mnt/part2
    [root@centos65 part]# mount  /app/partfile  /mnt/part2    -o  loop  
    [root@centos65 part]# mount
    /dev/sda2 on / type ext4 (rw)
    proc on /proc type proc (rw)
    sysfs on /sys type sysfs (rw)
    devpts on /dev/pts type devpts (rw,gid=5,mode=620)
    tmpfs on /dev/shm type tmpfs (rw,rootcontext="system_u:object_r:tmpfs_t:s0")
    /dev/sda3 on /app type ext4 (rw)
    /dev/sda1 on /boot type ext4 (rw)
    /dev/sr0 on /media type iso9660 (ro)
    none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
    /dev/sdb2 on /mnt/sdb2 type ext4 (rw,acl,noacl,acl)
    /app/partfile on /mnt/part type ext4 (rw,loop=/dev/loop0)
    /app/partfile2 on /mnt/part2 type ext4 (rw,loop=/dev/loop1)

    不挂载到loop1上,要先卸载,人为的关联到loop8上

    [root@centos65 part]# umount  /mnt/part2
    [root@centos65 part]# df
    Filesystem     1K-blocks    Used Available Use% Mounted on
    /dev/sda2       50264772 1550064  46154708   4% /
    tmpfs             502068       0    502068   0% /dev/shm
    /dev/sda3       20027260 1195956  17807304   7% /app
    /dev/sda1         999320   30492    916400   4% /boot
    /dev/sr0         3824484 3824484         0 100% /media
    /dev/sdb2        5039624   11168   4765796   1% /mnt/sdb2
    /app/partfile     999320    1292    945600   1% /mnt/part
    [root@centos65 part]# ls  /dev/loop*
    /dev/loop0  /dev/loop1  /dev/loop2  /dev/loop3  /dev/loop4  /dev/loop5  /dev/loop6  /dev/loop7  /dev/loop8
    [root@centos65 part]# losetup  /dev/loop8    /app/partfile2
    [root@centos65 part]# mount   /dev/loop8   /mnt/part2
    [root@centos65 part]# df
    Filesystem     1K-blocks    Used Available Use% Mounted on
    /dev/sda2       50264772 1550064  46154708   4% /
    tmpfs             502068       0    502068   0% /dev/shm
    /dev/sda3       20027260 1195956  17807304   7% /app
    /dev/sda1         999320   30492    916400   4% /boot
    /dev/sr0         3824484 3824484         0 100% /media
    /dev/sdb2        5039624   11168   4765796   1% /mnt/sdb2
    /app/partfile     999320    1292    945600   1% /mnt/part
    /dev/loop8         95054    1550     88384   2% /mnt/part2
    [root@centos65 part]# cd  /mnt/part2
    [root@centos65 part2]# ls
    lost+found

    显示所有的回环设备和文件的对应关系

    注意在6上要加选项a

    [root@centos65 part2]# losetup  -a
    /dev/loop0: [0803]:11 (/app/partfile)
    /dev/loop8: [0803]:12 (/app/partfile2)

    在7上直接使用目录即可

    [root@centos72 media]# losetup 
    NAME       SIZELIMIT OFFSET AUTOCLEAR RO BACK-FILE
    /dev/loop0         0      0         1  0 /app/partfile
    [root@centos72 media]# losetup   -a
    /dev/loop0: [2051]:67 (/app/partfile)

    回环设备loop8是使用mklod命令创建的,当机器重启之后就会丢失了

    [root@centos65 ~]# ll  /dev/loop*
    brw-rw----. 1 root disk 7, 0 Mar  2 17:56 /dev/loop0
    brw-rw----. 1 root disk 7, 1 Mar  2 17:56 /dev/loop1
    brw-rw----. 1 root disk 7, 2 Mar  2 17:56 /dev/loop2
    brw-rw----. 1 root disk 7, 3 Mar  2 17:56 /dev/loop3
    brw-rw----. 1 root disk 7, 4 Mar  2 17:56 /dev/loop4
    brw-rw----. 1 root disk 7, 5 Mar  2 17:56 /dev/loop5
    brw-rw----. 1 root disk 7, 6 Mar  2 17:56 /dev/loop6
    brw-rw----. 1 root disk 7, 7 Mar  2 17:56 /dev/loop7
    [root@centos65 ~]# ls  /dev/loop*
    /dev/loop0  /dev/loop1  /dev/loop2  /dev/loop3  /dev/loop4  /dev/loop5  /dev/loop6  /dev/loop7

    如果要使用更多的回环设备,8个以上,那么就要修改配置文件

    在配置文件里面添加max_loop=100,然后重启

    也就是指定了回环设备的数量

    [root@centos65 ~]# vim  /boot/grub/grub.conf 
    [root@centos65 ~]# cat   /boot/grub/grub.conf 
    # grub.conf generated by anaconda
    #
    # Note that you do not have to rerun grub after making changes to this file
    # NOTICE:  You have a /boot partition.  This means that
    #          all kernel and initrd paths are relative to /boot/, eg.
    #          root (hd0,0)
    #          kernel /vmlinuz-version ro root=/dev/sda2
    #          initrd /initrd-[generic-]version.img
    #boot=/dev/sda
    default=0
    timeout=5
    splashimage=(hd0,0)/grub/splash.xpm.gz
    hiddenmenu
    title CentOS 6 (2.6.32-642.el6.x86_64)
        root (hd0,0)
        kernel /vmlinuz-2.6.32-642.el6.x86_64 ro root=UUID=10d2b40d-dcd8-4c16-aa81-511c520213f6 rd_NO_LUKS rd_NO_LVM LANG=en_US.UTF-8 rd_NO_MD
    SYSFONT=latarcyrheb-sun16 crashkernel=auto KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet max_loop=100 initrd /initramfs-2.6.32-642.el6.x86_64.img [root@centos65 ~]# reboot Broadcast message from root@centos65.jd.com (/dev/pts/0) at 18:01 ... The system is going down for reboot NOW! [root@centos65 ~]# Connection closed by foreign host. Disconnected from remote host(192.168.137.65:22) at 18:19:30. Type `help' to learn how to use Xshell prompt. [c:~]$

    重启之后生成了100个设备文件了。在7上就不需要设置了,因为是按照需要自动生成的

    [root@centos65 ~]# ls  /dev/loop*
    /dev/loop0   /dev/loop18  /dev/loop27  /dev/loop36  /dev/loop45  /dev/loop54  /dev/loop63  /dev/loop72  /dev/loop81  /dev/loop90
    /dev/loop1   /dev/loop19  /dev/loop28  /dev/loop37  /dev/loop46  /dev/loop55  /dev/loop64  /dev/loop73  /dev/loop82  /dev/loop91
    /dev/loop10  /dev/loop2   /dev/loop29  /dev/loop38  /dev/loop47  /dev/loop56  /dev/loop65  /dev/loop74  /dev/loop83  /dev/loop92
    /dev/loop11  /dev/loop20  /dev/loop3   /dev/loop39  /dev/loop48  /dev/loop57  /dev/loop66  /dev/loop75  /dev/loop84  /dev/loop93
    /dev/loop12  /dev/loop21  /dev/loop30  /dev/loop4   /dev/loop49  /dev/loop58  /dev/loop67  /dev/loop76  /dev/loop85  /dev/loop94
    /dev/loop13  /dev/loop22  /dev/loop31  /dev/loop40  /dev/loop5   /dev/loop59  /dev/loop68  /dev/loop77  /dev/loop86  /dev/loop95
    /dev/loop14  /dev/loop23  /dev/loop32  /dev/loop41  /dev/loop50  /dev/loop6   /dev/loop69  /dev/loop78  /dev/loop87  /dev/loop96
    /dev/loop15  /dev/loop24  /dev/loop33  /dev/loop42  /dev/loop51  /dev/loop60  /dev/loop7   /dev/loop79  /dev/loop88  /dev/loop97
    /dev/loop16  /dev/loop25  /dev/loop34  /dev/loop43  /dev/loop52  /dev/loop61  /dev/loop70  /dev/loop8   /dev/loop89  /dev/loop98
    /dev/loop17  /dev/loop26  /dev/loop35  /dev/loop44  /dev/loop53  /dev/loop62  /dev/loop71  /dev/loop80  /dev/loop9   /dev/loop99
    [root@centos65 ~]# ls  /dev/loop -l
    ls: cannot access /dev/loop: No such file or directory
    [root@centos65 ~]# ls  /dev/loop*  -l
    brw-rw----. 1 root disk 7,  0 Mar  2 18:01 /dev/loop0
    brw-rw----. 1 root disk 7,  1 Mar  2 18:01 /dev/loop1
    brw-rw----. 1 root disk 7, 10 Mar  2 18:01 /dev/loop10
    brw-rw----. 1 root disk 7, 11 Mar  2 18:01 /dev/loop11
    brw-rw----. 1 root disk 7, 12 Mar  2 18:01 /dev/loop12
    brw-rw----. 1 root disk 7, 13 Mar  2 18:01 /dev/loop13
    brw-rw----. 1 root disk 7, 14 Mar  2 18:01 /dev/loop14
    brw-rw----. 1 root disk 7, 15 Mar  2 18:01 /dev/loop15
    brw-rw----. 1 root disk 7, 16 Mar  2 18:01 /dev/loop16
    brw-rw----. 1 root disk 7, 17 Mar  2 18:01 /dev/loop17
    brw-rw----. 1 root disk 7, 18 Mar  2 18:01 /dev/loop18
    brw-rw----. 1 root disk 7, 19 Mar  2 18:01 /dev/loop19
    brw-rw----. 1 root disk 7,  2 Mar  2 18:01 /dev/loop2
    brw-rw----. 1 root disk 7, 20 Mar  2 18:01 /dev/loop20
    brw-rw----. 1 root disk 7, 21 Mar  2 18:01 /dev/loop21

    又恢复到原来的设置

    [root@centos65 ~]# vim     /boot/grub/grub.conf 
    [root@centos65 ~]# cat      /boot/grub/grub.conf 
    # grub.conf generated by anaconda
    #
    # Note that you do not have to rerun grub after making changes to this file
    # NOTICE:  You have a /boot partition.  This means that
    #          all kernel and initrd paths are relative to /boot/, eg.
    #          root (hd0,0)
    #          kernel /vmlinuz-version ro root=/dev/sda2
    #          initrd /initrd-[generic-]version.img
    #boot=/dev/sda
    default=0
    timeout=5
    splashimage=(hd0,0)/grub/splash.xpm.gz
    hiddenmenu
    title CentOS 6 (2.6.32-642.el6.x86_64)
        root (hd0,0)
        kernel /vmlinuz-2.6.32-642.el6.x86_64 ro root=UUID=10d2b40d-dcd8-4c16-aa81-511c520213f6 rd_NO_LUKS rd_NO_LVM LANG=en_US.UTF-8 rd_NO_MD SYSFONT=latarcyrheb-sun16 crashkernel=auto  KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet  
        initrd /initramfs-2.6.32-642.el6.x86_64.img
    [root@centos65 ~]# 

    defaults:相当于rw, suid, dev, exec, auto, nouser, async

    [root@centos65 ~]# mount
    /dev/sda2 on / type ext4 (rw)
    proc on /proc type proc (rw)
    sysfs on /sys type sysfs (rw)
    devpts on /dev/pts type devpts (rw,gid=5,mode=620)
    tmpfs on /dev/shm type tmpfs (rw,rootcontext="system_u:object_r:tmpfs_t:s0")
    /dev/sda3 on /app type ext4 (rw)
    /dev/sda1 on /boot type ext4 (rw)
    /dev/sr0 on /media type iso9660 (ro)
    none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)

    注意之前使用mount挂载重启之后全部丢失了

    [root@centos65 ~]# df
    Filesystem     1K-blocks    Used Available Use% Mounted on
    /dev/sda2       50264772 1550336  46154436   4% /
    tmpfs             502068       0    502068   0% /dev/shm
    /dev/sda3       20027260 1195956  17807304   7% /app
    /dev/sda1         999320   30492    916400   4% /boot
    /dev/sr0         3824484 3824484         0 100% /media


    作者:wang618
    出处:https://www.cnblogs.com/wang618/
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文链接,否则保留追究法律责任的权利。

  • 相关阅读:
    线性代数学习笔记(代数版)
    洛谷P2765 魔术球问题(贪心 最大流)
    洛谷P2770 航空路线问题(费用流)
    洛谷P4013 数字梯形问题(费用流)
    洛谷P2774 方格取数问题(最小割)
    洛谷P2761 软件补丁问题(状压DP,SPFA)
    项目mysql数据导入数据的Java程序
    axd与ashx区别
    LD1-K(求差值最小的生成树)
    rabbitMQ入门
  • 原文地址:https://www.cnblogs.com/wang618/p/11158411.html
Copyright © 2020-2023  润新知