Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • 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/
################################################################################
@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