LVM Fundamentals Lab
LVM Fundamentals Lab
Christoph Doerbeck
Principal Solutions Architect, Red Hat
Jonathan Brassow
Principal Software Engineer, Red Hat
06.12.2013
lab3
lab3
Fundamentals of LVM
Please proceed to: student
summit2013
log in to workstation
log in to virtual machine
disable screen saver
disable screen lock
06/11/13
open a root shell 3
Quick Survey
Audience Profile
System Administrators?
Programmers?
RHCSA's?
RHCE's?
RHCA's?
Quick Survey
BASH Skills Test
ls /dev/vd{a,b,c}
ls /dev/vda{1..3}
Ctrl-R
Quick Survey
BASH Skills Test
ls /dev/vd{a,b,c} ls /dev/vda /dev/vdb /dev/vdc
● Agility
● Dynamically adjust storage configuration
● Grow, shrink or relocate your data/filesystems
● Aggregate or subdivide devices as needed
● Performance
● Striping across multiple devices
● Fault Tolerance (redundancy & resiliency)
● RAID 0, 1, 5, 6, 10
● Snapshots
Building Blocks of Storage Management
File-systems { Formatted LV's become filesystems
Volume Group
(VG) { A collection of Physical Volumes that are divided into discrete
allocatable chunks called “physical extents” (PEs).
Physical Volume
(PV) { An LVM concept that identifies physical devices for LVM use.
● Summary:
● A Linear Volume is a virtual device of any size, possibly
composed of multiple concatenated physical devices
● Usage:
● lvcreate -n <lv_name> -L <size> <VG>
● Additional Comments:
● Many options have short & long identifiers
● '--size' and '-L' are equivalent
● Options to specify size by # of extents, % free space
Mapping Linear Logical Extents (LE)
to Physical Extents (PE)
LV1
fdisk /dev/vdb
create partition vdb1 & set type “8E”
partprobe
pvcreate /dev/vdb1
vgcreate vg_summit /dev/vdb1
lvcreate n lab1 L 10M vg_summit
mkfs t ext4 /dev/vg_summit/lab1
mkdir p /mnt/lab1
mount /dev/vg_summit/lab1 /mnt/lab1
Lab 1 : Part 1 – Analyzing pvcreate
[root]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_desktop-lv_root
9.2G 2.1G 6.7G 24% /
tmpfs 499M 272K 499M 1% /dev/shm
/dev/vda1 485M 33M 428M 7% /boot
/dev/mapper/vg_summit-lab1
12M 1.2M 10M 11% /mnt/lab1
/dev/mapper/vg_summit-lab1
vs
/dev/vg_summit/lab1
Lab 1 : Part 1 – additional options & output
fdisk /dev/vdc
partprobe create partition vdc1 & set type “8E”
vgextend /dev/vg_summit /dev/vdc1
lvresize L 20M /dev/vg_summit/lab1
resize2fs /dev/vg_summit/lab1
Lab 1 : Part 2 – Analyzing vgextend
lvresize L +10M /dev/vg_summit/lab1 /dev/vdc1
resize2fs /dev/vg_summit/lab1
Lab 1 : Part 3 – Analyzing lvresize a second time
[root]# df -h /mnt/lab1
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_summit-lab1
32M 1.2M 29M 4% /mnt/lab1
umount /mnt/lab1
Mount
Optional : zero out data
Filesystem dd if=/dev/zero of=/dev/vg_summit/lab1
vgremove f vg_summit
Volume Group
pvremove f /dev/vd{b,c}1
Physical Volume
Device/Partition
Logical Volume Management
Striping and mirroring
LVM Stripes
● Summary:
● Striping (RAID0) aggregates storage devices, increases
performance BUT provides no redundancy.
● Usage:
● lvcreate -i <stripe_count> -n <lv_name> -L <size> <vg>
● Additional Comments:
● '-i' and '--stripes' are equivalent
● Set the stripe size: '-I/--stripesize <StripeSize>'
Lab 2 : Part 1 – Create a Striped LV
vgcreate vg_summit /dev/vd{b,c,d}1
lvcreate i 3 n lab2 L 100M vg_summit
mkfs t ext4 /dev/vg_summit/lab2
mkdir p /mnt/lab2
mount /dev/vg_summit/lab2 /mnt/lab2
Lab 2 : Part 1 – Analyzing vgcreate
lab2 is striped
Lab 2 : Part 1 – Analyzing mount
[root]# df -h /mnt/lab2
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_summit-lab2
105M 5.6M 94M 6% /mnt/lab2
/mnt/lab2 is ~100M
Lab 2 : Part 2 – Resize a Striped LV
vgextend vg_summit /dev/vd{e,f}1
lvresize i 2 L +100M vg_summit/lab2 /dev/vd{e,f}1
resize2fs /dev/vg_summit/lab2
Lab 2 : Part 2 – Analyzing vgcreate
[root]# df -h /mnt/lab2
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_summit-lab2
206M 5.8M 190M 3% /mnt/lab2
/mnt/lab2 is ~200M
LVM Mirrors
● Summary:
● LVM mirrors can maintain redundant copies of you data for
device fault tolerance.
● Usage:
● lvcreate -m <extra_copy_count> -n <lv_name> -L <size> <vg>
● Additional Comments:
● Prevent initial synchronization: '--nosync'
● Specify the log type: '--mirrorlog <core|disk>'
Lab 3 : Part 1 – Create a Mirrored LV
lvcreate m 1 n lab3 L 20M vg_summit
mkfs t ext4 /dev/vg_summit/lab3
mkdir p /mnt/lab3
mount /dev/vg_summit/lab3 /mnt/lab3
Lab 3 : Part 1 – Analyzing lvcreate
[root]# df -h /mnt/lab3
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_summit-lab3
20M 1.2M 18M 7% /mnt/lab3
Lab 3 : Part 3 – Upconvert a Mirrored LV (add another leg)
lvconvert m +1 vg_summit/lab3
cp vr /etc/sysconfig /mnt/lab3
Lab 3 : Part 2 – Analyzing lvconvert
add 1 additional
[root]# lvconvert -m +1 vg_summit/lab3
copy (mirror) to lab3
vg_summit/lab3: Converted: 40.0%
vg_summit/lab3: Converted: 100.0%
Logical volume lab3 converted.
segment is a mirror
● Summary:
● Splitting an image from a mirror gives point-in-time copy of a
mirrored LV.
● Usage:
● lvconvert --splitmirror 1 -n <new_lv_name> <vg>/<lv>
● Additional Comments:
● Split Mirror requires a name argument
● Mirror must have completed synchronization
● Be sure to 'sync' before splitting a mirror
Lab 3 : Part 3 – Split a Mirrored LV
sync
lvconvert splitmirrors 1 n lab3_split vg_summit/lab3
mkdir p /mnt/lab3_split
mount /dev/vg_summit/lab3_split /mnt/lab3_split
Lab 3 : Part 3 – Analyzing lvconvert
[root]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/vg_desktop-lv_root
9555048 2134780 6934892 24% /
tmpfs 510404 272 510132 1% /dev/shm
/dev/vda1 495844 32891 437353 7% /boot
/dev/mapper/vg_summit-lab2
210350 5902 193807 3% /mnt/lab2
/dev/mapper/vg_summit-lab3
19827 1422 17381 8% /mnt/lab3
/dev/mapper/vg_summit-lab3_split
19827 1422 17381 8% /mnt/lab3_split
Logical Volume Management
RAID
Kernel Space User Space
RAID0
RAID1
RAID4
mdadm
RAID5
MD core module
RAID6
RAID10
Architectural Overview (Before)
dm-linear
dm-striped
dm-mirror
LVM
dm-snap
libdevmapper
DM core module
Kernel Space User Space
RAID0
RAID1
RAID4
mdadm
RAID5
MD core module
RAID6
RAID10
dm-raid
Architectural Overview (Current)
dm-linear
dm-striped
dm-mirror
LVM
dm-snap
libdevmapper
DM core module
LVM RAID 1, 4, 5, 6 & 10
● Summary:
● RAID logical volumes provide device fault tolerance and
differing I/O patterns based on the type of RAID used.
● Usage:
● lvcreate --type raid[456] -i <stripe_count> -n <lv_name> -L <size> <vg>
● lvcreate --type raid1 -m <copy_count> -n <lv_name> -L <size> <vg>
● lvcreate --type raid10 -m 1 -i <#stripes> -n <lv_name> -L <size> <vg>
● Additional Comments:
● '--mirrorlog' is not available for RAID logical volumes
● RAID10 only supports 2-way mirrors (ie: -m 1)
Lab 4 – Create a RAID5 LV
lvcreate type raid5 i 2 n lab4 L 20M vg_summit
mkfs t ext4 /dev/vg_summit/lab4
mkdir p /mnt/lab4
mount /dev/vg_summit/lab4 /mnt/lab4
Lab 4 – Analysis
● Summary:
● 'lvconvert' can be used to change the segment type from
“mirror” to “raid1”
● Usage:
● lvconvert --type raid1 <vg>/<mirror-lv>
● Additional Comments:
● “raid1” provides better support for snapshots
● “raid1” supports transient failures
● This operation is not reversible, except via 'vgcfgrestore'
Lab 5 – Convert a Mirror to RAID1
lvconvert type raid1 vg_summit/lab3
Lab 5 – Analyzing lvconvert
lvrename vg_summit/lab3 vg_summit/lab5
mkdir p /mnt/lab5
umount /mnt/lab3
mount /dev/vg_summit/lab5 /mnt/lab5
Lab 5 - BONUS * Analyzing the renaming of Lab3 to Lab5
● Summary:
● Quick point-in-time copy of a filesystem without requiring
complete duplication of physical storage capacity.
● Usage:
● lvcreate -s -L <size> -n <name> <origin-vg>/<origin-lv>
● Additional Comments:
● '-s' and '--snapshot' are equivalent
● '-c/--chunksize <Size>' sets the COW copy size
(Default=4kiB)
Lab 6 – Create a Snapshot for general use
lvcreate s L 100m n lab6 vg_summit/lab3_split
mkdir p /mnt/lab6
mount /dev/vg_summit/lab6 /mnt/lab6
Lab 6 – Analyzing lvcreate
origin is LV lab3_split
ls god /mnt/lab3_split/sysconfig/iptables*
rm f /mnt/lab3_split/sysconfig/iptables*
ls god /mnt/lab3_split/sysconfig/iptables*
ls god /mnt/lab6/sysconfig/iptables*
Lab 6 – Analyzing the filesystems
[root]# rm -f /mnt/lab3_split/sysconfig/iptables*
● Summary:
● Merging a snapshot back to it's origin provides a convenient
method to return a filesystem to it's previous state.
● Usage:
● lvconvert --merge <vg>/<snap-lv>
● Additional Comments:
● Merging requires LV deactivation & reactivation
● Merging the root filesystem requires a reboot
Lab 7 : Merge LV to Previous State
umount /dev/vg_summit/{lab3_split,lab6}
lvconvert merge vg_summit/lab6
mount /dev/vg_summit/lab3_split /mnt/lab3_split
Lab 7 – Analyzing Merge
Filesystem restored
LVM Sparse Volumes
● Summary:
● Snapshots can be used as read/write volumes and can be created
without an origin. This provides a way to create large devices
without the need for the full physical space.
● Usage:
● lvcreate -s -V <virtual_size> -L <real_size> <VG>
● Additional Comments:
● A virtual 'zero' device is used as the origin for spare volumes
● When the real space is used-up, the volume is dead.
lvcreate s V 1G L 100M n lab8 vg_summit
mkfs t ext4 /dev/vg_summit/lab8
mkdir p /mnt/lab8
mount /dev/vg_summit/lab8 /mnt/lab8
Lab 7 – Analyzing creation of a sparse logical volume
[root]# df -h /mnt/lab8
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_summit-lab8 1008M 34M 924M 4% /mnt/lab8
Disk write Disk write
Exception
Store Thin Pool
Origin Exception
Store
Exception
Store
Logical Volume Logical Volume
LVM Thin Logical Volumes and Snapshots
● Summary:
● Thin logical volumes provide the means to reserve capacity
upfront & consume necessary physical space on demand.
● Usage:
● lvcreate -T <vg>/<pool_name> -L <size> -V <size> -n <lv_name>
● lvcreate -s <vg>/<origin_lv> -n <thin_snap_name>
● Additional Comments:
● No size specification for thin snapshots
● Thin snaps share a common storage pool which makes it
very efficient for large numbers of snapshots
Lab 9: Part 1 – Create a Thin Logical Volume
lvcreate T vg_summit/lab9_pool L 100M V 1G n lab9
mkfs.ext4 /dev/vg_summit/lab9
mkdir p /mnt/lab9
mount /dev/vg_summit/lab9 /mnt/lab9
Lab 9: Part 1 – Analyzing creation of a thin logical volume
[root]# df -h /mnt/lab9
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_summit-lab9 1008M 34M 924M 4% /mnt/lab8
lvcreate s vg_summit/lab9 n lab9_snap
mkdir p /mnt/lab9_snap
mount /dev/vg_summit/lab9_snap /mnt/lab9_snap
Lab 9: Part 2 – Analyzing creation of a thin logical volume
[root]# df -h /mnt/lab9_snap
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_summit-lab9_snap 1008M 34M 924M 4% /mnt/lab9_snap
● http://docs.redhat.com/docs/en-US/index.html
● Logical_Volume_Manager_Administration
● Storage_Administration_Guide
● Customer Portal
● https://access.redhat.com/home
Additional Self Help
06/11/13 83
Additional Exercises #1
Using snapshot & merge to roll-
back system updates
06/11/13 84
AdLab 1 : Part 1 – Cleanup all previous labs
umount /mnt/*
vgremove f vg_summit
AdLab 1 : Part 2 – Prepare for OS volume snapshot
vgextend vg_desktop /dev/vd{b,c,d,e,f}1
mkdir p /mnt/adlab1_arc
mount /dev/vg_desktop/adlab1_backup /mnt/adlab1_arc
AdLab 1 : Part 3 – Backup /boot
umount /boot
dd if=/dev/vda1 | gzip c9 > /mnt/adlab1_arc/boot.dd.gz
lvcreate s L 500M n adlab1_snap vg_desktop/lv_root
echo “##LAB7 COMMENT##” >> /boot/grub/grub.conf
echo “##LAB7 COMMENT##” > /etc/redhatrelease
rm rf /usr/share/doc/yum*
AdLab 1 : Part 4 – Analyzing the system after updates
file in / modified
AdLab 1 : Part 5 – Merge snapshot to origin
umount /boot
gzip dc /mnt/lab7_arc/boot.dd.gz | dd of=/dev/vda1
fsck /dev/vda1
mount /boot
lvconvert merge vg_desktop/adlab1_snap
reboot
AdLab 1 : Part 5 – Analyzing the system post reboot