Monday, December 7, 2015

HP-UX LVM CheatSheet

HP-UX LVM Cheat Sheet


Add the disk to be used in the LVM #pvcreate /dev/rdsk/cXtYdD
Add the disk to be used as a boot disk #pvcreate -B /dev/rdsk/cXtYdD
Force addition of a Disk to be used in LVM on the current System even if it is having LVM headers #pvcreate -f /dev/rdsk/cXtYdZ


Creation of a Volume Group
Create the VG Directory#mkdir /dev/MYVG

#cd /dev/MYVG


With a unique minor number create the VG Group Device Special file#mknod -c 64 0x0000YY group
Create the VG with one or more disks#vgcreate /dev/MYVG /dev/dsk/cXtYdZ


Add more disks to the VG#vgextend /dev/MYVG /dev/dsk/cXtyDZ


Create a Logical Volume #lvcreate -n <LV_Name> -L <Size_in_MB> /dev/MYVG
Create an LV of Zero Size (do not Specify the -L parameter)#lvcreate -n <LV_Name> /dev/MYVG
Create An LV specifying Number of Les#lvcreate -l <LV_size_in_LEs> - n <LV_Name> /dev/MYVG
Create an LV with the default names (such as lvol1, lvol2 etc) : Do not specify the -n parameter#lvcreate -L <Size_in_MB> /dev/MYVG
Create an LV with 1 mirror#lvcreate -L <Size_in_MB> -m 1 /dev/MYVG
Create an LV with BB Relocation off#lvcreate -L <Size_in_MB> -r n /dev/MYVG
Create an LV with the Strict Mirror Policy #lvcreate -n <LV_Name> -s y /dev/NYVG
Extend an LV to have to have PE on specific PV: You can create a Zero Size LV First#lvcreate -n <LV_name> /dev/MYVG

#lvextend -L 100 /dev/dsk/c0t0d0
Create an LV to be used as alternate SWAP or DUMP (These need that the LV has Bad Block Relocation Turned off, is Contiguous, good also to have strict mirror policy)#lvcreate -L 100 -cy -sy -rn -n <LV_Name> <VG_Name>
Default VG configuration Directory/etc/lvmconf
Default VG configuration backup file/etc/lvmconf/<VG_Name>.conf
LVM TAB file (Note /etc/lvmtab_p for VG versions 2 and above 11iv3 only)/etc/lvmtab
Reduce the Size of the LV (Reduces size to that Specified with -L, this is dangerous, before lvreduce to have lesser risks run fsadm -d -D -e -E; followed by reducing the FS size using fsadm -b <NEW_reduced_size_in_KB> /<MOUNT_POINT>#lvextend -L 100 /dev/dsk/c0t0d2
Mirror an Existing LV#lvextend -m 1 /dev/MYVG/lvol1
Mirror an LV but do not allow synchronization of the PE for the LV#lvextend or lvcreate using -s option
Mirror an Existing LV to a particular disk which is in the same VG#lvextend -m 1 /dev/MYVG/lvol1 /dev/dsk/cXtYDX
Create an Stripped LV with specific Stripe Size#lvcreate -L <Size_of_LV> -I <stripe_size> -i <number_of_stripes> -n <LV_Name> /dev/MYVG
Mirror a stripped LV (You will need 16TB+stripped mirror LV Patch on 11.23)#lvextend -m 1 /dev/MYVG/lvol1
Create a Stripped Mirrored LV (You will need 16 TB+stripped Mirror LV Patch on 11.23)#lvcreate -m 1 -L <Size_of_LV> -I <stripe_size> -i <number_of_stripes> -n <LV_Name> /dev/MYVG
Create a Distributed Extent Based Mirrored LV (You will need to have /etc/lvmpvg and the PVG groups defined first)#lvcreate -L <Size_of_LV> -n <LV_Name> -D y -s g /dev/MYVG
Change the LV Mirror Policy from Strict to Non-strict and vice versa y = Make Strict, n : for non-strict mirror policy#lvchnage -s y|n /dev/MYVG/lvol1
Split a Mirroed LV ( If no Suffix is given this creates the Split of the LV as lvol1b if the actual LV name is lvol1)#lvsplit -s <Suffix> /dev/MYVG/lVOL1


Merge the Split LV (Careful, the syntax specifies the Current LV lvol1 which has the most current information is the source is specified as the second argument and the destination lvol1b which may have older information)#lvmerge /dev/MYVG/lvol1b /dev/MYVG/lvol1
LV Split and Merge for a mirrored LV to take LV backupsSuppose /myfs is mounting the mirrored LV /dev/MYVG/lvol1

Split the LV: # lvsplit /dev/MYVG/lvol1

This creates the Split /dev/MYVG/lvol1b

FSCK on /dev/MYVG/lvol1b : # fsck -F <FS_Type> /dev/MYVG/lvol1b

Mount the FSCK-ed LV: #mount /dev/MYVG/lvol1b /new_myfs

Take backup of /new_myfs using tar/fbackup/cpio/dd/cp or any other Enterprise backup tools.

After Backup unmount and lvmerge:

#umount /new_myfs
#lvmerge /dev/MYVG/lvol1b /dev/MYVG/lvol1
UN mirror the LV#lvreduce -m 0 /dev/MYVG/lvol1
Unmirror the LV from a specific PV#lvreduce -m 0 /dev/MYVG/lvol1 /dev/dsk/cXtYdZ
Displaying the detailed information and LE/PE/PV mapping for the extents of an LV#lvdisplay -v /dev/MYVG/lvol1
Seeing if an LV has mirrors are Synced or are stale#lvdisplay -v /dev/MYVG/lvol1 | grep -i stale
Sync all the stale extents of an LV (This is very much needed when the failed disk has been replaced using vgcfgrestore and the LV have mirrors on it)#lvsync /dev/MYVG/lvol1
Rename an LVUnmount the LV if mounted as a File System
Rename the Device Special file for the LV
#mv /dev/MYVG/lvol1 /dev/MYVG/NEWLV
mount The LV with the new Name.

You may need to make changes to the /etc/fstab or the package configuration file with the new LV name so as to automatically mount the LV as per context.
Rename a VGUnmount all the File systems /LV of the VG

Deactivate the VG : #vgchange -a n /dev/MYVG

Preview Export the VG to create the VG Map file with the VGID: #vgexport -p -v -s -m /tmp/MYVG.mapfile /dev/MYVG

Export the VG : #vgexport /dev/MYVG

Create the NEW VG directory: #mkdir /dev/MYNEWVG

Create the NEW VG Group file: #mknod /dev/MYNEWVG/group c 64 0x0000ZZ

Preview Import the VG with the new name and the MAP File: #vgimport -p -v -s -m /tmp/MYVG.mapfile /dev/MYNEWVG


Actual Import the VG with the new name and the MAP File: #vgimport -v -s -m /tmp/MYVG.mapfile /dev/MYNEWVG

Activate the New VG after import: #vgchange -a y /dev/MYNEWVG (good to take an LVM configuration Backup for the VG after import: #vgcfgbackup /dev/MYNEWVG)

You may need to edit the /etc/fstab file or the Package files where the LV names are specified to reflect the correct LV Names

Mount as needed Manually or by the Service Guard Packages




Create a VG with MAX PV, MAX PE PER PV and EXTENT SIZE parameters#vgcreate -e 65535 -p 64 -s 64 /dev/MYVG /dev/dsk/cXtYdZ#
Activate a VG#vgchange -a y /dev/MYVG
Deactivate a VG (Ensure that the FS /LV are unmounted)#vgchange -a n /dev/MYVG
Synchronize all the stale PE in a VG#vgsync <VG_Name>
Mark a VG cluster aware#vgchange -c y /dev/MYVG
Activate a VG but do not auto synchronize the stales #vgchange -a s
Remove a PV from a VG (Ensure that the PV has no occupied PE/LE on it, you can use commands such as pvmove to evacuate all PE on a PV; or lvremvoe to remove an LV)#vgreduce /dev/MYVG /dev/dsk/cXtYdZ
Delete a VG (This requires that the VG does not have more than 1 PV in it)#vgremove /dev/MYVG
Export a VG (to remove the VG information from the system) : this removes the VG information from /etc/lvmtab /etc/lvmtab_p and the corresponding VG directory e.g., /dev/MYVG#vgexport /dev/MYVG
Create a Cluster aware VG (This requires CLVM)#vgcreate -c y /dev/MYVG /dev/dsk/cXtYdZ
Creating MAP File for a VG (For Importing the VG on the same or the other server): This will create the MAP file of the VG which will contain the VGID (because of -s option) with the LV namesPreview Export the VG to create the VG Map file with the VGID: vgexport -p -v -s -m /tmp/MYVG.mapfile /dev/MYVG




Taking VG Configuration Backup (Please note that for each LVM configuration Changes HP-UX LVM automatically takes a backup of the LVM configuration by automatically calling vgcfgbackup #vgcfgbackup /dev/MYVG
Seeing the Current PV Members in the VG Configuration backup#vgcfgrestore -l -n <VG_Name>
Replacing a Failed Disks: restoring the VG configuration backup on to the new disk (here cXtYdZ) is the path where the disk has been replaced#vgcfgrestore -n <VG_Name> /dev/rdsk/cXtYdZ


Prevent Running of the LVMM Autoconfiguration backup while making the LVM Changesuse -A n with the VG commands


Seeing the Free PE and PE Size in a VG#vgdisplay -v <VG_Name>


Move all the PE of a PV to another PV#pvmove <PV1> <PV2>
Move all the PE of an ZLV to another PV#pvmove -n <LV_Name> <Source_PV> <to_other+_PV1> <to_+other_PV2>
Move the First PE to make room for bigger VGRA#pvmove /dev/dsk/cXtYdZ:0
Move a Range 0f PE (11iv3 only)#pvmove /dev/dsk/cXtYdZ:0-115 <Optional_Target_PV>
Recreate the /etc/lvmtab file#vgscan -av




Deactivate a PV#pvchange -a n /dev/dsk/cXYdZ
Deactivate all paths for a PV#pvchange -a N /dev/dsk/cXtYdZ


See all the configurable limits for LVM in 11iv3#lvmadm -T


Change the VG parameters (please note that the the PE Size parameter cannot be changed for a VG without destorying it)#vgmodify -t -r -e <new_value> -p <new_value> /dev/MYVG : -t is to run vgmodify in test mode and -r for PE renumbering if needed

Actual Run which requires the VG to be deactivated : vgmodify -r -e <new_value> -p <new_value> /dev/MYVG
Create /etc/lvmtab with only PDSF of PV (11iv3 only)#vgscan -N or vgimport -N
Scan only the kernel structures of a LVM also only specific VG (11iv3 only) and update the information only for that VG in the LVMTAB file#vgscan -k -f /dev/vg00


Online Dynamic LUN expansion (11iv3 only) Use -r option for PE Renumbering also : see more in man page of#vgmodify -a -E <VG_name>


Change the version of VG (11iv3 only) See more for MAN page of the vgversion command#vgversion
Seeing the PV Key of for the PV (Useful in case of PV which are not responding)#lvdisplay -v -k /dev/MYVG/lvol1
Removing the PE from a unresponsive PV whose PV Key is 2 (for example)#lvreduce -m 0 /dev/MYVG/lvol1 -k 2
Activate a VG in read-only mode (helpful in the Service Guard Environment for Troubleshooting) : This activates the VG and the LV Inside that to be activated in Read-only mode for read-only operations)#vgchange -a r /dev/MYVG

No comments:

Post a Comment