Advertisements

Tag Archives: lvresize

Shrinking ext4 filesystem

I’m creating a new volume group with 3 10GB disks

root@linux:~ # pvcreate /dev/sdc
Physical volume “/dev/sdc” successfully created
root@linux:~ # pvcreate /dev/sdd
Physical volume “/dev/sdd” successfully created
root@linux:~ # pvcreate /dev/sde
Physical volume “/dev/sde” successfully created

root@linux:~ # vgcreate appvg /dev/sdc /dev/sdd /dev/sde
Volume group “appvg” successfully created

root@linux:~ # vgs appvg
VG #PV #LV #SN Attr VSize VFree
appvg 3 0 0 wz–n- 29.99g 29.99g

Creating a new 25GB logical volume

root@linux:~ # lvcreate -L 25g -n applv appvg
Logical volume “applv” created.

Creating a filesystem

root@linux:~ # mkfs -t ext4 /dev/appvg/applv
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
1638400 inodes, 6553600 blocks
327680 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
200 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000

Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 37 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.

Mounting the filesystem

root@linux:~ # mkdir /app

root@linux:~ # mount /dev/appvg/applv /app

root@linux:~ # df -hP /app
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/appvg-applv 25G 44M 24G 1% /app

I will remove the disk /dev/sde from the volume group. 25GB logical volume will shrink to 20GB.

Checking which disks the logical volume is using

root@linux:~ # lvdisplay -m /dev/mapper/appvg-applv
— Logical volume —
LV Path /dev/appvg/applv
LV Name applv
VG Name appvg
LV UUID 9tofzm-1zBU-DfbM-nmws-lqj7-QULb-U4Reqh
LV Write Access read/write
LV Creation host, time centos6.setaoffice.com, 2017-06-29 16:53:18 -0300
LV Status available
# open 1
LV Size 25.00 GiB
Current LE 6400
Segments 3
Allocation inherit
Read ahead sectors auto
– currently set to 256
Block device 253:6

— Segments —
Logical extents 0 to 2558:
Type linear
Physical volume /dev/sdc
Physical extents 0 to 2558

Logical extents 2559 to 5117:
Type linear
Physical volume /dev/sdd
Physical extents 0 to 2558

Logical extents 5118 to 6399:
Type linear
Physical volume /dev/sde
Physical extents 0 to 1281

Checking Total PE to calculate logical volume

root@linux:~ # pvdisplay /dev/sdc
— Physical volume —
PV Name /dev/sdc
VG Name appvg
PV Size 10.00 GiB / not usable 4.00 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 2559
Free PE 0
Allocated PE 2559
PV UUID ZnR27c-LPaE-0ZQa-t0Hc-yWLf-v06d-et7fb5

root@linux:~ # pvdisplay /dev/sdd
— Physical volume —
PV Name /dev/sdd
VG Name appvg
PV Size 10.00 GiB / not usable 4.00 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 2559
Free PE 0
Allocated PE 2559
PV UUID OZY6w8-fUq6-wbPE-ILcr-LwOP-AeaS-j2qd9E

Resizing logical volume

root@linux:~ # lvresize -l 5118 -r /dev/appvg/applv
fsck from util-linux-ng 2.17.2
/dev/mapper/appvg-applv: 11/1638400 files (0.0% non-contiguous), 146849/6553600 blocks
resize2fs 1.41.12 (17-May-2010)
Resizing the filesystem on /dev/mapper/appvg-applv to 5240832 (4k) blocks.
The filesystem on /dev/mapper/appvg-applv is now 5240832 blocks long.

Size of logical volume appvg/applv changed from 25.00 GiB (6400 extents) to 19.99 GiB (5118 extents).
Logical volume applv successfully resized.

Checking which disks the logical volume is using

root@linux:~ # lvdisplay -m /dev/mapper/appvg-applv
— Logical volume —
LV Path /dev/appvg/applv
LV Name applv
VG Name appvg
LV UUID 9tofzm-1zBU-DfbM-nmws-lqj7-QULb-U4Reqh
LV Write Access read/write
LV Creation host, time centos6.setaoffice.com, 2017-06-29 16:53:18 -0300
LV Status available
# open 0
LV Size 19.99 GiB
Current LE 5118
Segments 2
Allocation inherit
Read ahead sectors auto
– currently set to 256
Block device 253:6

— Segments —
Logical extents 0 to 2558:
Type linear
Physical volume /dev/sdc
Physical extents 0 to 2558

Logical extents 2559 to 5117:
Type linear
Physical volume /dev/sdd
Physical extents 0 to 2558

Removing disk from volume group and label from physical volume

root@linux:~ # vgreduce appvg /dev/sde
Removed “/dev/sde” from volume group “appvg”

root@linux:~ # pvremove /dev/sde
Labels on physical volume “/dev/sde” successfully wiped

Advertisements

LVM: Please specify number of stripes (-i) and stripesize (-I)

I tried to resize a logical volume but showed a message to specify stripes and stripesize

root@linux:~ # lvresize -L +200g -r /dev/vgER0data/lv_sapdata1
Please specify number of stripes (-i) and stripesize (-I)
Run `lvresize –help’ for more information.

Showing stripes and stripesize

root@linux:~ # lvdisplay /dev/vgER0data/lv_sapdata1 -m
— Logical volume —
LV Path /dev/vgER0data/lv_sapdata1
LV Name lv_sapdata1
VG Name vgER0data
LV UUID h2WKAp-h16f-O3Bo-QpEz-fTiW-s3Hr-K7W9sb
LV Write Access read/write
LV Creation host, time cavadb77, 2015-09-24 11:31:33 -0300
LV Status available
# open 1
LV Size 2.99 TiB
Current LE 783355
Segments 2
Allocation inherit
Read ahead sectors auto
– currently set to 32768
Block device 253:423

— Segments —
Logical extents 0 to 655359:
Type striped
Stripes 2
Stripe size 4.00 MiB
Stripe 0:
Physical volume /dev/mapper/ER0_data_disk_001p1
Physical extents 0 to 327679
Stripe 1:
Physical volume /dev/mapper/ER0_data_disk_002p1
Physical extents 0 to 327679

Logical extents 655360 to 783354:
Type linear
Physical volume /dev/mapper/ER0_data_disk_003
Physical extents 0 to 127994

To solve the problem in this case it was necessary to add a new LUN and resize the logical volume. The segment where it is linear, was kept this way. There is no way to convert

root@linux:~ # lvresize -L +100g -r -i2 -I4M /dev/mapper/vgER0data-lv_sapdata1
Size of logical volume vgER0data/lv_sapdata1 changed from 2.99 TiB (783355 extents) to 3.09 TiB (808955 extents).
Logical volume lv_sapdata1 successfully resized
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/mapper/vgER0data-lv_sapdata1 is mounted on /oracle/ER0/sapdata1; on-line resizing required
old desc_blocks = 192, new_desc_blocks = 198
Performing an on-line resize of /dev/mapper/vgER0data-lv_sapdata1 to 828369920 (4k) blocks.
The filesystem on /dev/mapper/vgER0data-lv_sapdata1 is now 828369920 blocks long.

 

Resizing an ext3 filesystem mounted on a logical volume in a Linux

My home directory got full

root@linux:~ # df -h /home
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/rootvg-homevol
101M 96M 94K 100% /home

Checking if the logical volume permits online resizing and if it was created with an older e2fsprogs version. Volumes created prior to SUSE Linux 10 SP2 are using an older e2fsprogs version and needs to be recreated

root@linux:~ # dumpe2fs -h /dev/mapper/rootvg-homevol | grep features
dumpe2fs 1.35 (28-Feb-2004)
Filesystem features: has_journal ext_attr resize_inode dir_index filetype needs_recovery sparse_super large_file

We checked that the volume has the resize_inode property so to extend the filesystem, first we extend the logical volume

root@linux:~ # lvextend -L 200M /dev/rootvg/homevol
Extending logical volume homevol to 200.00 MB
Logical volume homevol successfully resized

You can see that the filesystem is not yet showing the new size

root@linux:~ # df -h /home
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/rootvg-homevol
101M 96M 95K 100% /home

Now we increase the filesystem with resize2fs

root@linux:~ # resize2fs /dev/rootvg/homevol
resize2fs 1.41.9 (22-Aug-2009)
Filesystem at /dev/rootvg/homevol is mounted on /home; on-line resizing required
old desc_blocks = 1, new_desc_blocks = 1
Performing an on-line resize of /dev/rootvg/homevol to 204800 (1k) blocks.
The filesystem on /dev/rootvg/homevol is now 204800 blocks long.

Checking the new size

root@linux:~ # df -h /home
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/rootvg-homevol
194M 94M 90M 52% /home

If you receive a message saying that you can’t resize a mounted filesystem, use ext2online

root@suselinux10:~ # resize2fs /dev/localVG/sys.opt
resize2fs 1.38 (30-Jun-2005)
/dev/localVG/sys.opt is mounted; can’t resize a mounted filesystem!

root@suselinux10:~ # ext2online /dev/localVG/sys.opt
ext2online v1.1.18 – 2001/03/18 for EXT2FS 0.5b

You can also pass the flag -r to resize the filesystem without using resize2fs and use lvresize instead of lvextend

root@linux:~ # lvresize -L +2g -r /dev/vgHQ0ascs/lv_sapmnt_exe
Size of logical volume vgHQ0ascs/lv_sapmnt_exe changed from 5.00 GiB (1280 extents) to 7.00 GiB (1792 extents).
Logical volume lv_sapmnt_exe successfully resized
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/mapper/vgHQ0ascs-lv_sapmnt_exe is mounted on /export/sapmnt/HQ0/exe; on-line resizing required
old desc_blocks = 20, new_desc_blocks = 28
Performing an on-line resize of /dev/mapper/vgHQ0ascs-lv_sapmnt_exe to 7340032 (1k) blocks.
The filesystem on /dev/mapper/vgHQ0ascs-lv_sapmnt_exe is now 7340032 blocks long.

%d bloggers like this: