The disk a Lightsail machine comes with is fixed by the plan. When it fills up with photos, backups or logs, the first idea is to move up a plan, which costs more per month and also gives you more processor and memory that you may not need. The cheap alternative is to add a separate disk, of whatever size you want, and move onto it whatever takes up space. Lightsail allows this with a few clicks in the console and three or four commands on the machine. This guide explains them one by one.
Before you start: what each thing means
- Lightsail
- The simple version of Amazon's servers, with a fixed monthly price and its own console.
- System disk
- The disk the machine comes with, where everything is installed. Its size is set by the plan and cannot be enlarged separately.
- Data disk (block storage)
- An additional disk that you create separately, of whatever size you want, and attach to the machine. It is paid per GB per month.
- Attach
- Hooking the disk up to a machine. A disk can only be attached to one machine at a time, but you can detach it and attach it to another.
- Format and mount
- Formatting is preparing the empty disk to store files. Mounting is making it appear inside a folder on the machine (for example /datos).
- fstab
- The system file where it is recorded which disks are mounted at boot. Without that line, the disk disappears on reboot until you mount it by hand.
- Browser terminal
- The "Connect using SSH" button in the Lightsail console. It opens a window for typing commands on the machine.
Step by step
Create the disk in the console
In the Lightsail console, Storage tab, Create disk. Choose the same region and availability zone as your machine (otherwise you will not be able to attach it), the size in GB and a name (
datos-web). If you already know which machine it is for, select it so that it is attached on creation. Create. Look at the price per GB it shows: that is what you will pay per month, on top of the machine.Attach it to the machine
If you did not attach it on creation, open the disk, Attach to an instance, choose the machine and confirm. Lightsail tells you the path under which the disk appears inside the machine, usually
/dev/xvdf. Write it down.Prepare the disk from the terminal
Open the machine's browser terminal and check that the disk is there:
lsblkxvdf(or similar) should appear with the size you created and nothing mounted. Format it (only the first time: this erases whatever it holds) and create the folder where you will see it:sudo mkfs -t ext4 /dev/xvdf sudo mkdir /datos sudo mount /dev/xvdf /datos df -h /datosThe last command should show the
/datosfolder with the size of the new disk.Make it mount on its own at boot
Without this step, when the machine reboots the folder will be empty. Find out the disk's fixed identifier and add it to the boot file:
sudo blkid /dev/xvdf echo "UUID=el-uuid-que-te-ha-salido /datos ext4 defaults,nofail 0 2" | sudo tee -a /etc/fstab sudo mount -aReplace
el-uuid-que-te-ha-salidowith the valueblkidshowed (in quotes, after UUID=). Thenofailoption is important: if one day the disk is not there, the machine boots anyway instead of hanging.Move what takes up space
Typically it is the website uploads, backups or logs. For a website, for example, copy the uploads folder to the new disk and leave a link in its place pointing there:
sudo rsync -a /ruta/actual/uploads/ /datos/uploads/ sudo mv /ruta/actual/uploads /ruta/actual/uploads.antiguo sudo ln -s /datos/uploads /ruta/actual/uploadsCheck that the website sees the images and, after a few days, delete the
.antiguofolder. Give the web server user permissions on the new folder if needed (chown).Back it up too
Machine snapshots do not include additional disks. In the Storage tab, open the disk and turn on its own snapshots, or create them by hand when you make the machine's. If you ever restore the machine, you will have to create the disk from its snapshot and attach it to the new one.
What can go wrong
It will not let me attach the disk to the machine
They are in different availability zones. A disk can only be attached to machines in its own zone. Create the disk again in the correct zone (you will see it on the machine's card).
After rebooting, the folder is empty
The line in fstab is missing or has a typo. Mount by hand with sudo mount -a and look at the error it gives. If you put the path /dev/xvdf instead of the UUID, it may fail because the letter changes; always use the UUID.
I have formatted the wrong disk
If it was the system disk, the machine is lost: restore from the latest snapshot. That is why it pays to look twice at lsblk before running mkfs, and to take a snapshot of the machine before starting.
The bill has gone up more than expected
A disk is charged for its full size even if it is empty, and its snapshots separately. Size it for next year, not for ten years from now.
In Simplio
In Simplio you see each Lightsail machine's disks on its card, with their size and how much is used, and you can add one with a button, already in the correct zone. Preparing it on the machine (format, mount, set at boot) is launched from the script catalogue without opening a terminal. The backup schedule includes attached disks, and you get an alert when a disk goes past 85% usage, before the website stops accepting uploads.
The same task, in AWS and in Simplio
| In the AWS console | In Simplio | |
|---|---|---|
| Create and attach the disk | Lightsail console, Storage tab, correct zone, attach: 4 steps | "Add disk" button on the machine, with the zone already correct |
| Prepare it on the machine | Terminal, 6 commands, UUID and fstab by hand: 15 minutes and room for error | "Prepare disk" script from the catalogue: formats, mounts and leaves it set at boot |
| Disk backups | Turn them on separately and remember them when restoring | Backup schedule that includes attached disks |