Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save fed-franz/3e3e906fa06294e61930e81b473e1e5b to your computer and use it in GitHub Desktop.
Save fed-franz/3e3e906fa06294e61930e81b473e1e5b to your computer and use it in GitHub Desktop.
HowTo: create a Bitcoin Core Gitian Build (using: Debian VM on VirtualBox + gitian-build.sh)
#References:
#https://github.com/bitcoin-core/docs/blob/master/gitian-building.md
#https://github.com/bitcoin/bitcoin/blob/master/doc/release-process.md
#https://github.com/bitcoin/bitcoin/blob/master/doc/build-unix.md (actually not used in this guide, but useful as a reference)
1) Create a Debian VM as a building environment (it will be accessed via SSH)
------------------------------------------------------------------------------------------------------
Follow the instructions at:
https://github.com/bitcoin-core/docs/blob/master/gitian-building/gitian-building-create-vm-debian.md
2) Setup Gitian
------------------------------------------------------------------------------------------------------
Instructions taken from:
https://github.com/bitcoin-core/docs/blob/master/gitian-building/gitian-building-setup-gitian-debian.md
- 2.1) (as root)
---------------------------------------------------
ssh root@localhost -p 22222
apt-get install git ruby sudo apt-cacher-ng qemu-utils debootstrap lxc python-cheetah parted kpartx bridge-utils make ubuntu-archive-keyring curl
adduser gitianuser sudo
echo "%sudo ALL=NOPASSWD: /usr/bin/lxc-start" > /etc/sudoers.d/gitian-lxc
echo "%sudo ALL=NOPASSWD: /usr/bin/lxc-execute" >> /etc/sudoers.d/gitian-lxc
echo '#!/bin/sh -e' > /etc/rc.local
echo 'brctl addbr br0' >> /etc/rc.local
echo 'ifconfig br0 10.0.3.2/24 up' >> /etc/rc.local
echo 'iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE' >> /etc/rc.local
echo 'echo 1 > /proc/sys/net/ipv4/ip_forward' >> /etc/rc.local
echo 'exit 0' >> /etc/rc.local
echo 'export USE_LXC=1' >> /home/gitianuser/.profile
echo 'export GITIAN_HOST_IP=10.0.3.2' >> /home/gitianuser/.profile
echo 'export LXC_GUEST_IP=10.0.3.5' >> /home/gitianuser/.profile
reboot
- 2.2) (as gitianuser)
---------------------------------------------------
ssh gitianuser@localhost -p 22222
# Install python-vm-builder
# Note: When sudo asks for a password, enter the password for the user gitianuser not for root
wget http://archive.ubuntu.com/ubuntu/pool/universe/v/vm-builder/vm-builder_0.12.4+bzr494.orig.tar.gz
echo "76cbf8c52c391160b2641e7120dbade5afded713afaa6032f733a261f13e6a8e vm-builder_0.12.4+bzr494.orig.tar.gz" | sha256sum -c
# (verification -- must return OK)
tar -zxvf vm-builder_0.12.4+bzr494.orig.tar.gz
cd vm-builder-0.12.4+bzr494
sudo python setup.py install
cd ..
#Clone Bitcoin + Gitian repos
git clone https://github.com/devrandom/gitian-builder.git
git clone https://github.com/bitcoin/bitcoin
git clone https://github.com/bitcoin-core/gitian.sigs.git
#Build the Gitian VM (used for the real building process)
cd gitian-builder
bin/make-base-vm --lxc --arch amd64 --suite trusty
3) Actual build
------------------------------------------------------------------------------------------------------
#Keep using gitianuser
#Replace SIGNER with your name and VERSION with the version/branch you want to build (version numbers didn't work in my case)
#Useful gitian-build.sh options (use --help for more):
# -o|--os Specify which Operating Systems the build is for. Default is lwx. l for linux, w for windows, x for osx
# --no-commit Do not commit anything to git
# (this is necessary when you're compiling the original source but you're not a releaser)
# -c|--commit Indicate that the version argument is for a commit or branch
# (in my case this was necessary since for some reason the script could recognize any version number)
# -u|--url Specify the URL of the repository (if you want to compile your own fork).
export SIGNER=username
export VERSION=master
../bitcoin/contrib/gitian-build.sh --setup -c $SIGNER $VERSION
#This command build Bitcoin for Linux only
./bitcoin/contrib/gitian-build.sh --build --os l -c --no-commit $SIGNER $VERSION
###############################################################################
You will find the binaries in tarball files stored in:
/home/gitianuser/vm-builder-0.12.4+bzr494/bitcoin-binaries/$VERSION
- To copy the created tarball(s) you can use SCP:
e.g.: ($VERSION=master)
scp -P 22222 gitianuser@localhost://home/gitianuser/vm-builder-0.12.4+bzr494/bitcoin-binaries/master/bitcoin-0.15.99-aarch64-linux-gnu.tar.gz ./dev/my-local-testnet/
################################################################################
@leegod
Copy link

leegod commented Feb 8, 2018

too complicated... Why bitcoin source compiling and making windows runnable build file is so hard ?

@akshaynexus
Copy link

true that @leegod

@phantanthanh1996
Copy link

Hi sir, i am trying to build bitcoin wallet with your instruction but a i run when call ../bitcoin/contrib/gitian-build.sh --setup -c $SIGNER $VERSION

@phantanthanh1996
Copy link

Cannot build for OSX, SDK does not exist. Will build for other OSes
master
[sudo] password for gitianuser:
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package python-vm-builder
fatal: destination path 'gitian.sigs' already exists and is not an empty directory.
fatal: destination path 'bitcoin-detached-sigs' already exists and is not an empty directory.
fatal: destination path 'gitian-builder' already exists and is not an empty directory.
~/gitian-builder/gitian-builder ~/gitian-builder ~/gitian-builder
Reading package lists... Done
Building dependency tree
Reading state information... Done
lxc is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 1 not upgraded.
base-trusty-amd64 already exists, please remove it first
~/gitian-builder ~/gitian-builder
~/bitcoin ~/gitian-builder ~/gitian-builder
M contrib/gitian-build.sh
Already on 'master'
Your branch is up-to-date with 'origin/master'.
~/gitian-builder ~/gitian-builder
~/gitian-builder/gitian-builder ~/gitian-builder ~/gitian-builder

Signing master Windows

/usr/lib/ruby/2.1.0/psych.rb:464:in initialize': No such file or directory @ rb_sysopen - ../bitcoin/contrib/gitian-descriptors/gitian-win-signer.yml (Errno::ENOENT) from /usr/lib/ruby/2.1.0/psych.rb:464:in open'
from /usr/lib/ruby/2.1.0/psych.rb:464:in load_file' from ./bin/gbuild:215:in

'
/usr/lib/ruby/2.1.0/psych.rb:464:in initialize': No such file or directory @ rb_sysopen - ../bitcoin/contrib/gitian-descriptors/gitian-win-signer.yml (Errno::ENOENT) from /usr/lib/ruby/2.1.0/psych.rb:464:in open'
from /usr/lib/ruby/2.1.0/psych.rb:464:in load_file' from ./bin/gsign:58:in '
mv: cannot stat ‘build/out/bitcoin-*win64-setup.exe’: No such file or directory
mv: cannot stat ‘build/out/bitcoin-*win32-setup.exe’: No such file or directory
~/gitian-builder ~/gitian-builder
~/gitian-builder/gitian.sigs ~/gitian-builder ~/gitian-builder

Committing master Signed Sigs

fatal: pathspec 'master-win-signed/thanhpt' did not match any files
fatal: pathspec 'master-osx-signed/thanhpt' did not match any files
On branch master
Your branch is up-to-date with 'origin/master'.
nothing to commit, working directory clean

@phantanthanh1996
Copy link

../bitcoin/contrib/gitian-build.sh: line 247: pushd: ./bitcoin: No such file or directory
error: pathspec '0.16.0' did not match any file(s) known to git.
../bitcoin/contrib/gitian-build.sh: line 250: popd: directory stack empty

@reppolice
Copy link

gitian-build.sh seems to be replaced by a .py, my first attempt to use that ended in error, continuing ...

@fed-franz
Copy link
Author

gitian-build.sh seems to be replaced by a .py, my first attempt to use that ended in error, continuing ...

Hi @reppolice. You're right. The script has been replaced by a different one in python. Thanks for reporting it.

I'm not keeping this guide up to date, as I don't need it anymore.
This guide used to work for me when I released it in 2017, so it should be taken as valid only for older versions of Bitcoin Core (0.15 as of time of release). I will update the gist to make this clearer.

I will try to update the guide itself as soon as I have some spare time to dedicate to it. Meanwhile anyone feel free to contribute by reporting errors and possible fixes.

@www222fff
Copy link

@frz-dev Hi, is there gitian build notes on ubuntu? I met below issues on ubuntu, could you help?
************* WARNING: kvm not loaded, this will probably not work out

--- Building for focal amd64 ---
Stopping target if it is up
Making a new image copy
qemu-img: target-focal-amd64.qcow2: Could not open 'base-focal-amd64.qcow2': No such file or directory
Could not open backing image to determine size.
Traceback (most recent call last):
6: from ./bin/gbuild:334:in <main>' 5: from ./bin/gbuild:334:in each'
4: from ./bin/gbuild:336:in block in <main>' 3: from ./bin/gbuild:336:in each'
2: from ./bin/gbuild:341:in block (2 levels) in <main>' 1: from ./bin/gbuild:60:in build_one_configuration'
./bin/gbuild:23:in `system!': failed to run make-clean-vm --suite focal --arch amd64 (RuntimeError)

@fed-franz
Copy link
Author

fed-franz commented Jan 25, 2022

@www222fff The Gitian building project has been replaced by Guix.
You can find the updated instructions here: https://github.com/bitcoin/bitcoin/blob/master/doc/release-process.md#building.

If you need to use Gitian, you can try opening an issue at the project repo page: https://github.com/devrandom/gitian-builder

If you don't need your executables to be portable, I recommend building Bitcoin using the standard Make process.
You can find the official instructions here: https://github.com/bitcoin/bitcoin/blob/master/doc/build-unix.md

I also wrote a small guide here with all the necessary steps to build Bitcoin executables on Ubuntu: https://gist.github.com/frz-dev/3373a8b90285e8fc6f83bdfae75341de, but it is not up-to-date.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment