Resize a logical volume
From Crashcourse Wiki
If you're using LVM for your filesystem partitioning, you might need to occasionally resize a logical volume (and its corresponding filesystem, of course). As an example, consider my (ext3-format) 1G /opt filesystem, which isn't doing much useful at the moment, so we can resize it to 5G as an utterly pointless exercise.
NOTE: Apparently, you don't need to unmount the filesystem to resize it, so I'll be fixing up this page shortly.
Examining the logical volume
First, check the current filesystem properties:
# mount ... /dev/mapper/f8-opt on /opt type ext3 (rw) ... # df /opt Filesystem 1K-blocks Used Available Use% Mounted on /dev/mapper/f8-opt 1015704 60124 903152 7% /opt
So that filesystem is obviously 1G in size, and 7% full. In addition, given that my volume group name is clearly "f8", I can refer to that particular logical volume using one of two filenames:
# ls -l /dev/mapper/f8-opt brw-rw---- 1 root disk 253, 1 2007-12-24 05:23 /dev/mapper/f8-opt # ls -l /dev/f8/opt lrwxrwxrwx 1 root root 18 2007-12-24 05:23 /dev/f8/opt -> /dev/mapper/f8-opt
Check the current properties of that logical volume:
# lvdisplay /dev/f8/opt --- Logical volume --- LV Name /dev/f8/opt VG Name f8 LV UUID 7EbBEo-mwzB-y4bS-kyuC-H9f9-oEmW-1COYOx LV Write Access read/write LV Status available # open 0 LV Size 1.00 GB <---- Before the resize, of course. Current LE 32 Segments 1 Allocation inherit Read ahead sectors 0 Block device 253:1 #
Extending the /opt logical volume and filesystem
The steps:
- Unmount the filesystem.
- Extend the logical volume.
- Extend the (ext3) filesystem to match the size of the logical volume.
# umount /opt # lvextend -L +4G /dev/f8/opt [Make the logical volume 4G larger.] Extending logical volume opt to 5.00 GB Logical volume opt successfully resized # lvdisplay /dev/f8/opt --- Logical volume --- LV Name /dev/f8/opt VG Name f8 LV UUID 7EbBEo-mwzB-y4bS-kyuC-H9f9-oEmW-1COYOx LV Write Access read/write LV Status available # open 0 LV Size 5.00 GB <------ Excellent. Current LE 160 Segments 2 Allocation inherit Read ahead sectors 0 Block device 253:1 # e2fsck -f /dev/f8/opt [Check the filesystem for safety's sake.] ... # resize2fs /dev/f8/opt [By default, resize FS to new logical volume size.] resize2fs 1.40.2 (12-Jul-2007) Resizing the filesystem on /dev/f8/opt to 1310720 (4k) blocks. The filesystem on /dev/f8/opt is now 1310720 blocks long. #
And let's check the results:
# mount /opt # df /opt Filesystem 1K-blocks Used Available Use% Mounted on /dev/mapper/f8-opt 5078656 60880 4808064 2% /opt # find /opt ... should see old content here, of course ... #
Looks good, and we're done. Decreasing the size of a filesystem and logical volume, as well as working with other filesystem formats, is left as an exercise for the reader:
# man lvreduce
Feedback to rpjday@crashcourse.ca.
Return to Fedora_Cookbook.

