Create a Custom Mount Point with Noexec on Debian

Posted on May 26, 2018 at 11:14 am

Lets say we want to create a new mount point /test with flag “noexec” but we cannot create a new partition because, for example, we are using a VPS. How can we do that? Simple, we can create a file, make it an ext4 file system, mount it with “noexec” flag, and edit /etc/fstab to auto-mount /test on reboot. All files placed in /test will survive the reboot.

Create the directory /test:

mkdir /test

Create a 1GB file for our /test partition:

dd if=/dev/zero of=/var/testMountFile bs=1024 count=1000000

Make the new filesystem as ext4:

mkfs.ext4 /var/testMountFile

Mount the new /test filesystem with noexec:

mount -o rw,nodev,nosuid,noexec /var/testMountFile /test

Add this line to /etc/fstab so it mounts on reboot:

/var/testMountFile /test ext4 rw,nodev,nosuid,noexec 0 2

Reboot the VPS:

shutdown r now

Updated on October 2, 2018 at 10:23 pm

Receive updates via email

Other Posts

Updated Posts