Download presentation
Presentation is loading. Please wait.
Published byMarianna Lee Modified over 8 years ago
1
NovaLug May 2008NovaLug May 2008 For NovaLug An LVM Introduction THE MAGIC OF LVMTHE MAGIC OF LVM
2
NovaLug May 2008NovaLug May 2008 For NovaLug An LVM Introduction 2 LVM – an introduction LVM L OGICAL V OLUME M ANAGEMENT LVM - your new, better, more flexible and powerful partitions (and it'll probably make the coffee too) By Peter H. Larsen
3
NovaLug May 2008NovaLug May 2008 For NovaLug An LVM Introduction 3 Synopsis ➲ LVM provides logical partitions – called Volumes ➲ Volumes can easily be expanded when needed ➲ Does not suffer from the problems that static partition tables have ➲ Has built in raid 0 and 1 ➲ Snapshots and cloning supported
4
NovaLug May 2008NovaLug May 2008 For NovaLug An LVM Introduction 4 Agenda ➲ Hard drives and Traditional Partitions ➲ Why the need for change? ➲ LVM to the rescue – concepts ➲ LVM Components ➲ Demo ➲ Questions – please! And don't wait!
5
NovaLug May 2008NovaLug May 2008 For NovaLug An LVM Introduction 5 Hard drive anatomy ➲ Disk/device name ➲ Major/minor number ➲ Addressing: ● Track/Cylinder ● Head ● Sector ➲ MBR ➲ Partition Table ● Primary ● Extended ● Logical ● Boot
6
NovaLug May 2008NovaLug May 2008 For NovaLug An LVM Introduction 6 Traditional Partitions ➲ Static table ➲ Must be contiguous space ➲ Cannot extend partitions if space after them are already allocated ➲ Redundancy is built on top of partitions using “3 rd party” tools like md. ➲ Traditional PC bios code will still look for a “boot partition” to load after MBR. This means we still need a “real” boot partition.
7
NovaLug May 2008NovaLug May 2008 For NovaLug An LVM Introduction 7 LVM to the rescue ➲ Dynamic – can grow and change over time ➲ Is not contiguous storage. Logical volumes are allocated in blocks. Adding/subtracting space is EASY ➲ Resizing can be done non-linear A “partition” doesn't have to be contiguously allocated ➲ Redundancy built into LVM (raid 1). Supports raid 0 (striping) too ➲ Backup is easy using snapshots ➲ “Partitions” can span multiple disks
8
NovaLug May 2008NovaLug May 2008 For NovaLug An LVM Introduction 8 LVM Concepts ➲ Physical Volume ➲ Volume Group ➲ Logical Volume ➲ Disks belong to a group ➲ One or more logical volumes per group
9
NovaLug May 2008NovaLug May 2008 For NovaLug An LVM Introduction 9 The argument against single partition installs ➲ Cannot separate user-data and system data at upgrade ➲ Bad process can fill up whole system ➲ Very large block sizes ➲ Bad inodes / corruption impacts all of system including root ➲ Same file-system, cache etc. for all purposes
10
NovaLug May 2008NovaLug May 2008 For NovaLug An LVM Introduction 10 DM – Device Mapper ➲ LVM(2) builds on the Device Mapper (DM) ➲ DM provides a simple map of block devices to logical devices ➲ /sbin/dmsetup # dmsetup ls vgsys-lvswap (253, 5) vgsys-lvusr (253, 3) vgsys-lvroot (253, 0) vgsys-lvvar (253, 2) vgsys-lvvm (253, 7) vgsys-lvhome (253, 1) vgsys-lvtmp (253, 4) vgsys-lvu02 (253, 8) vgsys-lvu01 (253, 6)
11
NovaLug May 2008NovaLug May 2008 For NovaLug An LVM Introduction 11 LVM commands ➲ Physical Volume – starts with pv Physical Volume – starts with pv ➲ Volume Group – starts with vg Volume Group – starts with vg ➲ Logical Volume – starts with lv Logical Volume – starts with lv ➲ # lvm – a lvm shell # lvm – a lvm shell ➲ # dmsetup ls Device Mapper list # dmsetup ls Device Mapper list ➲ # pvdiskscan Scans all known devices for LVM # pvdiskscan Scans all known devices for LVM
12
NovaLug May 2008NovaLug May 2008 For NovaLug An LVM Introduction 12 Sample Environment ➲ 4 Disks (sda, sdb, sdc, sdd) ➲ First disk, sda, has existing system setup – two partitions. First partition is the /boot and the second partition is for LVM ➲ The 3 “new” disks have no yet been initialized. ➲ Goal: To setup LVM on the new disks in two volume groups
13
NovaLug May 2008NovaLug May 2008 For NovaLug An LVM Introduction 13 ➲ “Formats” device to hold LVM metadata. Can be applied to whole disks as well as traditional partitions ➲ # pvs Reports about the physical volumes ➲ # pvscan Scans the system for physical volumes ➲ # pvdisplay Show details about a physical volume ➲ # pvcreate Create physical volume ➲ # pvresize Resize phyiscal volume ➲ # pvremove Remove physical volume Commands – Physical Volume
14
NovaLug May 2008NovaLug May 2008 For NovaLug An LVM Introduction 14 Physcial Volume Examples # ls /dev/sd? /dev/sda /dev/sdb /dev/sdc /dev/sdd # fdisk -l /dev/sda Disk /dev/sda: 21.4 GB, 21474836480 bytes 255 heads, 63 sectors/track, 2610 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System /dev/sda1 * 1 13 104391 83 Linux /dev/sda2 14 2610 20860402+ 8e Linux LVM # pvscan PV /dev/sda2 VG vgsys lvm2 [19.88 GB / 1.94 GB free] Total: 1 [19.88 GB] / in use: 1 [19.88 GB] / in no VG: 0 [0 ]
15
NovaLug May 2008NovaLug May 2008 For NovaLug An LVM Introduction 15 Example: Creating Physical Volumes # pvcreate /dev/sdb Physical volume "/dev/sdb" successfully created # pvcreate /dev/sdc Physical volume "/dev/sdc" successfully created # pvcreate /dev/sdd Physical volume "/dev/sdd" successfully created # pvscan PV /dev/sda2 VG vgsys lvm2 [19.88 GB / 1.94 GB free] PV /dev/sdb lvm2 [20.00 GB] PV /dev/sdc lvm2 [50.00 GB] PV /dev/sdd lvm2 [50.00 GB]
16
NovaLug May 2008NovaLug May 2008 For NovaLug An LVM Introduction 16 Demo: Physical Volume Details # pvdisplay /dev/sdc --- NEW Physical volume --- PV Name /dev/sdc VG Name PV Size 50.00 GB Allocatable NO PE Size (KByte) 0 Total PE 0 Free PE 0 Allocated PE 0 PV UUID 4vqNKs-DWDn-IsQc-3LkC-mWCI- KKGT-W5kfBE
17
NovaLug May 2008NovaLug May 2008 For NovaLug An LVM Introduction 17 Volume Groups ➲ Groups physical volumes together (whole disks or partitions). Conceptually, this is the hard drive ➲ # vgs List volume groups ➲ # vgscan Scan system for volume groups ➲ # vgcreate Create a volume group ➲ # vgremove Delete/remove a volume group ➲ Lots more utils – expansion, merge, split etc.
18
NovaLug May 2008NovaLug May 2008 For NovaLug An LVM Introduction 18 Example: Setup volume groups # vgcreate vgora /dev/sdb Volume group "vgora" successfully created # vgcreate vgdata /dev/sdc /dev/sdd Volume group "vgdata" successfully created # vgs VG #PV #LV #SN Attr VSize VFree vgdata 2 0 0 wz--n- 99.99G 99.99G vgora 1 0 0 wz--n- 20.00G 20.00G vgsys 1 6 0 wz--n- 19.88G 1.94G # vgscan Reading all physical volumes. This may take a while... Found volume group "vgdata" using metadata type lvm2 Found volume group "vgora" using metadata type lvm2 Found volume group "vgsys" using metadata type lvm2
19
NovaLug May 2008NovaLug May 2008 For NovaLug An LVM Introduction 19 Example: Volume Group Details # vgdisplay vgdata --- Volume group --- VG Name vgdata System ID Format lvm2 Metadata Areas 2 Metadata Sequence No 7 VG Access read/write VG Status resizable MAX LV 0 Cur LV 2 Open LV 1 Max PV 0 Cur PV 2 Act PV 2 VG Size 99.99 GB PE Size 4.00 MB Total PE 25598 Alloc PE / Size 17920 / 70.00 GB Free PE / Size 7678 / 29.99 GB VG UUID Dbtqdw-HYHR-ZnG9-HcAZ-MPo2- MSRU-QUjcEX
20
NovaLug May 2008NovaLug May 2008 For NovaLug An LVM Introduction 20 Commands: Logical Volumes ➲ Structure to store data. Takes the direct place of partitions ➲ # lvs List existing volumes ➲ # lvscan Scan for available volumes ➲ # lvdisplay Display volume details ➲ # lvcreate Create new volume ➲ # lvextend Expand existing volume size ➲ # lvreduce Reduce existing volume size ➲ # lvchange Change existing volume attributes
21
NovaLug May 2008NovaLug May 2008 For NovaLug An LVM Introduction 21 Example: Logical Volume # lvcreate -L 10G -n lvu01 vgora Logical volume "lvu01" created # lvcreate -L 60G -n lvdata vgdata Logical volume "lvdata" created # lvs LV VG Attr LSize Origin Snap% Move Log Copy% lvdata vgdata -wi-a- 60.00G lvu01 vgora -wi-a- 10.00G lvhome vgsys -wi-ao 4.00G lvroot vgsys -wi-ao 2.00G lvswap vgsys -wi-ao 1.94G lvtmp vgsys -wi-ao 2.00G lvusr vgsys -wi-ao 4.00G lvvar vgsys -wi-ao 4.00G
22
NovaLug May 2008NovaLug May 2008 For NovaLug An LVM Introduction 22 Logical Volume Details # lvdisplay --- Logical volume --- LV Name /dev/vgdata/lvdata VG Name vgdata LV UUID Aj60Fh-uPZO-c2er-rSUH-xqMt- 38Pu-gqAt7p LV Write Access read/write LV Status available # open 0 LV Size 60.00 GB Current LE 15360 Segments 2 Allocation inherit Read ahead sectors 0 Block device 253:7
23
NovaLug May 2008NovaLug May 2008 For NovaLug An LVM Introduction 23 How is it allocated? ➲ Volume is allocated in “blocks” called extents ➲ Extents does not have to be allocated contiguously ➲ Adding more – or subtracting space, is a matter of moving blocks/extents around ➲ If reducing the size of a volume, remember to reduce the content FIRST (reduce the size of the file system).
24
NovaLug May 2008NovaLug May 2008 For NovaLug An LVM Introduction 24 Snapshots ➲ LVM1 supported read-only snapshots (2.4 kernels) ➲ LVM2 support RW snapshots ➲ Snapshots store changes. A snapshot of a 50GB disk takes almost no space if there are no changes. ➲ Changes to the original disk causes more data allocation to store “the difference” ➲ Changes are allowed directly onto the snapshot – will not effect original volume
25
NovaLug May 2008NovaLug May 2008 For NovaLug An LVM Introduction 25 Mirroring and Striping ➲ One or more mirror copies of a logical volume ➲ This is NOT real raid – the mirror copy may be on the same disk. There are no “degraded” functionality with LVM. ➲ Mirror helps if there are read/write errors on the disk. Does not help if the disk is lost. ➲ Raid 0 – stripping is supported. Goes across physical volumes
26
NovaLug May 2008NovaLug May 2008 For NovaLug An LVM Introduction 26 Device Mapping ➲ Use # dmsetup ls to view the actual device mapping for each lvm ➲ Common implementation is /dev/ /. ➲ Alternative /dev/mapper/ -
27
NovaLug May 2008NovaLug May 2008 For NovaLug An LVM Introduction 27 Metadata maintenance ➲ Is stored on the physical volume ➲ And in /etc/lvm ➲ /etc/lvm/lvm.conf is global defaults to control LVM behaviour (normally no change needed) ➲ # vgcfgbackup writes metadata to /etc/lvm/backup/ ➲ # vgcfgrestore restores visa versa ➲ When backing up your system, remember: partition table layout and LVM metadata must be easily accessible on “pre- restore” ➲ UUID glues things together – device names do not
28
NovaLug May 2008NovaLug May 2008 For NovaLug An LVM Introduction 28 Demo ➲ Use desktop with 3 blank drives ➲ Create/allocate physical volumes ➲ Create multiple volume groups ➲ Add logical volumes ➲ How to query/view LVM information
29
NovaLug May 2008NovaLug May 2008 For NovaLug An LVM Introduction 29 More Demo – if time allows ➲ Adding space - expansion ➲ Snapshots and backups ➲ Striping volumes ➲ Mirroring volumes ➲ LVM configuration files ➲ LVM recovery ➲ How to build on software raid
30
NovaLug May 2008NovaLug May 2008 For NovaLug An LVM Introduction 30 Questions?
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.