8月7日 创建文件系统和挂载

1、同步分区

  • centos6中同步分区
partx -a  /dev/sda ---同步硬盘新增加的分区
parx -d --nr 6 /dev/sda ---同步硬盘新删除的分区
- centos5、7中同步分区
partprobe /dev/sda ---增加和删除分区同步都用这个命令

2、创建文件系统

mke2fs:ext系列文件系统专用管理工具
-t {ext2|ext3|ext4}
-b {1024|2048|4096}
-L 'LABEL'
-j: 相当于-t ext3
mkfs.ext3 = mkfs-t ext3 = mke2fs -j = mke2fs -t ext3
-i#: 为数据空间中每多少个字节创建一个inode;此大小不应该小于block的大小
-N #:指定分区中创建多少个inode
-I 一个inode记录占用的磁盘空间大小,128---4096
-m #: 默认5%,为管理人员预留空间占总空间的百分比
-O FEATURE[,...]:启用指定特性
-O ^FEATURE:关闭指定特性

[root@centos6 ~]#mkfs.ext4 /dev/sdc1
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
1310720 inodes, 5242880 blocks
262144 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
160 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks: 
    32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
    4096000

Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 29 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
[root@centos6 ~]#blkid ---查看文件系统
/dev/sda1: UUID="a056e3b8-7cc2-4aea-9308-9b0744741394" TYPE="ext4" 
/dev/sda2: UUID="07e3094b-c50d-4568-aee5-b2f76d91c962" TYPE="ext4" 
/dev/sda3: UUID="4a2031c3-8595-489e-bc6d-1e2c31860c7b" TYPE="ext4" 
/dev/sda5: UUID="953b7594-f906-4d3e-8a3a-a6bb79b1c900" TYPE="swap" 
/dev/sdc1: UUID="bfde9976-3c32-46f6-90df-62dfb62d7309" TYPE="ext4" 
[root@centos6 ~]#lsblk -f  ---这种方法也可以查看文件系统
NAME   FSTYPE  LABEL            UUID                                 MOUNTPOINT
sr0    iso9660 CentOS_6.9_Final                                      /media/CentOS_6.9_Final
sda                                                                  
├─sda1 ext4                     a056e3b8-7cc2-4aea-9308-9b0744741394 /boot
├─sda2 ext4                     07e3094b-c50d-4568-aee5-b2f76d91c962 /
├─sda3 ext4                     4a2031c3-8595-489e-bc6d-1e2c31860c7b /app
├─sda4                                                               
└─sda5 swap                     953b7594-f906-4d3e-8a3a-a6bb79b1c900 [SWAP]
sdc                                                                  
├─sdc1 ext4                     bfde9976-3c32-46f6-90df-62dfb62d7309 
└─sdc2                                                               
sdd                                                                  
sdb                                                                  
├─sdb1                                                               
├─sdb2                                                               
├─sdb3                                                               
├─sdb4                                                               
└─sdb5  
tune2fs -l /dev/sdc1  ---查看文件系统的超级块信息,超级块中存放的是文件系统的元数据,也就是查看文件系统的元数据信息
 mkfs.ext2 -b 1024 /dev/sdb1  ---创建文件系统,并指定文件系统中文件的最小单位,为block,一般为1024-4096个字节,为了避免浪费,小文件用小块,大文件用大块
 mkfs.ext2 -m 1 /dev/sdb1  ---默认5%,为管理人员预留空间占总空间的百分比
mkfs.ext2 -L /mnt/sdb1 /dev/sdb1  ---创建文件系统并加卷标
[root@centos6 app]#blkid -U 953b7594-f906-4d3e-8a3a-a6bb79b1c900   ---根据UUID查设备名
/dev/sda5
[root@centos6 app]#blkid -L /mnt/sdb1  ---根据卷标查设备名
/dev/sdb1
[root@centos6 app]#findfs LABEL="/mnt/sdb1"  ---根据卷标查找设备名
/dev/sdb1
[root@centos6 app]#findfs UUID="f02a2c3d-a6f3-4af0-a3c0-af815f58a851"   ---根据UUID查找设备名
/dev/sdb1

3、对文件创建文件系统

[root@centos6 app]#dd if=/dev/zero of=f1 bs=1M count=100  ---创建一个大文件
100+0 records in
100+0 records out
104857600 bytes (105 MB) copied, 0.259005 s, 405 MB/s
[root@centos6 app]#ls
centos5mbr  f1  mbrcentos6
[root@centos6 app]#ll f1
-rw-r--r--. 1 root root 104857600 Aug  7 21:52 f1
[root@centos6 app]#mkfs.ext4 f1  ---创建ext4文件系统
mke2fs 1.41.12 (17-May-2010)
f1 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 28 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
[root@centos6 app]#blkid  ---直接输blkid查不到对文件创建的文件系统
/dev/sda1: UUID="a056e3b8-7cc2-4aea-9308-9b0744741394" TYPE="ext4" 
/dev/sda2: UUID="07e3094b-c50d-4568-aee5-b2f76d91c962" TYPE="ext4" 
/dev/sda3: UUID="4a2031c3-8595-489e-bc6d-1e2c31860c7b" TYPE="ext4" 
/dev/sda5: UUID="953b7594-f906-4d3e-8a3a-a6bb79b1c900" TYPE="swap" 
/dev/sdc1: UUID="bfde9976-3c32-46f6-90df-62dfb62d7309" TYPE="ext4" 
/dev/sdc2: UUID="9bba6ba4-45c5-448b-8be4-66313709d955" SEC_TYPE="ext2" TYPE="ext3" 
/dev/sdb1: UUID="f02a2c3d-a6f3-4af0-a3c0-af815f58a851" TYPE="ext2" LABEL="/mnt/sdb1" 
[root@centos6 app]#blkid f1   ---要加上路径对哪个文件创建的才可以看到
f1: UUID="0fb3a3f0-8189-484b-8af5-f8ebe86bf756" TYPE="ext4" 

总结:对文件也可以创建文件系统,但查文件系统的时候要用blkid加上文件的路径名。

4、tune2fs 修改文件系统的元数据信息

tune2fs:重新设定ext系列文件系统可调整参数的值
-l:查看指定文件系统超级块信息;super block
-L 'LABEL':修改卷标
-m #:修预留给管理员的空间百分比
-j: 将ext2升级为ext3
-O: 文件系统属性启用或禁用,–O ^has_journal
-o: 调整文件系统的默认挂载选项,–o ^acl
-U UUID: 修改UUID号
dumpe2fs:
块分组管理,32768块
-h:查看超级块信息,不显示分组信息

[root@centos6 app]#tune2fs -o acl /dev/sdc1  ---调整文件系统的默认挂载选项
[root@centos6 app]#tune2fs -L /mnt/sdc1 /dev/sdc1  ---修改文件系统的卷标
[root@centos6 app]#tune2fs -m 1 /dev/sdc1---修改预留空间百分比
tune2fs 1.41.12 (17-May-2010)
Setting reserved blocks percentage to 1% (52428 blocks)
[root@centos6 app]#tune2fs -j /dev/sdb1  ---将ext2文件系统升级为ext3文件系统,多了一个日志功能
tune2fs 1.41.12 (17-May-2010)
Creating journal inode: done
This filesystem will be automatically checked every 21 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
[root@centos6 app]#tune2fs -O ^has_journal /dev/sdb1  ----禁止日志功能,相当于降为ext2
[root@centos6 app]#tune2fs -O has_journal /dev/sdb1  ----增加日志功能,相当于降ext2升级为ext3
[root@centos6 app]#uuidgen  ---随机生成UUID
df37d4a3-7928-4de1-afe8-f84022ff882b
[root@centos6 app]#tune2fs -U df37d4a3-7928-4de1-afe8-f84022ff882b /dev/sdb1  ---修改文件系统的UUID
tune2fs 1.41.12 (17-May-2010)
[root@centos6 app]#blkid
/dev/sda1: UUID="a056e3b8-7cc2-4aea-9308-9b0744741394" TYPE="ext4" 
/dev/sda2: UUID="07e3094b-c50d-4568-aee5-b2f76d91c962" TYPE="ext4" 
/dev/sda3: UUID="4a2031c3-8595-489e-bc6d-1e2c31860c7b" TYPE="ext4" 
/dev/sda5: UUID="953b7594-f906-4d3e-8a3a-a6bb79b1c900" TYPE="swap" 
/dev/sdc1: UUID="bfde9976-3c32-46f6-90df-62dfb62d7309" TYPE="ext4" LABEL="/mnt/sdc1" 
/dev/sdc2: UUID="9bba6ba4-45c5-448b-8be4-66313709d955" SEC_TYPE="ext2" TYPE="ext3" 
/dev/sdb1: UUID="df37d4a3-7928-4de1-afe8-f84022ff882b" TYPE="ext2" 
[root@centos6 app]#dumpe2fs /dev/sdb1 ---查看文件系统的块组信息,每个块组都是32768块。
Group 0: (Blocks 0-32767)
  Primary superblock at 0, Group descriptors at 1-1 ---主超级块
  Reserved GDT blocks at 2-641
  Block bitmap at 642 (+642), Inode bitmap at 643 (+643)
  Inode table at 644-1149 (+644)
  31612 free blocks, 8085 free inodes, 2 directories
  Free blocks: 1156-32767
  Free inodes: 12-8096
Group 1: (Blocks 32768-65535)
  Backup superblock at 32768, Group descriptors at 32769-32769---备份超级块
  Reserved GDT blocks at 32770-33409
  Block bitmap at 33410 (+642), Inode bitmap at 33411 (+643)
  Inode table at 33412-33917 (+644)
  31618 free blocks, 8096 free inodes, 0 directories
  Free blocks: 33918-65535
  Free inodes: 8097-16192

总结:超级块存放文件系统的元数据信息,第一个块组的第一个块为主超级块,后续块组有些块组的第一个块为备份超级块。

5、破坏文件系统的主超级块,如何恢复

[root@centos6 app]#dd if=/dev/zero of=/dev/sdb1 bs=1M count=1---主超级块在0group的Block0,1块是4096个字节,破坏1M完全可以破坏文件系统的主超级块
1+0 records in
1+0 records out
1048576 bytes (1.0 MB) copied, 0.0177562 s, 59.1 MB/s
[root@centos6 app]#tune2fs -l /dev/sdb1---无法显示文件系统的元数据信息
tune2fs 1.41.12 (17-May-2010)
tune2fs: Bad magic number in super-block while trying to open /dev/sdb1
Couldn't find valid filesystem superblock.
[root@centos6 app]#fsck -y /dev/sdb1 ---文件系统检测和修复,-y表示自动恢复yes。还可以用-f进行详细的检测和修复。
[root@centos7 ~]#fsck /dev/sdc1  
fsck from util-linux 2.23.2
If you wish to check the consistency of an XFS filesystem or
repair a damaged filesystem, see xfs_repair(8).
[root@centos7 ~]#xfs_repair /dev/sdc1---centos7中要用这条命令检测修复文件系统

注意

常发生于死机或者非正常关机之后
挂载为文件系统标记为“no clean”
注意:一定不要在挂载状态下修复

6、挂载

  • 挂载的三种方法
[root@centos6 app]#mount /dev/sdc1 /mnt/sdc1  ---根据设备名挂载
[root@centos6 ~]#mount LABEL="/mnt/sdc1" /mnt/sdc1  ---根据卷标名挂载
[root@centos6 ~]#mount UUID="df37d4a3-7928-4de1-afe8-f84022ff882b" /mnt/sdc1 ---根据UUID挂载
  • 如果文件系统正在被访问怎么取消挂载
[root@centos6 ~]#df   ---/dev/sdc1已经挂载到/mnt/sdc1目录
Filesystem     1K-blocks    Used Available Use% Mounted on
/dev/sda2       50264772 4785968  42918804  11% /
tmpfs             502056      76    501980   1% /dev/shm
/dev/sda3       40185208  151424  37985784   1% /app
/dev/sda1         991512   34904    905408   4% /boot
/dev/sr0         3878870 3878870         0 100% /media/CentOS_6.9_Final
/dev/sdc1       20511356   44992  20256652   1% /mnt/sdc1
[root@centos6 ~]#cd /mnt/sdc1  ---进入这个目录,就表示这个文件系统正在使用
[root@centos6 sdc1]#ls
lost+found
[root@centos6 sdc1]#umount /mnt/sdc1  ---无法取消挂载
umount: /mnt/sdc1: device is busy.
        (In some cases useful info about processes that use
         the device is found by lsof(8) or fuser(1))
[root@centos6 sdc1]#lsof /mnt/sdc1  ---可以查看正在访问文件系统的进程
COMMAND  PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
bash    3142 root  cwd    DIR   8,33     4096    2 /mnt/sdc1
lsof    6953 root  cwd    DIR   8,33     4096    2 /mnt/sdc1
lsof    6954 root  cwd    DIR   8,33     4096    2 /mnt/sdc1
[root@centos6 sdc1]#fuser -v /mnt/sdc1  ---也可以查看正在访问文件系统的进程
                     USER        PID ACCESS COMMAND
/mnt/sdc1:           root       3142 ..c.. bash
[root@centos6 sdc1]#fuser -km /mnt/sdc1   ---杀死正在访问文件系统的所有进程,这样就可以取消挂载了
/mnt/sdc1:            3142c

Connection closed by foreign host.

Disconnected from remote host(centos6.9) at 23:14:51.

Type `help' to learn how to use Xshell prompt.
  • 查看挂载的四种方法
[root@centos6 ~]#df   ---第一种
Filesystem     1K-blocks    Used Available Use% Mounted on
/dev/sda2       50264772 4785976  42918796  11% /
tmpfs             502056      76    501980   1% /dev/shm
/dev/sda3       40185208  151424  37985784   1% /app
/dev/sda1         991512   34904    905408   4% /boot
/dev/sr0         3878870 3878870         0 100% /media/CentOS_6.9_Final
/dev/sdb1        7863731    4083   7335128   1% /mnt/sdc1
[root@centos6 ~]#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)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
/dev/sr0 on /media/CentOS_6.9_Final type iso9660 (ro,nosuid,nodev,uhelper=udisks,uid=0,gid=0,iocharset=utf8,mode=0400,dmode=0500)
/dev/sdb1 on /mnt/sdc1 type ext2 (rw)
[root@centos6 ~]#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
none /proc/sys/fs/binfmt_misc binfmt_misc rw 0 0
/dev/sr0 /media/CentOS_6.9_Final iso9660 ro,nosuid,nodev,uhelper=udisks,uid=0,gid=0,iocharset=utf8,mode=0400,dmode=0500 0 0
/dev/sdb1 /mnt/sdc1 ext2 rw 0 0
[root@centos6 ~]#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=487280k,nr_inodes=121820,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=487280k,nr_inodes=121820,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
none /proc/sys/fs/binfmt_misc binfmt_misc rw,relatime 0 0
/etc/auto.misc /misc autofs rw,relatime,fd=7,pgrp=1974,timeout=300,minproto=5,maxproto=5,indirect 0 0
-hosts /net autofs rw,relatime,fd=13,pgrp=1974,timeout=300,minproto=5,maxproto=5,indirect 0 0
/dev/sr0 /media/CentOS_6.9_Final iso9660 ro,nosuid,nodev,relatime,uid=0,gid=0,iocharset=utf8,mode=0400,dmode=0500 0 0
/dev/sdb1 /mnt/sdc1 ext2 rw,seclabel,relatime,errors=continue 0 0

总结:前三种方法比较常见,第四种方法查看内核追踪到的所有已挂载的设备,可以查看隐藏的挂载。

  • 文件挂载到目录上
centos6
[root@centos6 app]#dd if=/dev/zero of=f1 bs=1M count=100  ---创建一个大文件
[root@centos6 app]#mkfs.ext4 f1  ---创建文件系统
[root@centos6 app]#blkid f1   ---查看文件系统
f1: UUID="412e67d9-f43d-4010-af52-f8c69767760e" TYPE="ext4" 
[root@centos6 app]#mount -o loop /app/f1 /mnt/f1  ---挂载的时候要加上-o loop
[root@centos6 app]#df  ---挂载成功
Filesystem     1K-blocks    Used Available Use% Mounted on
/dev/sda2       50264772 4785044  42919728  11% /
tmpfs             502056      76    501980   1% /dev/shm
/dev/sda3       40185208  151424  37985784   1% /app
/dev/sda1         991512   34904    905408   4% /boot
/dev/sr0         3878870 3878870         0 100% /media/CentOS_6.9_Final
/dev/sdc1       20511356   44992  20256652   1% /mnt/sdc1
/app/f1            95054    1550     88384   2% /mnt/f1
[root@centos6 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)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
gvfs-fuse-daemon on /root/.gvfs type fuse.gvfs-fuse-daemon (rw,nosuid,nodev)
/dev/sr0 on /media/CentOS_6.9_Final type iso9660 (ro,nosuid,nodev,uhelper=udisks,uid=0,gid=0,iocharset=utf8,mode=0400,dmode=0500)
/dev/sdc1 on /mnt/sdc1 type ext4 (rw)
/app/f1 on /mnt/f1 type ext4 (rw,loop=/dev/loop0)  ---文件挂载到目录上调用的是loop设备。相当于是设备挂载到目录上
[root@centos6 app]#ls /dev/loop*  ---centos6中默认的loop设备只有8个,用光了就不可以将文件挂载到目录了
/dev/loop0  /dev/loop1  /dev/loop2  /dev/loop3  /dev/loop4  /dev/loop5  /dev/loop6  /dev/loop7
[root@centos6 app]#ll /dev/loop*
brw-rw----. 1 root disk 7, 0 Aug  8 08:03 /dev/loop0
brw-rw----. 1 root disk 7, 1 Aug  8 08:03 /dev/loop1
brw-rw----. 1 root disk 7, 2 Aug  8 08:03 /dev/loop2
brw-rw----. 1 root disk 7, 3 Aug  8 08:03 /dev/loop3
brw-rw----. 1 root disk 7, 4 Aug  8 08:03 /dev/loop4
brw-rw----. 1 root disk 7, 5 Aug  8 08:03 /dev/loop5
brw-rw----. 1 root disk 7, 6 Aug  8 08:03 /dev/loop6
brw-rw----. 1 root disk 7, 7 Aug  8 08:03 /dev/loop7
[root@centos6 app]#mknod /dev/loop8 b 7 8   ---可以用次方法创建loop设备
[root@centos6 app]#ll /dev/loop*
brw-rw----. 1 root disk 7, 0 Aug  8 08:03 /dev/loop0
brw-rw----. 1 root disk 7, 1 Aug  8 08:03 /dev/loop1
brw-rw----. 1 root disk 7, 2 Aug  8 08:03 /dev/loop2
brw-rw----. 1 root disk 7, 3 Aug  8 08:03 /dev/loop3
brw-rw----. 1 root disk 7, 4 Aug  8 08:03 /dev/loop4
brw-rw----. 1 root disk 7, 5 Aug  8 08:03 /dev/loop5
brw-rw----. 1 root disk 7, 6 Aug  8 08:03 /dev/loop6
brw-rw----. 1 root disk 7, 7 Aug  8 08:03 /dev/loop7
brw-r--r--. 1 root root 7, 8 Aug  8 09:54 /dev/loop8
[root@centos6 app]#losetup -a  ---查看loop设备的对应关系
/dev/loop0: [0803]:14 (/app/f1)  ---用-o loop挂载时将loop0和f1文件关联
[root@centos6 app]#umount /app/f1
[root@centos6 app]#df
Filesystem     1K-blocks    Used Available Use% Mounted on
/dev/sda2       50264772 4785040  42919732  11% /
tmpfs             502056      76    501980   1% /dev/shm
/dev/sda3       40185208  151424  37985784   1% /app
/dev/sda1         991512   34904    905408   4% /boot
/dev/sr0         3878870 3878870         0 100% /media/CentOS_6.9_Final
/dev/sdc1       20511356   44992  20256652   1% /mnt/sdc1
[root@centos6 app]#losetup /dev/loop8 /app/f1   ---将loop8设备和f1文件关联
[root@centos6 app]#losetup -a 
/dev/loop8: [0803]:14 (/app/f1)
[root@centos6 app]#mount /dev/loop8 /mnt/f1  ---把loop8挂载到目录上,就相当于把/app/f1文件挂载到目录上
[root@centos6 app]#df
Filesystem     1K-blocks    Used Available Use% Mounted on
/dev/sda2       50264772 4785040  42919732  11% /
tmpfs             502056      76    501980   1% /dev/shm
/dev/sda3       40185208  151424  37985784   1% /app
/dev/sda1         991512   34904    905408   4% /boot
/dev/sr0         3878870 3878870         0 100% /media/CentOS_6.9_Final
/dev/sdc1       20511356   44992  20256652   1% /mnt/sdc1
/dev/loop8         95054    1550     88384   2% /mnt/f1
[root@centos6 app]#vim /boot/grub/grub.conf 
  1 # grub.conf generated by anaconda
  2 #
  3 # Note that you do not have to rerun grub after making changes to this file
  4 # NOTICE:  You have a /boot partition.  This means that
  5 #          all kernel and initrd paths are relative to /boot/, eg.
  6 #          root (hd0,0)
  7 #          kernel /vmlinuz-version ro root=/dev/sda2
  8 #          initrd /initrd-[generic-]version.img
  9 #boot=/dev/sda
 10 default=0
 11 timeout=5
 12 splashimage=(hd0,0)/grub/splash.xpm.gz
 13 hiddenmenu
 14 title CentOS 6 (2.6.32-696.el6.x86_64)
 15         root (hd0,0)
 16         kernel /vmlinuz-2.6.32-696.el6.x86_64 ro root=UUID=07e3094b-c50d-4568-aee5-b2f76d91c962 rd_NO_LUKS rd_NO_LVM LANG=en_US.UT
    F-8 rd_NO_MD SYSFONT=latarcyrheb-sun16 crashkernel=auto  KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet max_loop=100   ---在16行kernel行尾后面加max_loop=100
 17         initrd /initramfs-2.6.32-696.el6.x86_64.img 
 18 title windows2016
 19         rootnoverify (hd0,2)
 20         chainloader +1
[root@centos6 ~]#ls /dev/loop*|wc -l   ---重启后发现loop设备增加到100个
100
8月7日 创建文件系统和挂载_第1张图片
QQ截图20170808102457.png
8月7日 创建文件系统和挂载_第2张图片
QQ截图20170808102942.png

此种方法只是临时的,下次开机又不会生效了。

centos7
[root@centos7 app]#dd if=/dev/zero of=f1 bs=1M count=100
100+0 records in
100+0 records out
104857600 bytes (105 MB) copied, 0.536575 s, 195 MB/s
[root@centos7 app]#ls
f1  httpd24  mbrcentos7  music  music.sh  test
[root@centos7 app]#mkfs.xfs f1   ---创建文件系统
meta-data=f1                     isize=512    agcount=4, agsize=6400 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=25600, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal log           bsize=4096   blocks=855, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
[root@centos7 app]#blkid f1  ---查看文件系统
f1: UUID="03d4663e-bf7b-40bb-b97d-0c57bf7acb68" TYPE="xfs" 
[root@centos7 app]#mkdir /mnt/f1
[root@centos7 app]#mount /app/f1 /mnt/f1  ---不需要-o loop就可以直接挂载
[root@centos7 app]#df
Filesystem     1K-blocks     Used Available Use% Mounted on
/dev/sda2       52403200 15339236  37063964  30% /
devtmpfs          485268        0    485268   0% /dev
tmpfs             499980       88    499892   1% /dev/shm
tmpfs             499980     7328    492652   2% /run
tmpfs             499980        0    499980   0% /sys/fs/cgroup
/dev/sda3       52403200   653616  51749584   2% /app
/dev/sda1        1038336   172280    866056  17% /boot
tmpfs             100000       16     99984   1% /run/user/0
/dev/sr0         8086368  8086368         0 100% /run/media/root/CentOS 7 x86_64
/dev/loop0         98980     5296     93684   6% /mnt/f1  ---挂载成功
[root@centos7 app]#ls /dev/loop*  ---centos7中loop设备由无数个,只要把文件挂载到目录就会自动生成
/dev/loop0  /dev/loop-control
  • 挂载选项
[root@centos6 ~]#mount -r /dev/sdc1 /mnt/sdc1 ---只读挂载
[root@centos6 ~]#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)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
gvfs-fuse-daemon on /root/.gvfs type fuse.gvfs-fuse-daemon (rw,nosuid,nodev)
/dev/sr0 on /media/CentOS_6.9_Final type iso9660 (ro,nosuid,nodev,uhelper=udisks,uid=0,gid=0,iocharset=utf8,mode=0400,dmode=0500)
/dev/sdc1 on /mnt/sdc1 type ext4 (ro)  ---ro为只读挂载
[root@centos6 ~]#mount -o remount,rw /mnt/sdc1  ---不需要取消挂载的情况下进行重新挂载并且增加挂载选项
[root@centos6 ~]#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)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
gvfs-fuse-daemon on /root/.gvfs type fuse.gvfs-fuse-daemon (rw,nosuid,nodev)
/dev/sr0 on /media/CentOS_6.9_Final type iso9660 (ro,nosuid,nodev,uhelper=udisks,uid=0,gid=0,iocharset=utf8,mode=0400,dmode=0500)
/dev/sdc1 on /mnt/sdc1 type ext4 (rw)   ---变为只读
[root@centos6 sdc1]#fdisk /dev/sdd  ---在centos6中新建一个分区
[root@centos6 sdc1]#mkfs.ext4 /dev/sdd1 ---创建文件系统
[root@centos6 sdc1]#blkid  ---查看文件系统
/dev/sda1: UUID="a056e3b8-7cc2-4aea-9308-9b0744741394" TYPE="ext4" 
/dev/sda2: UUID="07e3094b-c50d-4568-aee5-b2f76d91c962" TYPE="ext4" 
/dev/sda3: UUID="4a2031c3-8595-489e-bc6d-1e2c31860c7b" TYPE="ext4" 
/dev/sda5: UUID="953b7594-f906-4d3e-8a3a-a6bb79b1c900" TYPE="swap" 
/dev/sdc1: UUID="bfde9976-3c32-46f6-90df-62dfb62d7309" TYPE="ext4" LABEL="/mnt/sdc1" 
/dev/sdc2: UUID="9bba6ba4-45c5-448b-8be4-66313709d955" SEC_TYPE="ext2" TYPE="ext3" 
/dev/sdb1: UUID="659fa4d9-176c-426c-af84-4c0df241730e" TYPE="ext4" 
/dev/sdd1: UUID="af9d834a-18c4-4f10-af33-8e5ed7adbaf0" TYPE="ext4" 
[root@centos6 sdc1]#mkdir /mnt/sdd1
[root@centos6 sdc1]#mount /dev/sdd1 /mnt/sdd1  ---挂载
[root@centos6 sdc1]#df
Filesystem     1K-blocks    Used Available Use% Mounted on
/dev/sda2       50264772 4784628  42920144  11% /
tmpfs             502056      76    501980   1% /dev/shm
/dev/sda3       40185208  151424  37985784   1% /app
/dev/sda1         991512   34904    905408   4% /boot
/dev/sr0         3878870 3878870         0 100% /media/CentOS_6.9_Final
/dev/sdc1       20511356   44996  20256648   1% /mnt/sdc1
/dev/sdd1        5039592   10264   4766668   1% /mnt/sdd1
[root@centos6 sdc1]#cd /mnt/sdd1
[root@centos6 sdd1]#touch f1
[root@centos6 sdd1]#setfacl -m u:zhang:rwx f1  ---说明在centos6中
新建的分区和文件系统默认没有acl权限
setfacl: f1: Operation not supported
[root@centos6 sdd1]#mount -o remount,acl /mnt/sdd1  ---重新挂载并增加acl权限
[root@centos6 sdd1]#setfacl -m u:zhang:rwx f1 ---可以设置acl权限
[root@centos6 sdd1]#ll
total 20
-rw-rwxr--+ 1 root root     0 Aug  8 11:04 f1
drwx------. 2 root root 16384 Aug  8 11:03 lost+found
[root@centos7 app]#mount /dev/sdc1 /mnt/sdc1  
[root@centos7 app]#df
Filesystem     1K-blocks     Used Available Use% Mounted on
/dev/sda2       52403200 15336796  37066404  30% /
devtmpfs          485268        0    485268   0% /dev
tmpfs             499980       88    499892   1% /dev/shm
tmpfs             499980     7300    492680   2% /run
tmpfs             499980        0    499980   0% /sys/fs/cgroup
/dev/sda3       52403200   653616  51749584   2% /app
/dev/sda1        1038336   172280    866056  17% /boot
tmpfs             100000       16     99984   1% /run/user/0
/dev/sr0         8086368  8086368         0 100% /run/media/root/CentOS 7 x86_64
/dev/sdc1       10475520    32944  10442576   1% /mnt/sdc1
[root@centos7 app]#cd /mnt/sdc1/
[root@centos7 sdc1]#ls
[root@centos7 sdc1]#touch f1
[root@centos7 sdc1]#setfacl -m u:zhang:rw f1 ---可以设置acl权限
[root@centos7 sdc1]#ll
total 0
-rw-rw-r--+ 1 root root 0 Aug  8 11:10 f1
说明centos6中新建的分区和文件系统默认没有acl权限,而centos7中有。
  • 隐藏挂载
[root@centos6 ~]#mount -n /dev/sdc1 /mnt/sdc1  ---加-n选项可以隐藏挂载
[root@centos6 ~]#df  --看不到
Filesystem     1K-blocks    Used Available Use% Mounted on
/dev/sda2       50264772 4784632  42920140  11% /
tmpfs             502056      76    501980   1% /dev/shm
/dev/sda3       40185208  151424  37985784   1% /app
/dev/sda1         991512   34904    905408   4% /boot
/dev/sr0         3878870 3878870         0 100% /media/CentOS_6.9_Final
[root@centos6 ~]#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)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
gvfs-fuse-daemon on /root/.gvfs type fuse.gvfs-fuse-daemon (rw,nosuid,nodev)
/dev/sr0 on /media/CentOS_6.9_Final type iso9660 (ro,nosuid,nodev,uhelper=udisks,uid=0,gid=0,iocharset=utf8,mode=0400,dmode=0500)
[root@centos6 ~]#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
none /proc/sys/fs/binfmt_misc binfmt_misc rw 0 0
gvfs-fuse-daemon /root/.gvfs fuse.gvfs-fuse-daemon rw,nosuid,nodev 0 0
/dev/sr0 /media/CentOS_6.9_Final iso9660 ro,nosuid,nodev,uhelper=udisks,uid=0,gid=0,iocharset=utf8,mode=0400,dmode=0500 0 0
[root@centos6 ~]#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=487280k,nr_inodes=121820,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=487280k,nr_inodes=121820,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
none /proc/sys/fs/binfmt_misc binfmt_misc rw,relatime 0 0
/etc/auto.misc /misc autofs rw,relatime,fd=7,pgrp=2435,timeout=300,minproto=5,maxproto=5,indirect 0 0
-hosts /net autofs rw,relatime,fd=13,pgrp=2435,timeout=300,minproto=5,maxproto=5,indirect 0 0
gvfs-fuse-daemon /root/.gvfs fuse.gvfs-fuse-daemon rw,nosuid,nodev,relatime,user_id=0,group_id=0 0 0
/dev/sr0 /media/CentOS_6.9_Final iso9660 ro,nosuid,nodev,relatime,uid=0,gid=0,iocharset=utf8,mode=0400,dmode=0500 0 0
/dev/sdc1 /mnt/sdc1 ext4 rw,seclabel,relatime,barrier=1,data=ordered 0 0  ---只有用这种方法查看内核追踪到的所有已挂载的设备
  • 是否支持在这个设备上使用设备文件挂载
[root@centos6 ~]#mount -o nodev /dev/sdc1 /mnt/sdc1
[root@centos6 ~]#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)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
gvfs-fuse-daemon on /root/.gvfs type fuse.gvfs-fuse-daemon (rw,nosuid,nodev)
/dev/sr0 on /media/CentOS_6.9_Final type iso9660 (ro,nosuid,nodev,uhelper=udisks,uid=0,gid=0,iocharset=utf8,mode=0400,dmode=0500)
/dev/sdc1 on /mnt/sdc1 type ext4 (rw,nodev)  ---不支持使用设备文件
[root@centos6 ~]#cd /mnt/sdc1/
[root@centos6 sdc1]#ls
f1  f2  lost+found
[root@centos6 sdc1]#dd if=dev/zero of=f1 bs=1 count=2
dd: opening `dev/zero': No such file or directory  ---不可使用
  • 目录挂载到目录上
[root@centos6 app]#mount -B  /media/CentOS_6.9_Final/ /app/faa  ---将光盘目录挂载到/app/faa
[root@centos6 app]#df  ---看不到挂载情况
Filesystem     1K-blocks    Used Available Use% Mounted on
/dev/sda2       50264772 4784640  42920132  11% /
tmpfs             502056      76    501980   1% /dev/shm
/dev/sda3       40185208  151428  37985780   1% /app
/dev/sda1         991512   34904    905408   4% /boot
/dev/sr0         3878870 3878870         0 100% /media/CentOS_6.9_Final
/dev/sdc1       20511356   44996  20256648   1% /mnt/sdc1
[root@centos6 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)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
gvfs-fuse-daemon on /root/.gvfs type fuse.gvfs-fuse-daemon (rw,nosuid,nodev)
/dev/sr0 on /media/CentOS_6.9_Final type iso9660 (ro,nosuid,nodev,uhelper=udisks,uid=0,gid=0,iocharset=utf8,mode=0400,dmode=0500)
/dev/sdc1 on /mnt/sdc1 type ext4 (rw,nodev)
/media/CentOS_6.9_Final on /app/faa type none (rw,bind)  ---挂载调用的是bind
[root@centos6 app]#cd /app/faa
[root@centos6 faa]#ls  ---此时进入/app/faa看到是光盘的内容
CentOS_BuildTag  GPL       Packages                  RPM-GPG-KEY-CentOS-6           RPM-GPG-KEY-CentOS-Testing-6
EFI              images    RELEASE-NOTES-en-US.html  RPM-GPG-KEY-CentOS-Debug-6     TRANS.TBL
EULA             isolinux  repodata                  RPM-GPG-KEY-CentOS-Security-6
[root@centos6 ~]#mount --bind /etc/ /mnt/sdd1/   ---将/etc目录挂载到/mnt/sdd1下
[root@centos6 ~]#cd /mnt/sdd1/
[root@centos6 sdd1]#ls |wc -l  ---进入/mnt/sdd1目录看到就是/etc目录的内容
264
  • findmnt显示挂载情况
[root@centos6 ~]#findmnt /mnt/sdc1  
TARGET    SOURCE    FSTYPE OPTIONS
/mnt/sdc1 /dev/sdc1 ext4   rw,nodev,relatime,seclabel,barrier=1,data=ordered
[root@centos6 ~]#findmnt /dev/sdc1
TARGET    SOURCE    FSTYPE OPTIONS
/mnt/sdc1 /dev/sdc1 ext4   rw,nodev,relatime,seclabel,barrier=1,data=ordered
[root@centos6 ~]#echo $? ---可以判断目录或者设备是否已经挂载
0
[root@centos6 ~]#umount /dev/sdc1
[root@centos6 ~]#findmnt /dev/sdc1
[root@centos6 ~]#echo $?
1
[root@centos6 ~]#findmnt -s /dev/sdc1  ---用来判断目录或设备在配置文件中是否挂载
[root@centos6 ~]#echo $?
1
[root@centos6 ~]#cat /etc/fstab

#
# /etc/fstab
# Created by anaconda on Fri Jul 14 10:37:59 2017
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
UUID=07e3094b-c50d-4568-aee5-b2f76d91c962 /                       ext4    defaults        1 1
UUID=4a2031c3-8595-489e-bc6d-1e2c31860c7b /app                    ext4    defaults        1 2
UUID=a056e3b8-7cc2-4aea-9308-9b0744741394 /boot                   ext4    defaults        1 2
UUID=953b7594-f906-4d3e-8a3a-a6bb79b1c900 swap                    swap    defaults        0 0
tmpfs                   /dev/shm                tmpfs   defaults        0 0
devpts                  /dev/pts                devpts  gid=5,mode=620  0 0
sysfs                   /sys                    sysfs   defaults        0 0
proc                    /proc                   proc    defaults        0 0

总结:findmnt可以写在脚本里配合echo$?来判断设备或目录是否被挂载,配合-s使用可以判断在/etc/fstab中是否挂载。

  • 如何进行永久挂载

格式
/etc/fstab每行定义一个要挂载的文件系统
要挂载的设备或伪文件系统
设备文件
LABEL:LABEL=""
UUID:UUID=""
伪文件系统名称:proc, sysfs
挂载点
文件系统类型
挂载选项:defaults
转储频率:0:不做备份1:每天转储2:每隔一天转储
自检次序:0:不自检1:首先自检;一般只有rootfs才用1

①设备挂载到目录

 UUID=bfde9976-3c32-46f6-90df-62dfb62d7309 /mnt/sdc1   ext4  defaults 0 0       
LABEL=/mnt/sdc1     /mnt/sdc1   ext4  defaults 0 0
/dev/sdc1 /mnt/sdc1 ext4 default 0 0
第一列可以使用uuid、设备名和卷标名,最好使用uuid比较稳定
[root@centos6 ~]#mount -a  ----文件中挂载选项中含有auto才支持,default选项默认具有auto
[root@centos6 ~]#df  ---自动挂载成功
Filesystem     1K-blocks    Used Available Use% Mounted on
  ev/sda2       50264772 4784744  42920028  11% /
tmpfs             502056      76    501980   1% /dev/shm
/dev/sda3       40185208  151428  37985780   1% /app
/dev/sda1         991512   34904    905408   4% /boot
/dev/sr0         3878870 3878870         0 100% /media/CentOS_6.9_Final
/dev/sdc1       20511356   44996  20256648   1% /mnt/sdc1
LABEL=/mnt/sdc1     /mnt/sdc1   ext4  defaults,noacl   0 0  ---更改挂载选项后重新挂载
[root@centos6 ~]#mount -o remount /mnt/sdc1 ---不需要取消挂载,可以用此种方法对已经挂载的在文件中更改后进行重新挂载
[root@centos6 ~]#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)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
gvfs-fuse-daemon on /root/.gvfs type fuse.gvfs-fuse-daemon (rw,nosuid,nodev)
/dev/sr0 on /media/CentOS_6.9_Final type iso9660 (ro,nosuid,nodev,uhelper=udisks,uid=0,gid=0,iocharset=utf8,mode=0400,dmode=0500)
/dev/sdc1 on /mnt/sdc1 type ext4 (rw,noacl)   ---noacl挂载选项已经启用

②文件挂载到目录

[root@centos6 app]#blkid f1
f1: UUID="412e67d9-f43d-4010-af52-f8c69767760e" TYPE="ext4" 
vim /etc/fstab
UUID=412e67d9-f43d-4010-af52-f8c69767760e    /mnt/f1  ext4  loop   0  0  ---文件挂载到目录,挂载选项为loop
[root@centos6 app]#mount -a
[root@centos6 app]#df
Filesystem     1K-blocks    Used Available Use% Mounted on
/dev/sda2       50264772 4784756  42920016  11% /
tmpfs             502056      76    501980   1% /dev/shm
/dev/sda3       40185208  151428  37985780   1% /app
/dev/sda1         991512   34904    905408   4% /boot
/dev/sr0         3878870 3878870         0 100% /media/CentOS_6.9_Final
/dev/sdc1       20511356   44996  20256648   1% /mnt/sdc1
/app/f1            95054    1550     88384   2% /mnt/f1

③目录挂载到目录

/etc/ /app/faa     none   bind  0  0   ---目录挂载到目录不用文件系统,所以为none,挂载选项为bind
[root@centos6 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)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
gvfs-fuse-daemon on /root/.gvfs type fuse.gvfs-fuse-daemon (rw,nosuid,nodev)
/dev/sr0 on /media/CentOS_6.9_Final type iso9660 (ro,nosuid,nodev,uhelper=udisks,uid=0,gid=0,iocharset=utf8,mode=0400,dmode=0500)
/dev/sdc1 on /mnt/sdc1 type ext4 (rw,noacl)
/app/f1 on /mnt/f1 type ext4 (rw,loop=/dev/loop0)
/etc on /app/faa type none (rw,bind)  ---以挂载

④如何挂载网络共享资源
在centos7中开启一个网络共享资源

[root@centos7 ~]#df
Filesystem     1K-blocks     Used Available Use% Mounted on
/dev/sda2       52403200 15336972  37066228  30% /
devtmpfs          485268        0    485268   0% /dev
tmpfs             499980       88    499892   1% /dev/shm
tmpfs             499980     7300    492680   2% /run
tmpfs             499980        0    499980   0% /sys/fs/cgroup
/dev/sda3       52403200   653616  51749584   2% /app
/dev/sda1        1038336   172280    866056  17% /boot
tmpfs             100000       16     99984   1% /run/user/0
/dev/sr0         8086368  8086368         0 100% /run/media/root/CentOS 7 x86_64
/dev/sdc1       10475520    32944  10442576   1% /mnt/sdc1
[root@centos7 ~]#vim /etc/exports  ---在此文件中说明要共享的目录,*表示共享给所有人
  1 /mnt/sdc1 *
[root@centos7 ~]#systemctl start nfs-server.service  ---开启nfs网络共享服务

centos6中进行的操作

[root@centos6 ~]#showmount -e 192.168.25.144  ---可以看到nfs共享
Export list for 192.168.25.144:
/mnt/sdc1 *
[root@centos6 ~]#mkdir /mnt/nfs
[root@centos6 ~]#mount 192.168.25.144:/mnt/sdc1 /mnt/nfs/  ---把共享资源挂载到/mnt/nfs目录下
[root@centos6 ~]#df
Filesystem           1K-blocks    Used Available Use% Mounted on
/dev/sda2             50264772 4785664  42919108  11% /
tmpfs                   502056      76    501980   1% /dev/shm
/dev/sda3             40185208  151428  37985780   1% /app
/dev/sda1               991512   34904    905408   4% /boot
/dev/sr0               3878870 3878870         0 100% /media/CentOS_6.9_Final
192.168.25.144:/mnt/sdc1
                      10475520   32896  10442624   1% /mnt/nfs
[root@centos6 ~]#cd /mnt/nfs
[root@centos6 nfs]#ls  ---进入目录就可以看到共享的资源了
f1  f2

如果想要永久的保存,写到配置文件里

[root@centos6 ~]#umount /mnt/nfs
[root@centos6 ~]#df
Filesystem     1K-blocks    Used Available Use% Mounted on
/dev/sda2       50264772 4785672  42919100  11% /
tmpfs             502056      76    501980   1% /dev/shm
/dev/sda3       40185208  151428  37985780   1% /app
/dev/sda1         991512   34904    905408   4% /boot
/dev/sr0         3878870 3878870         0 100% /media/CentOS_6.9_Final
[root@centos6 ~]#vim + /etc/fstab        
 17 192.168.25.144:/mnt/sdc1  /mnt/nfs         nfs      defaults     0 0
文件系统写成nfs                                                                                                                                                                                                                
[root@centos6 ~]#mount -a
[root@centos6 ~]#df  ---可以看到自动挂载了
Filesystem           1K-blocks    Used Available Use% Mounted on
/dev/sda2             50264772 4785672  42919100  11% /
tmpfs                   502056      76    501980   1% /dev/shm
/dev/sda3             40185208  151428  37985780   1% /app
/dev/sda1               991512   34904    905408   4% /boot
/dev/sr0               3878870 3878870         0 100% /media/CentOS_6.9_Final
192.168.25.144:/mnt/sdc1
                      10475520   32896  10442624   1% /mnt/nfs

你可能感兴趣的:(8月7日 创建文件系统和挂载)