18
LVM VIMAL THAMIZHARASAN SENIOR LINUX TRAINER MAZENET SOLUTION-CHENNAI,T-NAGAR.

Red Hat - LVM - Mazenet Solution

Embed Size (px)

Citation preview

Page 1: Red Hat - LVM - Mazenet Solution

LVM

VIMAL THAMIZHARASANSENIOR LINUX TRAINER

MAZENET SOLUTION-CHENNAI,T-NAGAR.

Page 2: Red Hat - LVM - Mazenet Solution

Agenda

• Some basic background about Files and Filesystems under Linux

• What is LVM and why should I use it• How to create a simple LVM environment

Page 3: Red Hat - LVM - Mazenet Solution

What is Logical Volume Management?

• Software that allows the user to edit the storage configuration without

• manipulating the actual hardware and vice versa.

Page 4: Red Hat - LVM - Mazenet Solution

When to and not use LVMs• USE WHEN:

-Lots of DISKs and you need to simplify-Need flexiblity of file system expansion-When you want to learn an advanced storage

management topic• DON'T USE:

-SINGLE Partition Environments-If Command line (CLI) is scary to you-Without access to a System Administrator :

Page 5: Red Hat - LVM - Mazenet Solution

How Does LVM Work?

The LVM hides information

about where information is

stored, on which hardware,

and where exactly on that

hardware from the entire

Operating System allowing

it to manipulate theconfiguration of the

storagecapacities.

Page 6: Red Hat - LVM - Mazenet Solution

Layers to make it easier

• Layers in a typical system (before LVM)

Files/Dirs

Filesystems

Partitions Disks

Page 7: Red Hat - LVM - Mazenet Solution

What is a Disk?• The harddisk is the only Hardware piece we're

going to talk about here• It has various techie things in it:

- Cylinders, Heads, Sectors, mbr, partitions- It's own cpu, cache, firmware etc.

• but for this discussion a hard disk on a modern system can be seen as one continuous row of logical blocks.

• Typical disk names in Linux are hda, sda,vda.

Page 8: Red Hat - LVM - Mazenet Solution

Partitions• To store data on a disk this continuous row of logical blocks needs to be cut in sections called Partitions.• The original IBM PC from 1981 only had 4 primary

partitions.• This was later improved by adding extended partitions• Normally managed by fdisk or some graphical partition/volume manager.• One partition must be a continuous chunk of blocks .

Page 9: Red Hat - LVM - Mazenet Solution

Filesystems• Filesystems are a fancy way to hold together a group of

files and directories.• Without LVM one filesystem=one partition.• Common File Systems:

-In the Windows World:FAT (dos) FAT12/16/32NTFS

-In LinuxExt2/3, Reiserfs,jfs,xfsAnd many many more

Page 10: Red Hat - LVM - Mazenet Solution

Files on a linux (and unix) system

• At last we are at the top, the user level• Within User Level we have

–Files–Directories–Filesystems

Files Hold Data• Directories hold files and directories• Filesystems holds directories and files• Mount points hold Filesystems

Page 11: Red Hat - LVM - Mazenet Solution

Time for volumes

Volumes

Page 12: Red Hat - LVM - Mazenet Solution

• By adding another layer between partitions and filesystems we break the OneFS=OnePartition relation

• This have many advantages• 2 special reasons: –Can carve out non continues filesystems –Can add disks partitions together so they look like one big disk

Page 13: Red Hat - LVM - Mazenet Solution

Commands used in LVM Directory and Files

Directories and Files

## Directories/etc/lvm                    - default lvm directory location /etc/lvm/backup         - where the automatic backups go /etc/lvm/cache          - persistent filter cache /etc/lvm/archive        - where automatic archives go after a volume group change

/var/lock/lvm             - lock files to prevent metadata corruption # Files /etc/lvm/lvm.conf       - main lvm configuration file $HOME/.lvm               - lvm history

Physical Volumes

display

pvdisplay -v pvs -vpvs -a

Page 14: Red Hat - LVM - Mazenet Solution

Commands used in LVM adding

pvcreate /dev/sdb1## Create physical volume with specific UUID, used to recover volume groups (see miscellaneous section) pvcreate --uuid <UUID> /dev/sdb1

removing pvremove /dev/sdb1

moving

pvmove -v /dev/sdb2 /dev/sdb3 Note: moves any used extents from this volume to another volume, in readiness to remove that volume. However you cannot use this on mirrored volumes, you must convert back to non-mirror using "lvconvert -m 0"

Volume Groups

creating

vgcreate VolData00 /dev/sdb1 /dev/sdb2 /dev/sdb3vgcreate VolData00 /dev/sdb[123]vgcreate VolData00 -s 32 /dev/sdb1 Common Attributes that you may want to use:-l  maximum logical volumes-p maximum physical volumes-s physical extent size (default is 4MB)-A autobackup

Page 15: Red Hat - LVM - Mazenet Solution

Commands used in LVM extending vgextend VolData00 /dev/sdb3

reducing vgreduce VolData00 /dev/sdb3

vgreduce --removemissing --force VolData00

removing

vgremove VolData00

Common Attributes that you may want to use:

-f force the removal of any logical volumes

merging

# the old volumes group will be merged into the new volume group vgmerge New_Vol_Group Old_Vol_Group

Note: you must unmount any fielsystems and deactivate the vg that is being merged "vgchange -a n <vg>", then you can activiate it again afterwards "vgchange -a y <vg>", then perform a vgscan, dont forget to backup the configuration

spliting vgsplit Old_Vol_Group New_Vol_Group [physical volumes] [-n logical volume name]

Page 16: Red Hat - LVM - Mazenet Solution

Commands used in LVM Logical Volumes

display

lvdisplay -v lvdisplay --maps      display mirror volumeslvs -vlvs -a -o +devices ## lvs commands for mirror volumes lvs -a -o +deviceslvs -a -o +seg_pe_ranges --segments

## Stripe size lvs -v --segmentslvs -a -o +stripes,stripesize  

scanning lvscan -v lvmdiskscan

creating

## plain old volume lvcreate -L 10M VolData00

## plain old volume but with a specific name web01lvcreate -L 10M -n web01 VolData00 ## plain old volume but on a specific disk lvcreate -L 10M VolData00 /dev/sdb1## a striped volume called lvol1 (note the captial i for the stripe size), can use -l (extents) instead of -L lvcreate -i 3 -L 24M -n lvol1 vg01

Page 17: Red Hat - LVM - Mazenet Solution

extending

lvextend -L 20M /dev/VolData00/vol01

Note: you can extend a ext2/ext3 filesystem using the "resize2fs" or "fsadm" command

fsadm resize /dev/VolData01/data01resize2fs -p /dev/mapper/VolData01-data01 [size]

The -p option displays bars of progress while extendingthe filesystem

reducing/resizing

lvreduce -L 5M /dev/VolData00/vol01lvresize -L 5M /dev/VolData00/vol01

Note: rounding will occur when extending and reducing volumes to the next extent (4MB by default), you can use resize2fs or fsadm to shrink the filesystem

fsadm resize /dev/VolData01/data01 [size] resize2fs -p /dev/mapper/VolData01-data01 [size]

removing lvremove /dev/VolData00/vol01

Page 18: Red Hat - LVM - Mazenet Solution

THANK YOU ALL