All HowTo's Linux Redhat, Fedora and CentOS Linux

How to add a volume to a running CentOS/Redhat 7 Linux EC2

This article walks you through adding a volume to a CentOS 7 / Redhat 7 EC2 while it’s running. In this example we’re going to replace the “/var/log” directory with a larger one to prevent the system from running out of disk space due to large logs.

  • Log into AWS console.
  • Take note of the instance ID and AZ (availability zone) of the EC2 to attach the new volume to.
  • Click “Volume”.
  • Click “Create Volume”.
  • Set Size (EG 10GB).
  • Set AZ (EG ap-southeast-2a).
  • Click “Create”.
  • Set Volume name (EG My Instance /var/log).
  • Click “Attach”.
  • Set Instance association (EG i-1234567890).

Now we can log into the EC2 and work with the new filesystem.

  • Log into the attached system.
  • Run “lsblk” to find the new disk.

In this example, we’ll say the new volume was named “xvdf” by the kernel.

  • Create the partition with “fdisk /dev/xvdf”.
  • Create the filesystem with “mkfs.ext4 -m0 /dev/xvdf1”.
  • Create the temp mount point with “mkdir /mnt/logs”.
  • Mount the new filesystem with “mount /dev/xvdf1 /mnt/logs”.
  • Check disk space with “df -h”.
  • Sync the data over with “rsync -avz /var/log/* /mnt/logs/”.
  • Stop rsyslog with “systemctl stop rsyslog”.
  • Move the original logs directory out of the way with “mv /var/log /var/log.deleteme”.
  • Create a new mount point with “mkdir /var/log”.
  • Mount the new filesystem with “mount /dev/xvdf1 /var/log”.
  • A second time: Sync the data over with “rsync -avz /var/log.deleteme/* /var/log/”.
  • Correct SELinux with “restorecon -rv /var/log”.
  • Restart rsyslog with “systemctl start rsyslog”.

Now add the appropriate entry into “/etc/fstab”:

  • Add “/dev/xvdf1 /var/log ext4 defaults 0 0” to “/etc/fstab”.

Make sure rsyslog is able to log to “/var/log/message”. If not, check that you’ve mounted the new filesystem correctly and restart rsyslog.

At this point we have attached the new volume, mounted it and are back up and running with no down time. There is one last thing to do – remove the old “/var/log.deleteme” directory. Don’t do this right away. Make sure the system is working as you’d expect and then, later, delete it.

Similar Posts:

Leave a Reply

Your email address will not be published.