Tuesday, July 12, 2016

How to resize the tmpfs (/dev/shm) in Linux

There are times when the tmp file system may become full and a need arises for resizing (or increasing the size) of the file system. This can be achieved in two ways, one is to make the change temporarily without rebooting the host; the other is to make the change permanently so that everytime the host is rebooted, the tmp file system is mounted with the modified size.

Note that the size of tmp file system can be increased to a certain predefined limit. If the size specified during mount/resize(remount) is beyond the set limit, the mount would fail and the tmp file system will not be mounted.

To view the current size of the tmp file system, the following command can be run.

~]# df -h

The output would show something like below.

Filesystem            Size  Used Avail Use% Mounted on
/dev/sda3              91G   26G   61G  30% /
tmpfs                 1.9G  107M  1.8G   6% /dev/shm

  • Increasing/resizing the file system temporarily:
    The following command can be run to remount the tmp file system with an increased size.

    ~]# mount -o remount,resize=4g /dev/shm
    ~]#

  • Making the size change persist across reboot:
    To make the change persist across reboot, the entry for mounting the tmp file system in the file /etc/fstab must be modified as shown below.

    ~]# vim /etc/fstab
    #
    # /etc/fstab
    # Created by anaconda on Mon Feb 8 15:28:09 2016
    #
    # 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
    #
    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
    ~]#

Once the changes are made (using either approach) run the following command to see that the change in the size.

~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda3              91G   26G   61G  30% /
tmpfs                 4.0G  107M  3.9G   3% /dev/shm

0 comments:

Post a Comment