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
  • You may wish to add the output of vgs, lvs` and fdisk -l to your question (edit the question, don't post it as a comment). – Stephen Harris Aug 28 '16 at 2:56
  • when you say resize do you mean you are trying to make root filesystem smaller? – gogoud Aug 28 '16 at 2:59
  • Yes i would like to reduce root partition to 100 gb – Pranav Aug 28 '16 at 3:14
  • Without unmount it's may corrupt you drive. There blog post, where author resize root by ssh with unmount, from tmpfs: ivarch.com/blogs/oss/2007/01/… It's approach can be handy, when you not have livecd. P. S. I didn't try this instruction, so if you gonna do it, don't forget about backup. – Intey Aug 24 at 5:59

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

e2fsck -f /dev/s93079-vg/root

Resize the actual filesystem, a little smaller than the final target.

resize2fs /dev/s93079-vg/root 90G

Now, shrink the LVM to the desired size

lvreduce -L 100G /dev/s93079-vg/root

Finally, grow the the root filesystem to match the target LVM volume

resize2fs /dev/s93079-vg/root

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/

  • My problem is since this is a dedicated server I am unable to boot this from a liveCD or USB – Pranav Aug 28 '16 at 4:13
  • @Pranav Ok, I'm not sure if this question is really a duplicate - but have you looked at unix.stackexchange.com/a/227318 ? – Clayton Aug 29 '16 at 3:22

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.