add arguments to vbox-resize-disk1 script

This commit is contained in:
Lev Dubinets 2019-07-02 17:46:56 -07:00
parent 16fa9254f3
commit 1304230777
No known key found for this signature in database
GPG Key ID: 798E4C6433A5B976
3 changed files with 85 additions and 27 deletions

81
contrib/vbox-resize-disk1.sh Executable file
View File

@ -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 <deployment>] [-m <machine>] [-s <size>] [-f <file>] [-y]"
echo ""
echo "Options:"
echo " -d <deployment> NixOps deployment name. Default: bitcoin-node."
echo " -m <machine> NixOps machine name. Default: bitcoin-node."
echo " -s <size> New disk size in megabytes. Default: 307200 (300gb)."
echo " -f <file> 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

View File

@ -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

View File

@ -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