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

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 737|回复: 0
打印 上一主题 下一主题

[参考文档] Oracle Linux 6 -- Cannot initialize tmpfs size set with /etc/fstab

[复制链接]
跳转到指定楼层
楼主
发表于 2023-5-28 12:12:46 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
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.

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 支持支持 反对反对
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|手机版|小黑屋|重庆思庄Oracle、Redhat认证学习论坛 ( 渝ICP备12004239号-4 )

GMT+8, 2024-4-26 03:46 , Processed in 0.091530 second(s), 20 queries .

重庆思庄学习中心论坛-重庆思庄科技有限公司论坛

© 2001-2020

快速回复 返回顶部 返回列表