How to configure tmpfs size?

Configuring the size of a tmpfs filesystem in Linux can be done during the mounting process or by modifying an existing mount. Here’s how you can do it:

1. Mounting tmpfs with a Specific Size

When you mount a tmpfs, you can specify its size using the size option. Here’s the command syntax:

mount -t tmpfs -o size=SIZE tmpfs MOUNT_POINT
  • SIZE: Specify the size limit (e.g., 100M for 100 megabytes, 1G for 1 gigabyte).
  • MOUNT_POINT: The directory where you want to mount the tmpfs.

Example

To mount a tmpfs of 512 megabytes at /mnt/tmpfs, you would run:

sudo mount -t tmpfs -o size=512M tmpfs /mnt/tmpfs

2. Modifying an Existing tmpfs Mount

If you already have a tmpfs mounted and want to change its size, you can use the mount command with the remount option:

sudo mount -o remount,size=NEW_SIZE MOUNT_POINT

Example

To change the size of an existing tmpfs mounted at /mnt/tmpfs to 1 gigabyte:

sudo mount -o remount,size=1G /mnt/tmpfs

3. Persistent Configuration

To make the tmpfs mount persistent across reboots, you can add an entry to the /etc/fstab file. Here’s the format:

tmpfs   MOUNT_POINT   tmpfs   size=SIZE   0   0

Example

To configure a tmpfs of 256 megabytes at /mnt/tmpfs, add the following line to /etc/fstab:

tmpfs   /mnt/tmpfs   tmpfs   size=256M   0   0

Conclusion

Configuring the size of a tmpfs filesystem is straightforward, whether during the initial mount, modifying an existing mount, or making it persistent in /etc/fstab. Adjusting the size allows you to optimize memory usage based on your system's needs. If you have further questions or need clarification, feel free to ask!

0 Comments

no data
Be the first to share your comment!