Learn how to rename logical volume in Linux or Unix. Understand what happens in background when you change logical volume name of existing LVOL.
LVM i.e. logical volume manager is one of the widely used volume manager in Linux and Unix. Logical volume is portion of volume group which can be mounted on a mount point. Once mounted, space belonging to that logical volume is available for use to end user.
In this post we are going to see step by step how to rename logical volume. In Linux, lvrename is direct command which does this stuff for you. But first, we will see how it works in background so that you know the flow and you can rename LV even without lvrename command.
LV renaming procedure follows below flow :
- Stop all user/app access to related mount point (on which lvol is mounted) using fuser
- Un-mount LV using umount
- Rename device names of lvol using mv
- Mount LV using mount
- Edit /etc/fstab entry realted to this lvol using vi
Lets see example where we are renaming /dev/vg01/lvol1 which is mounted on /data to /dev/vg01/lvol_one. See below output for above mentioned steps (HPUX console).
# bdf /data
/dev/vg01/lvol1 524288 49360 471256 9% /data
# fuser -cku /data
# umount /data
# mv /dev/vg01/lvol1 /dev/vg01/lvol_one
# mv /dev/vg01/rlvol1 /dev/vg01/rlvol_one
# mount /data
# bdf /data
/dev/vg01/lvol_one 524288 49360 471256 9% /data
In above output you can see how we renamed logical volume just by renaming its device files.
In Linux, we have single command lvrename which does all above steps in background for you. You just need to provide it with old and new lvol name along with volume group where this lvol belongs. So, above scenario will have below command –
# lvrename vg01 lvol1 lvol_one
Renamed "lvol1" to "lvol_one" in volume group "vg01"
You can see in output that single command renamed lvol1 to lvol_one! This command also supports below option :
- -t For test
- -v Verbose mode
- -f Forceful operation
- -d debug