top of page

Is root running out of space?

May 27

3 min read

1

36

0


If you are using LVM, we can move directories to their own disk. Let's look at how we move the /var directory. This can help if root is running out of space. I would also recommend adding a whole blank disk to root but we can do that in a later video. You can of course use the same method to move /opt or other directories. Remember you need to be root, I don't want to put sudo in front of all the commands.


sdb is the disk I'm going to use. I always recommend using whole disks without partitions. That makes expanding in the future hassle free. I also recommend not using device names such as sdb. Always use by-id or by-uuid. Let's use by-id for our example.


You might see multiple symbolic links in /dev/disk/by-id/ pointing to the same device (like /dev/sdb). I would recommend choosing the most stable and consistent one — typically the ata- link, as it's generally based on the drive's firmware-reported serial number and tends to remain consistent across reboots and hardware scans.


ls -l /dev/disk/by-id/

ata-VBOX_HARDDISK_VB93e4a1ed-7968aa5a -> ../../sdb

scsi-0ATA_VBOX_HARDDISK_VB93e4a1ed-7968aa5a -> ../../sdb

scsi-1ATA_VBOX_HARDDISK_VB93e4a1ed-7968aa5a -> ../../sdb


Let's begin

  1. Let's add our new disk to LVM.

    pvcreate /dev/disk/by-id/ata-VBOX_HARDDISK_VB93e4a1ed-7968aa5a You can verify that the disk was added with pvs

  2. Here we are using the volume group rhel and extending it by using the by-id. vgextend rhel /dev/disk/by-id/ata-VBOX_HARDDISK_VB93e4a1ed-7968aa5a You can view information for the rhel volume group with vgs

  3. Create the logical volume "var" and give it the size 10G. If you use a small -l, not a capital -L, you can use a %, like lvcreate -n var -l +100%FREE rhel.  lvcreate -n var -L +10G rhel View the new logical volume with the command lvs

  4. Put the xfs file system on var.

    mkfs.xfs /dev/rhel/var

  5. Create a temporary directory.  mkdir /var.new

  6. Mount the logical volume var to the temporary directory. mount /dev/rhel/var /var.new/

  7. Copy everything from /var to /var.new rsync -avHAX /var/ /var.new/

  8. Check to see if everything was copied over. diff -r /var/ /var.new/

  9. Reboot into emergency mode. Add this to the end of the linux line in GRUB. systemd.unit=emergency.target Put in the root password.

  10. The file system is mounted as root only, remount it with write access. mount -o remount,rw /

  11. Rename /var to /var.old and /var.new to /var mv /var /var.old mv /var.new /var

  12. Mount the new /var with adding an entry to /etc/fstab. Let's use the UUID to mount it. I don't recommend using a device node like /dev/sdb, always use UUID's. Let's find the UUID for sdb, change it to whatever you use. First backup fstab! cp /etc/fstab /etc/fstab.org Make sure you use two >>, not one >. Two appends, one overwrites. Make sure to change rhel to your volume group name and var to the logical volume group name you created. blkid | awk '/\/dev\/mapper\/rhel-var/ {print $2}' >> /etc/fstab

  13. Your entry should look like this but with your UUID. UUID=4c5dde91-45c9-4dfc-a82c-9397903d8e80 /var xfs defaults 0 0

  14. If you are running SELinux, it's necessary to relabel everything during the next boot. touch /.autorelabel

  15. Reboot


If you check out your filesystem with df -Th, you should see var mounted.

/dev/mapper/rhel-var xfs 9.0G 1.2G 7.9G 13% /var


If you are wondering why I chose emergency.target instead of rescue.target.

Here's why:

  1. Emergency target:

    • Provides the most minimal boot environment

    • Typically mounts the root filesystem read-only by default

    • Loads almost no services

    • Minimal system state initialization

  2. Rescue target (in comparison):

    • Loads more system services

    • May attempt to mount more filesystems

    • More likely to trigger writes to /var

Related Posts

Comments

Share Your ThoughtsBe the first to write a comment.

© 2035 by Maya Nelson.
Powered and secured by Wix

Call

123-456-7890

Write

Follow

  • Facebook
  • Twitter
  • LinkedIn
  • Instagram
bottom of page