How to resize main filesystem
on my centos server I mounted a new volume /dev/sdb
. I would like to add space to root filesystem /dev/vda1
.
[user@prod current]$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/vda1 30G 11G 18G 37% /
devtmpfs 488M 0 488M 0% /dev
tmpfs 497M 0 497M 0% /dev/shm
tmpfs 497M 50M 447M 11% /run
tmpfs 497M 0 497M 0% /sys/fs/cgroup
tmpfs 100M 0 100M 0% /run/user/1000
/dev/sdb 50G 53M 47G 1% /mnt/volume_nyc3_01
Is there any way to decrease /dev/sdb
and increase /dev/vda1
? If possible without losing data on /dev/vda1
.
Solution 1:
I very much doubt that this is literally possible. But what you could do is move files or folders from /dev/vda1 to /dev/sdb and then make them appear in the same place on /dev/vda1 afterward. This would have the effect of increasing the available space on /dev/vda1.
For example, a simple solution would be to move the contents of /var, /home, /opt, or /usr to /dev/sdb and then mount /dev/sdb as whichever folder you moved. That is a pretty common way to handle this. Be careful with /sbin and /root, as they may need to exist before /dev/sdb is mounted in your setup. You would do this by changing the fstab (which may be done via a tool in your setup).
You could also partition /dev/sdb (I presume). Then you could mount it as more than one directory. This would involve adding entries to the fstab.
A third option would be to move the files from /dev/vda1 to /dev/sdb and then symlink them such that they appear in the same place in the file structure. You would often put these symlinks at the folder level. E.g. something like
ln -s /mnt/volume_nyc3_01/usr /usr
You would do this as root (possibly with sudo
). This would allow you to put arbitrary folders or files on /dev/sdb while still accessing them at the same place in the file system. I presume you already know how to use du
to find which files and folders are taking up the most space.
Solution 2:
If we consider /dev/vda
and /dev/sdb
as different (physical) disks, this is not easily achievable, to the point that it would be much easier to reinstall the server from scratch and put /
into a LVM volume from the start.
If absolutely necessary, this could be done with a lengthy downtime and lots of knowledge about what you need to do. It would be quite error-prone though and I would not recommend to even try.
/dev/vda
suggests this is some kind of virtual system. Depending on what the underlying system allows, it might be possible to resize the disk image providing /dev/vda
(and if necessary, delete/shrink the image providing /dev/sdb
). Talk to your admin/provider. In that case, after the system picks of the larger size of /dev/vda
, you could extend /dev/vda1
and then grow the /
file system.