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:
Solutions:
- Edit /etc/fstab ( remove the /home)
- Reboot server then run again
For / partition, I did:
resize2fs has the ability to resize mounted partitions.
From the manual of resize2fs:
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:
Some useful LVM commands (package lvm2-2.02.06-4):
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:
- umount /home or umount -l /home
- e2fsck -f /dev/VolGroup00/LogVol01
- resize2fs /dev/VolGroup00/LogVol01 69G
- lvreduce -L-2G /dev/VolGroup00/LogVol01 or we can use lvreduce -L 69G /dev/mapper/VolGroup-lv_home ( 69GB is disk space after resize)
- mount /home
Solutions:
- Edit /etc/fstab ( remove the /home)
- Reboot server then run again
For / partition, I did:
- 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)
- resize2fs /dev/VolGroup00/LogVol00
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:
Filesystem | 1K-blocks | Used | Available | Use% | Mounted on |
/dev/mapper/VolGroup00-LogVol00 | 9299624 | 6779304 | 2043564 | 77% | / |
/dev/sda5 | 497829 | 20904 | 451223 | 5% | /boot |
tmpfs | 1037084 | 0 | 1037084 | 0% | /dev/shm |
/dev/mapper/VolGroup00-LogVol01 | 68877776 | 14999888 | 51033628 | 23% | /home |
Some useful LVM commands (package lvm2-2.02.06-4):
- lvmdiskscan
- vgdisplay
- pvdisplay
- lvdispay
- vgcreate
- pvcreate
- lvscan
- pvscan
- vgscan
Nhận xét
Đăng nhận xét