Sunteți pe pagina 1din 6

Title: SOP for Managing Logical Volume Management (LVM) Storage

Prepared By: Mohd Nazri Bin Mazlan

A) Creating a Logical Volume

Refer to below steps on how to create a usable logical volume.

1. A physical device only needs to be prepared if it is still not existed and a new physical volume is
required to create or extend a volume group. As initials, one partition is created which is /dev/sdb1
with 10G Linux LVM (8e00) type as shown below.

[root@iridium ~]# gdisk /dev/sdb


GPT fdisk (gdisk) version 0.8.6

Partition table scan:


MBR: protective
BSD: not present
APM: not present
GPT: present

Found valid GPT with protective MBR; using GPT.

Command (? for help): p


Disk /dev/sdb: 41943040 sectors, 20.0 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): 384D43B0-D8BF-42D2-8055-B3FEC7EB2BBA
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 41943006
Partitions will be aligned on 2048-sector boundaries
Total free space is 2014 sectors (1007.0 KiB)

Number Start (sector) End (sector) Size Code Name


1 2048 20973567 10.0 GiB 8E00 Linux LVM

2. Create the physical volume. Label multiple devices at a time by using space-delimited device names
as arguments to pvcreate. A PV only needs to be created if there are no PVs free to create or extend a
VG.

[root@iridium ~]# pvcreate /dev/sdb1


WARNING: xfs signature detected on /dev/sdb1 at offset 0. Wipe it? [y/n]: y
Wiping xfs signature on /dev/sdb1.
Physical volume "/dev/sdb1" successfully created

3. Create a volume group. As arguments to vgcreate, define a VG name and list one or more PVs to
allocate to the VG.

[root@iridium ~]# vgcreate vg-nazri /dev/sdb1


Volume group "vg-nazri" successfully created

4. Create a logical volume. Use these arguments to lvcreate as a minimum: use the -n option to set the
LV name, the -L option to set the LV size in bytes or larger named values and identify the VG name
that the current LV is to be created in. Different tools will display the logical volume name using the
traditional name, /dev/vgname/lvname or the kernel device mapper name, /dev/mapper/vgname-
lvname.

[root@iridium ~]# lvcreate -n lv-nazri -L 5G vg-nazri


Logical volume "lv-nazri" created.

5. Add the file system. Use mkfs to create an XFS file system on the new logical volume.

[root@iridium ~]# mkfs.xfs /dev/vg-nazri/lv-nazri


meta-data=/dev/vg-nazri/lv-nazri isize=256 agcount=4, agsize=327680 blks
= sectsz=512 attr=2, projid32bit=1
= crc=0 finobt=0

1|P a g e
Title: SOP for Managing Logical Volume Management (LVM) Storage
Prepared By: Mohd Nazri Bin Mazlan

data = bsize=4096 blocks=1310720, imaxpct=25


= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=0
log =internal log bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0

5.1 To make the file system available across reboots, use mkdir to create a mount point directory.

[root@iridium ~]# mkdir /mnt/nazri

5.2 Add an entry to the /etc/fstab file.


[root@iridium ~]# vim /etc/fstab

...
...
/dev/mapper/rhel-swap swap swap defaults 0 0
/dev/mapper/vg--nazri-lv--nazri /mnt/nazri xfs defaults 0 0

5.3 Run mount -a to mount all file systems in /etc/fstab file, including the recently added entry. To
verify, use the mount or df command.
[root%iridium ~]# mount –a

[root@iridium ~]# mount | grep -i /dev/mapper/vg--nazri-lv--nazri


/dev/mapper/vg--nazri-lv--nazri on /mnt/nazri type xfs
(rw,relatime,seclabel,attr2,inode64,noquota)

[root@iridium ~]# df -h
Filesystem Size Used Avail Use% Mounted on
...
...
/dev/sda1 497M 124M 374M 25% /boot
/dev/mapper/vg--nazri-lv--nazri 5.0G 33M 5.0G 1% /mnt/nazri

6. To see the information of block device, use xfs_info.

[root@iridium bin]# xfs_info /dev/vg-nazri/lv-nazri


meta-data=/dev/mapper/vg--nazri-lv--nazri isize=256 agcount=5, agsize=327680 blks
= sectsz=512 attr=2, projid32bit=1
= crc=0 finobt=0
data = bsize=4096 blocks=1572864, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=0
log =internal bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0

EXAMPLES
Understanding xfs_info output.

Suppose one has the following "xfs_info /dev/sda" output:

meta-data=/dev/sda isize=256 agcount=32, agsize=16777184 blks


= sectsz=512 attr=2
data = bsize=4096 blocks=536869888, imaxpct=5
= sunit=32 swidth=128 blks
naming =version 2 bsize=4096
log =internal bsize=4096 blocks=32768, version=2
= sectsz=512 sunit=32 blks, lazy-count=1
realtime =none extsz=524288 blocks=0, rtextents=0

Here, the data section of the output indicates "bsize=4096", meaning the data
block size for this filesystem is 4096 bytes. This

2|P a g e
Title: SOP for Managing Logical Volume Management (LVM) Storage
Prepared By: Mohd Nazri Bin Mazlan

section also shows "sunit=32 swidth=128 blks", which means the stripe unit is
32*4096 bytes = 128 kibibytes and the stripe width
is 128*4096 bytes = 512 kibibytes. A single stripe of this filesystem
therefore consists of four stripe units (128 blocks / 32
blocks per unit).

B) Removing a Logical Volume

Refer to below steps to remove all logical volume components:

1. Prepare the file system.

[root@iridium ~]# umount /mnt/vmware-nfs

2. Remove the logical volume by using lvremove command. Use the device name as an argument. The
LV must be unmounted before running this command. It will ask for confirmation before removing the
LV.

[root@iridium ~]# lvremove /dev/vg-nazri/lv-nazri

Or

[root@iridium ~]# lvremove /dev/mapper/vg--nazri-lv--nazri

3. Remove the volume group by using vgremove command. Use the VG name as the argument.

[root@iridium ~]# vgremove vg-nazri

4. Remove the physical volumes by using pvremove command. Use a space delimited list of PV
devices to remove more than one a time. The PV metadata is wiped from the partition or disk.

[root@iridium ~]# pvremove /dev/sdb1 /dev/sdc1

C) Extending a Volume Group, Logical Volume and XFS File System

Refer to below steps on how to extend a volume group.

1. Another partition created which is /dev/sdb2 with the exact settings of /dev/sdb1. As initials, vg-
nazri is created inside partition /dev/sdb1 with size of 10G and Linux LVM (8e00) type.

[root@iridium /]# gdisk /dev/sdb


GPT fdisk (gdisk) version 0.8.6

Partition table scan:


MBR: protective
BSD: not present
APM: not present
GPT: present

Found valid GPT with protective MBR; using GPT.

Command (? for help): p


Disk /dev/sdb: 41943040 sectors, 20.0 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): 384D43B0-D8BF-42D2-8055-B3FEC7EB2BBA
Partition table holds up to 128 entries

3|P a g e
Title: SOP for Managing Logical Volume Management (LVM) Storage
Prepared By: Mohd Nazri Bin Mazlan

First usable sector is 34, last usable sector is 41943006


Partitions will be aligned on 2048-sector boundaries
Total free space is 2014 sectors (1007.0 KiB)

Number Start (sector) End (sector) Size Code Name


1 2048 20973567 10.0 GiB 8E00 Linux LVM
2 20973568 41943006 10.0 GiB 8E00 Linux LVM

2. Create the physical volume. Use the device name as the argument to pvcreate. A PV only needs to
be created if there are not PVs free to extend the VG.

[root@iridium ~]# pvcreate /dev/sdb2


Physical volume "/dev/sdb2" successfully created

3. Extend the volume group. Use the VG name and PV device name as arguments to vgextend.

[root@iridium ~]# vgextend vg-nazri /dev/sdb2


Volume group "vg-nazri" successfully extended

4. Verify the new VG space is available before proceed to extend the logical volume.

[root@iridium ~]# vgdisplay vg-nazri


--- Volume group ---
VG Name vg-nazri
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 3
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 1
Open LV 1
Max PV 0
Cur PV 2
Act PV 2
VG Size 19.99 GiB
PE Size 4.00 MiB
Total PE 5118
Alloc PE / Size 1280 / 5.00 GiB
Free PE / Size 3838 / 14.99 GiB
VG UUID xNzZG2-PTnf-ugAM-60PI-0oY0-6Twt-umtqkk

5. Extend the logical volume and XFS file system. One benefit of logical volumes is the ability to
increase their size without experiencing downtime.

5.1 This will increase logical volume lv-nazri by 500M. The “+” indicates add 500M to the existing
size which is 5G.

[root@iridium ~]# lvextend -L +500M /dev/mapper/vg--nazri-lv--nazri


Size of logical volume vg-nazri/lv-nazri changed from 5.00 GiB (1280 extents) to
5.49 GiB (1405 extents).
Logical volume lv-nazri successfully resized

5.2 Another way to specify the size by using -l option which generally use physical extents values, use
vgdisplay command to view the available PEs size. As per below, 213 extents is added to the current
size of the logical volume.

[root@iridium ~]# lvextend -l +213 /dev/mapper/vg--nazri-lv--nazri


Size of logical volume vg-nazri/lv-nazri changed from 5.49 GiB (1405 extents) to
6.32 GiB (1618 extents).
Logical volume lv-nazri successfully resized

4|P a g e
Title: SOP for Managing Logical Volume Management (LVM) Storage
Prepared By: Mohd Nazri Bin Mazlan

6. Extend the XFS file system. xfs_growfs /mountpoint command expands the file system to occupy
the extended LV. The file system needs to be mounted before running the command. You cannot grow
an XFS file system that is currently unmounted. There is currently no command to shrink an XFS file
system. Instead, you need to recreate the partition with a larger size and restore its contents from a
backup (if you deleted the original partition) or (from the contents of the original partition if you did
not delete it to free up disk space). A common mistake is to run lvextend but forgot to run xfs_growfs.
As an alternative, run the two steps consecutively to include –r as an option with the lvextend
command. This resizes the underlying file system together with the LV is extended using fsadm
command.
[root@iridium ~]# xfs_growfs /mnt/nazri
meta-data=/dev/mapper/vg--nazri-lv--nazri isize=256 agcount=4, agsize=327680 blks
= sectsz=512 attr=2, projid32bit=1
= crc=0 finobt=0
data = bsize=4096 blocks=1310720, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=0
log =internal bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 1310720 to 1656832

[root@iridium ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/rhel-root 18G 6.5G 11G 38% /
devtmpfs 880M 0 880M 0% /dev
tmpfs 889M 0 889M 0% /dev/shm
tmpfs 889M 8.8M 880M 1% /run
tmpfs 889M 0 889M 0% /sys/fs/cgroup
/dev/mapper/vg--nazri-lv--nazri 6.4G 33M 6.3G 1% /mnt/nazri
/dev/sda1 497M 124M 374M 25% /boot

D) Reducing a Volume Group

Refer to below steps to reduce a volume group.

1. Move the physical extents. Pvmove is used to relocate any physical extents used on the physical
volume to other PVs in the VG. This is only possible if there are enough free extents in the VG and if
all of those come from other PVs. Use the PV device name for which the PEs will be moved as the
argument of the command. As per below, this will move the PEs from /dev/sdb1 to other PVs with free
PEs in the same VG. Please note that it is recommended to backup data on all LV in the VG.
Unexpected power loss during the operation may leave the VG in an inconsistent state which could
cause loss of data on LVs in the VG.

[root@iridium ~]# pvmove /dev/sdc1

2. Reduce the volume group by using vgreduce command. It will remove the physical volume from the
volume group. Use the VG name and PV device name as arguments to the command. As per below,
the /dev/sdc1 PV is removed from vg-nazri VG and can be added to another VG. Alternatively,
pvremove command can be used to stop using the device as a PV permanently.

[root@iridium ~]# vgreduce vg-nazri /dev/sdc1

E) Partitioning the Unallocated Space: If the Disk Size Increased in VM

5|P a g e
Title: SOP for Managing Logical Volume Management (LVM) Storage
Prepared By: Mohd Nazri Bin Mazlan

Increase the underlying block device, partition and LVM volume first. Then, expand the partition
using xfs_growfs for XFS or resize2fs for ext2/3/4.

1. Check the name of the SCSI devices. It is required to rescan the SCSI devices after changing the
disk size in VMware. But this doesn’t apply for the server that has been booted, as the SCSI devices
rescan on boot.

[root@iridium rpm-installer]# ls -l /sys/class/scsi_device/


lrwxrwxrwx. 1 root root 0 Jul 25 09:12 0:0:0:0 ->
../../devices/pci0000:00/0000:00:15.0/0000:03:00.0/host0/
target0:0:0/0:0:0:0/scsi_device/0:0:0:0
lrwxrwxrwx. 1 root root 0 Jul 25 09:12 0:0:1:0 ->
../../devices/pci0000:00/0000:00:15.0/0000:03:00.0/host0/
target0:0:1/0:0:1:0/scsi_device/0:0:1:0
lrwxrwxrwx. 1 root root 0 Jul 25 09:12 1:0:0:0 ->
../../devices/pci0000:00/0000:00:07.1/ata1/host1/
target1:0:0/1:0:0:0/scsi_device/1:0:0:0

2. Then rescan the SCSI bus, replace with the actual SCSI bus name. It will rescan the current SCSI
bus and new disk size will show up.

[root@iridium rpm-installer]# cat /sys/class/scsi_device/1\:0\:0\:0/device/model


VMware IDE CDR00
[root@iridium rpm-installer]# cat /sys/class/scsi_device/0\:0\:0\:0/device/model
Virtual disk
[root@iridium rpm-installer]# echo 1 >
/sys/class/scsi_device/0\:0\:0\:0/device/rescan

F) Partitioning the Unallocated Space: If added a Disk in VM

1. The actions are similar with to those described above. But instead of rescanning an already existed
SCSI bus, we need to rescan the host to detect the new SCSI bus as a new disk has been added.

[root@iridium yum.repos.d]# ls /sys/class/scsi_host/


total 0
lrwxrwxrwx. 1 root root 0 Jul 25 09:12 host0 ->
../../devices/pci0000:00/0000:00:15.0/0000:03:00.0/host0/scsi_host/host0
lrwxrwxrwx. 1 root root 0 Jul 25 09:12 host1 ->
../../devices/pci0000:00/0000:00:07.1/ata1/host1/scsi_host/host1
lrwxrwxrwx. 1 root root 0 Jul 25 09:12 host10 ->
../../devices/pci0000:00/0000:00:11.0/0000:02:01.0/ata10/host10/scsi_host/host10
lrwxrwxrwx. 1 root root 0 Jul 25 09:12 host11 ->
../../devices/pci0000:00/0000:00:11.0/0000:02:01.0/ata11/host11/scsi_host/host11

2. The host device is called “host0”, rescan it as such. It won’t show the output, instead running “fdisk
–l” will show the new disk.

[root@iridium yum.repos.d]# echo "- - -" > /sys/class/scsi_host/host0/scan

6|P a g e

S-ar putea să vă placă și