I have a dedicated server with 2 TB storage.
My problem is that the whole storage is allotted to the root partition.
Whenever I try to resize it using lvresize
, the root partition gets corrupted and then I have to reprovision the server.
Is there any option to resize the root partition without unmounting in lvm? I am trying to reduce the root partition to 100GB.
Vgs
root@s93079:/home/customer# vgs
VG #PV #LV #SN Attr VSize VFree
s93079-vg 1 2 0 wz--n- 1.82t 0
Lvs
LV VG Attr LSize Pool Origin Data% Meta
% Move Log Cpy%Sync Convert
root s93079-vg -wi-ao---- 1.79t
swap_1 s93079-vg -wi-ao---- 32.00g
Fdisk – l
Device Boot Start End Sectors Size Id Type
/dev/sda1 * 2048 499711 497664 243M 83 Linux
/dev/sda2 501758 3907028991 3906527234 1.8T 5 Extend
/dev/sda5 501760 3907028991 3906527232 1.8T 8e Linux
Disk /dev/mapper/s93079--vg-root: 1.8 TiB, 1965782204416 byt
es, 3839418368 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk /dev/mapper/s93079--vg-swap_1: 32 GiB, 34355544064 byte
s, 67100672 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Vgdisplay
--- Volume group ---
VG Name s93079-vg
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.82 TiB
PE Size 4.00 MiB
Total PE 476870
Alloc PE / Size 476870 / 1.82 TiB
Free PE / Size 0 / 0
VG UUID dPrEwA-77pM-pGai-9jZB-ldMZ-iL20-HAe9
Dj
lvdisplay /dev/s93079-vg/root
--- Logical volume ---
LV Path /dev/s93079-vg/root
LV Name root
VG Name s93079-vg
LV UUID bpGNau-XirV-P7PA-8d6k-OCOy-TAwN-HXl
FVI
LV Write Access read/write
LV Creation host, time s93079, 2016-08-27 09:22:05 -0500
LV Status available
# open 1
LV Size 1.79 TiB
Current LE 468679
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 254:0
Lvdisplay /dev/s93079-vg/swap_1
--- Logical volume ---
LV Path /dev/s93079-vg/swap_1
LV Name swap_1
VG Name s93079-vg
LV UUID j74PLZ-E9gK-9Bbb-EkKq-xRJv-TuU4-FgH
gm
LV Write Access read/write
LV Creation host, time s93079, 2016-08-27 09:22:05 -0500
LV Status available
# open 2
LV Size 32.00 GiB
Current LE 8191
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 254:1
Df – h
/dev/dm-0 1.8T 923M 1.7T 1% /
udev 10M 0 10M 0% /dev
tmpfs 3.2G 8.5M 3.2G 1% /run
tmpfs 7.9G 0 7.9G 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 7.9G 0 7.9G 0% /sys/fs/cgroup
/dev/sda1 236M 33M 191M 15% /boot
Best Answer
No, not safely. From what I have read, the VG must be available (
vgchange --available y
, but not mounted). I recommend that you boot from a liveCD or USB so that you have tools loaded into memory, but all of your filesystems not mounted.Check the file system, we don't want to resize something in an inconsistent state
Resize the actual filesystem, a little smaller than the final target.
Now, shrink the LVM to the desired size
Finally, grow the the root filesystem to match the target LVM volume
While I browsed several guides, the most helpful blog I found on the topic was https://blog.shadypixel.com/how-to-shrink-an-lvm-volume-safely/