Sunday, 16 October 2011

Deleting File system, Removing LV, Reduce/Remove VG

Some time we don’t use some of the mount point and we want to remove that file system and use that space on some other server. To reclaim the disk from the server use the Plan of action explained below:
Unmount file system (FS)
Remove Logical Volume (LV)
Reduce/Remove Volume Group (VG)
Remove Physical Volume (PV) from LVM.

Umount file system (FS)
 To make sure nobody is using file system, use the fuser command.
# fuser –cu /data
/data:   28212c(user1)
u: Display the login user name in parentheses following each process ID.
c: Display the use of a mount point and any file beneath that  mount point.  Each file must be a file system mount point.

If u receives the above result then it means user1 is using this mount point, so check with user1, when he is going to finish his job one done you can process with the procedure.
To free up busy mount point you can use fuser command with k option:
 k :- Send the SIGKILL signal to each process using each file.
#fuser -kuc /data
unmount file system
 # umount /data
Cross check with #bdf command.
Remove entry form /etc/fstab file for /data file system
Remove Logical Volume (LV)
To remove LV use lvremove command, when prompted, press y to remove the volume.
 #lvremove /dev/vg03/lvol1
The logical volume "/dev/vg03/lvol1" is not empty;
do you really want to delete the logical volume (y/n) : y
Logical volume "/dev/vg03/lvol1" has been successfully removed.
Volume Group configuration for /dev/vg03 has been saved in /etc/lvmconf/vg03.conf

If the logical volume contains data, LVM prompts you for confirmation. You can use the -f flag to remove the logical volume without a confirmation request.
#lvremove -f /dev/vg03/lvol1


Reducing/Removing volume group

To remove a PV from a volume group, first verify that none of the physical extents (PE) on the disk are currently in use. Use the pvdisplay command to determine:
#pvdisplay -v /dev/vg03/disk42
--- Physical volumes ---
PE Size (Mbytes)                        8
Total PE                                       255
Free PE                                        250

--- Physical extents ---
PE              Status            LV                             LE
00001    current      /dev/vg03/lvol2               00001
00002    current      /dev/vg03/lvol2               00002
00003    current      /dev/vg03/lvol2               00003
00240    free                                                  00000
00241    free                                                  00000
00242    free                                                  00000

From the output we get that some PE is used by some other LV. So you first need to move these PE to other disk PE in the volume group.
#pvmove /dev/disk/disk42 /dev/disk/disk41
Physical volume "/dev/disk/disk42" has been successfully moved.
Volume Group configuration for /dev/vg03 has been saved in /etc/lvmconf/vg03.conf

Here you are moving disk 42 PE to the disk 41 and you can run the pvmove command while file systems are mounted and active.
Now you can reduce volume group as no part of disk 42 is in use.
#vgreduce /dev/vg03 /dev/disk/disk42
Volume group "vg03" has been successfully reduced.
Volume Group configuration for /dev/vg03 has been saved in /etc/lvmconf/vg03.conf

Verify if there is only one disk remaining in the volume group. We cannot remove the volume group if there is more than one physical disk in the volume group.
# vgdisplay -v vg03 |grep "PV Name"
PV Name         /dev/disk/disk41

 Remove the volume group vg03.
# vgremove vg03
Volume group "vg03" has been successfully removed.

Remove the directory and group DSFs for the volume group. Press y when prompted.
# rm -ir /dev/vg03
directory /dev/vg03: ? (y/n) y
/dev/vg03/group: ? (y/n) y
/dev/vg03: ? (y/n) y

Remove Physical Volume (PV) From LVM
Remove the LVM headers from both of the disks using the pvremove command.
# pvremove /dev/rdisk/disk42
The physical volume associated with "/dev/rdisk/disk42" has been removed.

3 comments:

  1. thanks it help in prompt need

    ReplyDelete
  2. Nice article. what about removing the disk files from the server. rmsf / rmsf -H . it would be great if you add those parts also in the article.

    ReplyDelete