sobota, 12 listopada 2011

Resizing root filesystem: KVM, LVM and EXT4

Ever faced a problem that you run out of the root filesystem space? I recently faced that problem on my KVM CentOS 6.0 box (a lot of experiments done on it) and wanted to solve it without reinstallation of the system. It seems to be possible without losing any data and not that difficult on all levels:

  • KVM virtual disk size
  • LVM volume group size
  • EXT4 filesystem size
Below you can find the instruction on how to do that:


1. Resize the KVM virtio disk image. First one need to resize the virtual disk for the KVM. In order to do that you shoudl create a new add on raw disk and append it to the existing disk image. I recommend to first move the original disk for the backup purposes. The steps to be done are shown below:


root@krystianek:/var/lib/libvirt/images# qemu-img create -f raw addon.raw 4G
Formatting 'addon.raw', fmt=raw size=4294967296


root@krystianek:/var/lib/libvirt/images# mv centos6.img centos6.img.backup
root@krystianek:/var/lib/libvirt/images# cat centos6.img.backup addon.raw > centos6
centos6.img.backup    centos6-oracle-1.img  centos6-oracle-2.img  centos6-oracle.img    
root@krystianek:/var/lib/libvirt/images# cat centos6.img.backup addon.raw > centos6.img

2. Boot from  LiveCD. It is required since you will be modyfing the root filesystem's volume group if you plan to modify another volume group/filesystem it may not be required. I used the CentOS LiveCD in order to do that.

3. Create a new partition. Create a new partition from the free disk space (4G). In my case I created a /dev/vda3 partition using the CentOS graphical disk utility.

4. Extend the LVM volume group. Add the newly /dev/vda3 device to the volume group

[root@livecd ~]# vgdisplay 
  --- Volume group ---
  VG Name               vg_centos6hosta
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  3
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               1
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               7.51 GiB
  PE Size               4.00 MiB
  Total PE              1922
  Alloc PE / Size       1922 / 7.51 GiB
  Free  PE / Size       0 / 0   
  VG UUID               DIeDAo-5Y1O-GEC0-JCb6-keUy-8Yc1-MhRBdN
   
[root@livecd ~]# vgextend vg_centos6hosta /dev/vda3 
  No physical volume label read from /dev/vda3
  Physical volume "/dev/vda3" successfully created
  Volume group "vg_centos6hosta" successfully extended
[root@livecd ~]# vgdisplay 
  --- Volume group ---
  VG Name               vg_centos6hosta
  System ID             
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  4
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               1
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               11.50 GiB
  PE Size               4.00 MiB
  Total PE              2945
  Alloc PE / Size       1922 / 7.51 GiB
  Free  PE / Size       1023 / 4.00 GiB
  VG UUID               DIeDAo-5Y1O-GEC0-JCb6-keUy-8Yc1-MhRBdN
   
[root@livecd ~]# lvresize -L+3995M /dev/mapper/vg_centos6hosta-lv_root 
  Rounding up size to full physical extent 3.90 GiB
  Extending logical volume lv_root to 8.50 GiB
  Logical volume lv_root successfully resized
[root@livecd ~]# 

5. Resize the filesystem residing on the LVM volume. Last but not least you have to resize the filesystem residing on the LVM volume group. For ext4 you can do it as follows (where vg_centos6hosta-lv_root is the root fs volume group):

[root@livecd ~]# e2fsck -f /dev/mapper/vg_centos6hosta-lv_root 
e2fsck 1.41.12 (17-May-2010)
_CentOS-6.0-x86_: recovering journal
Clearing orphaned inode 131145 (uid=27, gid=27, mode=0100600, size=0)
Clearing orphaned inode 131144 (uid=27, gid=27, mode=0100600, size=0)
Clearing orphaned inode 131140 (uid=27, gid=27, mode=0100600, size=0)
Clearing orphaned inode 131136 (uid=27, gid=27, mode=0100600, size=0)
Clearing orphaned inode 131130 (uid=27, gid=27, mode=0100600, size=0)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information

_CentOS-6.0-x86_: ***** FILE SYSTEM WAS MODIFIED *****
_CentOS-6.0-x86_: 139003/303104 files (0.1% non-contiguous), 1195597/1206272 blocks
[root@livecd ~]# resize2fs /dev/mapper/vg_centos6hosta-lv_root 
resize2fs 1.41.12 (17-May-2010)
Resizing the filesystem on /dev/mapper/vg_centos6hosta-lv_root to 2229248 (4k) blocks.
The filesystem on /dev/mapper/vg_centos6hosta-lv_root is now 2229248 blocks lo

Brak komentarzy:

Prześlij komentarz