/* Void Main's Red Hat Tips */

{ Red Hat Tips(); } else { main(); }
Resizing root File System on Logical Volume in FC3
#include <stddisclaimer.h>

WARNING!! Before trying this tip on a production partition without a backup you might want to read this thread.

Goal #1: Add free space from end of drive to "/" file system which is part of a logical volume. Part of this is done from the rescue CD but you could do all of it from the rescue CD if you wanted. Commands in red are in rescue mode.

Goal #2: Reverse the above process and shrink the logical volume and root file system to create free space at the end of a drive.

Prerequisites: Understand partition and file system basics.

Pros: Increase size of your root file system without backing up and deleting your partitions.

Cons: You should probably back up your system before doing this just in case. ;)

Let us begin:


Disk Before:

/dev/sda  - 4GB Disk
/dev/sda1 - /boot 75MB
/dev/sda2 - LVM - VolGroup00
  * /dev/VolGroup00/LogVol00 256MB SWAP 
  * /dev/VolGroup00/LogVol01 1.6GB / 
Free Space - 2.0GB

Disk After:

/dev/sda  - 4GB Disk
/dev/sda1 - /boot 75MB
/dev/sda2 - LVM - VolGroup00
/dev/sda3 - LVM - VolGroup00
  * /dev/VolGroup00/LogVol00 256MB SWAP 
  * /dev/VolGroup00/LogVol01 3.6GB / 
Free Space - 0GB

Before:

Take note of partition info with fdisk:


[root@fc3 ~]# fdisk -l

Disk /dev/sda: 4294 MB, 4294967296 bytes
255 heads, 63 sectors/track, 522 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          13      104391   83  Linux
/dev/sda2              14         230     1743052+  8e  Linux LVM

Take note of file system info with df:

[root@fc3 ~]# df -k
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/mapper/VolGroup00-LogVol01
                       1419128    575544    771496  43% /
/dev/sda1               101086      9045     86822  10% /boot
none                    128056         0    128056   0% /dev/shm

Take note of volume group info with vgdisplay:

[root@fc3 ~]# vgdisplay
  --- Volume group ---
  VG Name               VolGroup00
  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               2
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               1.66 GB
  PE Size               32.00 MB
  Total PE              53
  Alloc PE / Size       52 / 1.62 GB
  Free  PE / Size       1 / 32.00 MB
  VG UUID               XQ5u33-HIGu-rRv0-Bwbk-vqGl-wc8Z-SCTJQg

Take note of logical volume info info with lvdisplay:

[root@fc3 ~]# lvdisplay
  --- Logical volume ---
  LV Name                /dev/VolGroup00/LogVol01
  VG Name                VolGroup00
  LV UUID                HD1Sv3-kMLd-6VzL-Gh9s-poNm-A3hv-wgGS7I
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                1.38 GB
  Current LE             44
  Segments               1
  Allocation             inherit
  Read ahead sectors     0
  Block device           253:0

  --- Logical volume ---
  LV Name                /dev/VolGroup00/LogVol00
  VG Name                VolGroup00
  LV UUID                FiV0q0-EFIF-jq9b-W2WE-Jd5r-m1AE-ILi1ZL
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                256.00 MB
  Current LE             8
  Segments               1
  Allocation             inherit
  Read ahead sectors     0
  Block device           253:1

Take note of physical volume info info with pvdisplay:

[root@fc3 ~]# pvdisplay
  --- Physical volume ---
  PV Name               /dev/sda2
  VG Name               VolGroup00
  PV Size               1.66 GB / not usable 0
  Allocatable           yes
  PE Size (KByte)       32768
  Total PE              53
  Free PE               1
  Allocated PE          52
  PV UUID               JzVt2G-IHhe-33EN-xOCu-1nay-pIhs-3jb55M

The *scan utils also display useful information:

[root@fc3 ~]# pvscan
  PV /dev/sda2   VG VolGroup00   lvm2 [1.66 GB / 32.00 MB free]
  Total: 1 [1.66 GB] / in use: 1 [1.66 GB] / in no VG: 0 [0   ]

[root@fc3 ~]# lvscan
  ACTIVE            '/dev/VolGroup00/LogVol01' [1.38 GB] inherit
  ACTIVE            '/dev/VolGroup00/LogVol00' [256.00 MB] inherit

[root@fc3 ~]# vgscan
  Reading all physical volumes.  This may take a while...
  Found volume group "VolGroup00" using metadata type lvm2

Delete partition and create new larger partition with fdisk (be careful to use the same "first cylinder" in both old and new):

[root@fc3 ~]# fdisk /dev/sda

Command (m for help): p                                                    (list partitions)

Disk /dev/sda: 4294 MB, 4294967296 bytes
255 heads, 63 sectors/track, 522 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          13      104391   83  Linux
/dev/sda2              14         230     1743052+  8e  Linux LVM

Command (m for help): n                                                      (new partition)
Command action
   e   extended
   p   primary partition (1-4)
p                                                                        (primary partition)
Partition number (1-4): 3                                                     (partition #3)
First cylinder (231-522, default 231): <ENTER>                            (start cyl = 231)
Using default value 231
Last cylinder or +size or +sizeM or +sizeK (231-522, default 522): <ENTER> (last cyl = 522)
Using default value 522

Command (m for help): t                                              (change partition type)
Partition number (1-4): 3                                                  (on partition #3)
Hex code (type L to list codes): 8e                                           (to Linux LVM)
Changed system type of partition 3 to 8e (Linux LVM)

Command (m for help): p                                                    (list partitions)

Disk /dev/sda: 4294 MB, 4294967296 bytes
255 heads, 63 sectors/track, 522 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          13      104391   83  Linux
/dev/sda2              14         230     1743052+  8e  Linux LVM
/dev/sda3             231         522     2345490   8e  Linux LVM

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

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table.
The new table will be used at the next reboot.
Syncing disks.

Reboot:

[root@fc3 ~]# init 6

Create the new physical volume on the new partition:

[root@fc3 ~]# pvcreate /dev/sda3
  Physical volume "/dev/sda3" successfully created

Add the new physical volume to the volume group:

[root@fc3 ~]# vgextend VolGroup00 /dev/sda3
  Volume group "VolGroup00" successfully extended

Check our work so far with pvscan:

[root@fc3 ~]# pvscan
  PV /dev/sda2   VG VolGroup00   lvm2 [1.66 GB / 32.00 MB free]
  PV /dev/sda3   VG VolGroup00   lvm2 [2.22 GB / 2.22 GB free]
  Total: 2 [3.88 GB] / in use: 2 [3.88 GB] / in no VG: 0 [0   ]

Increase the size of the logical volume:

[root@fc3 ~]# lvextend -L+2.22G /dev/VolGroup00/LogVol01
  Rounding up size to full physical extent 2.25 GB
  Extending logical volume LogVol01 to 3.62 GB
  Logical volume LogVol01 successfully resized

Activate the changes to the volume group:

[root@fc3 ~]# lvm vgchange -a y VolGroup00
  2 logical volume(s) in volume group "VolGroup00" now active

Activate the changes to the logical volume:

[root@fc3 ~]# lvm lvchange -a y /dev/VolGroup00/LogVol01

Reboot with Rescue CD (Find Installation):
rescue screenshot

Unmount sysimage (our root file system):


sh-3.00# umount /mnt/sysimage/sys
sh-3.00# umount /mnt/sysimage/dev
sh-3.00# umount /mnt/sysimage/proc
sh-3.00# umount /mnt/sysimage/boot
sh-3.00# umount /mnt/sysimage

Check the existing file system for errors:
e2fsck screenshot


sh-3.00# e2fsck -f /dev/VolGroup00/LogVol01
e2fsck 1.35 (28-Feb-2004)
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
/dev/VolGroup00/LogVol01: 32235/180224 files (1.5% non-contiguous), 148616/360448 blocks

Resize the root (/) file system:


sh-3.00# resize2fs /dev/VolGroup00/LogVol01

And there was light!

Reboot:

After:

Check our work with the various commands we used before:


[root@fc3 ~]# vgdisplay
  --- Volume group ---
  VG Name               VolGroup00
  System ID
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  5
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               3.88 GB
  PE Size               32.00 MB
  Total PE              124
  Alloc PE / Size       124 / 3.88 GB
  Free  PE / Size       0 / 0
  VG UUID               XQ5u33-HIGu-rRv0-Bwbk-vqGl-wc8Z-SCTJQg

Bigger numbers, that's gotta be a good sign:

[root@fc3 ~]# lvdisplay
  --- Logical volume ---
  LV Name                /dev/VolGroup00/LogVol01
  VG Name                VolGroup00
  LV UUID                HD1Sv3-kMLd-6VzL-Gh9s-poNm-A3hv-wgGS7I
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                3.62 GB
  Current LE             116
  Segments               3
  Allocation             inherit
  Read ahead sectors     0
  Block device           253:0

  --- Logical volume ---
  LV Name                /dev/VolGroup00/LogVol00
  VG Name                VolGroup00
  LV UUID                FiV0q0-EFIF-jq9b-W2WE-Jd5r-m1AE-ILi1ZL
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                256.00 MB
  Current LE             8
  Segments               1
  Allocation             inherit
  Read ahead sectors     0
  Block device           253:1

Bigger numbers here too:

[root@fc3 ~]# pvdisplay
  --- Physical volume ---
  PV Name               /dev/sda2
  VG Name               VolGroup00
  PV Size               1.66 GB / not usable 0
  Allocatable           yes (but full)
  PE Size (KByte)       32768
  Total PE              53
  Free PE               0
  Allocated PE          53
  PV UUID               JzVt2G-IHhe-33EN-xOCu-1nay-pIhs-3jb55M

  --- Physical volume ---
  PV Name               /dev/sda3
  VG Name               VolGroup00
  PV Size               2.22 GB / not usable 0
  Allocatable           yes (but full)
  PE Size (KByte)       32768
  Total PE              71
  Free PE               0
  Allocated PE          71
  PV UUID               njSXJM-7xDm-V72u-xn6M-Ruyg-jVL3-LY9RkA

Not very interesting:

[root@fc3 ~]# vgscan
  Reading all physical volumes.  This may take a while...
  Found volume group "VolGroup00" using metadata type lvm2

Look mom, bigger numers:

[root@fc3 ~]# lvscan
  ACTIVE            '/dev/VolGroup00/LogVol01' [3.62 GB] inherit
  ACTIVE            '/dev/VolGroup00/LogVol00' [256.00 MB] inherit

An extra PV shows up here:

[root@fc3 ~]# pvscan
  PV /dev/sda2   VG VolGroup00   lvm2 [1.66 GB / 0    free]
  PV /dev/sda3   VG VolGroup00   lvm2 [2.22 GB / 0    free]
  Total: 2 [3.88 GB] / in use: 2 [3.88 GB] / in no VG: 0 [0   ]

Our ultimate goal has been achieved, more free space in "/":

[root@fc3 ~]# df -k
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/mapper/VolGroup00-LogVol01
                       3741400    570228   3019132  16% /
/dev/sda1               101086      9045     86822  10% /boot
none                    128056         0    128056   0% /dev/shm

And it was good...

I also reversed the above process and shrunk things down to original sizes with free space at the end of the drive (all from the rescue CD):

Boot Rescue CD:

Unmount sysimage:
# umount /mnt/sysimage/sys
# umount /mnt/sysimage/dev
# umount /mnt/sysimage/proc
# umount /mnt/sysimage/boot
# umount /mnt/sysimage


Reduce the file system (smaller than needed for safety):
1) # e2fsck -f /dev/VolGroup00/LogVol01
2) # resize2fs /dev/VolGroup00/LogVol01 1400000K
3) # e2fsck -f /dev/VolGroup00/LogVol01

Reduce the logical volume to 44 extents:
4) # lvm lvdisplay
5) # lvm lvreduce -l44 /dev/VolGroup00/LogVol01

Activate changes:
6) # lvm lvchange -a y /dev/VolGroup00/LogVol01

Reduce the volume group:
7) # lvm vgreduce VolGroup00 /dev/sda3
8) # lvm vgchange -a y VolGroup00

Remove the /dev/sda3 PV:
9) # lvm pvremove /dev/sda3

Delete the /dev/sda3 partition:
10) # fdisk /dev/hda
      d
      3
      w

Reboot back into rescue CD:
11) # exit

Unmount sysimage:
# umount /mnt/sysimage/sys
# umount /mnt/sysimage/dev
# umount /mnt/sysimage/proc
# umount /mnt/sysimage/boot
# umount /mnt/sysimage

Enlarge file system to full capacity of logical volume:
12) # e2fsck -f /dev/VolGroup00/LogVol01
13) # resize2fs /dev/VolGroup00/LogVol01
14) # e2fsck -f /dev/VolGroup00/LogVol01

Reboot without rescue CD

Notice when booted from the rescue CD I prefaced the lv*/pv*/vg* commands with "lvm". On a fully installed system all of these commands are really just symbolic links to the "lvm" command and when called via the other names lvm knows to act accordingly. On the rescue CD these symbolic links do not exist but you can just pass the command you want to run as the first parameter to the lvm command to get the same result. Sorry I didn't break the shrink process down into more detail like I did with the enlarging process but since I was booted from the rescue CD I didn't have the copy/paste capabilities, and I'm lazy. I might clean it up later. I highly recommend that you look at the section in the LVM HOWTO for each task that we have performed. It's a very good document.

Further Reading:
fdisk/partition HOWTO(Excellent Resource)
LVM HOWTO (Excellent Resource)
FedoraForum Thread #1
FedoraForum Thread #2
$ man  lvm

Have fun!

Forums

Valid HTML 4.01!