How to resize or expand LVM partitions

A few week ago, I installed FC6 on my laptop and my slash (/) partition started to run out of space. So I decided that I would shrink my big partition and expand my / partition. Fortunately, I installed FC6 using LVM2 (Logical Volume Manager) which makes it very easy to resize partitions without even rebooting.

Here is how I did.

My partition was like this:
Filesystem                  1K-blocks    Used    Available    Use%    Mounted on
/dev/mapper/VolGroup00-LogVol00    7935392    6773500    752292    91%    /
/dev/sda5                    497829      20904    451223      5%      /boot
tmpfs                        1037084      0       1037084     0%      /dev/shm
/dev/mapper/VolGroup00-LogVol01    70877776    14988144    51045372    23%    /home


My / partition is about 8 Gb and my /home partition is about 71 Gb.

For /home, I did:
  1. umount /home or umount -l /home
  2. e2fsck -f /dev/VolGroup00/LogVol01
  3. resize2fs /dev/VolGroup00/LogVol01 69G
  4. lvreduce -L-2G /dev/VolGroup00/LogVol01 or we can use  lvreduce -L 69G /dev/mapper/VolGroup-lv_home ( 69GB is disk space after resize)
  5. mount /home
Notes: If divice show busy at step 2 3.
Solutions:
- Edit /etc/fstab ( remove the /home)
- Reboot server then run again

For / partition, I did:
  1. lvextend -L+2G /dev/VolGroup00/LogVol00 ( or we can use this command, it's will take all the disk space to this volume: lvextend -l +100%FREE /dev/mapper/VolGroup-lv_root)
  2. resize2fs /dev/VolGroup00/LogVol00
e2fsck and resize2fs belong to package e2fsprogs-1.39-7.fc6.

resize2fs has the ability to resize mounted partitions.
From the manual of resize2fs:
[...] If the filesystem is mounted, it can be used to expand the size of the mounted filesystem, assuming the kernel supports on-line resizing. (As of this writing, the Linux 2.6 kernel supports on-line resize for filesystems mounted using ext3 only.). [...]
[root@tosca ~]# resize2fs /dev/VolGroup00/LogVol00resize2fs 1.39 (29-May-2006)Filesystem at /dev/VolGroup00/LogVol00 is mounted on /; on-line resizing required
Performing an on-line resize of /dev/VolGroup00/LogVol00 to 2400256 (4k) blocks.
The filesystem on /dev/VolGroup00/LogVol00 is now 2400256 blocks long.

I finaly end up with the following partionning:
Filesystem1K-blocksUsedAvailableUse%Mounted on
/dev/mapper/VolGroup00-LogVol0092996246779304204356477%/
/dev/sda5497829209044512235%/boot
tmpfs1037084010370840%/dev/shm
/dev/mapper/VolGroup00-LogVol0168877776149998885103362823%/home

Some useful LVM commands (package lvm2-2.02.06-4):
  • lvmdiskscan
  • vgdisplay
  • pvdisplay
  • lvdispay
  • vgcreate
  • pvcreate
  • lvscan
  • pvscan
  • vgscan
Some useful links:

Nhận xét

Bài đăng phổ biến từ blog này

CLEANING UP THE ZABBIX DATABASE

Configuring DHCP Relay service on the FortiGate unit

WAN link load balancing