Site Tools


linux:general:lvm

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
linux:general:lvm [2019/01/30 12:08] lunetikklinux:general:lvm [2020/11/16 17:39] (current) lunetikk
Line 35: Line 35:
 <code> <code>
 pvcreate /dev/sdb1 pvcreate /dev/sdb1
-vgcreate data /dev/sdb1 +vgcreate datavg /dev/sdb1 
-lvcreate -l 100%FREE -n backup data +lvcreate -l 100%FREE -n backuplv datavg 
-mkfs.ext3 -Ldata /dev/data/backup  +mkfs.ext3 -Lbackup /dev/datavg/backuplv  
-#mkfs.xfs -Ldata /dev/data/backup+#mkfs.xfs -Lbackup /dev/datavg/backuplv
 vi /etc/fstab vi /etc/fstab
-/dev/mapper/data-backup /data                    ext3     defaults        0 0+/dev/mapper/datavg-backuplv /data                    ext3     defaults        0 0 
 +</code> 
 + 
 +=== Extend Physical Volume (PV) === 
 + 
 +Get the "PV Name"/ Partition via 
 +<code>pvdisplay 
 + 
 +  --- Physical volume --- 
 +  PV Name               /dev/sdc1 
 +  VG Name               datavg 
 +  PV Size               <600.00 GiB / not usable 2.00 MiB 
 +... 
 +</code> 
 + 
 +(Resize VMDK to 1,3TB) Check if your disk resize has already been recognized via  
 +<code>cat /proc/partitions 
 + 
 +major minor  #blocks  name 
 +... 
 +         32  629145600 sdc 
 +         33  629144576 sdc1 
 +... 
 +</code> 
 + 
 +sdc is not 1,3TB, so get the scsi target via 
 +<code>lsscsi -v 
 + 
 +... 
 +[2:0:0:0]    disk    VMware   Virtual disk     1.0   /dev/sdc 
 +  dir: /sys/bus/scsi/devices/2:0:0: [/sys/devices/pci0000:00/0000:00:17.0/0000:13:00.0/host2/target2:0:0/2:0:0:0] 
 +... 
 +</code> 
 + 
 +Then rescan the adapter 
 +<code>echo 1 > /sys/class/scsi_disk/2\:0\:0\:0/device/rescan</code> 
 + 
 +The OS now knows that the disk has 1,3TB 
 +<code>cat /proc/partitions 
 + 
 +major minor  #blocks  name 
 +... 
 +         32 1395864371 sdc 
 +         33  629144576 sdc1 
 +... 
 +</code> 
 + 
 +Resize the partition (see Create new Physical Volume (PV))\\ 
 +The partitiontable might have an old state, to refresh it try the following commands 
 +<code>partprobe 
 + 
 +kpartx -a /dev/sdc 
 + 
 +partx -a /dev/sdc 
 +</code> 
 +Looking at /proc/partitions should now list sdc and sdc1 with 1,3TB, if not you should restart your VM to refresh the table.\\ 
 + 
 +If both sdc and sdc1 are up to date, resize the PV 
 +<code>pvresize -v -d /dev/sdc1 
 + 
 +    Archiving volume group "datavg" metadata (seqno 7). 
 +    Resizing volume "/dev/sdc1" to 2791726694 sectors. 
 +    Resizing physical volume /dev/sdc1 from 153599 to 340786 extents. 
 +    Updating physical volume "/dev/sdc1" 
 +    Creating volume group backup "/etc/lvm/backup/datavg" (seqno 8). 
 +  Physical volume "/dev/sdc1" changed 
 +  1 physical volume(s) resized or updated / 0 physical volume(s) not resized 
 +</code> 
 + 
 +pvdisplay and vgdisplay are now resized 
 +<code>pvdisplay 
 + 
 + --- Physical volume --- 
 +  PV Name               /dev/sdc1 
 +  VG Name               datavg 
 +  PV Size               <1.30 TiB / not usable <2.80 MiB 
 + 
 + 
 +vgdisplay 
 + 
 +  --- Volume group --- 
 +  VG Name               datavg 
 +  ... 
 +  VG Size               <1.30 TiB
 </code> </code>
  
 === Extend Logical Volume (LV) === === Extend Logical Volume (LV) ===
  
-Create a new partition for free space (example above)\\ +Extend the disk (PV/VG, example above)\\ 
-Then extend the LV+Then extend the LV (100% is the full VG, check the "Other commands"-section for other parameters)
 <code> <code>
-pvcreate /dev/sdb1 
-vgextend data /dev/sdb1 
 lvextend -l +100%FREE /dev/data/backup      lvextend -l +100%FREE /dev/data/backup     
 +#if ext3/4 use
 resize2fs /dev/data/backup resize2fs /dev/data/backup
 +#if xfs use
 +xfs_growfs /dev/data/backup
 </code> </code>
  
Line 72: Line 156:
 |  lvdisplay    show all LVs  |\\ |  lvdisplay    show all LVs  |\\
 |  vgchange -ay <VGNAME>  |  activate LV  |\\ |  vgchange -ay <VGNAME>  |  activate LV  |\\
 +|  vgextend datavg /dev/sdd  |  add disk sdd (unpartitioned) to VG datavg  |\\
 |  lvextend -L+5G /dev/data/backup  |  extend by 5GB  |\\ |  lvextend -L+5G /dev/data/backup  |  extend by 5GB  |\\
 +|  lvextend -L 10G /dev/data/backup  |  extend to 10GB total  |\\
 +|  lvcreate -L20G -n backuplv datavg  |  create LV with 20GB total  |\\
 +|  lvresize -r -L+5G /dev/data/backup  |  extend by 5GB and do resize2fs/ xfs_growfs  |\\
  
 === Useful links === === Useful links ===
Line 83: Line 171:
 === Cant mount a logical volume === === Cant mount a logical volume ===
  
-== Description ==+__**Description**__
  
 Mounting the device leads to the following error Mounting the device leads to the following error
Line 96: Line 184:
 </code> </code>
  
-== Reason ==+__**Reason**__
  
 Its deactivated. Its deactivated.
Line 106: Line 194:
 </code> </code>
  
-== Fix ==+__**Fix**__
  
 Run the following command to activate it Run the following command to activate it
Line 114: Line 202:
  
 <code>mount <PATH></code> <code>mount <PATH></code>
 +
 \\ \\
 +
 +=== New added disk doesnt appear in /proc/partitions ===
 +
 +__**Description**__
 +
 +After adding a new disk to your VM the disk doesnt appear in /proc/partition
 +
 +__**Reason**__
 +
 +The VM didnt rescan the scsi devices
 +
 +__**Fix**__
 +
 +Run the following command rescan the scsi hosts for new devices
 +<code>for host in /sys/class/scsi_host/*; do echo "- - -" | sudo tee $host/scan; lsblk -S ; done</code>
 +
 \\ \\
 ~~DISCUSSION:closed~~ ~~DISCUSSION:closed~~
linux/general/lvm.1548846486.txt.gz · Last modified: 2019/01/30 12:08 by lunetikk