119 lines
3.2 KiB
Markdown
119 lines
3.2 KiB
Markdown
# Reducing the root LV
|
|
|
|
## Contents
|
|
|
|
- [Overview](#overview)
|
|
- [Procedure](#procedure)
|
|
- [Without lvresize -r flag](#without-lvresize--r-flag)
|
|
- [With lvresize -r flag](#with-lvresize--r-flag)
|
|
|
|
|
|
## Overview
|
|
|
|
Reducing the root logical volume requires booting into a rescue environment that has the LVM utilities.
|
|
|
|
> Some rescue images have a version of the LVM utilities that were released missing a critical shim needed to resize filesystems using the `-r` flag to `lvresize`. It may or may not be necessary to resize the filesystem as a separate step, both are outlined.
|
|
|
|
|
|
## Procedure
|
|
|
|
Given this current configuration of a 250G boot volume:
|
|
|
|
| **Mount** | **Size** | **VG / LV** |
|
|
| --------- | --------- | ---------------- |
|
|
| /boot | 250M | n/a |
|
|
| /tmp | 2G | vglocal / lvtmp |
|
|
| swap | 2G | vglocal / lvswap |
|
|
| / | remainder | vglocal / lvroot |
|
|
|
|
|
|
We'll reduce the root (/) volume and grow swap and /tmp to end up with:
|
|
|
|
| **Mount** | **Size** | **VG / LV** |
|
|
| --------- | --------- | ---------------- |
|
|
| /boot | 250M | n/a |
|
|
| /tmp | 4G | vglocal / lvtmp |
|
|
| swap | 32G | vglocal / lvswap |
|
|
| / | remainder | vglocal / lvroot |
|
|
|
|
|
|
### Without lvresize -r flag
|
|
|
|
```
|
|
##
|
|
## DO NOT MOUNT ANY FILESYSTEMS DURING RESCUE BOOT
|
|
##
|
|
|
|
# activate all LVM
|
|
lvm vgchange -a y
|
|
|
|
# fsck the filesystems; it's normal to get a message about a time error that needs fixed
|
|
fsck -fC /dev/vglocal/lvroot
|
|
fsck -fC /dev/vglocal/lvtmp
|
|
|
|
# shrink the ext3/4 root far below what we need
|
|
resize2fs -p /dev/vglocal/lvroot 200G
|
|
|
|
# reduce the root LV a bit above what we just resized (+5GB)
|
|
lvm lvresize /dev/vglocal/lvroot --size 205G
|
|
|
|
# increase swap and tmp LVs
|
|
lvm lvresize /dev/vglocal/lvswap --size 32G
|
|
lvm lvresize /dev/vglocal/lvtmp --size 4G
|
|
|
|
# re-grow the root LV back to max space
|
|
lvm lvresize -l +100%FREE /dev/vglocal/lvroot
|
|
|
|
# re-grow the / and /tmp ext3/4 to fill the increased LVs
|
|
resize2fs -p /dev/vglocal/lvroot
|
|
resize2fs -p /dev/vglocal/lvtmp
|
|
|
|
# fsck the filesystems again
|
|
fsck -fC /dev/vglocal/lvroot
|
|
fsck -fC /dev/vglocal/lvtmp
|
|
|
|
# rescue image 'mkswap' is sometimes not able to see a large swap
|
|
reboot
|
|
|
|
# finally, make a new swap signature that sees the whole LV
|
|
swapoff /dev/vglocal/lvswap
|
|
mkswap /dev/vglocal/lvswap
|
|
swapon /dev/vglocal/lvswap
|
|
```
|
|
|
|
### With lvresize -r flag
|
|
|
|
```
|
|
##
|
|
## DO NOT MOUNT ANY FILESYSTEMS DURING RESCUE BOOT
|
|
##
|
|
|
|
# activate all LVM
|
|
lvm vgchange -a y
|
|
|
|
# fsck the filesystems; it's normal to get a message about a time error that needs fixed
|
|
fsck -fC /dev/vglocal/lvroot
|
|
fsck -fC /dev/vglocal/lvtmp
|
|
|
|
# reduce the size of LV root a tad more than we need
|
|
lvm lvresize -r /dev/vglocal/lvroot --size 200G
|
|
|
|
# increase swap and tmp LVs
|
|
lvm lvresize /dev/vglocal/lvswap --size 32G
|
|
lvm lvresize /dev/vglocal/lvtmp --size 4G
|
|
|
|
# re-grow the root LV back to max space
|
|
lvm lvresize -r -l +100%FREE /dev/vglocal/lvroot
|
|
|
|
# fsck the filesystems again
|
|
fsck -fC /dev/vglocal/lvroot
|
|
fsck -fC /dev/vglocal/lvtmp
|
|
|
|
# rescue image 'mkswap' is sometimes not able to see a large swap
|
|
reboot
|
|
|
|
# finally, make a new swap signature that sees the whole LV
|
|
swapoff /dev/vglocal/lvswap
|
|
mkswap /dev/vglocal/lvswap
|
|
swapon /dev/vglocal/lvswap
|
|
```
|