Open zefhemel opened 11 years ago
There is an option to specify the base image size here: https://github.com/NixOS/nixpkgs/blob/0761f81da71fc6a940c7f51129b6c7717db78e87/nixos/modules/virtualisation/virtualbox-image.nix#L11-L22 but I'm not exactly sure how to set that option in the nixops configs...
Did you ever figure this out?
A command to get the path to the .vdi
file could be used in conjunction with VBoxManage modifyhd --resize
I've used the following to successfully resize some nixops VDIs, in case the commands are helpful:
#!/usr/bin/env bash
set -e
set -o pipefail
STOPPED=0
for MACHINE in hydra slave1
do
echo "Looking for '$MACHINE' VM" 1>&2
VMUUID=$(vboxmanage list vms | grep -o "nixops-[^ ]*-$MACHINE")
echo "Found VM ID: $VMUUID" 1>&2
echo "Looking for disk" 1>&2
DISK=$(vboxmanage showvminfo "$VMUUID" | grep "^SATA" | grep -o "/.*\.vdi")
echo "Found disk '$DISK'" 1>&2
SIZE=$(vboxmanage showhdinfo "$DISK" | grep "^Capacity:" | grep -o "[0-9]* MBytes" | grep -o "[0-9]*")
echo "Has size '$SIZE'" 1>&2
DESIRED=100000
if [[ "$SIZE" -lt "$DESIRED" ]]
then
echo "Size is too small, resizing" 1>&2
if [[ "$STOPPED" -eq 0 ]]
then
echo "Stopping hydra deployment" 1>&2
STOPPED=1
nixops stop
fi
echo "Resizing" 1>&2
vboxmanage modifyhd "$DISK" --resize "$DESIRED"
else
echo "Disk doesn't need resizing" 1>&2
fi
done
if [[ "$STOPPED" -eq 1 ]]
then
echo "Redeploying" 1>&2
./deploy.sh
fi
However, this only affects the disk size; I then had to resize the partition and grow the filesystem (I did this with GParted on a live CD). As long as NixOps is stopped, it doesn't seem to mind (i.e. it's happy to use the resized drive without complaining)
To complement @Warbo's instructions here's what I wrote for our hydra server's manual
If more space is needed, one can resize the disk.
Assuming the deployment is called hydra
Find the disk file.
export DISK_FILE=$(nixops export -d hydra | nix-shell -p jq --command "jq -r '..|.\"virtualbox.disks\"?|select(.!=null)' | jq -r .disk1.path")
nixops stop -d hydra
VBoxManage modifyhd --resize 64000 $DISK_FILE
nixops start -d hydra
nixops ssh -d hydra hydra -- fdisk -u /dev/sda
Send these instructions to fdisk
p
to print the partition table; take note of the number, start, end, type of sda1d
to delete itn
new partitionp
primary1
(the number of the partition you deleted)2048
(the first sector of /dev/sda1 from the parition table you deleted)w
to write the new partition table.Load the new partition table (If this doesn't work run nixops reboot -d hydra
)
nixops ssh -d hydra hydra -- partx /dev/sda
Expand the file system
nixops ssh -d hydra hydra -- resize2fs /dev/sda1
nixops ssh -d hydra hydra -- df -h
echo good job 👍
The default partition in virtualbox runs out of space quite quickly, so I have to destroy and recreate it. It would be great to have a
deployment.virtualbox
attribute for this.