I have read in several places that it's good practice to mount /
, /home
and /var
on separate partitions for a server, as a way of mitigating the risk of an unwanted app/action filling-up the disk.
In all the cloud providers in which I have created instances, though (AWS, OVH and GCP), the default available image for Ubuntu normally comes with a single /
partition.
Is the "good practice" mentionned above somehow irrelevant for cloud, or is it just being ignored? As the root partition is obviously mounted when I log into the server, is there a way for me to shrink it and re-allocate empty space?
We use one partition per volume (with the exception of the first volume that includes boot and swap). This has many advantages (of course always depending on the application).
If your application has a large DB + many Files from my experience it's a good practice to separate data file system from root file system. Most obvious reason is that it's way easier to enlarge or shrink a data partition, but changing the boot partition is way more complicated. In most cases you need to unmount the partition in order to resize it.
You don´t need to reboot/enter maintenance mode the server in order to resize/modify/add/delete volumes/partitions.
Another reason is optimizing costs, so having different volumes at different costs is possible with this configuration.
About shrinking the root partition, what I normally do is choose a configuration with the disk size that fit's to the needs of my root file system. (I use Debian, very similar to Ubuntu and I use 15 GB root partition). I link /var/log to a data partition, which is normally what is causing space problems. In this way root partition remains pretty much the same size. Just make sure applications running clean up /tmp files.
You have also many other advantages:
1) You can create/build a new server (the root partition) and just move data from one server to the other. Easy way to update OS Version (less risk, less downtime)
2) If you separate applications from data, you can have another volume for applications and gives additional flexibility.
3) I your VM provider has different types of disks (different speeds, different prices) you can choose fast volumes for DB and slower volumes for executable (normally run once) and seldom used data.
etc) I am sure many other reasons to separate volumes/filesystems. Here just a few.
Partitioning disks within Linux is quite an opinionated subject. I would argue that it is less important to partition away things like /var and /home on modern systems, as the disks we deal with are larger or the machines are more transient.
It is a good idea to partition /home separately from the rest of the OS on any system that will be used interactively by people, for two reasons:
Most cloud providers tailor their default setups to the second case, the idea that machines will not stay around for a long period of time. If your running web sites on cloud platforms, you will generally want to use load balancers, and auto-scaling groups, where servers are scaled up/down based on use, and when you have an error you just blow them away and start a new one.
The other part to this, is cloud providers generally allow for multiple attached volumes. If you were to want to treat servers are more permanent, the recommended practice would be to attach an additional volume to the instance, over the top of say /srv/www, /home, or wherever your persistent data will live. That way you can reattach your website, to a new server, when you want to upgrade the OS.