Рубрики
File system Linux

Extend root partition on CentOS7 on a fly

Problem:
no space left on » / » (centos-root).
0 bytes left.


Solution:
Rescan device
Create a partition (sda3)
Extend VG without meta backup
Extend LV without meta backup
xfs.grow root partition.

echo «1» > /sys/class/block/sda/device/rescan

# if add new disk,
# or if reboot is available expand partiton with gparted
# or fdisk by deleting and creating new partition
echo "1" > /sys/class/block/sda/device/rescan

fdisk /dev/sda
  ### create sda3 partition
  ### n
  ### primary 
  ### (yyy)
  
# check VG name
vgdisplay

# 'centos' is a VG name in this example: VG Name centos
vgextend -A n centos /dev/sda3

# Get lv volume Example: /dev/mapper/centos_centos-root
blkid

# Extend volume to 100% of free space in VG
lvextend -A n -l 100%VG /dev/mapper/centos-root

# Grow filesystem to max available space
xfs_growfs /dev/mapper/centos-root

# verify free space on " / "
df -h


Рубрики
File system Linux

File systems

Check what is the logging type is used in the filesystem:

dmesg | grep EXT

If you need to change logging type remount partition with data=xxx specified (mount command or /etc/fstab) where xxx can be:
data=ordered
data=writeback
data=journal


data=ordered — first metadata is saved only then real data will be written to disk and confirmed as saved. (reliable but slower writeback)

data=writeback — async logging, saving data can be confirmed before real data is saved, software should end operations based on POSIX spec with fsync command.

data=journal — saving both metadata and data itself (slow)

Change file system fsck check period:

tune2fs -l /dev/sdb1 show current information
tune2fs -c 150 -i 80 /dev/sdb1 change it to 150 mount/remount operations («-c») or 80 days («-i»).

Manually recheck file system:
umount /dev/sdb1
fsck.ext4 -f /dev/sdb1
mount /dev/sdb1

Generate UUID for the file system:

tune2fs -U random /dev/sdb1 Generate random UUID

tune2fs -U 5cf24d64-b279-4565-9bfd-e6ec3436845b /dev/sdb1 Set exact UUID for FS

Check the current UUID:
blkid

Extend LVM volume and FS on it (to 30G):
lvextend -L 30G /dev/mapper/vg1-test
resize2fs /dev/mapper/vg1-test

1 st step expand the disk.
in VMware or another hypervisor.

2nd step:
Re-scan expanded disk on a fly (for example expanded vmware para-virtual drive):
echo "1" > /sys/class/block/sdX/device/rescan

3rd step:
resize the partition using fdisk

fdisk /dev/sdX

Delete partition:
Command (m for help): d
Selected partition 1
Partition 1 is deleted

Create a new primary partition:
Command (m for help): n
Select (default p):
Using default response p

Write changes to disk:
Command (m for help): w
The partition table has been altered!

Rescan partitions:
#partprobe

4th step:
check type of filesystem with blkid
if filesystem id «xfs»
to expand partition use:
#xfs_growfs -d /dev/sdX1

check new «xfs» file system info:
xfs_info /dev/sdX1

If the partition is GPT:
use
#partprobe
if you see an error similar to this:
Error: The backup GPT table is not at the end of the disk, as it should be.
Fix partition at first:
parted -l
fix
fix

Now you can use fdisk to recreate the partition:
#fdisk /dev/sdX
d
n
w


Resize file system (ext4)
resize2fs /dev/sdX1

Done