Logical Volume Manager Configuration
Step by Step guide to Create and manage Logical Volume Manager in Redhat Linux.
1. Creating an LVM Logical Volume on Three Disks (or more if you have available).
2. Creating a Striped Logical Volume
3. Splitting a Volume Group
4. Removing a Disk from a Logical Volume
1. Creating an LVM Logical Volume on Three Disks.
Plan:
logical volume name: new_logical_volume
Disks: /dev/sda1, /dev/sdb1, and /dev/sdc1
partition type: Linux LVM which is 8e.
Warning: Verify that disks does not contain any important data.
a. Creating the Physical Volumes
# pvcreate /dev/sda1 /dev/sdb1 /dev/sdc1
# pvdisplay # command to display physical volume detail.
Note: Each physical volume has a UUID.
b. Creating the Volume Group
# vgcreate new_vol_group /dev/sda1 /dev/sdb1 /dev/sdc1
# vgs or # Displays new volume group attributes
# vgdisplay volume_name
Note: volume group name is new_vol_group
c. Creating the Logical Volume
# lvcreate -L 2G -n new_logical_volume new_vol_group # Creates 2 GB Logical volume
# lvcreate -L 3GB -n mylvvol new_vol_group # Creates 3 GB Logical volume
# lvdisplay # Displays Logical Volume attributes.
Here, L flag is sued to size while n flag is for new logical volume name.
Note: creates 2gb of logical volume new_logical_volume from the volume group new_vol_group.
You can create multiple logical volumes on a single volume group.
d. Creating the File System using mkfs command.
# mkfs.gfs2 -p lock_nolock -j 1 /dev/new_vol_group/new_logical_volume or
# mkfs.ext4 /dev/new_vol_group/new_logical_volume
Note: You can use mke2fs, mkfs.ext3, mkfs.ext4 commands with different options.
e. mount the logical volume
# mount /dev/new_vol_group/new_logical_volume /mnt
f. Add entry to /etc/fstab to be mounted across the reboot.
g. Resize the logical volume to expand or shrink the filesystem.
# lvresize -L 5GB /dev/new_vol_group/new_logical_volume
# resize2fs /dev/new_vol_group/new_logical_volume 5G
# lvresize -L 3GB /dev/new_vol_group/new_logical_volume
# resize2fs /dev/new_vol_group/new_logical_volume 3G
Note: To shrink you have to unmount the filesystem. To resize with new storage space added, use resize2fs command. The filessytem must be ext3 and up to resize the volume.
# resize2fs /dev/new_vol_group/new_logical_volume 5G
h. Remove the logical volume
# lvremove /dev/new_vol_group/new_logical_volume
i. Rename Logical Volume
# lvrename new_vol_group new_logical_volume my_logical_volume
# lvresize -L 10GB /dev/new_vol_group/my_logical_volume
Note: Only renames logical Volume not the volume group.
j. Rename Volume Group.
# vgrename new_vol_group my_vol_group
Note: Once you rename Logical volume or the volume group, make sure to change your mount point and the /etc/fstab entry.
=================================================================
2. Creating a Striped Logical Volume
Plan:
LVM striped logical volume: striped_logical_volume
Disk for stripping: /dev/sda1, /dev/sdb1, and /dev/sdc1
Warning: Any data on the disk will be lost.
a. Creating the Physical Volumes
# pvcreate /dev/sda1 /dev/sdb1 /dev/sdc1
b. Creating the Volume Group
# vgcreate volgroup01 /dev/sda1 /dev/sdb1 /dev/sdc1
Verify the volume group attributes,
# vgs
c. Creating the Logical Volume
# lvcreate -i3 -I4 -L2G -n striped_logical_volume volgroup01
The command creates striped logical volume striped_logical_volume with 2 gigabytes in size, with three stripes and a stripe size of 4 kilobytes from the volume group volgroup01.
d. Creating the File System
# mkfs.gfs2 -plock_nolock -j 1 /dev/volgroup01/striped_logical_volume
e. Mount the filesystem.
# mount /dev/volgroup01/striped_logical_volume /mnt
# df -h /mnt
3. Splitting a Volume Group
Plan:
modify ?? below...
If there is enough unused space on the physical volumes, a new volume group can be created without adding new disks.
In the initial set up, the logical volume mylv is carved from the volume group myvol, which in turn consists of the three physical volumes, /dev/sda1, /dev/sdb1, and /dev/sdc1.
After completing this procedure, the volume group myvg will consist of /dev/sda1 and /dev/sdb1. A second volume group, yourvg, will consist of /dev/sdc1.
a. Determining Free Space
determine how much free space is currently available in the volume group using pvscan
# pvscan - change the output. ..
PV /dev/sda1 VG myvg lvm2 [17.15 GB / 0 free]
PV /dev/sdb1 VG myvg lvm2 [17.15 GB / 12.15 GB free]
PV /dev/sdc1 VG myvg lvm2 [17.15 GB / 15.80 GB free]
Total: 3 [51.45 GB] / in use: 3 [51.45 GB] / in no VG: 0 [0 ]
b. Moving the Data
You can move all the used physical extents in /dev/sdc1 to /dev/sdb1 with the pvmove command. The pvmove command can take a long time to execute.
# pvmove /dev/sdc1 /dev/sdb1
Verify that the space on /dev/sdc1 is free using the pvscan command.
# pvscan
PV /dev/sda1 VG myvg lvm2 [17.15 GB / 0 free]
PV /dev/sdb1 VG myvg lvm2 [17.15 GB / 10.80 GB free]
PV /dev/sdc1 VG myvg lvm2 [17.15 GB / 17.15 GB free]
Total: 3 [51.45 GB] / in use: 3 [51.45 GB] / in no VG: 0 [0 ]
c. Splitting the Volume Group
Using vfsplit command you can create new volume group yourvg, to split the volume group myvg.
Make sure your logical volume is inactive. If there are any mounts, unmount before deactiviting the logical volume.
Use lvchange or vgchange command to deactivate the logical volume.
# lvchange -a n /dev/myvg/mylv
# vgsplit myvg yourvg /dev/sdc1
The above command deactivates the logical volume mylv and splits the volume group yourvg from volume group myvg, moving physical volume /etc/sdc1 into new volume group yourvg.
Verify the volume group attributes.
# vgs
d. Creating the New Logical Volume
Now, create new logical volume yourlv after creating the new volume group.
# lvcreate -L5G -n yourlv yourvg
e. Create a File System and mount the New Logical Volume
# mkfs.gfs2 -plock_nolock -j 1 /dev/yourvg/yourlv
f. Activating and Mounting the Original Logical Volume
# lvchange -a y mylv
# mount /dev/myvg/mylv /mnt
# df
4. Removing a Disk from a Logical Volume
You can remove a disk from existing logical volume to use the disk for other volume or to replace the failed disk. To process, you must have to move the extents on the LVM physical volume to a different disk or the set of disks.
A. Moving Extents to Existing Physical Volumes
Plan:
We have a logical volume that is distributed across four physical volumes in the volume group myvg.
a.
# pvs -o+pv_used
PV VG Fmt Attr PSize PFree Used
/dev/sda1 myvg lvm2 a- 17.15G 12.15G 5.00G
/dev/sdb1 myvg lvm2 a- 17.15G 12.15G 5.00G
/dev/sdc1 myvg lvm2 a- 17.15G 12.15G 5.00G
/dev/sdd1 myvg lvm2 a- 17.15G 2.15G 15.00G
We want to move the extents off of /dev/sdb1 so that we can remove it from the volume group.
You need to have free extents on other physical volumes in volume group. The extents will be distributed to the other devices.
# pvmove /dev/sdb1
/dev/sdb1: Moved: 2.0%
...
/dev/sdb1: Moved: 79.2%
...
/dev/sdb1: Moved: 100.0%
Check the distribution of extents using pvs command.
# pvs -o+pv_used
b. Remove the physical volume /dev/sdb1 from the volume group using vgreduce command.
# vgreduce myvg /dev/sdb1
# pvs
Now, disk can be physically remove or use for other purpose.
B. Moving Extents to a New Disk
Plan:
The logical volume is distributed across three physical volumes in the volume group myvg as follows:
# pvs -o+pv_used
PV VG Fmt Attr PSize PFree Used
/dev/sda1 myvg lvm2 a- 17.15G 7.15G 10.00G
/dev/sdb1 myvg lvm2 a- 17.15G 15.15G 2.00G
/dev/sdc1 myvg lvm2 a- 17.15G 15.15G 2.00G
We want to move the extents of /dev/sdb1 to a new device, /dev/sdd1.
a. Creating the New Physical Volume
scenario: Create a new physical volume from /dev/sdd1.
# pvcreate /dev/sdd1
b. Adding the New Physical Volume to the Volume Group
# vgextend myvg /dev/sdd1
# pvs -o+pv_used
c. Moving the Data
Use the pvmove command to move the data from /dev/sdb1 to /dev/sdd1.
# pvmove /dev/sdb1 /dev/sdd1
# pvs -o+pv_used
d. Removing the Old Physical Volume from the Volume Group
After you have moved the data off /dev/sdb1, you can remove it from the volume group.
# vgreduce myvg /dev/sdb1
Based on the online doc @redhat....
http://docs.redhat.com/docs/en-US/Red_Hat_Enterprise_Linux/6/html-single/Logical_Volume_Manager_Administration/index.html#troubleshooting
No comments:
Post a Comment