logical volume manager
We gebruiken een ubuntu16.04 virtuele machine en plaatsen er 3 extra harddisks bij, 'dynamic' grootte 80GB.
- inventaris
Na opstarten en inloggen kijken we na in de server of hij de schijven herkent:
$ sudo fdisk -l
( ... of makkelijker metlsblk
)Disk /dev/sdb: 85.9 GB, 85899345920 bytes ... Disk /dev/sdb doesn't contain a valid partition table Disk /dev/sdc: 85.9 GB, 85899345920 bytes ... Disk /dev/sdc doesn't contain a valid partition table Disk /dev/sdd: 85.9 GB, 85899345920 bytes ... Disk /dev/sdd doesn't contain a valid partition table
- partitionneren
Hoewel het niet noodzakelijk is partities te gebruiken als Physical Volume (de schijf zelf als geheel lukt ook) gaan we op de 3 schijven telkens 1 partitie plaatsen. We willen dit doen metgdisk
.
gdisk
is niet geinstalleerd, dat doen we met:
$ sudo apt-get install gdisk
We hebben straks ook nog lvm2 nodig dus die installeren we ook:
$ sudo apt-get install lvm2
Vervolgens partitionneren we/dev/sdb
:
$ sudo gdisk /dev/sdb
GPT fdisk (gdisk) version 0.8.8 Partition table scan: MBR: not present BSD: not present APM: not present GPT: not present Creating new GPT entries. Command (? for help): n <ENTER> Partition number (1-128, default 1): <ENTER> First sector (34-167772126, default = 2048) or {+-}size{KMGTP}: <ENTER> Last sector (2048-167772126, default = 167772126) or {+-}size{KMGTP}: <ENTER> Current type is 'Linux filesystem' Hex code or GUID (L to show codes, Enter = 8300): L 0700 Microsoft basic data 0c01 Microsoft reserved 2700 Windows RE ... 8200 Linux swap 8300 Linux filesystem 8301 Linux reserved 8302 Linux /home 8400 Intel Rapid Start 8e00 Linux LVM a500 FreeBSD disklabel a501 FreeBSD boot ... ef00 EFI System ef01 MBR partition scheme ef02 BIOS boot partition Press the <Enter> key to see more codes: 8e00 fb00 VMWare VMFS fb01 VMWare reserved fc00 VMWare kcore crash p fd00 Linux RAID Hex code or GUID (L to show codes, Enter = 8300): 8e00 Changed type of partition to 'Linux LVM' Command (? for help): w Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING PARTITIONS!! Do you want to proceed? (Y/N): y OK; writing new GUID partition table (GPT) to /dev/sdb. The operation has completed successfully.
We herhalen dit voor schijven
/dev/sdc
en/dev/sdd
.
- Physical Volumes aanmaken
We maken de drie partities klaar voor gebruik met LVM door ze te taggen metpvcreate
$ sudo pvcreate /dev/sdb1
Physical volume "/dev/sdb1" successfully created
$ sudo pvcreate /dev/sdc1
Physical volume "/dev/sdc1" successfully created
$ sudo pvcreate /dev/sdd1
Physical volume "/dev/sdd1" successfully created
- volume group
We plaatsen alle 3 de physical volumes die we zonet aanmaakten in EEn volume-group:
$ sudo vgcreate balu-vg /dev/sdb1 /dev/sdc1 /dev/sdd1
Volume group "balu-vg" successfully created
- logical volumes
In onze volumegroup die 3 physical volumes overspant, maken we nu een aantal logische volumes:
$ sudo lvcreate --size=100G --name=kanga balu-vg
Logical volume "kanga" created
$ sudo lvcreate --size=20G --name=logs balu-vg
Logical volume "logs" created
$ sudo lvcreate --size=40G --name=people balu-vg
Logical volume "people" created
-
formatteren
We formatteren nu onze volumes ...
sudo mkfs.ext4 /dev/mapper/balu--vg-kanga
sudo mkfs.ext4 /dev/mapper/balu--vg-logs
De devicename van onze volumes is een beetje raar .. - mounten en
/etc/fstab
$ sudo mkdir /mnt/kanga
$ sudo mount /dev/mapper/balu--vg-kanga /mnt/kanga
/etc/fstab
# # kanga # /dev/mapper/balu--vg-kanga /mnt/kanga ext4 defaults 0 0
- volumes op scherm brengen
physical volumes:
$ sudo pvs
PV VG Fmt Attr PSize PFree /dev/sdb1 balu-vg lvm2 a-- 80.00g 0 /dev/sdc1 balu-vg lvm2 a-- 80.00g 39.99g /dev/sdd1 balu-vg lvm2 a-- 80.00g 40.00g
logical volumes:
$ sudo lvs
LV VG Attr LSize Pool Origin Data% Move Log Copy% Convert people balu-vg -wi-a---- 40.00g kanga balu-vg -wi-ao--- 100.00g logs balu-vg -wi-a---- 20.00g
volume group(s):
$ sudo vgdisplay
--- Volume group --- VG Name balu-vg System ID Format lvm2 Metadata Areas 3 Metadata Sequence No 4 VG Access read/write VG Status resizable MAX LV 0 Cur LV 3 Open LV 1 Max PV 0 Cur PV 3 Act PV 3 VG Size 239.99 GiB PE Size 4.00 MiB Total PE 61437 Alloc PE / Size 40960 / 160.00 GiB Free PE / Size 20477 / 79.99 GiB VG UUID Nho1ZM-18gy-auDd-Hesg-ciTF-ri82-aOl7AH
uitgebreid: logical volumes ..
$ sudo lvdisplay
--- Logical volume --- LV Path /dev/balu-vg/kanga LV Name kanga VG Name balu-vg LV UUID VmJffZ-kJZY-26fA-oHkJ-cXGw-EcsY-MPSHKx LV Write Access read/write LV Creation host, time ub14-lvm2, 2016-06-07 13:44:46 +0200 LV Status available # open 1 LV Size 100.00 GiB Current LE 25600 Segments 2 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 252:0 --- Logical volume --- LV Path /dev/balu-vg/logs LV Name logs VG Name balu-vg LV UUID fPyx8x-dPfz-xHV7-y4Mg-90Zc-vprL-SpeeVU LV Write Access read/write LV Creation host, time ub14-lvm2, 2016-06-07 13:44:59 +0200 LV Status available # open 0 LV Size 20.00 GiB Current LE 5120 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 252:1 --- Logical volume --- LV Path /dev/balu-vg/people LV Name ambetantemensen VG Name balu-vg LV UUID IvCDba-jhW1-fK0D-NJDM-yt2i-eKIp-arJu0i LV Write Access read/write LV Creation host, time ub14-lvm2, 2016-06-07 13:45:16 +0200 LV Status available # open 0 LV Size 40.00 GiB Current LE 10240 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 252:2
- volume uitbreiden
lvextend:
A logical volume can be extended using thelvextend
command. You can specify either the amount by which you want to increase the size of the volume:
lvextend --size +40G /dev/vg0/foo
or the final size that you want to achieve:
lvextend --size 120G /dev/vg0/foo
lvresize:
An alternative tolvextend
is to use thelvresize
command:
lvresize --size +40G /dev/vg0/foo
or:
lvresize --size 120G /dev/vg0/foo
EXT4
An ext4 file system may be grown while mounted using theresize2fs
command:
# resize2fs /dev/mapper/blah
voorbeeld:$ sudo resize2fs /dev/mapper/balu--vg-eenbeer
XFS
An XFS file system may be grown while mounted using thexfs_growfs
command:
# xfs_growfs /mount/point
voorbeeld:$ sudo xfs_growfs /dev/mapper/balu--vg-mowgli
of als de size bekend is in blocks met ..
# xfs_growfs /mount/point -D size
BTRFS
A btrFS file system may be grown while mounted using thebtrfs filesystem resize
command:
$ sudo lvextend /dev/mapper/kroko_vg-butter --size +100G
Size of logical volume kroko_vg/butter changed from 750.00 GiB (192000 extents) to 850.00 GiB (217600 extents).
Logical volume butter successfully resized.
$ sudo btrfs filesystem resize 850G /home/mountainview/butter
$ df -h
Filesystem Size Used Avail Use% Mounted on /dev/sda1 20G 2.0G 17G 11% / ... /dev/mapper/kroko_vg-butter 850G 17M 848G 1% /home/mountainview/butter