重庆思庄Oracle、、PostgreSQL、Redhat认证学习论坛

标题: Oracle Linux 6 -- Cannot initialize tmpfs size set with /etc/fstab [打印本页]

作者: 刘泽宇    时间: 2023-5-28 12:12
标题: Oracle Linux 6 -- Cannot initialize tmpfs size set with /etc/fstab
SYMPTOMS
tmpfs, which is a on-memory temporary filesystem, can be created and mounted on Linux. Be default, the tmpfs filesystem is set to be 50% of physical memory size. The size of the filesystem can also be set to the size set in mount option, such as size=<N> with suffix of k, m, or g, as well as %. It is also possible to set the size in /etc/fstab so that tmpfs can be mounted upon boot.

However, on Oracle Linux 6 (up to 6.3), the initial tmpfs size is always set to the default size regardless of the option set in /etc/fstab.

Example: Physical Memory = 800MB

We set the following line in /etc/fstab so that /dev/shm is mounted as tmpfs with 30% of memory size.

tmpfs /dev/shm tmpfs defaults,size=30% 0 0
However, upon reboot, df command result shows that /dev/shm has size of 385 megabytes,  which is approximately 50% of physical memory.

# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 8.8G 1.7G 6.7G 20% /
tmpfs 385M 0 385M 0% /dev/shm
/dev/sda1 99M 45M 50M 48% /boot
Once you remount, /dev/shm is set to 231 megabytes, which is 30% of physical memory.

# mount -o remount /dev/shm
# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 8.8G 1.7G 6.7G 20% /
tmpfs 231M 0 231M 0% /dev/shm
/dev/sda1 99M 45M 50M 48% /boot

CAUSE
/dev/tmpfs is mounted by init script included in the initramfs. In other words, /dev/tmpfs is mounted before root (/) filesystem is mounted, but the /etc/rc.d/rc.sysinit does not remount on /dev/tmpfs. This is why any optional setting in /etc/fstab is not honored.

Example: Oracle Linux 6.1
From init script extracted from /boot/initramfs-2.6.32-100.34.1.el6uek.x86_64.img, init it hardcoded to munt /dev/shm with default option.

106 mkdir /dev/shm
107 mkdir /dev/pts
108 mount -t devpts -o gid=5,mode=620 devpts /dev/pts >/dev/null 2>&1
109 mount -t tmpfs tmpfs /dev/shm >/dev/null 2>&1

SOLUTION
Edit /etc/rc.d/rc.sysinit script file, search for the following part, then add one line to remount /dev/shm at the end of if ... fi clause.

if [ "$READONLY" != "yes" ] ; then
        # Clear mtab
        (> /etc/mtab) &> /dev/null

        # Remove stale backups
        rm -f /etc/mtab~ /etc/mtab~~

        # Enter mounted filesystems into /etc/mtab
        mount -f /
        mount -f /proc >/dev/null 2>&1
        mount -f /sys >/dev/null 2>&1
        mount -f /dev/pts >/dev/null 2>&1
        mount -f /dev/shm >/dev/null 2>&1
        mount -f /proc/bus/usb >/dev/null 2>&1
        mount -o remount /dev/shm
fi
On next reboot, /dev/shm is mounted with the specified option set in /etc/fstab.

The other solution is to simply update to Oracle Linux 6.4 or later, where the init script remounts /dev/shm upon boot.






欢迎光临 重庆思庄Oracle、、PostgreSQL、Redhat认证学习论坛 (http://bbs.cqsztech.com/) Powered by Discuz! X3.2