Friday, 11 July 2008

Some sample LVM commands


#backup the config of a volume group
vgcfgbackup -f /tmp/vg02.backup vg02

# save vg configuration in human readable format
vgdisplay -v vg02 > /tmp/vg02.config

# extend VG onto new disk and in this case, it's alternate path
vgextend /dev/vg02 /dev/dsk/c18t0d0 /dev/dsk/c17t0d0

# extend a logical volume to be 301120MB long
lvextend -L 301120 /dev/vg02/lvol1

# extend the (umounted) filesystem
extendfs -F vxfs /dev/vg02/lvol1

## remove the disks. restore original size
# destroy the lv. pvmove might allow you to move from one PV to another and not have to do this
lvremove /dev/vg10/lvol1

# pull the released PVs out of the VG
vgreduce /dev/vg10 /dev/dsk/c18t10d4 /dev/dsk/c17t10d4

# recreate the LV
lvcreate -L 117760 -n lvol1 vg010

# recreate it's filesystem
newfs -F vxfs -o largefiles /dev/vg10/rlvol1

##### to import disks that have been created as BCVs (/dev/rdsk/c0t0d0 /dev/rdsk/c0t0d1 /dev/rdsk/c0t0d2)
# create the BCV (clone, split)
# change the VGIDs on the disks so that they can be imported
vgchgid /dev/rdsk/c0t0d0 /dev/rdsk/c0t0d1 /dev/rdsk/c0t0d2
# make a new volume group by hand
mkdir /dev/vgbcv
mknod /dev/vgbcv/group c 64 0x040000
# import the pvs into it.
vgimport /dev/vgbcv /dev/dsk/c0t0d0 /dev/dsk/c0t0d1 /dev/dsk/c0t0d2
# Activate the VGs
vgchange -a y /dev/vgbcv
# backup the config
vgcfgbackup /dev/vgbcv
# mount and use
mkdir /bcv/lvol1 /bcv/lvol2
mount /dev/vgbcv/lvol1 /bcv/lvol1
mount /dev/vgbcv/lvol2 /bcv/lvol2


##########
# /etc/lvmrc contains defalts for LV
# like AUTO_VG_ACTIVATE=1 etc.
# it's sourced by /sbin/lvmrc during boot.


##########
# from ITRC
#a cross-device link error is typically issued if the PVID on disk does not match the one stored in lvmtab. A corrupted or wiped-out LVM header may be also a potential reson.
#
# Run this to see the VGIDs in lvmtab:
strings -t d /etc/lvmtab |grep /dev |grep -v /dev/dsk | while read offset path; do
xd -An -j$(($offset+1024)) -N8 -tuL /etc/lvmtab | read vgid1 vgid2
echo $path $vgid1-$vgid2
done | sort -n
# Run this to see a VGID on a given disk:
xd -An -j8208 -N8 -tuL /dev/dsk/cXtYdZ
##########

## vgcfgrestore for vg02 from multiple disks, from ITRC
# vgcfgrestore -n /dev/vg02 /dev/rdsk/c3t8d0
Volume Group configuration has been restored to /dev/rdsk/c3t8d0
# vgcfgrestore -n /dev/vg02 /dev/rdsk/c3t9d0
Volume Group configuration has been restored to /dev/rdsk/c3t9d0
# vgcfgrestore -n /dev/vg02 /dev/rdsk/c3t10d0
Volume Group configuration has been restored to /dev/rdsk/c3t10d0
# vgcfgrestore -n /dev/vg02 /dev/rdsk/c3t11d0
Volume Group configuration has been restored to /dev/rdsk/c3t11d0
## then this to get the LVs back?
vgexport /dev/vg02
vgscan -av
# and (might need to name the disks in the vgimport, might not.)
vgimport /dev/vg02

No comments: