<p>Bitcoin Core contains a tool to do this properly (filtering out any orphan blocks, putting everything in the correct order — which will work a lot better than just concatenating the block files. It's documented in its own README, here: <a href="https://github.com/bitcoin/bitcoin/tree/master/contrib/linearize" rel="noreferrer">https://github.com/bitcoin/bitcoin/tree/master/contrib/linearize</a></p>

<p>In short:</p>

<ol>
<li>Launch Bitcoin with an <code>rpcuser</code> and <code>rpcpassword</code> set in your config file, with the correct location as per <a href="https://en.bitcoin.it/wiki/Running_Bitcoin#Bitcoin.conf_Configuration_File" rel="noreferrer">https://en.bitcoin.it/wiki/Running_Bitcoin#Bitcoin.conf_Configuration_File</a></li>
<li>Checkout the Bitcoin source from Github and <code>cd</code> to <code>contrib/linearize</code>.</li>
<li>Copy <code>example-linearize.cfg</code> to <code>linearize.cfg</code> and update it with your <code>rpcuser</code>/<code>rpcpassword</code> values, along with the maximum block height you want to output (<code>max_height</code>), and the path to your data directory (<code>input</code>), as well as the path to your desired output file (<code>output_file</code>).</li>
<li>Run <code>./linearize-hashes.py linearize.cfg &gt; hashlist.txt</code> followed by <code>./linearize-data.py linearize.cfg</code>.</li>
</ol>

CC BY-SA 3.0
2017-07-01T20:42:18.520Z
After spending a HUGE amount of time on this issue, Peter Josling's answer needs upvoting more. Concatenating the files from a node without sanitizing them leads to unexpected results, such as the syncing client jumping to network download after an orphan branch is detected. My rep will not allow me to comment or upvote, but anyone building a bootstrap file really needs to be aware of the pitfalls of simply concatenating the blk*.dat files
lavajumper
CC BY-SA 4.0
2019-01-05T12:52:43.590Z
in 2019 this should be the right answer. Thank you
qpaycm
CC BY-SA 3.0
2016-02-15T12:46:15.350Z
2016-02-15T12:46:15.350Z
Peter Josling
<p> From Mac</p>

<ol>
<li>Open terminal</li>
<li><p>Go to the folder where the blocks are. In this
case Bitcoin's folder (it's the same for other bitcoin forks)</p>

<pre><code>cd "Library/Application Support/Bitcoin/blocks/"
</code></pre></li>
<li><p>Run this code that will concatenate all the blk files. Make sure to include all the numbered
blocks you find on your Bitcoin's folder. In this case there are 4</p>

<pre><code>cat blk000*.dat &gt; bootstrap.dat
</code></pre></li>
<li><p>Done.</p></li>
</ol>

CC BY-SA 3.0
2015-05-12T06:49:18.757Z
2015-05-13T02:38:08.553Z
2015-05-13T02:38:08.553Z
David Lopez
<p>Making your own bootstrap.dat is fairly simple. In windows, drop to your command prompt and use the following command. </p>

<pre><code>Copy /b blk00000.dat+blk00001.dat+blk00002.dat bootstrap.dat
</code></pre>

<p>You'll want to keep going with the + blk*.dat files until you reach the last one. To make things easier for you, just run a batch file which can take care of adding them all without having to input each blk*.dat file. Simply copy and paste the code below into a text file and name it something like Create_Bootstrap.cmd and run it from your /blocks folder.</p>

<pre><code>@echo off 
setlocal enableDelayedExpansion 

set BITCOINDIR=%APPDATA%\bitcoin\blocks
for /F %%x in ('dir /B/D/ON %BITCOINDIR%\blk*.*') do (
  IF NOT [!B!] == [] set B=!B!+
  set FILENAME=%BITCOINDIR%\%%x
  set B=!B!"!FILENAME!"
)
copy /b %B% bootstrap.dat
</code></pre>

<p>or just use "copy /b blk*.dat bootstrap.dat" </p>

CC BY-SA 3.0
2015-02-14T00:06:13.790Z
2016-02-05T01:48:22.493Z
2016-02-05T01:48:22.493Z
m0gliE
<p>It is somewhat intuitive what files need to be copy and where once you have a full node built.  What is not so intuitive is how to bootstrap a full node before you have built your first full node. You first need to know where the files need to be placed for the various '<a href="https://en.bitcoin.it/wiki/Running_Bitcoin#Bitcoin.conf_Configuration_File" rel="nofollow">OSes</a>'. I'm not sure if there are little or big endian issues with copying the raw Blockchain node files between different OSes. </p>

<p>Another approach is to let the protocol handle the problem. Secondary and tertiary nodes build very quickly if they a on your own high bandwidth LAN.  Just point a secondary node (by tweaking its bitcoind.conf file) to the primary node that is already built using the "connect=Your_IPv4_LAN_Address". Such builds move very quickly... You might find it to be faster than writing the ledger to a thumb drive and copying it to another computer.</p>

CC BY-SA 3.0
2015-02-14T02:40:13.947Z
2015-02-14T12:48:42.200Z
2015-02-14T12:48:42.200Z
skaht
<p>The block files are in the same format as the bootstrap file. Their format is really simple: just concatenate all blocks after prefixing them by the network number (to avoid mixing the testnets) and the block length.</p>

<pre><code>[network number] [length] [block header] [block transactions]
[network number] [length] [block header] [block transactions]
[network number] [length] [block header] [block transactions]
... repeat for all blocks
</code></pre>

<p>To create a bootstrap file, all you need to do is to just grab the data from <code>blk00001.dat</code> up to your last block file (here that's <code>blk000054.dat</code>) and put all of it in the <code>bootstrap.dat</code> file, preferably sorted so that it can just import them all in one go without having to swap blocks.</p>

<p>I <em>think</em> you might even be able to just concatenate the block files themselves, as they are already in the right format, and the format supports concatenation.</p>

CC BY-SA 3.0
2014-03-05T11:35:56.453Z
Didn't know of this functionality, makes me wonder what's the point of these files since you can always download an archive with all `blkXXX.dat` files and uncompress it at the appropriate directory, getting exactly the same results except without the renaming to ".old" at the end :-S
Joe Pineda
CC BY-SA 4.0
2021-02-03T05:26:21.697Z
Note: this is no longer a preferred method. Concatenating the files together will cause issues with orphan branches. See Peter Josling's answer below.
Burke9077
CC BY-SA 3.0
2013-04-29T19:16:40.837Z
2013-04-29T19:16:40.837Z
Tom van der Woerdt
<p>Since I have been tearing down and setting up bitcoin clients a lot for some experiments lately, I was wondering whether there is a simple way to speed up the synchronization with the network. One method that comes to mind is the <code>bootstrap.dat</code> file distributed by some people. The problem is that the last 40'000 blocks, which are the most expensive to get and verify, are not included.</p>

<p>Now I was wondering how to create such a <code>bootstrap.dat</code> myself, from a good copy I have on another machine. Any idea?</p>

<blockchain><synchronization><bootstrap.dat>
Creating my own bootstrap.dat?
cdecker
# Creating my own bootstrap.dat?

(Asked by: username_0 on 2013-04-29)

Since I have been tearing down and setting up bitcoin clients a lot for some experiments lately, I was wondering whether there is a simple way to speed up the synchronization with the network. One method that comes to mind is the `bootstrap.dat` file distributed by some people. The problem is that the last 40'000 blocks, which are the most expensive to get and verify, are not included.

Now I was wondering how to create such a `bootstrap.dat` myself, from a good copy I have on another machine. Any idea?

**Tags:** blockchain, synchronization, bootstrap.dat


---

## 5 answers

### Answer by username_7 on 2013-04-29. Score: 6 | Accepted answer

The block files are in the same format as the bootstrap file. Their format is really simple: just concatenate all blocks after prefixing them by the network number (to avoid mixing the testnets) and the block length.

```
[network number] [length] [block header] [block transactions]
[network number] [length] [block header] [block transactions]
[network number] [length] [block header] [block transactions]
... repeat for all blocks

```

To create a bootstrap file, all you need to do is to just grab the data from `blk00001.dat` up to your last block file (here that's `blk000054.dat`) and put all of it in the `bootstrap.dat` file, preferably sorted so that it can just import them all in one go without having to swap blocks.

I *think* you might even be able to just concatenate the block files themselves, as they are already in the right format, and the format supports concatenation.

> **Comments:**
> **username_8**: Didn't know of this functionality, makes me wonder what's the point of these files since you can always download an archive with all `blkXXX.dat` files and uncompress it at the appropriate directory, getting exactly the same results except without the renaming to ".old" at the end :-S  
> **username_9**: Note: this is no longer a preferred method. Concatenating the files together will cause issues with orphan branches. See username_1's answer below.  

---

### Answer by username_1 on 2016-02-15. Score: 17

Bitcoin Core contains a tool to do this properly (filtering out any orphan blocks, putting everything in the correct order — which will work a lot better than just concatenating the block files. It's documented in its own README, here: <https://github.com/bitcoin/bitcoin/tree/master/contrib/linearize>

In short:

1. Launch Bitcoin with an `rpcuser` and `rpcpassword` set in your config file, with the correct location as per <https://en.bitcoin.it/wiki/Running_Bitcoin#Bitcoin.conf_Configuration_File>
2. Checkout the Bitcoin source from Github and `cd` to `contrib/linearize`.
3. Copy `example-linearize.cfg` to `linearize.cfg` and update it with your `rpcuser`/`rpcpassword` values, along with the maximum block height you want to output (`max_height`), and the path to your data directory (`input`), as well as the path to your desired output file (`output_file`).
4. Run `./linearize-hashes.py linearize.cfg > hashlist.txt` followed by `./linearize-data.py linearize.cfg`.

> **Comments:**
> **username_2**: After spending a HUGE amount of time on this issue, username_1's answer needs upvoting more. Concatenating the files from a node without sanitizing them leads to unexpected results, such as the syncing client jumping to network download after an orphan branch is detected. My rep will not allow me to comment or upvote, but anyone building a bootstrap file really needs to be aware of the pitfalls of simply concatenating the blk*.dat files  
> **username_3**: in 2019 this should be the right answer. Thank you  

---

### Answer by username_4 on 2015-05-12. Score: 4

 From Mac

1. Open terminal
2. Go to the folder where the blocks are. In this
   case Bitcoin's folder (it's the same for other bitcoin forks)

   ```
   cd "Library/Application Support/Bitcoin/blocks/"

   ```
3. Run this code that will concatenate all the blk files. Make sure to include all the numbered
   blocks you find on your Bitcoin's folder. In this case there are 4

   ```
   cat blk000*.dat > bootstrap.dat

   ```
4. Done.


---

### Answer by username_5 on 2015-02-14. Score: 2

Making your own bootstrap.dat is fairly simple. In windows, drop to your command prompt and use the following command.

```
Copy /b blk00000.dat+blk00001.dat+blk00002.dat bootstrap.dat

```

You'll want to keep going with the + blk\*.dat files until you reach the last one. To make things easier for you, just run a batch file which can take care of adding them all without having to input each blk\*.dat file. Simply copy and paste the code below into a text file and name it something like Create\_Bootstrap.cmd and run it from your /blocks folder.

```
@echo off 
setlocal enableDelayedExpansion 

set BITCOINDIR=%APPDATA%\bitcoin\blocks
for /F %%x in ('dir /B/D/ON %BITCOINDIR%\blk*.*') do (
  IF NOT [!B!] == [] set B=!B!+
  set FILENAME=%BITCOINDIR%\%%x
  set B=!B!"!FILENAME!"
)
copy /b %B% bootstrap.dat

```

or just use "copy /b blk\*.dat bootstrap.dat"


---

### Answer by username_6 on 2015-02-14. Score: -1

It is somewhat intuitive what files need to be copy and where once you have a full node built. What is not so intuitive is how to bootstrap a full node before you have built your first full node. You first need to know where the files need to be placed for the various '[OSes](https://en.bitcoin.it/wiki/Running_Bitcoin#Bitcoin.conf_Configuration_File)'. I'm not sure if there are little or big endian issues with copying the raw Blockchain node files between different OSes.

Another approach is to let the protocol handle the problem. Secondary and tertiary nodes build very quickly if they a on your own high bandwidth LAN. Just point a secondary node (by tweaking its bitcoind.conf file) to the primary node that is already built using the "connect=Your\_IPv4\_LAN\_Address". Such builds move very quickly... You might find it to be faster than writing the ledger to a thumb drive and copying it to another computer.


---

