]>
Commit | Line | Data |
---|---|---|
2c47a00b WL |
1 | Gitian building |
2 | ================ | |
3 | ||
4 | *Setup instructions for a gitian build of Bitcoin using a Debian VM or physical system.* | |
5 | ||
6 | Gitian is the deterministic build process that is used to build the Bitcoin | |
3f7a61fc MF |
7 | Core executables. It provides a way to be reasonably sure that the |
8 | executables are really built from source on GitHub. It also makes sure that | |
2c47a00b WL |
9 | the same, tested dependencies are used and statically built into the executable. |
10 | ||
11 | Multiple developers build the source code by following a specific descriptor | |
12 | ("recipe"), cryptographically sign the result, and upload the resulting signature. | |
13 | These results are compared and only if they match, the build is accepted and uploaded | |
14 | to bitcoin.org. | |
15 | ||
16 | More independent gitian builders are needed, which is why I wrote this | |
17 | guide. It is preferred to follow these steps yourself instead of using someone else's | |
18 | VM image to avoid 'contaminating' the build. | |
19 | ||
2c47a00b WL |
20 | Table of Contents |
21 | ------------------ | |
22 | ||
23 | - [Create a new VirtualBox VM](#create-a-new-virtualbox-vm) | |
24 | - [Connecting to the VM](#connecting-to-the-vm) | |
25 | - [Setting up Debian for gitian building](#setting-up-debian-for-gitian-building) | |
26 | - [Installing gitian](#installing-gitian) | |
bfc29dcd | 27 | - [Setting up the gitian image](#setting-up-the-gitian-image) |
2c47a00b WL |
28 | - [Getting and building the inputs](#getting-and-building-the-inputs) |
29 | - [Building Bitcoin](#building-bitcoin) | |
30 | - [Building an alternative repository](#building-an-alternative-repository) | |
31 | - [Signing externally](#signing-externally) | |
32 | - [Uploading signatures](#uploading-signatures) | |
33 | ||
a98b8707 GM |
34 | Preparing the Gitian builder host |
35 | --------------------------------- | |
2c47a00b | 36 | |
a98b8707 | 37 | The first step is to prepare the host environment that will be used to perform the Gitian builds. |
3f7a61fc | 38 | This guide explains how to set up the environment, and how to start the builds. |
2c47a00b | 39 | |
a98b8707 GM |
40 | Debian Linux was chosen as the host distribution because it has a lightweight install (in contrast to Ubuntu) and is readily available. |
41 | Any kind of virtualization can be used, for example: | |
42 | - [VirtualBox](https://www.virtualbox.org/), covered by this guide | |
43 | - [KVM](http://www.linux-kvm.org/page/Main_Page) | |
44 | - [LXC](https://linuxcontainers.org/), see also [Gitian host docker container](https://github.com/gdm85/tenku/tree/master/docker/gitian-bitcoin-host/README.md). | |
2c47a00b | 45 | |
a98b8707 GM |
46 | You can also install on actual hardware instead of using virtualization. |
47 | ||
48 | Create a new VirtualBox VM | |
49 | --------------------------- | |
2c47a00b WL |
50 | In the VirtualBox GUI click "Create" and choose the following parameters in the wizard: |
51 | ||
633bb8b0 | 52 | ![](gitian-building/create_vm_page1.png) |
2c47a00b WL |
53 | |
54 | - Type: Linux, Debian (64 bit) | |
55 | ||
56 | ![](gitian-building/create_vm_memsize.png) | |
57 | ||
58 | - Memory Size: at least 1024MB, anything lower will really slow the build down | |
59 | ||
60 | ![](gitian-building/create_vm_hard_drive.png) | |
61 | ||
62 | - Hard Drive: Create a virtual hard drive now | |
63 | ||
64 | ![](gitian-building/create_vm_hard_drive_file_type.png) | |
65 | ||
66 | - Hard Drive file type: Use the default, VDI (VirtualBox Disk Image) | |
67 | ||
68 | ![](gitian-building/create_vm_storage_physical_hard_drive.png) | |
69 | ||
70 | - Storage on Physical hard drive: Dynamically Allocated | |
71 | ||
72 | ![](gitian-building/create_vm_file_location_size.png) | |
73 | ||
74 | - Disk size: at least 40GB; as low as 20GB *may* be possible, but better to err on the safe side | |
75 | - Push the `Create` button | |
76 | ||
bfc29dcd | 77 | Get the [Debian 7.7 net installer](http://cdimage.debian.org/debian-cd/7.7.0/amd64/iso-cd/debian-7.7.0-amd64-netinst.iso) (a more recent minor version should also work, see also [Debian Network installation](https://www.debian.org/CD/netinst/)). |
2c47a00b WL |
78 | This DVD image can be validated using a SHA256 hashing tool, for example on |
79 | Unixy OSes by entering the following in a terminal: | |
80 | ||
bfc29dcd | 81 | echo "d440e85b4121f94608748139f25dbce1ad36771348b002fe07d4d44b9d9e623f debian-7.7.0-amd64-netinst.iso" | sha256sum -c |
2c47a00b WL |
82 | # (must return OK) |
83 | ||
84 | After creating the VM, we need to configure it. | |
85 | ||
244fdc7b | 86 | - Click the `Settings` button, then go to the `Network` tab. Adapter 1 should be attached to `NAT`. |
2c47a00b WL |
87 | |
88 | ![](gitian-building/network_settings.png) | |
89 | ||
90 | - Click `Advanced`, then `Port Forwarding`. We want to set up a port through where we can reach the VM to get files in and out. | |
91 | - Create a new rule by clicking the plus icon. | |
92 | ||
93 | ![](gitian-building/port_forwarding_rules.png) | |
94 | ||
95 | - Set up the new rule the following way: | |
96 | - Name: `SSH` | |
97 | - Protocol: `TCP` | |
98 | - Leave Host IP empty | |
99 | - Host Port: `22222` | |
100 | - Leave Guest IP empty | |
101 | - Guest Port: `22` | |
102 | ||
103 | - Click `Ok` twice to save. | |
104 | ||
105 | Then start the VM. On the first launch you will be asked for a CD or DVD image. Choose the downloaded iso. | |
106 | ||
107 | ![](gitian-building/select_startup_disk.png) | |
108 | ||
2c47a00b WL |
109 | Installing Debian |
110 | ------------------ | |
111 | ||
bfc29dcd | 112 | This section will explain how to install Debian on the newly created VM. |
2c47a00b WL |
113 | |
114 | - Choose the non-graphical installer. We do not need the graphical environment, it will only increase installation time and disk usage. | |
115 | ||
116 | ![](gitian-building/debian_install_1_boot_menu.png) | |
117 | ||
118 | **Note**: Navigation in the Debian installer: To keep a setting at the default | |
119 | and proceed, just press `Enter`. To select a different button, press `Tab`. | |
120 | ||
121 | - Choose locale and keyboard settings (doesn't matter, you can just go with the defaults or select your own information) | |
122 | ||
123 | ![](gitian-building/debian_install_2_select_a_language.png) | |
124 | ![](gitian-building/debian_install_3_select_location.png) | |
125 | ![](gitian-building/debian_install_4_configure_keyboard.png) | |
126 | ||
127 | - The VM will detect network settings using DHCP, this should all proceed automatically | |
128 | - Configure the network: | |
129 | - System name `debian`. | |
130 | - Leave domain name empty. | |
131 | ||
132 | ![](gitian-building/debian_install_5_configure_the_network.png) | |
133 | ||
3f7a61fc | 134 | - Choose a root password and enter it twice (remember it for later) |
2c47a00b WL |
135 | |
136 | ![](gitian-building/debian_install_6a_set_up_root_password.png) | |
137 | ||
138 | - Name the new user `debian` (the full name doesn't matter, you can leave it empty) | |
139 | ||
140 | ![](gitian-building/debian_install_7_set_up_user_fullname.png) | |
141 | ![](gitian-building/debian_install_8_set_up_username.png) | |
142 | ||
3f7a61fc | 143 | - Choose a user password and enter it twice (remember it for later) |
2c47a00b WL |
144 | |
145 | ![](gitian-building/debian_install_9_user_password.png) | |
146 | ||
147 | - The installer will set up the clock using a time server, this process should be automatic | |
148 | - Set up the clock: choose a time zone (depends on the locale settings that you picked earlier; specifics don't matter) | |
149 | ||
150 | ![](gitian-building/debian_install_10_configure_clock.png) | |
151 | ||
152 | - Disk setup | |
153 | - Partitioning method: Guided - Use the entire disk | |
154 | ||
155 | ![](gitian-building/debian_install_11_partition_disks.png) | |
156 | ||
157 | - Select disk to partition: SCSI1 (0,0,0) | |
158 | ||
159 | ![](gitian-building/debian_install_12_choose_disk.png) | |
160 | ||
161 | - Partitioning scheme: All files in one partition | |
162 | ||
163 | ![](gitian-building/debian_install_13_partition_scheme.png) | |
164 | ||
165 | - Finish partitioning and write changes to disk -> *Yes* (`Tab`, `Enter` to select the `Yes` button) | |
166 | ||
167 | ![](gitian-building/debian_install_14_finish.png) | |
168 | ![](gitian-building/debian_install_15_write_changes.png) | |
169 | ||
170 | - The base system will be installed, this will take a minute or so | |
171 | - Choose a mirror (any will do) | |
172 | ||
173 | ![](gitian-building/debian_install_16_choose_a_mirror.png) | |
174 | ||
175 | - Enter proxy information (unless you are on an intranet, you can leave this empty) | |
176 | ||
177 | ![](gitian-building/debian_install_18_proxy_settings.png) | |
178 | ||
179 | - Wait a bit while 'Select and install software' runs | |
180 | - Participate in popularity contest -> *No* | |
181 | - Choose software to install. We need just the base system. | |
182 | ||
183 | ![](gitian-building/debian_install_19_software_selection.png) | |
184 | ||
185 | - Make sure only 'SSH server' and 'Standard System Utilities' are checked | |
186 | - Uncheck 'Debian Desktop Environment' and 'Print Server' | |
187 | ||
188 | ![](gitian-building/debian_install_20_install_grub.png) | |
189 | ||
190 | - Install the GRUB boot loader to the master boot record? -> Yes | |
191 | ||
192 | ![](gitian-building/debian_install_21_finish_installation.png) | |
193 | ||
194 | - Installation Complete -> *Continue* | |
195 | - After installation, the VM will reboot and you will have a working Debian VM. Congratulations! | |
196 | ||
197 | Connecting to the VM | |
198 | ---------------------- | |
199 | ||
200 | After the VM has booted you can connect to it using SSH, and files can be copied from and to the VM using a SFTP utility. | |
201 | Connect to `localhost`, port `22222` (or the port configured when installing the VM). | |
202 | On Windows you can use putty[1] and WinSCP[2]. | |
203 | ||
204 | For example to connect as `root` from a Linux command prompt use | |
205 | ||
206 | $ ssh root@localhost -p 22222 | |
207 | The authenticity of host '[localhost]:22222 ([127.0.0.1]:22222)' can't be established. | |
208 | ECDSA key fingerprint is 8e:71:f9:5b:62:46:de:44:01:da:fb:5f:34:b5:f2:18. | |
209 | Are you sure you want to continue connecting (yes/no)? yes | |
210 | Warning: Permanently added '[localhost]:22222' (ECDSA) to the list of known hosts. | |
211 | root@localhost's password: (enter root password configured during install) | |
212 | Linux debian 3.2.0-4-amd64 #1 SMP Debian 3.2.54-2 x86_64 | |
213 | root@debian:~# | |
214 | ||
215 | Replace `root` with `debian` to log in as user. | |
216 | ||
217 | [1] http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html | |
218 | [2] http://winscp.net/eng/index.php | |
219 | ||
220 | Setting up Debian for gitian building | |
221 | -------------------------------------- | |
222 | ||
223 | In this section we will be setting up the Debian installation for Gitian building. | |
224 | ||
225 | First we need to log in as `root` to set up dependencies and make sure that our | |
226 | user can use the sudo command. Type/paste the following in the terminal: | |
227 | ||
2c47a00b WL |
228 | ```bash |
229 | apt-get install git ruby sudo apt-cacher-ng qemu-utils debootstrap lxc python-cheetah parted kpartx bridge-utils | |
230 | adduser debian sudo | |
231 | ``` | |
232 | ||
233 | When you get a colorful screen with a question about the 'LXC directory', just | |
234 | go with the default (`/var/lib/lxc`). | |
235 | ||
3f7a61fc | 236 | Then set up LXC and the rest with the following, which is a complex jumble of settings and workarounds: |
2c47a00b WL |
237 | |
238 | ```bash | |
239 | # the version of lxc-start in Debian 7.4 needs to run as root, so make sure | |
240 | # that the build script can exectute it without providing a password | |
241 | echo "%sudo ALL=NOPASSWD: /usr/bin/lxc-start" > /etc/sudoers.d/gitian-lxc | |
242 | # add cgroup for LXC | |
243 | echo "cgroup /sys/fs/cgroup cgroup defaults 0 0" >> /etc/fstab | |
244 | # make /etc/rc.local script that sets up bridge between guest and host | |
245 | echo '#!/bin/sh -e' > /etc/rc.local | |
246 | echo 'brctl addbr br0' >> /etc/rc.local | |
247 | echo 'ifconfig br0 10.0.3.2/24 up' >> /etc/rc.local | |
248 | echo 'exit 0' >> /etc/rc.local | |
5a79c653 WL |
249 | # make sure that USE_LXC is always set when logging in as debian, |
250 | # and configure LXC IP addresses | |
2c47a00b | 251 | echo 'export USE_LXC=1' >> /home/debian/.profile |
5a79c653 WL |
252 | echo 'export GITIAN_HOST_IP=10.0.3.2' >> /home/debian/.profile |
253 | echo 'export LXC_GUEST_IP=10.0.3.5' >> /home/debian/.profile | |
2c47a00b WL |
254 | reboot |
255 | ``` | |
256 | ||
5a79c653 WL |
257 | At the end the VM is rebooted to make sure that the changes take effect. The steps in this |
258 | section need only to be performed once. | |
2c47a00b WL |
259 | |
260 | Installing gitian | |
261 | ------------------ | |
262 | ||
263 | Re-login as the user `debian` that was created during installation. | |
264 | The rest of the steps in this guide will be performed as that user. | |
265 | ||
266 | There is no `python-vm-builder` package in Debian, so we need to install it from source ourselves, | |
267 | ||
268 | ```bash | |
269 | wget http://archive.ubuntu.com/ubuntu/pool/universe/v/vm-builder/vm-builder_0.12.4+bzr489.orig.tar.gz | |
270 | echo "ec12e0070a007989561bfee5862c89a32c301992dd2771c4d5078ef1b3014f03 vm-builder_0.12.4+bzr489.orig.tar.gz" | sha256sum -c | |
271 | # (verification -- must return OK) | |
272 | tar -zxvf vm-builder_0.12.4+bzr489.orig.tar.gz | |
273 | cd vm-builder-0.12.4+bzr489 | |
274 | sudo python setup.py install | |
275 | cd .. | |
276 | ``` | |
277 | ||
278 | **Note**: When sudo asks for a password, enter the password for the user *debian* not for *root*. | |
279 | ||
bfc29dcd | 280 | Clone the git repositories for bitcoin and gitian. |
2c47a00b WL |
281 | |
282 | ```bash | |
283 | git clone https://github.com/devrandom/gitian-builder.git | |
284 | git clone https://github.com/bitcoin/bitcoin | |
285 | ``` | |
286 | ||
bfc29dcd | 287 | Setting up the gitian image |
2c47a00b WL |
288 | ------------------------- |
289 | ||
bfc29dcd MF |
290 | Gitian needs a virtual image of the operating system to build in. |
291 | Currently this is Ubuntu Precise x86_64. | |
292 | This image will be copied and used every time that a build is started to | |
2c47a00b | 293 | make sure that the build is deterministic. |
bfc29dcd | 294 | Creating the image will take a while, but only has to be done once. |
2c47a00b WL |
295 | |
296 | Execute the following as user `debian`: | |
297 | ||
298 | ```bash | |
299 | cd gitian-builder | |
2c47a00b WL |
300 | bin/make-base-vm --lxc --arch amd64 --suite precise |
301 | ``` | |
302 | ||
bfc29dcd | 303 | There will be a lot of warnings printed during build of the image. These can be ignored. |
2c47a00b WL |
304 | |
305 | **Note**: When sudo asks for a password, enter the password for the user *debian* not for *root*. | |
306 | ||
307 | Getting and building the inputs | |
308 | -------------------------------- | |
309 | ||
dd14a0e7 CF |
310 | Follow the instructions in [doc/release-process.md](release-process.md) in the bitcoin repository |
311 | under 'Fetch and build inputs' to install sources which require manual intervention. Also follow | |
312 | the next step: 'Seed the Gitian sources cache', which will fetch all necessary source files allowing | |
313 | for gitian to work offline. | |
2c47a00b | 314 | |
dd14a0e7 CF |
315 | Building Bitcoin |
316 | ---------------- | |
2c47a00b | 317 | |
dd14a0e7 CF |
318 | To build Bitcoin (for Linux, OSX and Windows) just follow the steps under 'perform |
319 | gitian builds' in [doc/release-process.md](release-process.md) in the bitcoin repository. | |
2c47a00b | 320 | |
dd14a0e7 | 321 | This may take a long time as it also builds the dependencies needed for each descriptor. |
bfc29dcd | 322 | These dependencies will be cached after a successful build to avoid rebuilding them where possible. |
2c47a00b WL |
323 | |
324 | At any time you can check the package installation and build progress with | |
325 | ||
326 | ```bash | |
327 | tail -f var/install.log | |
328 | tail -f var/build.log | |
1fa89a54 | 329 | ``` |
2c47a00b WL |
330 | |
331 | Output from `gbuild` will look something like | |
332 | ||
333 | Initialized empty Git repository in /home/debian/gitian-builder/inputs/bitcoin/.git/ | |
334 | remote: Reusing existing pack: 35606, done. | |
335 | remote: Total 35606 (delta 0), reused 0 (delta 0) | |
336 | Receiving objects: 100% (35606/35606), 26.52 MiB | 4.28 MiB/s, done. | |
337 | Resolving deltas: 100% (25724/25724), done. | |
338 | From https://github.com/bitcoin/bitcoin | |
339 | ... (new tags, new branch etc) | |
dd14a0e7 | 340 | --- Building for precise x86_64 --- |
2c47a00b WL |
341 | Stopping target if it is up |
342 | Making a new image copy | |
343 | stdin: is not a tty | |
344 | Starting target | |
345 | Checking if target is up | |
346 | Preparing build environment | |
347 | Updating apt-get repository (log in var/install.log) | |
348 | Installing additional packages (log in var/install.log) | |
349 | Grabbing package manifest | |
350 | stdin: is not a tty | |
351 | Creating build script (var/build-script) | |
352 | lxc-start: Connection refused - inotify event with no name (mask 32768) | |
353 | Running build script (log in var/build.log) | |
354 | ||
2c47a00b WL |
355 | Building an alternative repository |
356 | ----------------------------------- | |
357 | ||
3f7a61fc | 358 | If you want to do a test build of a pull on GitHub it can be useful to point |
2c47a00b WL |
359 | the gitian builder at an alternative repository, using the same descriptors |
360 | and inputs. | |
361 | ||
362 | For example: | |
363 | ```bash | |
364 | URL=https://github.com/laanwj/bitcoin.git | |
365 | COMMIT=2014_03_windows_unicode_path | |
366 | ./bin/gbuild --commit bitcoin=${COMMIT} --url bitcoin=${URL} ../bitcoin/contrib/gitian-descriptors/gitian-linux.yml | |
367 | ./bin/gbuild --commit bitcoin=${COMMIT} --url bitcoin=${URL} ../bitcoin/contrib/gitian-descriptors/gitian-win.yml | |
3f7a61fc | 368 | ./bin/gbuild --commit bitcoin=${COMMIT} --url bitcoin=${URL} ../bitcoin/contrib/gitian-descriptors/gitian-osx.yml |
2c47a00b WL |
369 | ``` |
370 | ||
371 | Signing externally | |
372 | ------------------- | |
373 | ||
3f7a61fc MF |
374 | If you want to do the PGP signing on another device that's also possible; just define `SIGNER` as mentioned |
375 | and follow the steps in the build process as normal. | |
2c47a00b WL |
376 | |
377 | gpg: skipped "laanwj": secret key not available | |
378 | ||
379 | When you execute `gsign` you will get an error from GPG, which can be ignored. Copy the resulting `.assert` files | |
380 | in `gitian.sigs` to your signing machine and do | |
381 | ||
382 | ```bash | |
bfc29dcd MF |
383 | gpg --detach-sign ${VERSION}-linux/${SIGNER}/bitcoin-linux-build.assert |
384 | gpg --detach-sign ${VERSION}-win/${SIGNER}/bitcoin-win-build.assert | |
385 | gpg --detach-sign ${VERSION}-osx-unsigned/${SIGNER}/bitcoin-osx-build.assert | |
2c47a00b WL |
386 | ``` |
387 | ||
388 | This will create the `.sig` files that can be committed together with the `.assert` files to assert your | |
389 | gitian build. | |
390 | ||
391 | Uploading signatures | |
392 | --------------------- | |
393 | ||
a98b8707 | 394 | After building and signing you can push your signatures (both the `.assert` and `.assert.sig` files) to the |
3f7a61fc | 395 | [bitcoin/gitian.sigs](https://github.com/bitcoin/gitian.sigs/) repository, or if that's not possible create a pull |
a98b8707 | 396 | request. You can also mail the files to me ([email protected]) and I'll commit them. |