Ubuntu: Configuring mongo DB to work with NTFS drive


I have 120 GB SSD Drive with two partitions (NTFS with Windows and ext4 with Ubintu) and 2TB NTFS HDD shared between Windows and Ubuntu.

I configured my HDD to be properly mounted on system boot:

# /etc/fstab: static file system information.  UUID=B400515500512022 /media/B400515500512022 ntfs-3g auto,users,uid=1000,gid=1001,fmask=113,dmask=002,utf8 0 0  

I also created special group (gid=1001) to handle permissions and added mongodb user to it:


So, now ntfsdrive group have proper permissions (rw for files and rwx for directories) for the whole drive, including mongodb folder:

drwxrwxr-x 1 leonid ntfsdrive       4096 Feb  6 12:51 mongodb  

But mongodb still refuses to run on this drive:

Wed Feb  6 12:51:31 [initandlisten] MongoDB starting : pid=7480 port=27017 dbpath=/media/B400515500512022/mongodb 64-bit host=ubuntu  Wed Feb  6 12:51:31 [initandlisten] db version v2.2.3, pdfile version 4.5  Wed Feb  6 12:51:31 [initandlisten] git version: f570771a5d8a3846eb7586eaffcf4c2f4a96bf08  Wed Feb  6 12:51:31 [initandlisten] build info: Linux ip-10-2-29-40 #1 SMP Fri Nov 20 17:48:28 EST 2009 x86_64 BOOST_LIB_VERSION=1_49  Wed Feb  6 12:51:31 [initandlisten] options: { config: "/etc/mongodb.conf", dbpath: "/media/B400515500512022/mongodb", logappend: "true", logpath: "/var/log/mongodb/mongodb.log" }  Wed Feb  6 12:51:31 [initandlisten] journal dir=/media/B400515500512022/mongodb/journal  Wed Feb  6 12:51:31 [initandlisten] recover : no journal files present, no recovery needed  Wed Feb  6 12:51:31 [initandlisten] info preallocateIsFaster couldn't run due to: couldn't open file /media/B400515500512022/mongodb/journal/tempLatencyTest for writing errno:1 Operation not permitted; returning false  Wed Feb  6 12:51:31 [initandlisten] exception in initAndListen: 13516 couldn't open file /media/B400515500512022/mongodb/journal/j._0 for writing errno:1 Operation not permitted, terminating  Wed Feb  6 12:51:31 dbexit:   Wed Feb  6 12:51:31 [initandlisten] shutdown: going to close listening sockets...  Wed Feb  6 12:51:31 [initandlisten] shutdown: going to flush diaglog...  Wed Feb  6 12:51:31 [initandlisten] shutdown: going to close sockets...  Wed Feb  6 12:51:31 [initandlisten] shutdown: waiting for fs preallocator...  Wed Feb  6 12:51:31 [initandlisten] shutdown: lock for final commit...  Wed Feb  6 12:51:31 [initandlisten] shutdown: final commit...  Wed Feb  6 12:51:31 [initandlisten] shutdown: closing all files...  Wed Feb  6 12:51:31 [initandlisten] closeAllFiles() finished  Wed Feb  6 12:51:31 [initandlisten] journalCleanup...  Wed Feb  6 12:51:31 [initandlisten] removeJournalFiles  Wed Feb  6 12:51:31 [initandlisten] shutdown: removing fs lock...  Wed Feb  6 12:51:31 dbexit: really exiting now  

I have no problems running mongodb with the same configuration (including mongodb folder permissions) on my ext4 drive.

Is there a way to solve this problem, or my only option is to add ext4 partition to my HDD drive?


Having replicated this myself, it appears that using the mount options you specify allows the mongodb user to write to the NTFS volume, but there is something specific that MongoDB is trying to do with the files that is not permitted by these options; perhaps it cannot set the umask or ownership on its files exactly how it wants to.

The solution is to use the permissions option when mounting the NTFS volume rather than specifying the owner explicitly. See the ntfs-3g man page for further details.

So /etc/fstab would look like this:

UUID=B400515500512022 /media/B400515500512022 ntfs-3g defaults,locale=en_US.UTF-8,permissions 0 0  

On a fresh NTFS volume mounted at /media/B400515500512022, you can then run:

sudo mkdir /media/B400515500512022/mongodb  sudo chown mongodb:mongodb /media/B400515500512022/mongodb  

before running:

sudo -u mongodb mongod --dbpath /media/B400515500512022/mongodb  

You may wish to check that this does not cause problems when accessing the files from Windows.


As a temporary solution I reconfigured mongodb upstart script. I configured it to run mongodb using my own user instead of mongodb user.

To do so I changed the following line in the /etc/init/mongodb.conf file:

if [ "x$ENABLE_MONGODB" = "xyes" ]; then exec start-stop-daemon --start --quiet --chuid mongodb --exec  /usr/bin/mongod -- --config /etc/mongodb.conf; fi  

Both --chuid mongodb:ntfsdrive and --chuid leonid options resulted in the same error, so I completely removed --chuid option from it:

if [ "x$ENABLE_MONGODB" = "xyes" ]; then exec start-stop-daemon --start --quiet --exec  /usr/bin/mongod -- --config /etc/mongodb.conf; fi  

Running mongodb using my own user isn't a good solution, so I think I'll partition my HDD drive to prevent similar problems.

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »