如何在RHEL/CentOS 7.0中使用tmpfs

本文详细介绍了CentOS7中tmpfs文件系统的作用、用途及如何通过systemctl、手动挂载和立即创建的方式进行配置。重点突出tmpfs作为临时存储空间的特点及其在系统中的常见应用。

http://linux.cn/article-5622-1.html

今天我们来谈谈 Centos 7 中的一个文件系统tmpfs,这是一个将所有文件和文件夹写到虚拟内存中而不是实际写到磁盘中的虚拟文件系统。这意味中tmpfs中所有的内容都是临时的,在tmpfs卸载、系统重启或者电源切断后内容都将会丢失。技术的角度上来说,tmpfs将所有的内容放在内核内部缓存中并且会调整大小来容纳文件,并可从交换空间中交换出不需要的页。

CentOS默认使用tmpfs做的几种用途可用df -h命令的输出来看:

 
 
  1. # df h

df

df

  • /dev - 含有针对所有设备的设备文件的目录
  • /dev/shm - 包含共享内存分配
  • /run - 用于系统日志
  • /sys/fs/cgroup - 用于cgrpups, 一个针对特定进程限制、管制和审计资源利用的内核特性

显然,它也可以用作/tmp目录, 你可以用下面的两种方法来做到:

使用systemctl来在/tmp中启用tmpfs

你可以使用systemctl命令在tmp目录启用tmpfs, 首先用下面的命令来检查这个特性是否可用:

 
 
  1. # systemctl is-enabled tmp.mount

这会显示当先的状态,(如果未启用,)你可以使用下面的命令来启用它:

 
 
  1. # systemctl enable tmp.mount

systemctl

systemctl

这会让系统控制/tmp目录并在该目录下挂载一个tmpfs文件系统。

手动挂载/tmp文件系统

你可以在/etc/fstab中添加下面这行,来手工在/tmp下挂载 tmpfs。

 
 
  1. tmpfs /tmp tmpfs size=512m 0 0

接着运行这条命令

 
 
  1. # mount a

df

df

这应该就会在df -h中显示tmpfs了,同样也会在你下次重启时自动挂载。

立即创建tmpfs

如果由于一些原因,你需要在一个文件夹下立即创建tmpfs,你可以使用下面的命令:

 
 
  1. # mount -t tmpfs -o size=1G tmpfs /mnt/mytmpfs

当然你可以在size选项中指定你希望的大小和希望的挂载点,只要记住是有效的目录就行了。


via: http://linoxide.com/file-system/use-tmpfs-rhel-centos-7-0/


[OHOS ERROR] [NINJA] command failed: "/home/yeyangxi/xts/arkui/prebuilts/build-tools/linux-x86/bin/ninja -w dupbuild=warn -C /home/yeyangxi/xts/arkui/out/arkui-x arkui_targets" , ret_code: 1 [OHOS ERROR] [NINJA] [59/37473] ACTION //arkcompiler/runtime_core/static_core/plugins/ets/tools/declgen_ts2sts:build_declgen(//build_plugins/toolchain/aosp:aosp_clang_arm64_release) [OHOS ERROR] [NINJA] FAILED: aosp_clang_arm64_release/obj/arkcompiler/runtime_core/static_core/plugins/ets/tools/declgen_ts2sts/panda-declgen-1.0.0.tgz [OHOS ERROR] [NINJA] /usr/bin/env ../../arkcompiler/runtime_core/static_core/plugins/ets/tools/declgen_ts2sts/compile_declgen.py /home/yeyangxi/xts/arkui/arkcompiler/runtime_core/static_core/plugins/ets/tools/declgen_ts2sts/ /home/yeyangxi/xts/arkui/out/arkui-x/aosp_clang_arm64_release/obj/arkcompiler/runtime_core/static_core/plugins/ets/tools/declgen_ts2sts [OHOS ERROR] [NINJA] Traceback (most recent call last): [OHOS ERROR] [NINJA] File "/home/yeyangxi/xts/arkui/out/arkui-x/../../arkcompiler/runtime_core/static_core/plugins/ets/tools/declgen_ts2sts/compile_declgen.py", line 61, in <module> [OHOS ERROR] [NINJA] main(sys.argv[1:]) [OHOS ERROR] [NINJA] File "/home/yeyangxi/xts/arkui/out/arkui-x/../../arkcompiler/runtime_core/static_core/plugins/ets/tools/declgen_ts2sts/compile_declgen.py", line 56, in main [OHOS ERROR] [NINJA] run_build(dest_and_exec_path) [OHOS ERROR] [NINJA] File "/home/yeyangxi/xts/arkui/out/arkui-x/../../arkcompiler/runtime_core/static_core/plugins/ets/tools/declgen_ts2sts/compile_declgen.py", line 44, in run_build [OHOS ERROR] [NINJA] run_cmd(cmd, execution_path) [OHOS ERROR] [NINJA] File "/home/yeyangxi/xts/arkui/out/arkui-x/../../arkcompiler/runtime_core/static_core/plugins/ets/tools/declgen_ts2sts/compile_declgen.py", line 39, in run_cmd [OHOS ERROR] [NINJA] raise Exception(stderr.decode()) [OHOS ERROR] [NINJA] Exception: npm ERR! code ELIFECYCLE [OHOS ERROR] [NINJA] npm ERR! errno 2 [OHOS ERROR] [NINJA] npm ERR! @panda/declgen@1.0.0 tsc: `tsc` [OHOS ERROR] [NINJA] npm ERR! Exit status 2 [OHOS ERROR] [NINJA] npm ERR! [OHOS ERROR] [NINJA] npm ERR! Failed at the @panda/declgen@1.0.0 tsc script. [OHOS ERROR] [NINJA] npm ERR! This is probably not a problem with npm. There is likely additional logging output above. [OHOS ERROR] [NINJA] npm WARN Local package.json exists, but node_modules missing, did you mean to install? [OHOS ERROR] [NINJA] [OHOS ERROR] [NINJA] npm ERR! A complete log of this run can be found in: [OHOS ERROR] [NINJA] npm ERR! /home/yeyangxi/.npm/_logs/2025-09-21T17_49_10_790Z-debug.log [OHOS ERROR] [NINJA] npm ERR! code ELIFECYCLE [OHOS ERROR] [NINJA] npm ERR! errno 2 [OHOS ERROR] [NINJA] npm ERR! @panda/declgen@1.0.0 compile: `npm run tsc` [OHOS ERROR] [NINJA] npm ERR! Exit status 2 [OHOS ERROR] [NINJA] npm ERR! [OHOS ERROR] [NINJA] npm ERR! Failed at the @panda/declgen@1.0.0 compile script. [OHOS ERROR] [NINJA] npm ERR! This is probably not a problem with npm. There is likely additional logging output above. [OHOS ERROR] [NINJA] npm WARN Local package.json exists, but node_modules missing, did you mean to install? [OHOS ERROR] [NINJA] [OHOS ERROR] [NINJA] npm ERR! A complete log of this run can be found in: [OHOS ERROR] [NINJA] npm ERR! /home/yeyangxi/.npm/_logs/2025-09-21T17_49_10_858Z-debug.log [OHOS ERROR] [NINJA] npm ERR! code ELIFECYCLE [OHOS ERROR] [NINJA] npm ERR! errno 2 [OHOS ERROR] [NINJA] npm ERR! @panda/declgen@1.0.0 build: `npm run clean && npm run compile` [OHOS ERROR] [NINJA] npm ERR! Exit status 2 [OHOS ERROR] [NINJA] npm ERR! [OHOS ERROR] [NINJA] npm ERR! Failed at the @panda/declgen@1.0.0 build script. [OHOS ERROR] [NINJA] npm ERR! This is probably not a problem with npm. There is likely additional logging output above. [OHOS ERROR] [NINJA] npm WARN Local package.json exists, but node_modules missing, did you mean to install? [OHOS ERROR] [NINJA] [OHOS ERROR] [NINJA] npm ERR! A complete log of this run can be found in: [OHOS ERROR] [NINJA] npm ERR! /home/yeyangxi/.npm/_logs/2025-09-21T17_49_10_902Z-debug.log [OHOS ERROR] [NINJA] [OHOS INFO] User Cpu%: 0.0% [OHOS INFO] System Cpu%: 0.0% [OHOS INFO] Idle CPU%: 0% [OHOS INFO] Total Memory: 24.8GB [OHOS INFO] Free Memory: 8.1GB [OHOS INFO] Swap Memory: 7.0GB [OHOS INFO] Filesystem: /dev/sdb, Size: 492G, Used: 249G, Available: 220G, Use%: 54%, Mounted on: / [OHOS INFO] Filesystem: tmpfs, Size: 13G, Used: 0, Available: 13G, Use%: 0%, Mounted on: /mnt/wsl [OHOS INFO] Filesystem: tools, Size: 239G, Used: 149G, Available: 90G, Use%: 63%, Mounted on: /init [OHOS INFO] Filesystem: none, Size: 13G, Used: 0, Available: 13G, Use%: 0%, Mounted on: /dev [OHOS INFO] Filesystem: none, Size: 13G, Used: 16K, Available: 13G, Use%: 1%, Mounted on: /run [OHOS INFO] Filesystem: none, Size: 13G, Used: 0, Available: 13G, Use%: 0%, Mounted on: /run/lock [OHOS INFO] Filesystem: none, Size: 13G, Used: 0, Available: 13G, Use%: 0%, Mounted on: /run/shm [OHOS INFO] Filesystem: none, Size: 13G, Used: 0, Available: 13G, Use%: 0%, Mounted on: /run/user [OHOS INFO] Filesystem: tmpfs, Size: 13G, Used: 0, Available: 13G, Use%: 0%, Mounted on: /sys/fs/cgroup [OHOS INFO] Filesystem: drivers, Size: 239G, Used: 149G, Available: 90G, Use%: 63%, Mounted on: /usr/lib/wsl/drivers [OHOS INFO] Filesystem: lib, Size: 239G, Used: 149G, Available: 90G, Use%: 63%, Mounted on: /usr/lib/wsl/lib [OHOS INFO] Filesystem: C:\, Size: 239G, Used: 149G, Available: 90G, Use%: 63%, Mounted on: /mnt/c [OHOS INFO] Filesystem: D:\, Size: 1.9T, Used: 770G, Available: 1.1T, Use%: 42%, Mounted on: /mnt/d [OHOS ERROR] [NINJA] Traceback (most recent call last): [OHOS ERROR] [NINJA] File "/home/yeyangxi/xts/arkui/build/hb/containers/status.py", line 47, in wrapper [OHOS ERROR] [NINJA] return func(*args, **kwargs) [OHOS ERROR] [NINJA] ^^^^^^^^^^^^^^^^^^^^^ [OHOS ERROR] [NINJA] File "/home/yeyangxi/xts/arkui/build/hb/modules/ohos_build_module.py", line 70, in run [OHOS ERROR] [NINJA] raise exception [OHOS ERROR] [NINJA] File "/home/yeyangxi/xts/arkui/build/hb/modules/ohos_build_module.py", line 67, in run [OHOS ERROR] [NINJA] super().run() [OHOS ERROR] [NINJA] File "/home/yeyangxi/xts/arkui/build/hb/modules/interface/build_module_interface.py", line 70, in run [OHOS ERROR] [NINJA] raise exception [OHOS ERROR] [NINJA] File "/home/yeyangxi/xts/arkui/build/hb/modules/interface/build_module_interface.py", line 68, in run [OHOS ERROR] [NINJA] self._ninja() [OHOS ERROR] [NINJA] File "/home/yeyangxi/xts/arkui/build/hb/util/timer_util.py", line 30, in inner [OHOS ERROR] [NINJA] res = func(*arg, **kwarg) [OHOS ERROR] [NINJA] ^^^^^^^^^^^^^^^^^^^ [OHOS ERROR] [NINJA] File "/home/yeyangxi/xts/arkui/build/hb/modules/interface/build_module_interface.py", line 125, in _ninja [OHOS ERROR] [NINJA] self._target_compilation() [OHOS ERROR] [NINJA] File "/home/yeyangxi/xts/arkui/build/hb/modules/ohos_build_module.py", line 112, in _target_compilation [OHOS ERROR] [NINJA] self.target_compiler.run() [OHOS ERROR] [NINJA] File "/home/yeyangxi/xts/arkui/build/hb/services/ninja.py", line 39, in run [OHOS ERROR] [NINJA] self._execute_ninja_cmd() [OHOS ERROR] [NINJA] File "/home/yeyangxi/xts/arkui/build/hb/services/ninja.py", line 70, in _execute_ninja_cmd [OHOS ERROR] [NINJA] SystemUtil.exec_command( [OHOS ERROR] [NINJA] File "/home/yeyangxi/xts/arkui/build/hb/util/system_util.py", line 135, in exec_command [OHOS ERROR] [NINJA] LogUtil.get_failed_log(log_path) [OHOS ERROR] [NINJA] File "/home/yeyangxi/xts/arkui/build/hb/util/log_util.py", line 209, in get_failed_log [OHOS ERROR] [NINJA] LogUtil.get_compiler_failed_log(log_path) [OHOS ERROR] [NINJA] File "/home/yeyangxi/xts/arkui/build/hb/util/log_util.py", line 196, in get_compiler_failed_log [OHOS ERROR] [NINJA] raise OHOSException( [OHOS ERROR] [NINJA] exceptions.ohos_exception.OHOSException: COMPILE Failed! Please check error in /home/yeyangxi/xts/arkui/out/arkui-x/error.log, and for more build information in /home/yeyangxi/xts/arkui/out/arkui-x/build.log [OHOS ERROR] [NINJA] [OHOS ERROR] [NINJA] Code: 4000 [OHOS ERROR] [NINJA] [OHOS ERROR] [NINJA] Reason: COMPILE Failed! Please check error in /home/yeyangxi/xts/arkui/out/arkui-x/error.log, and for more build information in /home/yeyangxi/xts/arkui/out/arkui-x/build.log [OHOS ERROR] [NINJA] [OHOS ERROR] [NINJA] Error Type: Ninja build error [OHOS ERROR] [NINJA] [OHOS ERROR] [NINJA] Description: An unknown error occurred while executing 'ninja -C'. [OHOS ERROR] [NINJA] [OHOS ERROR] [NINJA] Solution: no solution [OHOS ERROR] [NINJA] =====build error===== yeyangxi@UICD-yeyangxi:~/xts/arkui$ ^C yeyangxi@UICD-yeyangxi:~/xts/arkui$ npm run clean npm ERR! code ENOENT npm ERR! syscall open npm ERR! path /home/yeyangxi/xts/arkui/package.json npm ERR! errno -2 npm ERR! enoent Could not read package.json: Error: ENOENT: no such file or directory, open '/home/yeyangxi/xts/arkui/package.json' npm ERR! enoent This is related to npm not being able to find a file. npm ERR! enoent npm ERR! A complete log of this run can be found in: /home/yeyangxi/.npm/_logs/2025-09-21T17_49_49_482Z-debug-0.log yeyangxi@UICD-yeyangxi:~/xts/arkui$ ^C yeyangxi@UICD-yeyangxi:~/xts/arkui$
最新发布
09-23
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值