The answer depends on whether you can unmount the partition to shrink, or not. In your case, you probably cannot unmount the partition. In Linux (UNIX/MAC OS), mounting a partition refers to using the file system and mapping it to the mount point (in your case /
). Unmounting means that you stop using the filesystem, and remove the mapping to the mount point. You cannot unmount the filesystem containing your running OS.
If the partition can be unmounted
Lets assume you want to shrink a 200GB ext4 partition on /dev/sda4
mounted to /data
. It currently contains music and movies or similar, so you can temporarily unmount it. You want to create a 4GB swap.
sudo umount /dev/sda4
to unmount the partition.
sudo resize2fs /dev/sda4 196G
to resize the ext4 filesystem to 196 GB, assuming that there is enough space. Now, you have to shrink the partition. I currently belive you need to use cfdisk
to delete the existing partition, and recreate a smaller partition in its place. You can then also create a new partition for the swap.
sudo cfdisk /dev/sda
will give you a text-based gui to inspect your partition table. I would recommend you to print
the partition table to a file or screen at that point, and take note of the current configuration as backup. You can then select /dev/sda4
and delete
the partition. In its place, free space
will be displayed. Use new
to create a new partition with 196 GB in its place, and set the type to ext4. Then, move to the trailing free space and create the 4GB swap partition with type swap
. Note: I did not test these commands, as I can't play around with my /
at the moment.
If the partition cannot be unmounted
You cannot shrink a mounted ext3/4 partition (see manpage of resize2fs
). As you are running your OS from /
, you cannot unmount /
. That means you have to boot another OS (e.g. from USB key) to do the changes.
In your case, it is a remote server (on KVM most likely), so you might not be able to boot from USB/ a live OS image. There might be other ways to change the partitioning from your vServer provider through an admin GUI. I believe that is your best bet currently.