LVM Layout
(source: RedHat Logical Volume Manager Administration)
LVM Components (from bottom to top)
- Hard Disks
- Partitions
- LVM will work fine with the entire disk (without creating a partition) as a PV. But this is not recommended.
- Other OS or disk utility (e.g. fdisk) will not recognize the LVM metadata and display the disk as free, so the disk is likely being overwritten by mistake.
- The best pratice is to create a partition on the hard disk, then initialize the partition as a PV.
- It is generally recommended that creating a single partition that covers the whole disk. (see RedHat Logical Volumen Manager Administration)
- Using an entire disk a PV or using a partition as a PV will have a different procedure when growing the hard disk size in the VM (see “Expanding LVM Storage”)
- Physical Volumnes
- Volume Group
- Logical Volumes
- File Systems
LVM Setup
- Add a new hard disk
- Rescan the SCSI bus
- ls /sys/class/scsi_host/
- echo “- - -“ > /sys/class/scsci_host/<host_name>/scan
- tail -f /var/log/message
- or
- ls /sys/class/scsi_disk/
- each ‘1’ > /sys/class/scsi_disk/<0\:0\:0\:0>/device/rescan
- tail -f /var/log/message
- Prepare the disk partition
- fdisk -l
- fdisk </dev/sdb>
- n - add a new parition
- p - primary partition
- 1 - partition number
- default - first cylinder
- default - last cylinder
- t - change a partition’s system id
- 1 - partition number
- 8e - Linux LVM
- w - write table to disk and exit
- fdisk -l to verify the new partition
- Update partition table changes to kernel
- reboot
- or partprobe </dev/sdb>
- Update (04/18/2016): In RHEL 6, partprobe will only trigger the OS to update the partitions on a disk that none of its partitions are in use (e.g. mounted). If any partition on a disk is in use, partprobe will not trigger the OS to update partition in the system because it it considered unsafe in some situations. So a reboot is required. see “How to use a new partition in RHEL6 without reboot?”
- Initialize disks or disk partitions
- pvcreate </dev/sdb> - skip step #3, use the entire disk as a PV, not recommended
- pvcreate </dev/sdb1> - use the partition created in step #3 as a PV, best practice
- pvdisplay
- pvs
- Create a volume group
- vgcreate <volume_group_name> </dev/sdb1>
- vgdisplay
- vgs
- Create a logical volume
- lvcreate --name <logical_volume_name> --size <size> <volume_group_name>
- or lvcreate -n <logical_volume_name> -L <size> <volume_group_name>
- lvdisplay
- lvs
- Create the file system on the logical volume
- mkfs.ext4 /dev/<volume_group_name>/<logical_volume_name>
- Mount the new volume
- mkdir </mount_point>
- mount /dev/<volume_group_name>/<logical_volume_name> </mount_point>
- Add the new mount point in /etc/fstab
- vi /etc/fstab
- /dev/<volume_group_name>/<logical_volume_name> </mount_point> ext4 defaults 0 0
No comments:
Post a Comment