Linux中的shm和tmpfs介绍以及ORA-00845 MEMORY_TARGET not supported on this system
Tags: /dev/shmLinuxMEMORY_TARGETORA-00845OStmpfs共享内存
简介
linux中/dev
目录下一般都是一些设备文件,例如磁盘、内存、摄像头等。
使用redhat系列的操作系统,可以发现系统默认挂载了/dev/shm,挂载类型为tmpfs。tmpfs(temporary filesystem)是Linux特有的文件系统,标准挂载点是/dev/shm.
/dev/shm共享内存
/dev/shm
这个目录是linux下一个利用内存虚拟出来的一个目录,这个目录中的文件都是保存在内存中,而不是磁盘上。其大小是非固定的,即不是预先分配好的内存来存储的。(shm =shared memory)
默认的Linux发行版中的内核配置都会开启tmpfs,映射到了/dev/下的shm目录。可以通过df 命令查看结果.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | [root@docker35 ~]# free -h total used free shared buff/cache available Mem: 78G 4.3G 46G 2.0G 27G 71G Swap: 10G 0B 10G [root@docker35 ~]# df -h | grep tmpfs devtmpfs 40G 0 40G 0% /dev tmpfs 40G 0 40G 0% /dev/shm tmpfs 40G 123M 40G 1% /run tmpfs 40G 0 40G 0% /sys/fs/cgroup [root@lhrblog ~]# df -h | egrep -e "tmpfs|shm" tmpfs 64M 0 64M 0% /dev shm 64M 4.0K 64M 1% /dev/shm tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup tmpfs 1.9G 213M 1.7G 12% /run tmpfs 379M 0 379M 0% /run/user/0 |
其他的几个tmpfs
的挂载目录,其实质上于/dev/shm
是一致的。
/dev/shm/是linux下一个非常有用的目录,因为这个目录不在硬盘上,而是在内存里。因此在linux下,就不需要大费周折去建ramdisk,直接使用/dev/shm/就可达到很好的优化效果。
tmpfs临时文件系统
tmpfs(temporary filesystem)是Linux/Unix系统上的一种基于内存的虚拟文件系统。tmpfs可以使用您的内存或swap分区来存储文件(即它的存储空间在virtual memory 中, VM由real memory和swap组成)。tmpfs有些像虚拟磁盘(ramdisk),但不一样。像虚拟磁盘一样,tmpfs 可以使用您的 RAM,但它也可以使用您的交换分区来存储。而且传统的虚拟磁盘是个块设备,并需要一个 mkfs 之类的命令才能真正地使用它,tmpfs 是一个文件系统,而不是块设备;您只是安装它,它就可以使用了。
tmpfs有以下优势:
1、动态文件系统的大小,/dev/shm/需要注意的一个是容量问题,在linux下,它默认最大为内存的一半大小,在Docker容器中,/dev/shm/目录默认情况下是64MB,使用df -h命令可以看到。但它并不会真正的占用这块内存,如果/dev/shm/下没有任何文件,它占用的内存实际上就是0字节;如果它最大为1G,里头放有 100M文件,那剩余的900M仍然可为其它应用程序所使用,但它所占用的100M内存,是绝不会被系统回收重新划分的。
2、tmpfs 的另一个主要的好处是它闪电般的速度。因为典型的 tmpfs 文件系统会完全驻留在 RAM 中,读写几乎可以是瞬间的。
3、tmpfs 数据在重新启动之后不会保留,因为虚拟内存本质上就是易失的。所以有必要做一些脚本做诸如加载,绑定的操作。
修改/dev/shm大小
默认为最大一半内存大小在某些场合可能不够用,并且默认的inode数量很低一般都要调高些,这时可以用mount命令来管理它。
1 | mount -o size=1500M -o nr_inodes=1000000 -o noatime,nodiratime -o remount /dev/shm |
在2G的机器上,将最大容量调到1.5G,并且inode数量调到1000000,这意味着大致可存入最多一百万个小文件。
如果需要永久修改/dev/shm的值,需要修改/etc/fstab
1 2 3 | tmpfs /dev/shm tmpfs defaults,size=1.5G 0 0 mount -o remount /dev/shm |
/dev/shm应用
首先在/dev/shm建个tmp文件夹,然后与实际/tmp绑定:
1 2 3 | mkdir /dev/shm/tmp chmod 1777 /dev/shm/tmp mount –bind /dev/shm/tmp /tmp(–bind ) |
在使用mount –bind olderdir newerdir命令来挂载一个目录到另一个目录后,newerdir的权限和所有者等所有信息会发生变化。挂载后的目录继承了被挂载目录的所有属性,除了名称。
ORA-00845: MEMORY_TARGET not supported on this system
Oracle 11g的AMM(Automatic Memory Management)内存管理模式就是使用/dev/shm;若使用ASMM(Automatic Shared Memory Management),则不会使用/dev/shm,也就不会报错。
所以有时候修改MEMORY_MAX_TARGET会出现ORA-00845的错误。
简单来说就是 MEMORY_MAX_TARGET 的设置不能超过 /dev/shm 的大小。
永久修改,需要修改/etc/fstab:
1 | tmpfs /dev/shm tmpfs defaults,size=4G 0 0 |
临时修改,可以使用命令:
1 | mount -o remount,size=4G /dev/shm |
由于docker容器中没有/etc/fstab文件,所以我们只能每次重启容器后都修改一下/dev/shm大小。
1 2 3 | mount -o remount,size=4G /dev/shm echo "mount -o remount,size=4G /dev/shm" >> /etc/rc.local chmod +x /etc/rc.d/rc.local |
ORA-00845错误模拟
在Oracle 11g中如果采用AMM内存管理,那么当MEMORY_TARGET的值大于/dev/shm的时候,就会报ORA-00845: MEMORY_TARGET not supported on this system错误,解决办法增加/dev/shm大小,在redhat系列系统中,/dev/shm的默认值是系统总内存的一半
1、错误重现
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 | SQL>SELECT * FROM V$VERSION; BANNER ——————————————————————————– Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 – Production PL/SQL Release 11.2.0.3.0 – Production CORE 11.2.0.3.0 Production TNS for Linux: Version 11.2.0.3.0 – Production NLSRTL Version 11.2.0.3.0 – Production SQL>show parameter memory; NAME TYPE VALUE ———————————— ———– —————————— hi_shared_memory_address integer 0 memory_max_target big integer 500M memory_target big integer 500M shared_memory_address integer 0 SQL>alter system set memory_max_target=800m; alter system set memory_max_target=800m * ERROR at line 1: ORA-02095: specified initialization parameter cannot be modified SQL>alter system set memory_max_target=800m scope=spfile; System altered. SQL>alter system set memory_target=800m scope=spfile; System altered. SQL>shutdown immediate; Database closed. Database dismounted. ORACLE instance shut down. SQL>exit Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 – Production With the Partitioning, OLAP, Data Mining and Real Application Testing options [oracle@lhraxxt admin]$ sqlplus / as sysdba SQL*Plus: Release 11.2.0.3.0 Production on Sat Nov 5 19:01:18 2011 Copyright (c) 1982, 2011, Oracle. All rights reserved. Connected to an idle instance. SQL>startup ORA-00845: MEMORY_TARGET not supported on this system SQL>!oerr ora 845 00845, 00000, "MEMORY_TARGET not supported on this system" // *Cause: The MEMORY_TARGET parameter was not supported on this operating system or /dev/shm was not sized correctly on Linux. // *Action: Refer to documentation for a list of supported operating systems. Or, size /dev/shm to be at least the SGA_MAX_SIZE on each Oracle instance running on the system. |
2、修改/dev/shm大小
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | [root@lhraxxt ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/vg_lhraxxt-lv_root 17G 13G 3.9G 77% / tmpfs 590M 0 590M 0% /dev/shm /dev/sda1 485M 30M 430M 7% /boot [root@lhraxxt ~]# mount -o size=900M -o nr_inodes=1000000 -o noatime,nodiratime -o remount /dev/shm [root@lhraxxt ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/vg_lhraxxt-lv_root 17G 13G 3.9G 77% / tmpfs 900M 0 900M 0% /dev/shm /dev/sda1 485M 30M 430M 7% /boot [root@lhraxxt ~]# vi /etc/fstab \# \# /etc/fstab \# Created by anaconda on Sat Nov 5 02:49:30 2011 \# \# 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 \# /dev/mapper/vg_lhraxxt-lv_root / ext4 defaults 1 1 UUID=7ace6c04-d232-43ac-9ef5-70ea92fe49bd /boot ext4 defaults 1 2 /dev/mapper/vg_lhraxxt-lv_swap swap swap defaults 0 0 tmpfs /dev/shm tmpfs defaults,size=900M 0 0 devpts /dev/pts devpts gid=5,mode=620 0 0 sysfs /sys sysfs defaults 0 0 proc /proc proc defaults 0 0 |
3、启动数据库验证
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | [oracle@lhraxxt admin]$ sqlplus / as sysdba SQL*Plus: Release 11.2.0.3.0 Production on Sat Nov 5 19:03:51 2011 Copyright (c) 1982, 2011, Oracle. All rights reserved. Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 – Production With the Partitioning, OLAP, Data Mining and Real Application Testing options sys@XFF>show parameter memory; NAME TYPE VALUE ———————————— ———– —————————— hi_shared_memory_address integer 0 memory_max_target big integer 800M memory_target big integer 800M shared_memory_address integer 0 |
4、官方解释
Starting with Oracle Database 11g, the Automatic Memory Management feature requires more shared memory (/dev/shm)and file descriptors. The size of the shared memory should be at least the greater of MEMORY_MAX_TARGET and MEMORY_TARGET for each Oracle instance on the computer. If MEMORY_MAX_TARGET or MEMORY_TARGET is set to a non zero value, and an incorrect size is assigned to the shared memory, it will result in an ORA-00845 error at startup.
5、解决问题建议
5.1. If you are installing Oracle 11g on a Linux system, note that Memory Size (SGA and PGA), which sets the initialization parameter MEMORY_TARGET or MEMORY_MAX_TARGET, cannot be greater than the shared memory filesystem (/dev/shm) on your operating system. To resolve the current error, increase the /dev/shm file size.
5.2. If configuring AMM is not possible due to lack of space on /dev/shm mount point, you can configure ASMM instead of AMM, i.e. set SGA_TARGET, SGA_MAX_SIZE and PGA_AGGREGATE_TARGET instead of MEMORY_TARGET.
在redhat6中,修改了fstab中修改后,不能生效,需要重新挂载
1 2 3 4 5 | vi /etc/fstab tmpfs /dev/shm tmpfs defaults,size=900M 0 0 vi /etc/rc.local mount -o remount /dev/shm |
ORA-00845: MEMORY_TARGET示例2
Linux操作系统,oracle 11.2.0.4 启动实例时出现如下错误:
1 2 | SQL> startup nomount pfile=/u03/app/oracle/11.2.0/db/dbs/initcssb.ora ORA-00845: MEMORY_TARGET not supported on this system |
查看错误帮助信息
1 2 3 4 | [oracle11@oracle11g dbs]$ oerr ora 845 00845, 00000, "MEMORY_TARGET not supported on this system" // *Cause: The MEMORY_TARGET parameter was not supported on this operating system or /dev/shm was not sized correctly on Linux. // *Action: Refer to documentation for a list of supported operating systems. Or, size /dev/shm to be at least the SGA_MAX_SIZE on each Oracle instance running on the system. |
错误原因是这个操作系统不支持MEMORY_TARGET参数或/dev/shm在Linux上的大小不正确造成的,这是该操作系统上的第二个实例,第一个实例设置了MEMORY_TARGET参数,所以并不是不支持这个参数,原因就只有/dev/shm大小不正确了,解决方法是要将/dev/shm的最小值设置为操作系统上运行实例SGA_MAX_SIZE所设置的大小。/dev/shm/是linux下一个目录,/dev/shm目录不在磁盘上,而是在内存里,因此使用linux /dev/shm/的效率非常高,直接写进内存。
tmpfs有以下特点:
1.tmpfs 是一个文件系统,而不是块设备;您只是安装它,它就可以使用了。
2.动态文件系统的大小。
3.tmpfs 的另一个主要的好处是它闪电般的速度。因为典型的 tmpfs 文件系统会完全驻留在 RAM 中,读写几乎可以是瞬间的。
4.tmpfs 数据在重新启动之后不会保留,因为虚拟内存本质上就是易失的。所以有必要做一些脚本做诸如加载、绑定的操作。
linux下/dev/shm的容量默认最大为内存的一半大小,使用df -h命令可以看到。但它并不会真正的占用这块内存,如果/dev/shm/下没有任何文件,它占用的内存实际上就是0字节;如果它最大为1G,里头放有100M文件,那剩余的900M仍然可为其它应用程序所使用,但它所占用的100M内存,是绝不会被系统回收重新划分的。
linux /dev/shm容量(大小)是可以调整,在有些情况下(如oracle数据库)默认的最大一半内存不够用,并且默认的inode数量很低一般都要调高些,这时可以用mount命令来管理它。
mount -o size=1500M -o nr_inodes=1000000 -o noatime,nodiratime -o remount /dev/shm
在2G的机器上,将最大容量调到1.5G,并且inode数量调到1000000,这意味着大致可存入最多一百万个小文件通过/etc/fstab文件来修改/dev/shm的容量(增加size选项即可),修改后,重新挂载即可。
这里该实例的SGA_MAX_SIZE为1G,下面的命令查看/dev/shm的大小。
1 2 3 4 5 | [root@oracle11g ~]# df -lh Filesystem Size Used Avail Use% Mounted on /dev/sda1 23G 20G 1.6G 93% / /dev/sdb1 9.9G 5.8G 3.6G 62% /u02 tmpfs 2G 1.3M 0.7G 65% /dev/shm |
从上面结果可以看到/dev/shm可用大小只有0.7G,执行下面的命令来进行修改。
1 2 3 4 5 6 7 8 9 10 | [root@oracle11g ~]# vi /etc/fstab LABEL=/ / ext3 defaults 1 1 /dev/sdb1 /u02 ext3 defaults 1 2 tmpfs /dev/shm tmpfs defaults,size=4G 0 0 devpts /dev/pts devpts gid=5,mode=620 0 0 sysfs /sys sysfs defaults 0 0 proc /proc proc defaults 0 0 LABEL=SWAP-sda2 swap swap defaults 0 0 "/etc/fstab" 7L, 540C written |
卸载/dev/shm,但/dev/shm正被访问
1 2 3 | [root@oracle11g ~]# umount /dev/shm umount: /dev/shm: device is busy umount: /dev/shm: device is busy |
用fuser处理,fuser命令,-k:kill processes accessing the named file(杀死所有正在访问指定文件的进程),-m 表示指定文件所在的文件系统或者块设备(处于 mount 状态)。所有访问该文件系统的进程都被列出。
1 2 3 4 5 6 7 8 9 | [root@oracle11g ~]# fuser -km /dev/shm /dev/shm: 3152m 3154m 3156m 3160m 3162m 3164m 3166m 3168m 3170m 3172m 3174m 3176m 3178m 3180m 3182m 3184m 3186m 3193m 3195m 3197m 3199m 3201m 3236m 3248m 3250m 3256m 3292m 4366m [root@oracle11g ~]# umount /dev/shm [root@oracle11g ~]# mount /dev/shm [root@oracle11g ~]# df -lh Filesystem Size Used Avail Use% Mounted on /dev/sda1 23G 20G 1.6G 93% / /dev/sdb1 9.9G 5.8G 3.6G 62% /u02 tmpfs 4.0G 0 4.0G 0% /dev/shm |
再重新启动实例
1 2 3 4 5 6 7 8 | SQL> startup nomount pfile=/u03/app/oracle/11.2.0/db/dbs/initcssb.ora ORACLE instance started. Total System Global Area 1334786560 bytes Fixed Size 1364480 bytes Variable Size 171970048 bytes Database Buffers 1155189248 bytes Redo Buffers 6262784 bytes |
小结:Oracle 11g的AMM内存管理模式就是使用/dev/shm,所以有时候修改MEMORY_TARGET或者MEMORY_MAX_TARGET会出现ORA-00845的错误,在安装配置实例内存时为了避免出现这个故障可以对Linux系统中的/dev/shm进行调整,让其可用大小至少等于实例的sga_max_size。
其它虚拟内核文件系统
虚拟内核文件系统(VirtualKernel File Systems),是指那些是由内核产生但不存在于硬盘上(存在于内存中)的文件系统。例如
1、proc
proc文件系统为操作系统本身和应用程序之间的通信提供了一个安全的接口。通过它里面的一些文件,可以获取系统状态信息并修改某些系统的配置信息。当我们在内核中添加了新功能或设备驱动时,经常需要得到一些系统状态的信息,一般这样的功能需要经过一些像ioctl()这样的系统调用来完成。
2、devfs
我们知道,/dev目录下的每一个文件都对应的是一个设备,devfs也是挂载于/dev目录下。在2.6内核以前使用devfs来提供一种类似于文件的方法来管理位于/dev目录下的所有设备。但是devfs文件系统有一些缺点,有时一个设备映射的设备文件可能不同。例如,我的U盘可能对应sda,也可能对应sdb,没有足够的主/辅设备号,当设备过多的时候,显然这会成为一个问题。
3、sysfs
为了克服devfs的上述问题,2.6内核引入了一个新的文件系统sysfs,它挂载于/sys目录下。sysfs文件系统把连接在系统上的设备和总线组织成为一个分级的文件,用户空间的程序同样可以利用这些信息,以实现和内核的交互。sysfs文件系统是当前系统上实际设备树的一个直观反映,它是通过kobject子系统来建立这个信息的,当一个kobject被创建的时候,对应的文件和目录也就被创建了。
4、tmpfs
tmpfs(temporary filesystem)是Linux特有的文件系统,标准挂载点是/dev/shm.
Tmpfsis a file system which keeps all files in virtual memory.
Everythingin tmpfs is temporary in the sense that no files will be
created on your hard drive. If you unmount a tmpfs instance,
everything stored therein is lost.
tmpfsputs everything into the kernel internal caches and grows and
shrinks to accommodate the files it contains and is able to swap
unneeded pages out to swap space. It has maximum size limits which can
be adjusted on the fly via ‘mount -o remount …’
Ifyou compare it to ramfs (which was the template to create tmpfs)
you gain swapping and limit checking. Another similar thing is the RAM
disk (/dev/ram*), which simulates a fixed size hard disk in physical
RAM, where you have to create an ordinary filesystem on top. Ramdisks
cannot swap and you do not have the possibility to resize them.
Sincetmpfs lives completely in the page cache and on swap, all tmpfs
pages currently in memory will show up as cached. It will not show up
as shared or something like that. Further on you can check the actual
RAM+swap use of a tmpfs instance with df(1) and du(1).
tmpfshas the following uses:
1)There is always a kernel internal mount which you will not see at
all. This is used for shared anonymous mappings and SYSV shared
memory.
Thismount does not depend on CONFIG_TMPFS. If CONFIG_TMPFS is not
set, the user visible part of tmpfs is not build. But the internal
mechanisms are always present.
2)glibc 2.2 and above expects tmpfs to be mounted at /dev/shm for
POSIX shared memory (shm_open, shm_unlink). Adding the following
line to /etc/fstab should take care of this:
tmpfs/dev/shm tmpfs defaults 0 0
Rememberto create the directory that you intend to mount tmpfs on
if necessary (/dev/shm is automagically created if you use devfs).
Thismount is not needed for SYSV shared memory. The internal
mount is used for that. (In the 2.3 kernel versions it was
necessary to mount the predecessor of tmpfs (shm fs) to use SYSV
shared memory)
3)Some people (including me) find it very convenient to mount it
e.g. on /tmp and /var/tmp and have a big swap partition. But be
aware: loop mounts of tmpfs files do not work due to the internal
design. So mkinitrd shipped by most distributions will fail with a
tmpfs /tmp.
4)And probably a lot more I do not know about
tmpfshas a couple of mount options:
size:The limit of allocated bytes for this tmpfs instance. The
default is half of your physical RAM without swap. If you
oversize your tmpfs instances the machine will deadlock
since the OOM handler will not be able to free that memory.
nr_blocks: The same as size, but in blocks of PAGECACHE_SIZE.
nr_inodes: The maximum number of inodes for this instance. The default
is half of the number of your physical RAM pages.
Theseparameters accept a suffix k, m or g for kilo, mega and giga and
can be changed on remount.
Tospecify the initial root directory you can use the following mount
options:
mode:The permissions as an octal number
uid: The user id
gid: The group id
Theseoptions do not have any effect on remount. You can change these
parameters with chmod(1), chown(1) and chgrp(1) on a mounted filesystem.
So‘mount -t tmpfs -o size=10G,nr_inodes=10k,mode=700 tmpfs /mytmpfs’
will give you tmpfs instance on /mytmpfs which can allocate 10GB
RAM/SWAP in 10240 inodes and it is only accessible by root.
TODOs:
1)give the size option a percent semantic: If you give a mount option
size=50% the tmpfs instance should be able to grow to 50 percent of
RAM + swap. So the instance should adapt automatically if you add
or remove swap space.
\2) loop mounts: This is difficult since loop.c relies on the readpage
operation. This operation gets a page from the caller to be filled
with the content of the file at that position. But tmpfs always has
the page and thus cannot copy the content to the given page. So it
cannot provide this operation. The VM had to be changed seriously
to achieve this.
\3) Show the number of tmpfs RAM pages. (As shared?)
Author:
Christoph Rohland , 1.12.01
Doc ID 1399209.1
Starting with Oracle Database 11g, the Automatic MemoryManagement feature requires more shared memory (/dev/shm) and file descriptors.The size of the shared memory must be at least the greater of theMEMORY_MAX_TARGET and MEMORY_TARGET parameters for each Oracle instance on thecomputer. If the MEMORY_MAX_TARGET parameter or the MEMORY_TARGET parameter isset to a nonzero value, and an incorrect size is assigned to the shared memory,it results in an ORA-00845 error at startup.
On Linux systems, if the operating system /dev/shm mount size is too small forthe Oracle system global area (SGA) and program global area (PGA), then youencounter the following error:
The cause of this error is an insufficient /dev/shm allocation.The total memory size of the SGA and PGA, which sets the initializationparameter MEMORY_TARGET or MEMORY_MAX_TARGET, cannot be greater than the sharedmemory file system (/dev/shm) on your operating system.
Linux umount 报 device is busy 的处理方法
今天在IDC 辐射了半天,又弄了套DG。 在Linux 挂盘这块也小学了两招。
一. umout 移动硬盘
开始用sftp 将安装文件copy到服务器的时候,速度太慢了,500k/s。几个G的东西,copy 这些就要半个多小时,扛不住,拿移动硬盘来copy了。结果移动硬盘的格式不对。 是NTFS 格式,Linux 识别不了。 只能格式化成FAT32的。 而GG 的win7 系统又不具备格式化成FAT32的功能。 有点小变态。让同事在XP 下帮我格式化了。
安装文件copy到服务器后,同事直接将移动硬盘从服务器上拔下来了。 导致的结果是,用df 命令查看,挂载的移动硬盘还存在。
[root@qs-wg-db1 ~]# df -lh
Filesystem Size Used Avail Use% Mounted on
/dev/sdb3 125G 3.3G 115G 3% /
/dev/sdb1 99M 12M 82M 13% /boot
tmpfs 3.9G 0 3.9G 0% /dev/shm
/dev/sda1 275G 72G 189G 28% /u01
/dev/sdc1 10G 2.0G 8.1G 20% /datatmp
就是这个/dev/sdc1。
这时使用umount 命令,会提示设备忙,无法挂载。
处理方法:
[root@qs-wg-db1 ~]# fuser -km /datatmp
[root@qs-wg-db1 ~]# df -lh
Filesystem Size Used Avail Use% Mounted on
/dev/sdb3 125G 3.3G 115G 3% /
/dev/sdb1 99M 12M 82M 13% /boot
tmpfs 3.9G 0 3.9G 0% /dev/shm
/dev/sda1 275G 72G 189G 28% /u01
/dev/sdc1 10G 2.0G 8.1G 20% /datatmp
[root@qs-wg-db1 ~]# umount /datatmp
[root@qs-wg-db1 ~]# df -lh
Filesystem Size Used Avail Use% Mounted on
/dev/sdb3 125G 3.3G 115G 3% /
/dev/sdb1 99M 12M 82M 13% /boot
tmpfs 3.9G 0 3.9G 0% /dev/shm
/dev/sda1 275G 72G 189G 28% /u01
成功umount了。
二. umount 光驱
安装DB 之前,检查了一下相关包,少了3个。 从系统安装盘上找了包,安装了一下。 当时是直接将/dev/cdrom mount 到了/mnt目录。 也是图个方便。 结果收工时去拿盘,光驱弹不出来。 同事让我把cdrom umout掉。 同样的提示,设备忙。
处理方法:
[root@qs-wg-db1 ~]#fuser –km /dev/cdrom
[root@qs-wg-db1 ~]#eject -- 弹出光驱
在网上搜了一下,正确挂载CD-ROM的方法应该如下:
# mkdir cdrom
# mount /dev/cdrom /mnt/cdrom
或者
# mount /dev/cdrom /media/cdrom
直接挂载在/mnt,/media等系统目录下,在umount时会出现出错信息“umount: /mnt/cdrom: device is busy”的情况。
如果一个文件系统处于“busy”状态的时候,不能卸载该文件系统。如下情况将导致文件系统处于“busy”状态:
1 2 3 4 5 | \1) 文件系统上面有打开的文件 \2) 某个进程的工作目录在此文件系统上 \3) 文件系统上面的缓存文件正在被使用 |
三. fuser 命令
1 | 前面2个umout 都使用了这个fuser 命令。 man了一下这个命令。 内容如下: |
[root@qs-wg-db1 ~]# man fuser
FUSER(1) User Commands FUSER(1)
NAME
1 | fuser - identify processes using files or sockets |
SYNOPSIS
1 2 3 4 5 | fuser [-a|-s|-c] [-4|-6] [-n space ] [-k [-i] [-signal ] ] [-muvf] name fuser -l fuser -V |
DESCRIPTION
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | fuser displays the PIDs of processes using the specified files or file systems. In the default display mode, each file name is followed by a letter denoting the type of access: c current directory. e executable being run. f open file. f is omitted in default display mode. F open file for writing. F is omitted in default display mode. r root directory. m mmap'ed file or shared library. fuser returns a non-zero return code if none of the specified files is accessed or in case of a fatal error. If at least one access has been found, fuser returns zero. In order to look up processes using TCP and UDP sockets, the corresponding name space has to be selected with the -n option. By default fuser will look in both IPv6 and IPv4 sockets. To change the default, behavior, use the -4 and -6 options. The socket(s) can be specified by the local and remote port, and the remote address. All fields are optional, but commas in front of missing fields must be present: [lcl_port][,[rmt_host][,[rmt_port]]] Either symbolic or numeric values can be used for IP addresses and port numbers. |
fuser outputs only the PIDs to stdout, everything else is sent to stderr.
OPTIONS
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | -a Show all files specified on the command line. By default, only files that are accessed by at least one process are shown. -c Same as -m option, used for POSIX compatibility. -f Silently ignored, used for POSIX compatibility. -k Kill processes accessing the file. Unless changed with -signal, SIGKILL is sent. An fuser process never kills itself, but may kill other fuser processes. The effective user ID of the process executing fuser is set to its real user ID before attempting to kill. -i Ask the user for confirmation before killing a process. This option is silently ignored if -k is not present too. -l List all known signal names. -m name specifies a file on a mounted file system or a block device that is mounted. All processes accessing files on that file system are listed. If adirectory file is specified, it is automatically changed to name/. to use any file system that might be mounted on that directory. -n space Select a different name space. The name spaces file (file names, the default), udp (local UDP ports), and tcp (local TCP ports) are supported. For ports, either the port number or the symbolic name can be specified. If there is no ambiguity, the shortcut notation name/Ispace (e.g. 80/tcp ) can be used. -s Silent operation. -u and -v are ignored in this mode. -a must not be used with -s. -signal Use the specified signal instead of SIGKILL when killing processes. Signals can be specified either by name (e.g. -HUP) or by number (e.g. -1). This option is silently ignored if the -k option is not used. -u Append the user name of the process owner to each PID. -v Verbose mode. Processes are shown in a ps-like style. The fields PID, USER and COMMAND are similar to ps. ACCESS shows how the process accesses the file. If the access is by the kernel (e.g. in the case of a mount point, awap file, etc.), kernel is shown instead of the PID. -V Display version information. -4 Search only for IPv4 sockets. This option must not be used with the -6 option and only has an effect with the tcp and udp namespaces. -6 Search only for IPv6 sockets. This option must not be used with the -4 option and only has an effect with the tcp and udp namespaces. \- Reset all options and set the signal back to SIGKILL. |
FILES
1 | /proc location of the proc file system |
fuser 命令显示访问某个文件的进程的PID. 其中-k 和 -m 参数上面红色部分有说明。-k 是kill 访问这个文件的进程。 没有进程访问,就可以成功umount了.
参考
https://www.cnblogs.com/haoxiaoyu/p/f53e68d2d09ba861dbdc1fa521f1a54d.html