diff --git a/contrib/vbox-resize-disk1.sh b/contrib/vbox-resize-disk1.sh new file mode 100755 index 0000000..81d1a0d --- /dev/null +++ b/contrib/vbox-resize-disk1.sh @@ -0,0 +1,81 @@ +#!/usr/bin/env nix-shell +#! nix-shell -i bash -p jq + +while getopts ":d:m:s:f:yh" opt; do + case $opt in + d) + DEPLOYMENT="$OPTARG" + ;; + m) + MACHINE="$OPTARG" + ;; + s) + NEW_SIZE="$OPTARG" + ;; + f) + DISK_FILE="$OPTARG" + ;; + y) + YES="yes" + ;; + h) + echo "Usage: $0 [-d ] [-m ] [-s ] [-f ] [-y]" + echo "" + echo "Options:" + echo " -d NixOps deployment name. Default: bitcoin-node." + echo " -m NixOps machine name. Default: bitcoin-node." + echo " -s New disk size in megabytes. Default: 307200 (300gb)." + echo " -f Path to vbox disk file/VDI. Default: read from nixops export." + echo " -y Don't ask for confirmation." + exit 0 + ;; + \?) + echo "Invalid option: -$OPTARG" >&2 + exit 1 + ;; + :) + echo "Option -$OPTARG requires an argument." >&2 + exit 1 + ;; + esac +done + +DEPLOYMENT=${DEPLOYMENT:-"bitcoin-node"} +MACHINE=${MACHINE:-"bitcoin-node"} +NEW_SIZE=${NEW_SIZE:-307200} +DISK_FILE=${DISK_FILE:-$(nixops export -d $DEPLOYMENT | jq -r '..|."virtualbox.disks"?|select(.!=null)' | jq -r .disk1.path)} + +echo "Resizing virtualbox disk for use with nixops and nix-bitcoin." +echo "Using deployment: $DEPLOYMENT" +echo "Using machine: $MACHINE" +echo "Using size: $NEW_SIZE" +echo "Using disk file: $DISK_FILE" + +if [ "$YES" != "yes" ]; then + read -p "Continue? [Y/n] " -n 1 -r + echo + if [[ ! "$REPLY" =~ ^[Yy]$ ]]; then + exit 1 + fi +fi + +set -ex + +nixops stop -d $DEPLOYMENT +VBoxManage modifyhd --resize $NEW_SIZE "$DISK_FILE" +nixops start -d $DEPLOYMENT + +# ( +# echo d # [d]elete 50gb partition +# echo n # [n]ew partitoin +# echo p # [p]rimary partition +# echo # partition number (Accept default: 1) +# echo # first sector (Accept default: 1) +# echo # last sector (Accept default: determined by $NEW_SIZE) +# echo w # [w]rite changes +# ) | fdisk +nixops ssh -d $DEPLOYMENT $MACHINE -- '(echo d; echo n; echo p; echo; echo; echo; echo w; ) | fdisk /dev/sda' + +nixops reboot -d $DEPLOYMENT +nixops ssh -d $DEPLOYMENT $MACHINE -- resize2fs /dev/sda1 +nixops ssh -d $DEPLOYMENT $MACHINE -- df -h diff --git a/docs/install.md b/docs/install.md index 4fe05f1..c13ccfa 100644 --- a/docs/install.md +++ b/docs/install.md @@ -115,7 +115,15 @@ You can also build Nix from source by following the instructions at https://nixo This will now create a nix-bitcoin node on the target machine. -6. Nixops automatically creates an ssh key for use with `nixops ssh`. Access `bitcoin-node` through ssh in nix-shell with +6. Resize the virtualbox disk + + ``` + ./contrib/vbox-resize-disk1.sh + ``` + + NixOps provides a virtualbox disk thats 50gb in size, but we need more than that to house the Bitcoin blockchain. By default, his script will resize the disk to 300gb. Run it with `-h` to see options. Make sure to run this from within your nix-shell. + +7. Nixops automatically creates an ssh key for use with `nixops ssh`. Access `bitcoin-node` through ssh in nix-shell with ``` nixops ssh operator@bitcoin-node