40
NoVALUG: LVM and Gang February 2015 1 LVM and gang By Peter Larsen [email protected] @egoalter

Lvm and gang 2015

Embed Size (px)

Citation preview

NoVALUG: LVM and GangFebruary 2015 1

LVM and gang

By Peter [email protected]

@egoalter

NoVALUG: LVM and GangFebruary 2015 2

Attributions● I suck at drawing – therefore my hat off to:● Materials borrowed from Kbolino at en.wikipedia

Licensed under CC BY-SA 2.5 via Wikimedia Commons● Materials borrowed from Paul Frields, Licensed under CC BY-

SA 2.5● Materials borrowed from Shmuel Csaba Otto Traian. Licensed

under CC BY-SA 3.0

NoVALUG: LVM and GangFebruary 2015 3

Why LVM?● Traditional partitions are inflexible and dumb● Partions get in the way as changes are needed● Partitions doesn't provide any other value than a place for a file

system● Partition outlived their success. Who needs static sizing on 4TB

drives or SSDs?● LVM has little to no processing overhead● LVM provides backup of the structural setup – try that with

partitions!

NoVALUG: LVM and GangFebruary 2015 4

Agenda● Some background on harddrives and partitions

● An LVM overview – show some static examples

– Traditional setup

– Snapshots

– Thin provisioning

– Mirroring and striping

– Cache pools● DEMO: Basic setup at install – it's THAT easy!

● DEMO: How to convert from partitions to LVM

● DEMO: Installing LVM from scratch

NoVALUG: LVM and GangFebruary 2015 5

Hard drive basics● Sectors and blocks (LHA vs. CHS)● Sector sizing (groups of contig blocks)● Allocation principles● File systems

NoVALUG: LVM and GangFebruary 2015 6

Hard drive basics

NoVALUG: LVM and GangFebruary 2015 7

Partitions● Legacy requirement● Bios driven● Simple to implement – easy mapping between disk and partition

addresses● Common Types: MSDOS (MBR) and GUID Partition Table

(GPT) (there are a lots more)● Boot process and partitions

– BIOS -> POST -> Primary Device sector/block 0 -> execute

– In the MS world, MBR partions would contain code that looked for the primary partition marked as “boot”. Linux/Grub does not.

NoVALUG: LVM and GangFebruary 2015 8

Partion to Sector mapping

Disk Sectors

Partition 1 Partition 2Partition 3

Free

● How do you expand partition 1 to take advantage of some of the free space?

– Move Partition 3, Move partition 2, enlarge partition 1

– LOTS of writes for a small increase

NoVALUG: LVM and GangFebruary 2015 9

MBR Partitions● MBR located in first sector● Partition table part of first sector● Lose first sector and disk is

gone!● 4 primary partitions● Extended -> logical added later.● A partition has a start and and

end sector. Has to be contigious

NoVALUG: LVM and GangFebruary 2015 10

GPT partitions● Partition table duplicated● GPT is more safe from

crashes● GPT supports very large

partitions (> 2TB)● GPT supports EFI● Lots

NoVALUG: LVM and GangFebruary 2015 11

MBR vs. GPT● GPT has a larger overhead● GPT is more safe from

crashes● GPT supports very large

partitions (> 2TB)● GPT supports EFI

NoVALUG: LVM and GangFebruary 2015 12

Partition Problems● Static – change is hard and slow● Change often means moving full file systems● Moving a file system

– takes a long time

– Is a complex process of many steps

NoVALUG: LVM and GangFebruary 2015 13

Booting

NoVALUG: LVM and GangFebruary 2015 14

GRUB Bootloader● GRand Unified Bootloader (

www.gnu.org/software/grub/)● Stage 1: Boot record● Stage 1.5: empty sectors

usually in overhead or “boot” volume

● Stage 2: Any location (lvm, md, partition, extended, logical etc)

NoVALUG: LVM and GangFebruary 2015 15

Kernel and initramfs● Grub finishes by loading a kernel into memory specifying an

initramfs location● Kernel loaded into memory will load specified ramdisk as root,

and execute /sbin/init – symlinked to systemd● Initramfs loads all primary drivers in order to be able to mount

the root file system, load luks disks, activate volumes, HBAs, activate md-arrays etc

● Once base drivers are loaded, the REAL root volume is mounted read-only replacing the initramfs volume. Control is passed to systemd on the new root

NoVALUG: LVM and GangFebruary 2015 16

Customizing Boot● When changing device locations, a new initramfs must be

generated.– # dracut

● Grub specifies root device location and /boot location. If you move /boot to LVM, these entries must be changed.

– # vim /boot/grub2/grub.cfg

– # grub2-install

NoVALUG: LVM and GangFebruary 2015 17

Logical Volume ManagementLVM

NoVALUG: LVM and GangFebruary 2015 18

LVM Basics● Physical Volume● Volume Group● Logical Volume

NoVALUG: LVM and GangFebruary 2015 19

Example

NoVALUG: LVM and GangFebruary 2015 20

LVM building blocks● Extents● Metadata

NoVALUG: LVM and GangFebruary 2015 21

Physcal Extents

NoVALUG: LVM and GangFebruary 2015 22

Volume Group Extents

NoVALUG: LVM and GangFebruary 2015 23

Logical Extents

NoVALUG: LVM and GangFebruary 2015 24

CommandsDisplayDisplay CRUDCRUD ManageManage

Physical Volume # pvs# pvdisplay# pvscan

# pvcreate# pvremove# pvmove

# pvchange# pvck

Volume Group # vgs# vgdisplay# vgscan

# vgcreate# vgremove# vgmerge# vgsplit# vgextend# vgreduce

# vgcfg{backup|restore}# vgconvert# vgchange

Logical Volume # lvs# lvdisplay# lvscan

# lvcreate# lvremove# lvresize# lvreduce# lvextend

# lvscan# lvchange# lvconvert

NoVALUG: LVM and GangFebruary 2015 25

Tricks and tips● Lock down elible devices for LVM if you do a lot of VMs● After big changes remember to backup the metadata

configuration● Accidentially removed the wrong volume? Vgcfgrestore is your

friend!● Duplicate your LVM setup using vgcfgbackup/restore

NoVALUG: LVM and GangFebruary 2015 26

Thin Provisioning● LVM supports “virtual sizing” making volumes much bigger than

the actual physical capacity● Create “thinpool” using the -T parameter and a size with -L● Create virtual volumes using the -T parameter and –virtualsize

to specify a virtual size● # lvcreate -n thinpool -L 20G -T myvg● # lvcreate -n largevolume1 –virtualsize 15G myvg/thinpool● # lvcreate -n largevolume2 –virtualsize 25G myvg/thinpool● Space runs out when the thinpool is full. See poolmetadatasize

NoVALUG: LVM and GangFebruary 2015 27

Snapshotting● Coolest feature ever – easily

remove changes since last check point

● Creates special volume that contains changes to blocks. By looking up extents first in the change list, and if not found then in the original – a copy of the “before” and “after” are kept

● Copy on Write

NoVALUG: LVM and GangFebruary 2015 28

Snapshot commands● # lvcreate -s myvg/original-lv -n mysnapshot -L 20G ● Use –virtualsize to create a virtual much larger volume● Size contains changes – should be as large as the volume itself to

allow for all blocks to change● You can create as many snapshots as you want on the same image● You can change the original volume too! (or set it R/O)● Commit your changes

# lvconvert –merge myvg/mysnapshot● Rollback

# lvremove myvg/mysnapshot

NoVALUG: LVM and GangFebruary 2015 29

Snapshot Use Case: Backups!● Backups take time● A live system changes over

time● Snapshot freezes system in

time for a consistent backup!

NoVALUG: LVM and GangFebruary 2015 30

Snapshot Use Case: Virtual Machines● Using a snapshot with your VM allows you to instantly revert to

an old working stage● Easy way to experiment and rollback mistakes made

NoVALUG: LVM and GangFebruary 2015 31

Mirroring and striping● Legacy mirroring and striping still in LVM but not recommended● Use RAID instead● Mirroring and stripes required a “logging” volume for journaling

NoVALUG: LVM and GangFebruary 2015 32

RAID● LVM comes with build in RAID

– raid0, raid1, raid4, raid5, raid6, raid10

● Can be used as an alternative to md● # lvcreate –type raid5 -n raidvolume -L 20G myvg

NoVALUG: LVM and GangFebruary 2015 33

Cache pools● Use cache pools to create “small” volumes on fast devices like

SSD to front/link them with slow devices like HDD– # lvcreate --type cache-pool -L 1G -n my_lv_cachepool vg /dev/fast1

– # lvcreate --type cache -L 100G -n my_lv vg/my_lv_cachepool /dev/slow1

– # lvcreate --type cache -L 100G -n my_lv vg/my_lv_cachepool /dev/slow1

NoVALUG: LVM and GangFebruary 2015 34

Cool stuff you can do● Consistent backup● Easy resize a file system● Adding new space without changing mount points etc● VM Storage● Create “large storage” without needing large drives

NoVALUG: LVM and GangFebruary 2015 35

LVM Configuration

● /etc/lvm/lvm.conf● /etc/lvm/backup● /etc/lvm/archive● /etc/lvm/profiles

NoVALUG: LVM and GangFebruary 2015 36

Setup at install time● Default with Fedora/CentOS/Ubuntu● Recommendations

– Do not allocate all space

– Save 10% for snapshots and later expansions

– Add all mount points to LVM (maybe except /boot)

– Always create separate /home

NoVALUG: LVM and GangFebruary 2015 37

Getting rid of traditional partitions● Show demo

NoVALUG: LVM and GangFebruary 2015 38

Converting existing partition based system to LVM with /boot on LVM!

● Show Demo

NoVALUG: LVM and GangFebruary 2015 39

Creating LVM install manually● Setting up an advanced LVM when the installer has no clue

NoVALUG: LVM and GangFebruary 2015 40

Questions?

Presentation available at: http://www.slideshare.net/plarsen67/lvm-and-gang-2015