home       inleiding       sysadmin       services       links       bash       werk       nothing      

logical volume manager

We gebruiken een ubuntu16.04 virtuele machine en plaatsen er 3 extra harddisks bij, 'dynamic' grootte 80GB.
 

  1. inventaris
     
    Na opstarten en inloggen kijken we na in de server of hij de schijven herkent:
     
    $ sudo fdisk -l   ( ... of makkelijker met  lsblk)
    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

     

  2. 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 met gdisk.
     
    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.
     

  3. Physical Volumes aanmaken
     
    We maken de drie partities klaar voor gebruik met LVM door ze te taggen met pvcreate:
    $ 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

     

  4. 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
     
  5. logical volumes
     
    In onze volume group 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
    ``` 
  6. 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 ..

  7. 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    

     

  8. 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
  9. volume uitbreiden
     
    lvextend:
    A logical volume can be extended using the lvextend 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 to lvextend is to use the lvresize command:
     
    lvresize --size +40G /dev/vg0/foo
     
    or:
     
    lvresize --size 120G /dev/vg0/foo
     
    An ext4 file system may be grown while mounted using the resize2fs command:
     
    # resize2fs /dev/mapper/blah
     
    voorbeeld: $ sudo resize2fs /dev/mapper/balu--vg-eenbeer
     
    An XFS file system may be grown while mounted using the xfs_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