Tag: pvdisplay

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

lvlnboot: Boot volume should be the first logical volume on the physical volume

If you run lvlnboot and try to set the boot volume but it gives you the error saying that the boot volume should be the first logical volume

root@hpux:~ # /usr/sbin/lvlnboot -b /dev/vg00/lvol1
lvlnboot: Boot volume should be the first logical volume on the physical volume

Check with pvdisplay and check which volume shows on the Physical Extents section. It must match with the logical volume you’re declaring above.

In this case, it should show /dev/vg00/lvol1 instead of /dev/vg00/lvermhome

root@hpux:~ # pvdisplay -v /dev/disk/disk31_p2 | more
— Physical volumes —
PV Name /dev/disk/disk31_p2
VG Name /dev/vg00
PV Status available
Allocatable yes
VGDA 2
Cur LV 11
PE Size (Mbytes) 32
Total PE 3171
Free PE 1323
Allocated PE 1848
Stale PE 0
IO Timeout (Seconds) default
Autoswitch On
Proactive Polling On

— Distribution of physical volume —
LV Name LE of LV PE for LV
/dev/vg00/lvol1 56 56
/dev/vg00/lvol2 256 256
/dev/vg00/lvol3 160 160
/dev/vg00/lvol4 64 64
/dev/vg00/lvol5 160 160
/dev/vg00/lvol6 64 64
/dev/vg00/lvol7 320 320
/dev/vg00/lvol8 160 160
/dev/vg00/lvol9 256 256
/dev/vg00/lvol10 320 320
/dev/vg00/lvermhome 32 32

— Physical extents —
PE Status LV LE
00000 current /dev/vg00/lvermhome 00000
00001 current /dev/vg00/lvermhome 00001
00002 current /dev/vg00/lvermhome 00002

I mirrored a new disk to replace the old boot disk. So that’s why it showed this message in this case.

pvmove: Insufficient free space with both disks the same size

I was migrating some LUNs to another storage.

After creating the LUNs with the same size, I intended to move the data to the new disk but I was getting there was insufficient free space

root@linux:~ # pvmove /dev/mapper/bkpcvrdd01 /dev/mapper/bkpcvrdd01newp1
Insufficient free space: 12800 extents needed, but only 12799 available
Unable to allocate mirror extents for pvmove0.
Failed to convert pvmove LV to mirrored

What happens is that the source disk is bigger than the new disk.

root@linux:~ # pvdisplay /dev/mapper/bkpcvrdd01 /dev/mapper/bkpcvrdd01newp1
— Physical volume —
PV Name /dev/mapper/bkpcvrdd01
VG Name bkpcvrdvg
PV Size 50.00 GB / not usable 640.00 KB
Allocatable yes (but full)
PE Size (KByte) 4096
Total PE 12800
Free PE 0
Allocated PE 12800
PV UUID giRfdd-oDKH-12W7-ObwE-nFoN-nF0L-3OFlK5

— Physical volume —
PV Name /dev/mapper/bkpcvrdd01newp1
VG Name bkpcvrdvg
PV Size 50.00 GB / not usable 3.31 MB
Allocatable yes
PE Size (KByte) 4096
Total PE 12799
Free PE 12799
Allocated PE 0
PV UUID MXxLNF-hDbU-eaEp-0wyW-ly1l-N1FJ-Bh2fNk

Both are the same size but due to the physical structure, each disk shows a different size.

Run fdisk -l and observe the size. This is the disk after a LUN expansion.

root@linux:~ # fdisk -l /dev/mapper/bkpcvrdd01new

Disk /dev/mapper/bkpcvrdd01new: 54.2 GB, 54223962112 bytes
255 heads, 63 sectors/track, 6592 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/mapper/bkpcvrdd01newp1 1 6592 52950208+ 8e Linux LVM

Now compare both disk sizes:

53.6 GB, 53687746560 bytes
53.6 GB, 53686370304 bytes

Scanning for new disk in a VMware host running Suse Linux 10 SP4

Scanning for new disk in a VMware host running Suse 10 SP4

root@linux:~ # cat /etc/*release
SUSE Linux Enterprise Server 10 (x86_64)
VERSION = 10
PATCHLEVEL = 4
LSB_VERSION=”core-2.0-noarch:core-3.0-noarch:core-2.0-x86_64:core-3.0-x86_64″

I use the following command to scan the SCSI bus

root@linux:~ # echo “- – -” > /sys/class/scsi_host/host0/scan

List the disks. It’s the last one

root@linux:~ # fdisk -l

Then I make a partition for the disk. The first time, when there is not a valid DOS partition I like to write and call fdisk again

root@linux:~ # fdisk /dev/sdf
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel. Changes will remain in memory only,
until you decide to write them. After that, of course, the previous
content won’t be recoverable.

The number of cylinders for this disk is set to 9137.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

Running again and this time creating the partition

root@linux:~ # fdisk /dev/sdf

The number of cylinders for this disk is set to 9137.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)

Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-9137, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-9137, default 9137):
Using default value 9137

Command (m for help): t
Selected partition 1
Hex code (type L to list codes): 8e
Changed system type of partition 1 to 8e (Linux LVM)

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

Add the partition to LVM

root@linux:~ # pvcreate /dev/sdf1
Physical volume “/dev/sdf1” successfully created

Verify the file system size

root@linux:~ # df -h /usr/oradata/oradvt061t
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/softwarevg-dvt061lv
168G 133G 26G 84% /usr/oradata/oradvt061t

Add the disk to the volume group

root@linux:~ # vgextend softwarevg /dev/sdf1
Volume group “softwarevg” successfully extended

See the characteristics of the volume group

root@linux:~ # vgdisplay softwarevg
— Volume group —
VG Name softwarevg
System ID
Format lvm2
Metadata Areas 4
Metadata Sequence No 11
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 4
Open LV 4
Max PV 0
Cur PV 4
Act PV 4
VG Size 385.98 GB
PE Size 4.00 MB
Total PE 98810
Alloc PE / Size 69376 / 271.00 GB
Free PE / Size 29434 / 114.98 GB
VG UUID 0BsKwN-18al-1TT8-gctq-fRK4-ccJl-fNXL6g

And the disk added

root@dsv080:~ # pvdisplay /dev/sdf1
— Physical volume —
PV Name /dev/sdf1
VG Name softwarevg
PV Size 69.99 GB / not usable 793.00 KB
Allocatable yes
PE Size (KByte) 4096
Total PE 17918
Free PE 17918
Allocated PE 0
PV UUID 21Q3wb-2tKn-xUdP-9ZBa-tqbp-vhvS-MhSbVt

Increase the logical volume using the new disk

root@linux:~ # lvextend -l +17918 /dev/softwarevg/dvt061lv
Extending logical volume dvt061lv to 239.99 GB
Logical volume dvt061lv successfully resized

Then resize the file system

root@linux:~ # ext2online /dev/softwarevg/dvt061lv
ext2online v1.1.18 – 2001/03/18 for EXT2FS 0.5b

Verify the file system size

root@linux:~ # df -h /usr/oradata/oradvt061t
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/softwarevg-dvt061lv
237G 133G 92G 60% /usr/oradata/oradvt061t