This was playing with filesystems on rocky linux 9. I found one situation where a VM had a root file system mounted directly to a 30GB device, which was filling up and causing issues as it was the location of the app and could not be extended. There was more storage available that could be allocated to some of the locations on this disk such as the app directory. A solution could be to mount this dir onto a new filesystem. In the below example I used /var. This assumes using super user. The idea being that we move the existing /var off the root filesystem and mount a new directory to its own filesystem.ย
Firstly this is out put of the ‘vgs’ command in this scenario. Volume group is named rl.ย
ย
vgs
VG #PV #LV #SN Attr VSize VFree
rl 2 5 0 wz--n- 62.99g <30.00g
create lv, give it 2G, assign the name ‘var’ and format:
lvcreate -L 2G -n var rl
mkfs.xfs /dev/rl/var
#or for ext4:
mkfs.ext4 /dev/rl/var Backup data and copy over after mounting.ย
To do this we dont want anything touching the files, one way is to boot into rescue mode: (this is rocky/redhat 9 equiv to runlevel 1)
Can only do this if you have access via console as no services or network will be running. Can then copy/move files without as much risk.
https://www.liquidweb.com/kb/linux-runlevels-explained/
ย
systemctl isolate rescue.target
#To get back and to check which init or mode you are in:
systemctl isolate multi-user.target
systemctl get-default mount to file system, backup and move files and add to fstab so mount persists a reboot, using ext4 or mkfs depending on partition created. After this, reboot system.
mkdir /newvar
mount /dev/rl/var /newvar
#backup old location:
cp -apx /var/* /newvar
mv /var /var.old
mkdir /var
mount /var add to /etc/fstab:
/dev/mapper/rl-var /var ext4 defaults 0 0
#can then reboot