mount –o remount,rw /

当系统出现故障进入单用户模式时,通常 / 根目录会以只读方式挂载,这时如果想要修改文件,会发现所有文件都是只读状态,无法修改。好在 Linux 下的 mount 命令支持一个remount 选项,只需要执行如下命令:

mount –o remount,rw /

proc、tmpfs、sysfs、devpts 等都是 Linux 内核映射到用户空间的虚拟文件系统,它们不和具体的物理设备关联,但它们具有普通文件系统的特征,应用层程序可以像访问普通文件系统一样来访问他们。
比如内核的 proc 文件系统默认被挂载到了 /proc 目录,当然我们也可以再把它挂载到其它的目录,比如 /mnt 目录下:

$ sudo mount -t proc none /mnt

由于 proc 是内核虚拟的一个文件系统,并没有对应的设备,所以这里的 -t 参数不能省略。由于没有对应的源设备,这里的 none 可以是任意字符串,取个有意义的名字就可以了,因为用 mount 命令查看挂载点信息时第一列显示的就是这个字符串。

在 Linux 上我们还可以通过 tmpfs 文件系统轻松地构建出内存磁盘来。比如在内存中创建一个 512M 的 tmpfs 文件系统,并挂载到 /mnt 下,这样所有写到 /mnt 目录下的文件都存储在内存中,速度非常快,不过要注意,由于数据存储在内存中,所以断电后数据会丢失掉:

$ sudo mount -t tmpfs -o size=512m tmpfs /mnt

mount 命令用来挂载文件系统。其基本命令格式为:
mount -t type [-o options] device dir
device:指定要挂载的设备,比如磁盘、光驱等。
dir:指定把文件系统挂载到哪个目录。
type:指定挂载的文件系统类型,一般不用指定,mount 命令能够自行判断。
options:指定挂载参数,比如 ro 表示以只读方式挂载文件系统。

-o <选项> 指定挂载文件系统时的选项,有些也可写到在 /etc/fstab 中。常用的有:
   defaults 使用所有选项的默认值(auto、nouser、rw、suid)
   auto/noauto 允许/不允许以 –a选项进行安装
   dev/nodev 对/不对文件系统上的特殊设备进行解释
   exec/noexec 允许/不允许执行二进制代码
   suid/nosuid 确认/不确认suid和sgid位
   user/nouser 允许/不允许一般用户挂载
   codepage=XXX 代码页
   iocharset=XXX 字符集
   ro 以只读方式挂载
   rw 以读写方式挂载
   remount 重新安装已经安装了的文件系统
   loop 挂载“回旋设备”以及“ISO镜像文件”

/*
root@test:~# mount  -h

Usage:
 mount [-lhV]
 mount -a [options]
 mount [options] [--source] <source> | [--target] <directory>
 mount [options] <source> <directory>
 mount <operation> <mountpoint> [<target>]

Mount a filesystem.

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 <path>      alternative file to /etc/fstab
 -i, --internal-only     don't call the mount.<type> helpers
 -l, --show-labels       show also filesystem labels
 -n, --no-mtab           don't write to /etc/mtab
 -o, --options <list>    comma-separated list of mount options
 -O, --test-opts <list>  limit the set of filesystems (use with -a)
 -r, --read-only         mount the filesystem read-only (same as -o ro)
 -t, --types <list>      limit the set of filesystem types
     --source <src>      explicitly specifies source (path, label, uuid)
     --target <target>   explicitly specifies mountpoint
 -v, --verbose           say what is being done
 -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 <label>     synonym for LABEL=<label>
 -U, --uuid <uuid>       synonym for UUID=<uuid>
 LABEL=<label>           specifies device by filesystem label
 UUID=<uuid>             specifies device by filesystem UUID
 PARTLABEL=<label>       specifies device by partition label
 PARTUUID=<uuid>         specifies device by partition UUID
 <device>                specifies device by path
 <directory>             mountpoint for bind mounts (see --bind/rbind)
 <file>                  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).
*/
posted @ 2020-01-06 21:56  codestacklinuxer  阅读(4893)  评论(0编辑  收藏  举报