<p>In my view, we cannot move LevelDB index files such as chainstate, etc. to an external slow storage.</p>
<p>According to this <a href="https://github.com/jimhashhq/bitcoin/blob/3c0377db483c50c5a9aecfc4684d6329951a1c7c/doc/file-partition.md" rel="nofollow noreferrer">link</a>, we should only move the <code>blkxxxxx.dat</code> and <code>revxxxxx.dat</code> files to an external storage. These files are inside <code>${datadir}/blocks/</code> by default. Since the <code>index</code> directory (<code>${datadir}/blocks/index</code>) contains high i/o-frequency LevelDB index files, moving it to an external storage will increase the initial blockchain synchronization time.</p>
<p>So take the following steps (I followed the instructions of the <a href="https://github.com/jimhashhq/bitcoin/blob/3c0377db483c50c5a9aecfc4684d6329951a1c7c/doc/file-partition.md" rel="nofollow noreferrer">link</a>):</p>
<ol>
<li>run bitcoind.</li>
</ol>
<blockquote>
<p>Let it run for a few minutes, or long enough that it has started synchronizing <a href="https://github.com/jimhashhq/bitcoin/blob/3c0377db483c50c5a9aecfc4684d6329951a1c7c/doc/file-partition.md" rel="nofollow noreferrer">[ref]</a></p>
</blockquote>
<ol start="2">
<li><p>Then kill the bitcoind.</p>
</li>
<li><p>Next, Move the &quot;index&quot; folder up one level (so that it may remain on the local storage):</p>
</li>
</ol>
<pre><code>mv -f ~/.bitcoin/blocks/index ~/.bitcoin/
</code></pre>
<ol start="4">
<li>Move the blocks folder to the shared directory:</li>
</ol>
<pre><code>mv -f ~/.bitcoin/blocks ~/blockchain/
</code></pre>
<ol start="5">
<li>Create a symbolic (soft) link to the local index directory at blocks directory in the shared storage (<em>use absolute path</em>):</li>
</ol>
<pre><code>ln -s /root/.bitcoin/index /root/blockchain/blocks/index
</code></pre>
<ol start="6">
<li>Now, create a symbolic (soft) link to the blocks directory at .bitcoin in the local storage (<em>again use absolute path</em>)::</li>
</ol>
<pre><code>ln -s /root/blockchain/blocks/ /root/.bitcoin/blocks
</code></pre>

CC BY-SA 4.0
2020-07-27T14:48:37.863Z
2020-07-27T14:48:37.863Z
Taghi
<p>I am going to run a bitcoin core on a Linux server (Ubuntu 20.04). I don't have enough storage to store blockchain data. Therefore, I want to save the data over an NFS server (CentOS release 6.10). However, I get an error when I set the <code>-datadir</code> to the shared folder.</p>
<p>The content of <code>/etc/exports</code> file in the NFS server (I've seen the configuration from <a href="https://community.time4vps.com/discussion/224/kvm-ubuntu-configuring-nfs-server-and-nfs-client-sides/p1" rel="nofollow noreferrer">here</a>):</p>
<pre><code>/home/storage/  BITCOIN.CORE_IP(rw,sync,no_root_squash,no_subtree_check)
</code></pre>
<p>I mounted the remote shared directory in the Ubuntu 20.04 Linux server using the following command:</p>
<pre><code>mount NFS_SERVER_IP:/home/storage/ /root/blockchain/
</code></pre>
<p>everything works fine, and the file system disk space usage report is: (<code>df -h</code>)</p>
<pre><code>Filesystem                   Size  Used Avail Use% Mounted on
NFS_SERVER_IP:/home/storage/  1.0T  682M  1.0T   1% /root/blockchain
</code></pre>
<p>After running the following command to change the data directory to the shared directory:</p>
<pre><code>./bitcoin-0.20.0/bin/bitcoind -datadir=/root/blockchain
</code></pre>
<p>I get the following error:</p>
<pre><code>Error: Cannot obtain a lock on data directory /root/blockchain. Bitcoin Core is probably already running.
</code></pre>
<p>I should note that the shared directory is empty before running the bitcoind, then after that, it contains an empty file, which name is <code>.lock</code>. Moreover, If I set the <code>-datadir</code> to any local folder, it will not return any error!</p>
<p>Thanks.</p>

CC BY-SA 4.0
2020-07-27T02:23:32.160Z
Are you running bitcoind under a user with permission to write to that directory?
Raghav Sood
CC BY-SA 4.0
2020-07-27T05:23:38.737Z
@RaghavSood I run the following command to see what user bitcoind is running as: ` ps -eo user,group,comm |egrep 'bitcoind' |awk '{print "Bitcoin user: " $1}' `
the result is: ` Bitcoin user: root `. I can mkdir and touch under the root user.
Taghi
CC BY-SA 4.0
2020-07-27T05:31:40.307Z
You might have another bitcoin instance running on the same machine, or on another machine connected to the same shared drive - try stopping all Bitcoin instance, deleting the `.lock` file (if it still exists), and then starting it again
Raghav Sood
CC BY-SA 4.0
2020-07-27T05:42:05.733Z
@RaghavSood I have tried this multiple times, but nothing changes :((
Taghi
CC BY-SA 4.0
2020-07-27T21:12:28.367Z
Network file systems often don't support the same locking primitives that are expected from local filesystems.
Pieter Wuille
<bitcoin-core><datadir>
Bitcoin core datadir over NFS
Taghi
# Bitcoin core datadir over NFS

(Asked by: username_0 on 2020-07-26)

I am going to run a bitcoin core on a Linux server (Ubuntu 20.04). I don't have enough storage to store blockchain data. Therefore, I want to save the data over an NFS server (CentOS release 6.10). However, I get an error when I set the `-datadir` to the shared folder.

The content of `/etc/exports` file in the NFS server (I've seen the configuration from [here](https://community.time4vps.com/discussion/224/kvm-ubuntu-configuring-nfs-server-and-nfs-client-sides/p1)):

```
/home/storage/  BITCOIN.CORE_IP(rw,sync,no_root_squash,no_subtree_check)

```

I mounted the remote shared directory in the Ubuntu 20.04 Linux server using the following command:

```
mount NFS_SERVER_IP:/home/storage/ /root/blockchain/

```

everything works fine, and the file system disk space usage report is: (`df -h`)

```
Filesystem                   Size  Used Avail Use% Mounted on
NFS_SERVER_IP:/home/storage/  1.0T  682M  1.0T   1% /root/blockchain

```

After running the following command to change the data directory to the shared directory:

```
./bitcoin-0.20.0/bin/bitcoind -datadir=/root/blockchain

```

I get the following error:

```
Error: Cannot obtain a lock on data directory /root/blockchain. Bitcoin Core is probably already running.

```

I should note that the shared directory is empty before running the bitcoind, then after that, it contains an empty file, which name is `.lock`. Moreover, If I set the `-datadir` to any local folder, it will not return any error!

Thanks.

**Tags:** bitcoin-core, datadir

> **Comments:**
> **username_1**: Are you running bitcoind under a user with permission to write to that directory?  
> **username_0**: @username_1 I run the following command to see what user bitcoind is running as: ` ps -eo user,group,comm |egrep 'bitcoind' |awk '{print "Bitcoin user: " $1}' ` the result is: ` Bitcoin user: root `. I can mkdir and touch under the root user.  
> **username_1**: You might have another bitcoin instance running on the same machine, or on another machine connected to the same shared drive - try stopping all Bitcoin instance, deleting the `.lock` file (if it still exists), and then starting it again  
> **username_0**: @username_1 I have tried this multiple times, but nothing changes :((  
> **username_2**: Network file systems often don't support the same locking primitives that are expected from local filesystems.  

---

## 1 answers

### Answer by username_0 on 2020-07-27. Score: 0 | Accepted answer

In my view, we cannot move LevelDB index files such as chainstate, etc. to an external slow storage.

According to this [link](https://github.com/jimhashhq/bitcoin/blob/3c0377db483c50c5a9aecfc4684d6329951a1c7c/doc/file-partition.md), we should only move the `blkxxxxx.dat` and `revxxxxx.dat` files to an external storage. These files are inside `${datadir}/blocks/` by default. Since the `index` directory (`${datadir}/blocks/index`) contains high i/o-frequency LevelDB index files, moving it to an external storage will increase the initial blockchain synchronization time.

So take the following steps (I followed the instructions of the [link](https://github.com/jimhashhq/bitcoin/blob/3c0377db483c50c5a9aecfc4684d6329951a1c7c/doc/file-partition.md)):

1. run bitcoind.

> Let it run for a few minutes, or long enough that it has started synchronizing [[ref]](https://github.com/jimhashhq/bitcoin/blob/3c0377db483c50c5a9aecfc4684d6329951a1c7c/doc/file-partition.md)

2. Then kill the bitcoind.
3. Next, Move the "index" folder up one level (so that it may remain on the local storage):

```
mv -f ~/.bitcoin/blocks/index ~/.bitcoin/

```

4. Move the blocks folder to the shared directory:

```
mv -f ~/.bitcoin/blocks ~/blockchain/

```

5. Create a symbolic (soft) link to the local index directory at blocks directory in the shared storage (*use absolute path*):

```
ln -s /root/.bitcoin/index /root/blockchain/blocks/index

```

6. Now, create a symbolic (soft) link to the blocks directory at .bitcoin in the local storage (*again use absolute path*)::

```
ln -s /root/blockchain/blocks/ /root/.bitcoin/blocks

```


---

