Reducing a Digital Ocean volume in size

Fremantle

· system administration · Digital Ocean · volumes ·

For my own future reference:

  1. Create new volume.
  2. Mount it:
    sudo mount -o discard,defaults,noatime /dev/disk/by-id/scsi-0DO_Volume_data2 /mnt/data2
  3. Stop Apache:
    sudo apache2ctl stop
  4. Copy everything from old to new with rsync (note trailing slashes):
    rsync -av /mnt/data/ /mnt/data2/
  5. Unmount the old volume:
    sudo umount /mnt/data
  6. Mount new to old place:
    sudo mount -o discard,defaults,noatime /dev/disk/by-id/scsi-0DO_Volume_data2 /mnt/data
  7. Restart Apache:
    sudo apache2ctl start
  8. Edit the entry in fstab to use the new volume ID:
    /dev/disk/by-id/scsi-0DO_Volume_data2 /mnt/data2 ext4 defaults,nofail,discard 0 0
  9. Remove the temporary mount point:
    sudo rmdir data2/
  10. Restart to make sure everything comes back up as it should (this isn't an elegant way to do this—but I'm lazy, not many people use this server, and this definately tests what I want it to).
    sudo shutdown -r now