记录:348
场景:在CentOS 7.9操作系统上,使用mount命令挂载镜像到指定目录、挂载磁盘到指定目录;使用umount命令卸载已挂载到指定目录的磁盘或者镜像。
版本:
操作系统:CentOS 7.9
1.mount命令应用
(1)把iso镜像挂载到指定目录
命令:mount -o loop /home/apps/software/CentOS-7-x86_64-Everything-2009.iso /mnt/local_iso/
解析:把CentOS-7-x86_64-Everything-2009.iso镜像挂载到指定的/mnt/local_iso/目录;loop是挂载loop设备类型。
(2)把磁盘挂载到指定目录
命令:mount /dev/sdb /mnt/data
解析:/dev/sdb是磁盘在系统中的设备路径,系统新加的一个磁盘,需要创建文件系统和挂载到指定目录后,才能使用其存储空间。
(3)把磁盘分区挂载到指定目录
场景:磁盘/dev/sdb划分了两个分区,/dev/sdb1和/dev/sdb2,挂载时候,就直接使用分区挂载。
挂载磁盘分区1到目录:mount /dev/sdb1 /mnt/hz_data01
挂载磁盘分区2到目录:mount /dev/sdb2 /mnt/hz_data02
解析:/dev/sdb是磁盘在系统中的设备路径,/dev/sdb1和/dev/sdb2是磁盘在系统中两个分区的路径。
2.umount命令应用
(1)卸载已挂载到目录的iso镜像
卸载命令:umount /mnt/local_iso/
解析:卸载后,需要使用,必须重新挂载。
(2)卸载已挂载到目录的磁盘
卸载目录已挂载的磁盘:umount /dev/sdb
解析:执行umount后,目录就不可用了,也就无法使用磁盘空间了,如需使用,需重新挂载。
(3)卸载已挂载到目录的磁盘分区
卸载目录已挂载的磁盘分区sdb1:umount /dev/sdb1
卸载目录已挂载的磁盘分区sdb2:umount /dev/sdb2
解析:执行umount后,目录就不可用了,也就无法使用磁盘空间了,如需使用,需重新挂载。
3.命令帮助手册
(1)mount命令帮助手册
命令:mount --help
解析:查看mount支持的全部命令和选项,在实际工作中,查看这个手册应该是必备之选。
- Usage:
- mount [-lhV]
- mount -a [options]
- mount [options] [--source] <source> | [--target]
- mount [options] <source>
- mount
[] -
- Options:
- -a, --all mount all filesystems mentioned in fstab
- -c, --no-canonicalize don't canonicalize paths
- -f, --fake dry run; skip the mount(2) syscall
- -F, --fork fork off for each device (use with -a)
- -T, --fstab
alternative file to /etc/fstab - -h, --help display this help text and exit
- -i, --internal-only don't call the mount.<type> helpers
- -l, --show-labels lists all mounts with LABELs
- -n, --no-mtab don't write to /etc/mtab
- -o, --options
comma-separated list of mount options
- -O, --test-opts
limit the set of filesystems (use with -a)
- -r, --read-only mount the filesystem read-only (same as -o ro)
- -t, --types
limit the set of filesystem types
- --source
explicitly specifies source (path, label, uuid) - --target
explicitly specifies mountpoint - -v, --verbose say what is being done
- -V, --version display version information and exit
- -w, --rw, --read-write mount the filesystem read-write (default)
- -h, --help display this help and exit
- -V, --version output version information and exit
- Source:
- -L, --label
- -U, --uuid
synonym for UUID= - LABEL=
specifies device by filesystem label - UUID=
specifies device by filesystem UUID - PARTLABEL=
specifies device by partition label - PARTUUID=
specifies device by partition UUID -
specifies device by path -
mountpoint for bind mounts (see --bind/rbind) -
regular file for loopdev setup - Operations:
- -B, --bind mount a subtree somewhere else (same as -o bind)
- -M, --move move a subtree to some other place
- -R, --rbind mount a subtree and all submounts somewhere else
- --make-shared mark a subtree as shared
- --make-slave mark a subtree as slave
- --make-private mark a subtree as private
- --make-unbindable mark a subtree as unbindable
- --make-rshared recursively mark a whole subtree as shared
- --make-rslave recursively mark a whole subtree as slave
- --make-rprivate recursively mark a whole subtree as private
- --make-runbindable recursively mark a whole subtree as unbindable
- For more details see mount(8).
- [root@hadoop200 ~]#
(2)umount命令帮助手册
命令:umount --help
解析:查看umount支持的全部命令和选项,在实际工作中,查看这个手册应该是必备之选。
- Usage:
- umount [-hV]
- umount -a [options]
- umount [options] <source> |
-
- Options:
- -a, --all unmount all filesystems
- -A, --all-targets unmount all mountpoins for the given device
- in the current namespace
- -c, --no-canonicalize don't canonicalize paths
- -d, --detach-loop if mounted loop device, also free this loop device
- --fake dry run; skip the umount(2) syscall
- -f, --force force unmount (in case of an unreachable NFS system)
- -i, --internal-only don't call the umount.<type> helpers
- -n, --no-mtab don't write to /etc/mtab
- -l, --lazy detach the filesystem now, and cleanup all later
- -O, --test-opts
limit the set of filesystems (use with -a)
- -R, --recursive recursively unmount a target with all its children
- -r, --read-only In case unmounting fails, try to remount read-only
- -t, --types
limit the set of filesystem types
- -v, --verbose say what is being done
- -h, --help display this help and exit
- -V, --version output version information and exit
- For more details see umount(8).
以上,感谢。
2022年11月28日