files to simulate harddisks in LINUX, this way you can learn how it works without the need of real harddisks.
LVM is very usefull because you can join many harddisks into a virtual device (also known as Logical Volume), that will appear on /dev/volume_group_name/logical_volume_name that will contains the sum of the all harddisks spaces, so you don't need to have a mounting point for each harddisk. LVM also allows you to add news harddisks to the volume group and resize the space on the fly.
CREATING THE LOGICAL VOLUME
1) Create the fake disk1 and map to /dev/loop1 (to simulate a harddisk)
# dd if=/dev/zero of=fakedisk1 bs=1M count=100
# losetup /dev/loop1 fakedisk1
Now fakedisk1 and /dev/loop1 is the same thing, but /dev/loop1 will looks like a harddisk device to Linux.
2) Create fake disk2 and map to /dev/loop2 (to simulate another harddisk)
# dd if=/dev/zero of=fakedisk2 bs=1M count=100
# losetup /dev/loop2 fakedisk2
3) Creating a PV (Physical Volume), this command destroys any data on /dev/loop1 (fakedisc1) and /dev/loop2 (fakedisck2), but they are already empty files, so don't worry. In a real disk you must take care. This command format the disks so can be used with LVM.
# pvcreate /dev/loop1
# pvcreate /dev/loop2
4) Create the VG (Volume Group)
# vgcreate testVG /dev/loop1 /dev/loop2
5) Create the Logical Volume (LV) using all the harddisks free spaces:
# lvcreate -l 100%FREE -n testLV testVG
6) Format the LV (Logical Volume) with any filesystem you like
Example, formatting with ext4 filesystem
# mkfs.ext4 /dev/testVG/testLV
7) Mount the filesystem
# mkdir /mnt/testlvm
# mount /dev/testVG/testLV /mnt/testlvm
8) Show the mounting point
# df
Sist. Arq. Tam Usad
/dev/mapper/testVG-testLV 188M 9.8M 178M 6% /mnt/testlvm
VERIFYING LVM INFORMATION
# Show the Physical Volumes (PV) and wich group belongs:
# pvdisplay
--- Physical volume ---
PV Name /dev/loop1
VG Name testVG
PV Size 100.00 MiB / not usable 4.00 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 24
Free PE 0
Allocated PE 24
PV UUID vV9Pq0-XfD1-TYZU-Vd9c-tLC5-zYhc-0vP1ah
--- Physical volume ---
PV Name /dev/loop2
VG Name testVG
PV Size 100.00 MiB / not usable 4.00 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 24
Free PE 0
Allocated PE 24
PV UUID EPo5Bj-bgVL-79dQ-IhzB-pzEK-f1IR-3sX0Vz
# Show the Volume Group (VG) detailed information:
  # vgdisplay
  --- Volume group ---
  VG Name               testVG
  System ID
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  2
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                1
  Open LV               1
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               192.00 MiB
  PE Size               4.00 MiB
  Total PE              48
  Alloc PE / Size       48 / 192.00 MiB
  Free  PE / Size       0 / 0
  VG UUID               k4JsiS-vE1X-pt5B-rDb7-MXdz-J581-WpFd4q
# Show Logical Volume (LV) information:
  # lvdisplay
https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/4/html/Cluster_Logical_Volume_Manager/LVM_examples.html#vol_create_ex
  --- Logical volume ---
  LV Path                /dev/testVG/testLV
  LV Name                testLV
  VG Name                testVG
  LV UUID                vtJOn2-Od3X-M8O2-0iIB-arE6-CHiG-V1ZYtT
  LV Write Access        read/write
  LV Creation host, time aegeus, 2016-06-06 19:38:41 -0300
  LV Status              available
  # open                 1
  LV Size                192.00 MiB
  Current LE             48
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           254:0
ADDING A NEW DISK TO THE VOLUME GROUP
1) Create a third fake disk:
# dd if=/dev/zero of=fakedisk3 bs=1M count=100
2) Create the Physical Volume
3) Add the new disk to the existing Volume Group
# vgextend testVG /dev/loop3
4) Verify the unallocated free space in volume group:
# pvscan
# dd if=/dev/zero of=fakedisk3 bs=1M count=100
  # losetup /dev/loop3 fakedisk3
  # pvcreate /dev/loop3
# vgextend testVG /dev/loop3
4) Verify the unallocated free space in volume group:
# pvscan
  PV /dev/loop1   VG testVG   lvm2 [96.00 MiB / 0    free]
  PV /dev/loop2   VG testVG   lvm2 [96.00 MiB / 0    free]
  PV /dev/loop3   VG testVG   lvm2 [96.00 MiB / 96.00 MiB free]
  Total: 3 [288.00 MiB] / in use: 3 [288.00 MiB] / in no VG: 0 
5) Increase the logical volume space: 
  # lvextend /dev/testVG/testLV /dev/loop3
6) Verify there is no more free space:
  # pvscan
  PV /dev/loop1   VG testVG   lvm2 [96.00 MiB / 0    free]
  PV /dev/loop2   VG testVG   lvm2 [96.00 MiB / 0    free]
  PV /dev/loop3   VG testVG   lvm2 [96.00 MiB / 0    free]
7) Expand the filesystem
  # resize2fs /dev/testVG/testLV
8) Verify that your partition now have more free space:
# df
Sist. Arq.                 Tam    Usad    Dispon. Uso% Montado em
/dev/mapper/testVG-testLV  279M   6.1M    259M    3% /mnt/testlvm
Nenhum comentário:
Postar um comentário