lvm-raid
lvm-raid
under Linux
1 Preface 3
2 RAID 4
2.2 Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
3.6.4 Outputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
4 Ap pendix 17
1 Preface
This document denotes in short steps how to handle the logical volume manager (LVM)
and software RAID under Linux. It is not a description nor intended to be complete in
any way.
2 RAID
2 RAID
2.2 Notes
The most more complicated RAID Levels are available in hardware only. Linux software
RAID supports at least the levels: 0, 1, 5, 6 and a few more.
This represents ideal values not cared about bottlenecks caused by other components
(CPU, RAM, BUS etc.)
RAID level 0 1 10/01 2 3 4 5 6 Z
AUTOSTART=true
2.5 Test, check and manage the RAID 2 RAID
• monitor with:
# mdadm; dmesg
# mdadm -D /dev/md0
# cat /proc/mdstat
• disassemble a RAID:
# mdadm -S /dev/md0
Assume a system crash and boot a live medium, p.e. the grml-CD (http://grml.org).
To find the RAIDs on the machine use:
# mdadm -D --scan
# fdisk -l /dev/md0
• deliver volume sizes independent from the sizes of the underlying hard drives
Look at the section 3.6.4 for some sample outputs. The most commands accept more
than one device, p.e.
# pvcreate /dev/sdc1
/dev/sdd1
The device names ar not consistent here, but this doesn’t matter.
1. install lvm2
# apt-get install lvm2
# rpm -ivh lvm2-2.02.21-5.el4.x86_64.rpm (the exact version doesn’t
mat-
ter)
# yum install lvm2
2. create partitions
/dev/sdc1 /dev/sdd1
5. create a new Volume Group (VG) named ”vg1” with a Physical Extend (PE) size of
32 Mb and assign the Physical Volume /dev/sdc1 to it and show the volume groups
# vgcreate -s 32M vg1 /dev/sdc1 ; vgdisplay
or, if you want to include all PVs at once:
# vgcreate -s 32M vg1 /dev/sdc1 /dev/sdd1 ; vgdisplay
6. create a new Logical Volume (LV) with name ”lv1” 7.4 GB size in the Volume Group
”vg1” and show it
# lvcreate -L 7.4G -n lv1 vg1 ; lvdisplay /dev/vg1/lv1
or assign the amount of extends as seen in ”vgdisplay" -> "Free PE"
# lvcreate -l 236 -n lv1 vg1 ; lvdisplay /dev/vg1/lv1
Create a new Logical Volume spanned over two Physical Volumes in vg1 - a RAID 0
# lvcreate -n lvstriped -l 236 -i 2 vg1
Two notes:
(A) File systems cannot be modified when they are in use. Boot into single user mode
before changes or reboot the machine without the file system mounted. Don’t forget
to modify /etc/fstab and reboot the machine finally.
(B) If (A) is not possible, keep in mind: NFS caches file system sizes. Restart NFS after
changes and make an exportfs -r.
The procedure:
2. enhance the existing Volume Group ”vg1” and check the amount of new Physical
Extends (p.e.: 430)
# vgextend vg1 /dev/sdd1 ; vgdisplay
3. assign the new, free Physical Extends to the logical volume ”lv1”
# lvextend -l 430 /dev/vg1/lv1 ; lvdisplay
or assign the (additional) amount of space
# lvextend -L +1000M /dev/vg1/lv1 ; lvdisplay
Assume a system crash and boot a live medium, p.e. the grml-CD (http://grml.org).
# pvs
PV VG Fmt Attr PSize PFree
/dev/sda1 vg1 lvm a- 74.50G 0
2
/dev/sdb1 vg1 lvm a- 74.50G 0
2
2. check the logical volume
# lvdisplay vg1
--- Logical volume ---
LV Name /dev/vg1/lv1
V Name vg1
G
LV UUID mmv77R-zrhD-HuO2-CvQq-piys-FFNL-
LV Write Access swiNB2
read/write
LV Status available
# open 0
LV Size 149.00
GB Current LE 4768
Segments 2
Allocation inherit
Read sectors auto
ahead
- currently set to 256
Block device 253:0
# lvremove -f /dev/vg1/lv1
# vgremove /dev/vg1
Move the data from one Physical Volume away to remove the PV. There must be still free
Extends in the volume group.
# pvmove -v /dev/sde1
and take out the cleaned Physical Volume from the Volume Group:
3.5.3 Ma ke a snapshot
The 500Mb is the amount of changed data possible until the snapshot has to be neglected.
3.5 Move or Modify a LVM 3 LOGICAL VOLUME MANAGER - LVM
old machine:
# pvscan
# umount /mnt/vg1/lv1
# vgchange -a n /dev/vg1
# vgexport /dev/vg1
new machine:
vgcreate create a VG
vgdisplay show properties of a VG
vgs report information about VGs
vgchange change properties of a VG
vgremove delete a VG
vgextend add PVs to a VG
vgreduce reduce the size of a VG
vgrename rename a VG
vgexport log off a VG from the system for transfer to other machine(s)
vgimport log on an imported VG
vgsplit split a VG p.e. for export/import
vgmerge concatanate two VG
vgcfgbackup save VG-descriptors into /et c/ lvm/backup
vgcfgrestore restore VG-descriptors from /et c/ lvm/backup
vgck check meta-data of a VG
vgconvert convert meta-data-format from lvm1 to lvm2
vgmknodes restore the VG-directory and the needed device-files
vgscan scan all harddrives for VGs
3.6 LVM commands 3 LOGICAL VOLUME MANAGER - LVM
3.6.4 Outputs
# pvdisplay
--- Physical volume ---
PV Name /dev/hde1
V Name vg1
G
PV Size 74.53 GB / not usable 31.06
Allocatable yes (but full) MB
PE Size (KByte) 32768
Total PE 2384
Free PE 0
Allocated PE 2384
PV UUID cEbIFe-zoEn-WWtX-I9V8-jE3m-GNgj-
IIoYvi
--- Physical volume ---
PV Name /dev/hdg1
V Name vg1
G
PV Size 74.51 GB / not usable 5.46 MB
Allocatable yes (but full)
PE Size (KByte) 32768
Total PE 2384
Free PE 0
Allocated PE 2384
PV UUID TAECKa-CHdC-3N46-CIKF-9muR-qoDI-
Yz2s2T
# open
1
//
LV Size
7.4
GB
3.6 LVM commands 3 LOGICAL VOLUME MANAGER - LVM
Current LE
# vgdisplay 236
--- Volume group ---
//
VG Name vg1
Segments
System ID 2
Format lvm2
Metadata s 2
Area
Metadata ence 1
Sequ
VG Access No read/write
VG Status resizable
MAX LV 0
Cur LV 0
Open LV 0
Ma PV 0
x PV
Cur 2
Act PV 2
VG Size 149.00
GB PE Size 32.00 MB
Total PE 4768
Alloc PE / Size 0/0
Free PE / Size 4768 / 149.00 GB // free physical extends
VG UUID KDXvtE-ID6R-Y2Fg-chg6-OPUl-KjDz-NzMtjI
# lvdisplay
logical extends
Allocation inherit
Read sectors 0
aheaddevice
Block 253:0 // major/minor
// block device
number
4 APPENDIX
4 Ap pendix
http://tldp.org/guides.html http://linuxwiki.de/mdadm
http://www.brandonhutchinson.com/Mounting_a_Linux_LVM_volume
.html http://www.linuxhaven.de/dlhp/HOWTO/DE-LVM-HOWTO-
{1..7}.html
4.2 Sample setup 4 APPENDIX
Figure 3: Sample setup - how RAID and LVM may work together