Advertisements

Tag Archives: lvcreate

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

HP-UX: LVM – Failure possibly caused by PVG-Strict or Distributed allocation policies

Tried to create a logical volume and HP-uX gave an error message

root@hpux:~ # lvcreate -s g -D y -r N -L 400000 -n lvsapdata8 /dev/vgLP0data
Warning: The “-r” option has been ignored as it is not supported
for volume group version 2.0 or higher
Logical volume “/dev/vgLP0data/lvsapdata8” has been successfully created with
character device “/dev/vgLP0data/rlvsapdata8”.
lvcreate: Not enough free physical extents available.
Logical volume “/dev/vgLP0data/lvsapdata8” could not be extended.
Failure possibly caused by PVG-Strict or Distributed allocation policies.

The problem was the combination of strict allocation policy and distributed allocation. Since I had 7 disks in the volume group and a new disk was added, this logical volume creation was not meeting the options set

-s strict Set the strict allocation policy. Mirror copies
of a logical extent can be allocated to share or
not share the same physical volume or physical
volume group. strict can have one of the
following values:

y Set a strict allocation policy. Mirrors of
a logical extent cannot share the same
physical volume. This is the default.

g Set a PVG-strict allocation policy.
Mirrors of a logical extent cannot share
the same physical volume group. A PVG-
strict allocation policy cannot be set on a
logical volume in a volume group that does
not have a physical volume group defined.

n Do not set a strict or PVG-strict
allocation policy. Mirrors of a logical
extent can share the same physical volume.

-D distributed Set the distributed allocation policy.
distributed can have one of the following
values:

y Turn on distributed allocation.

n Turn off distributed allocation. This is
the default.

When the distributed allocation policy is turned
on, only one free extent is allocated from the
first available physical volume. The next free
extent is allocated from the next available
physical volume. Allocation of free extents
proceeds in round-robin order on the list of
available physical volumes.

When the distributed allocation policy is turned
off, all available free extents are allocated
from each available physical volume before
proceeding to the next available physical
volume. This is the default.

The distributed allocation policy REQUIRES the
PVG-strict allocation policy (-s g) to ensure
that mirrors of distributed extents do not
overlap (for maximum availability).

lvcreate(1M) will obtain the list of available
physical volumes from /etc/lvmpvg. See
vgextend(1M) for more information on physical
volume groups and /etc/lvmpvg.

When a logical volume with distributed extents
is mirrored, the resulting layout is commonly
referred to as EXTENT-BASED MIRRORED STRIPES.

Note that EXTENT-BASED MIRRORED STRIPES can be
created without the distributed allocation
policy by adding one extent at a time to the
desired physical volumes through lvextend(1M).

The distributed allocation policy is
incompatible with the striped scheduling policy
(-i stripes) and the contiguous allocation
policy (-C y).

The lvchange(1M) command can be used to assign
the distributed allocation policy to an existing
logical volume.

See lvdisplay(1M) for display values.

See EXAMPLES.

lvcreate – Aborting. Failed to wipe start of new LV

root@linux:~ # lvcreate -L 400g -n lv_test vg_test
Volume “vg_test/lv_test” is not active locally.
Aborting. Failed to wipe start of new LV.

Add vg_test to volume_list parameter in /etc/lvm/lvm.conf

vi /etc/lvm/lvm.conf
volume_list = [ “vgo2o”, “vgroot”, “vg_test” ]

Then try again

root@linux:~ # lvcreate -L 400g -n lv_test vg_test
Logical volume “lv_test” created.

%d bloggers like this: