Mongodb – cannot set dbPath to mounted disk

Solution for Mongodb – cannot set dbPath to mounted disk
is Given Below:

$ mount | grep 1TB
/dev/sdb2 on /media/nd/ext1TB type ext4 (rw,relatime)

$ sudo mkdir -p /media/nd/ext1TB/dbpath/mongodb/data/mongodb
$ sudo chown -R mongodb:mongodb /media/nd/ext1TB/dbpath/mongodb

$ ls -l /media/nd/ext1TB/dbpath/mongodb/data/
total 4
drwxr-xr-x 4 mongodb mongodb 4096 Thg 7  31 05:00 mongodb

$ ls -l /var/lib/ | grep mongo
drwxr-xr-x  4 mongodb       mongodb       4096 Thg 7  31 05:34 mongodb

$ cat /etc/mongod.conf 
# mongod.conf

# for documentation of all options, see:
#   http://docs.mongodb.org/manual/reference/configuration-options/

# Where and how to store data.
storage:
#  dbPath: /var/lib/mongodb
  dbPath: /media/nd/ext1TB/dbpath/mongodb/data/mongodb
  journal:
    enabled: true
#  engine:
#  wiredTiger:
  • Error: “error”:”Location28596: Unable to determine status of lock file in the data directory /media/nd/ext1TB/dbpath/mongodb/data/mongodb: boost::filesystem::status: Permission denied:
$ sudo tail -f /var/log/mongodb/mongod.log


{"t":{"$date":"2021-07-31T05:01:34.177+07:00"},"s":"I",  "c":"CONTROL",  "id":20698,   "ctx":"-","msg":"***** SERVER RESTARTED *****"}
{"t":{"$date":"2021-07-31T05:01:34.179+07:00"},"s":"I",  "c":"CONTROL",  "id":23285,   "ctx":"main","msg":"Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'"}
{"t":{"$date":"2021-07-31T05:01:34.179+07:00"},"s":"I",  "c":"NETWORK",  "id":4915701, "ctx":"main","msg":"Initialized wire specification","attr":{"spec":{"incomingExternalClient":{"minWireVersion":0,"maxWireVersion":13},"incomingInternalClient":{"minWireVersion":0,"maxWireVersion":13},"outgoing":{"minWireVersion":0,"maxWireVersion":13},"isInternalClient":true}}}
{"t":{"$date":"2021-07-31T05:01:34.180+07:00"},"s":"W",  "c":"ASIO",     "id":22601,   "ctx":"main","msg":"No TransportLayer configured during NetworkInterface startup"}
{"t":{"$date":"2021-07-31T05:01:34.180+07:00"},"s":"I",  "c":"NETWORK",  "id":4648601, "ctx":"main","msg":"Implicit TCP FastOpen unavailable. If TCP FastOpen is required, set tcpFastOpenServer, tcpFastOpenClient, and tcpFastOpenQueueSize."}
{"t":{"$date":"2021-07-31T05:01:34.184+07:00"},"s":"W",  "c":"ASIO",     "id":22601,   "ctx":"main","msg":"No TransportLayer configured during NetworkInterface startup"}
{"t":{"$date":"2021-07-31T05:01:34.185+07:00"},"s":"I",  "c":"REPL",     "id":5123008, "ctx":"main","msg":"Successfully registered PrimaryOnlyService","attr":{"service":"TenantMigrationDonorService","ns":"config.tenantMigrationDonors"}}
{"t":{"$date":"2021-07-31T05:01:34.185+07:00"},"s":"I",  "c":"REPL",     "id":5123008, "ctx":"main","msg":"Successfully registered PrimaryOnlyService","attr":{"service":"TenantMigrationRecipientService","ns":"config.tenantMigrationRecipients"}}
{"t":{"$date":"2021-07-31T05:01:34.185+07:00"},"s":"I",  "c":"CONTROL",  "id":4615611, "ctx":"initandlisten","msg":"MongoDB starting","attr":{"pid":104113,"port":27017,"dbPath":"/media/nd/ext1TB/dbpath/mongodb/data/mongodb","architecture":"64-bit","host":"nd-desktop"}}
{"t":{"$date":"2021-07-31T05:01:34.185+07:00"},"s":"I",  "c":"CONTROL",  "id":23403,   "ctx":"initandlisten","msg":"Build Info","attr":{"buildInfo":{"version":"5.0.1","gitVersion":"318fd9cabc59dc9651f3189b622af6e06ab6cd33","openSSLVersion":"OpenSSL 1.1.1f  31 Mar 2020","modules":[],"allocator":"tcmalloc","environment":{"distmod":"ubuntu2004","distarch":"x86_64","target_arch":"x86_64"}}}}
{"t":{"$date":"2021-07-31T05:01:34.185+07:00"},"s":"I",  "c":"CONTROL",  "id":51765,   "ctx":"initandlisten","msg":"Operating System","attr":{"os":{"name":"Ubuntu","version":"20.04"}}}
{"t":{"$date":"2021-07-31T05:01:34.185+07:00"},"s":"I",  "c":"CONTROL",  "id":21951,   "ctx":"initandlisten","msg":"Options set by command line","attr":{"options":{"config":"/etc/mongod.conf","net":{"bindIp":"127.0.0.1","port":27017},"processManagement":{"timeZoneInfo":"/usr/share/zoneinfo"},"storage":{"dbPath":"/media/nd/ext1TB/dbpath/mongodb/data/mongodb","journal":{"enabled":true}},"systemLog":{"destination":"file","logAppend":true,"path":"/var/log/mongodb/mongod.log"}}}}
{"t":{"$date":"2021-07-31T05:01:34.186+07:00"},"s":"E",  "c":"CONTROL",  "id":20557,   "ctx":"initandlisten","msg":"DBException in initAndListen, terminating","attr":{"error":"Location28596: Unable to determine status of lock file in the data directory /media/nd/ext1TB/dbpath/mongodb/data/mongodb: boost::filesystem::status: Permission denied: "/media/nd/ext1TB/dbpath/mongodb/data/mongodb/mongod.lock""}}
...

Updated

  • my system
$ cat /etc/issue
Ubuntu 20.04.2 LTS n l
  • @barrypicker: I started the service as systemd and when I run with default dbPath (/var/lib/mongodb), ps command given output below
$ sudo systemctl start mongod
$ ps -ef | grep mongod
mongodb   117894       1 16 08:11 ?        00:00:00 /usr/bin/mongod --config /etc/mongod.conf