Difference between revisions of "LVM"
Jump to navigation
Jump to search
(→Create) |
(→Remove) |
||
(5 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
Notes on LVM |
Notes on LVM |
||
⚫ | |||
⚫ | |||
⚫ | |||
# VG commands => virtual groups |
# VG commands => virtual groups |
||
# LV commands => logical volumes |
# LV commands => logical volumes |
||
⚫ | |||
Create a bunch of small (100MB) virtual disks for use with LVM. |
Create a bunch of small (100MB) virtual disks for use with LVM. |
||
Line 66: | Line 67: | ||
== Manage == |
== Manage == |
||
== |
=== Move disk === |
||
Goal: move content of loop1 to loop5 |
|||
#pvs |
|||
PV VG Fmt Attr PSize PFree |
|||
'''/dev/loop1 lpic lvm2 a- 99.00M 0''' |
|||
/dev/loop2 lpic lvm2 a- 99.00M 0 |
|||
/dev/loop3 lpic lvm2 a- 99.00M 41.00M |
|||
/dev/loop4 lpic lvm2 a- 99.00M 99.00M |
|||
'''/dev/loop5 lpic lvm2 a- 99.00M 99.00M''' |
|||
# pvmove /dev/loop1 /dev/loop5 |
|||
/dev/loop1: Moved: 100.0% |
|||
# pvs |
|||
PV VG Fmt Attr PSize PFree |
|||
'''/dev/loop1 lpic lvm2 a- 99.00M 99.00M''' |
|||
/dev/loop2 lpic lvm2 a- 99.00M 0 |
|||
/dev/loop3 lpic lvm2 a- 99.00M 41.00M |
|||
/dev/loop4 lpic lvm2 a- 99.00M 99.00M |
|||
'''/dev/loop5 lpic lvm2 a- 99.00M 0''' |
|||
=== Remove physical disk === |
|||
Goal: remove /dev/loop4 from VG ''lpic'' |
|||
# pvs |
|||
PV VG Fmt Attr PSize PFree |
|||
/dev/loop1 lpic lvm2 a- 99.00M 99.00M |
|||
/dev/loop2 lpic lvm2 a- 99.00M 0 |
|||
/dev/loop3 lpic lvm2 a- 99.00M 41.00M |
|||
'''/dev/loop4 lpic lvm2 a- 99.00M 99.00M''' |
|||
/dev/loop5 lpic lvm2 a- 99.00M 0 |
|||
# vgreduce lpic /dev/loop4 |
|||
Removed "/dev/loop4" from volume group "lpic" |
|||
# pvremove /dev/loop4 |
|||
Labels on physical volume "/dev/loop4" successfully wiped |
|||
# pvs |
|||
PV VG Fmt Attr PSize PFree |
|||
/dev/loop1 lpic lvm2 a- 99.00M 99.00M |
|||
/dev/loop2 lpic lvm2 a- 99.00M 0 |
|||
/dev/loop3 lpic lvm2 a- 99.00M 41.00M |
|||
/dev/loop5 lpic lvm2 a- 99.00M 0 |
|||
=== Add physical disk === |
|||
# pvs |
|||
PV VG Fmt Attr PSize PFree |
|||
/dev/loop1 lpic lvm2 a- 99.00M 99.00M |
|||
/dev/loop2 lpic lvm2 a- 99.00M 0 |
|||
/dev/loop3 lpic lvm2 a- 99.00M 41.00M |
|||
/dev/loop5 lpic lvm2 a- 99.00M 0 |
|||
# pvcreate /dev/loop4 |
|||
Physical volume "/dev/loop4" successfully created |
|||
# pvs |
|||
PV VG Fmt Attr PSize PFree |
|||
/dev/loop1 lpic lvm2 a- 99.00M 99.00M |
|||
/dev/loop2 lpic lvm2 a- 99.00M 0 |
|||
/dev/loop3 lpic lvm2 a- 99.00M 41.00M |
|||
'''/dev/loop4 lvm2 -- 100.00M 100.00M''' |
|||
/dev/loop5 lpic lvm2 a- 99.00M 0 |
|||
# vgextend lpic /dev/loop4 |
|||
Volume group "lpic" successfully extended |
|||
# pvs |
|||
PV VG Fmt Attr PSize PFree |
|||
/dev/loop1 lpic lvm2 a- 99.00M 99.00M |
|||
/dev/loop2 lpic lvm2 a- 99.00M 0 |
|||
/dev/loop3 lpic lvm2 a- 99.00M 41.00M |
|||
/dev/loop4 lpic lvm2 a- 99.00M 99.00M |
|||
/dev/loop5 lpic lvm2 a- 99.00M 0 |
Latest revision as of 15:49, 11 February 2011
Notes on LVM
- PV commands => working on physical volume aka disk
- VG commands => virtual groups
- LV commands => logical volumes
Create
Create a bunch of small (100MB) virtual disks for use with LVM.
DISK_DIR=/var/tmp/disks mkdir -p ${DISK_DIR} && for i in 1 2 3 4 5; do dd if=/dev/zero of=${DISK_DIR}/disk${i} bs=100M count=1 && losetup /dev/loop${i} ${DISK_DIR}/disk${i} && pvcreate /dev/loop${i} done
Output should look like this
1+0 records in 1+0 records out 104857600 bytes (105 MB) copied, 0.50751 s, 207 MB/s Physical volume "/dev/loop1" successfully created 1+0 records in 1+0 records out 104857600 bytes (105 MB) copied, 1.94502 s, 53.9 MB/s Physical volume "/dev/loop2" successfully created 1+0 records in 1+0 records out 104857600 bytes (105 MB) copied, 4.12227 s, 25.4 MB/s Physical volume "/dev/loop3" successfully created 1+0 records in 1+0 records out 104857600 bytes (105 MB) copied, 1.51487 s, 69.2 MB/s Physical volume "/dev/loop4" successfully created 1+0 records in 1+0 records out 104857600 bytes (105 MB) copied, 3.88262 s, 27.0 MB/s Physical volume "/dev/loop5" successfully created
Confirm the output
# pvs PV VG Fmt Attr PSize PFree /dev/loop1 lvm2 -- 100.00M 100.00M /dev/loop2 lvm2 -- 100.00M 100.00M /dev/loop3 lvm2 -- 100.00M 100.00M /dev/loop4 lvm2 -- 100.00M 100.00M /dev/loop5 lvm2 -- 100.00M 100.00M
Create Virtual Group
# vgcreate -s 1024K lpic /dev/loop[1-5] Volume group "lpic" successfully created # pvs PV VG Fmt Attr PSize PFree /dev/loop1 lpic lvm2 a- 99.00M 99.00M /dev/loop2 lpic lvm2 a- 99.00M 99.00M /dev/loop3 lpic lvm2 a- 99.00M 99.00M /dev/loop4 lpic lvm2 a- 99.00M 99.00M /dev/loop5 lpic lvm2 a- 99.00M 99.00M /dev/sda2 VolGroup00 lvm2 a- 37.12G 0 # vgs VG #PV #LV #SN Attr VSize VFree lpic 5 0 0 wz--n- 495.00M 495.00M
Create Logical Volume
# lvcreate -n lv_lpic -L 256M lpic Logical volume "lv_lpic" created # lvs LV VG Attr LSize Origin Snap% Move Log Copy% Convert lv_lpic lpic -wi-a- 256.00M
Manage
Move disk
Goal: move content of loop1 to loop5
#pvs PV VG Fmt Attr PSize PFree /dev/loop1 lpic lvm2 a- 99.00M 0 /dev/loop2 lpic lvm2 a- 99.00M 0 /dev/loop3 lpic lvm2 a- 99.00M 41.00M /dev/loop4 lpic lvm2 a- 99.00M 99.00M /dev/loop5 lpic lvm2 a- 99.00M 99.00M # pvmove /dev/loop1 /dev/loop5 /dev/loop1: Moved: 100.0% # pvs PV VG Fmt Attr PSize PFree /dev/loop1 lpic lvm2 a- 99.00M 99.00M /dev/loop2 lpic lvm2 a- 99.00M 0 /dev/loop3 lpic lvm2 a- 99.00M 41.00M /dev/loop4 lpic lvm2 a- 99.00M 99.00M /dev/loop5 lpic lvm2 a- 99.00M 0
Remove physical disk
Goal: remove /dev/loop4 from VG lpic
# pvs PV VG Fmt Attr PSize PFree /dev/loop1 lpic lvm2 a- 99.00M 99.00M /dev/loop2 lpic lvm2 a- 99.00M 0 /dev/loop3 lpic lvm2 a- 99.00M 41.00M /dev/loop4 lpic lvm2 a- 99.00M 99.00M /dev/loop5 lpic lvm2 a- 99.00M 0 # vgreduce lpic /dev/loop4 Removed "/dev/loop4" from volume group "lpic" # pvremove /dev/loop4 Labels on physical volume "/dev/loop4" successfully wiped # pvs PV VG Fmt Attr PSize PFree /dev/loop1 lpic lvm2 a- 99.00M 99.00M /dev/loop2 lpic lvm2 a- 99.00M 0 /dev/loop3 lpic lvm2 a- 99.00M 41.00M /dev/loop5 lpic lvm2 a- 99.00M 0
Add physical disk
# pvs PV VG Fmt Attr PSize PFree /dev/loop1 lpic lvm2 a- 99.00M 99.00M /dev/loop2 lpic lvm2 a- 99.00M 0 /dev/loop3 lpic lvm2 a- 99.00M 41.00M /dev/loop5 lpic lvm2 a- 99.00M 0 # pvcreate /dev/loop4 Physical volume "/dev/loop4" successfully created # pvs PV VG Fmt Attr PSize PFree /dev/loop1 lpic lvm2 a- 99.00M 99.00M /dev/loop2 lpic lvm2 a- 99.00M 0 /dev/loop3 lpic lvm2 a- 99.00M 41.00M /dev/loop4 lvm2 -- 100.00M 100.00M /dev/loop5 lpic lvm2 a- 99.00M 0 # vgextend lpic /dev/loop4 Volume group "lpic" successfully extended # pvs PV VG Fmt Attr PSize PFree /dev/loop1 lpic lvm2 a- 99.00M 99.00M /dev/loop2 lpic lvm2 a- 99.00M 0 /dev/loop3 lpic lvm2 a- 99.00M 41.00M /dev/loop4 lpic lvm2 a- 99.00M 99.00M /dev/loop5 lpic lvm2 a- 99.00M 0