From 13042307776c7be72e4cd9b8e019a1b4c5d5155a Mon Sep 17 00:00:00 2001 From: Lev Dubinets <3114081+ldub@users.noreply.github.com> Date: Tue, 2 Jul 2019 17:46:56 -0700 Subject: [PATCH] add arguments to vbox-resize-disk1 script --- contrib/vbox-resize-disk1.sh | 81 ++++++++++++++++++++++++++++++++++++ docs/install.md | 7 ++-- scripts/vbox-resize-disk1.sh | 24 ----------- 3 files changed, 85 insertions(+), 27 deletions(-) create mode 100755 contrib/vbox-resize-disk1.sh delete mode 100644 scripts/vbox-resize-disk1.sh 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 24d8bb6..c13ccfa 100644 --- a/docs/install.md +++ b/docs/install.md @@ -116,11 +116,12 @@ 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. Resize the virtualbox disk - ``` - ./scripts/vbox-resize-disk1.sh + + ``` + ./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. Make sure to run this from within your nix-shell. + 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 diff --git a/scripts/vbox-resize-disk1.sh b/scripts/vbox-resize-disk1.sh deleted file mode 100644 index 4046f5b..0000000 --- a/scripts/vbox-resize-disk1.sh +++ /dev/null @@ -1,24 +0,0 @@ -set -ex - -DEPLOYMENT="bitcoin-node" -MACHINE="bitcoin-node" -DISK_FILE=$(nixops export -d $DEPLOYMENT | nix-shell -p jq --command "jq -r '..|.\"virtualbox.disks\"?|select(.!=null)' | jq -r .disk1.path") - -nixops stop -d $DEPLOYMENT -VBoxManage modifyhd --resize 307200 "$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: 524287999) -# 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