title: Permission denied error Change dbpath for mongodb in centos
body: <p>I am attempting to update the dbpath for mongo db. I am following the steps as below:</p>
  
  <p>1) Create new directory : <code>sudo mkdir /mnt/database/mongo</code></p>
  
  <p>2) Change owner : <code>sudo cp -R /var/lib/mongo/ /mnt/database/</code></p>
  
  <p>3) Copy DB files: <code>sudo chown mongod:mongod -R /mnt/database/mongo</code></p>
  
  <p>4) Update mongo configuration file: </p>
  
  <p>storage:</p>
  
  <p>dbPath: /mnt/database/mongo</p>
  
  <p>5) Restart mongod service: <code>sudo systemctl restart mongod</code></p>
  
  <p>The service restart command gives the following error:</p>
  
  <p>Job for <code>mongod.service</code> failed because the control process exited with error code. See <code>systemctl status mongod.service</code> and <code>journalctl -xe</code> for details.</p>
  
  <p>Logfile contents:</p>
  
  <pre><code> I  CONTROL  [initandlisten] options: { config: "/etc/mongod.conf", net: { bindIp: "127.0.0.1", port: 27017 }, processManagement: { fork: true, pidFilePath: "/var/run/mongodb/mongod.pid", timeZoneInfo: "/usr/share/zoneinfo" }, storage: { dbPath: "/mnt/database/mongo", journal: { enabled: true } }, systemLog: { destination: "file", logAppend: true, path: "/var/log/mongodb/mongod.log" } }
  2020-04-17T04:56:00.666+0000 I  STORAGE  [initandlisten] exception in initAndListen: Location28596: Unable to determine status of lock file in the data directory /mnt/database/mongo: boost::filesystem::status: Permission denied: "/mnt/database/mongo/mongod.lock", terminating
  </code></pre>
  
  <p>Am I missing any steps with regards to permission. </p>
  
  <p>System logs: /var/log/messages
  systemd: Stopping MongoDB Database Server...
  systemd: Starting MongoDB Database Server...
  mongod: about to fork child process, waiting until server is ready for connections.
  mongod: forked process: 17968
  mongod: ERROR: child process failed, exited with error number 100
  mongod: To see additional information in this output, start without the "--fork" option.
   systemd: mongod.service: control process exited, code=exited status=100
   systemd: Failed to start MongoDB Database Server.
   systemd: Unit mongod.service entered failed state.
   systemd: mongod.service failed.</p>
  
  <p>Directory permissions: </p>
  
  <p>/mnt : 
  drwxr-xr-x.   6 mongod mongod   mnt</p>
  
  <p>/mnt/database:</p>
  
  <p>drwxrwxrwx. 3 mongod mongod    database</p>
  
  <p>/mnt/database/mongo:</p>
  
  <p>drwxrwxrwx. 4 mongod mongod    mongo</p>
  
  <p>Files under /mnt/database/mongo:</p>
  
  <pre><code>-rwxrwxrwx. 1 mongod mongod 20480 collection-0-1788044936069962496.wt
  -rwxrwxrwx. 1 mongod mongod 36864 collection-2-1788044936069962496.wt
  -rwxrwxrwx. 1 mongod mongod  4096 collection-4-1788044936069962496.wt
  drwxrwxrwx. 2 mongod mongod    90 diagnostic.data
  -rwxrwxrwx. 1 mongod mongod 20480 index-1-1788044936069962496.wt
  -rwxrwxrwx. 1 mongod mongod 36864 index-3-1788044936069962496.wt
  -rwxrwxrwx. 1 mongod mongod  4096 index-5-1788044936069962496.wt
  -rwxrwxrwx. 1 mongod mongod 12288 index-6-1788044936069962496.wt
  drwxrwxrwx. 2 mongod mongod   110 journal
  -rwxrwxrwx. 1 mongod mongod 20480 _mdb_catalog.wt
  -rwxrwxrwx. 1 mongod mongod 36864 sizeStorer.wt
  -rwxrwxrwx. 1 mongod mongod   114 storage.bson
  -rwxrwxrwx. 1 mongod mongod    47 WiredTiger
  -rwxrwxrwx. 1 mongod mongod  4096 WiredTigerLAS.wt
  -rwxrwxrwx. 1 mongod mongod    21 WiredTiger.lock
  -rwxrwxrwx. 1 mongod mongod  1185 WiredTiger.turtle
  -rwxrwxrwx. 1 mongod mongod 61440 WiredTiger.wt
  </code></pre>
  
  <p>The security context of mongodb directoreies:</p>
  
  <p>ls -Z /mnt/database</p>
  
  <pre><code>drwxrwxrwx. mongod mongod unconfined_u:object_r:mnt_t:s0   mongo
  </code></pre>