linux_wiki:logical_volume_management_lvm

Differences

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

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
linux_wiki:logical_volume_management_lvm [2015/12/23 13:22]
billdozor
linux_wiki:logical_volume_management_lvm [2019/05/25 23:50] (current)
Line 6: Line 6:
  
 **Checklist** **Checklist**
-  * The hard disk being formatted is not in use/blank. These steps will erase all data on the target disk.+  * Distro(s): Any 
 +  * Other: The hard disk being formatted is not in use/blank. These steps will erase all data on the target disk.
  
 ---- ----
  
-====== Expanding Storage ======+====== Expanding or New ======
  
-Expanding storage steps. +Whether expanding or creating new storage, the summarized steps are:
- +
-===== Summarized Steps ===== +
- +
-To expand storage for a logical volume, the summarized steps are:+
   * Add virtual disk to VM   * Add virtual disk to VM
-  * Re-Scan SCSI Bus (if needed)+  * Scan SCSI Bus (if needed)
   * Format the Disk with a partition   * Format the Disk with a partition
   * Create physical volume using the new disk's partition   * Create physical volume using the new disk's partition
-  * Extend the volume group using the new physical volume 
-  * Extend the logical volume 
-  * Verify new LVM layout 
-  * Grow the file system 
-  * Cleanup (if a pvmove of the logical volume was done to a new disk) 
-    * Verify old physical volume is not used 
-    * Reduce the volume group by removing the physical volume 
-    * Remove the physical volume LVM label 
-    * Delete virtual disk from virtual management UI 
  
 ---- ----
  
-===== Add Disk =====+===== Add/Expand Disk =====
  
-Add disk to the system either physically or virtually if a VM.+Add or expand the disk to the system either physically or virtually if a VM.
  
 ---- ----
  
-===== Re-Scan SCSI Bus =====+==== Add Disk: Scan SCSI Bus ====
  
 If adding a disk to a virtual machine and the new disk does not show up: If adding a disk to a virtual machine and the new disk does not show up:
 +
 +\\
 +**One Liner Method**<code bash>echo "- - -" > /sys/class/scsi_host/$(grep mpt /sys/class/scsi_host/host?/proc_name | grep -o -E '(host[0-9])')/scan</code>
 +
 +\\
 +**Manual Method**
   * Find the host bus number<code bash>grep mpt /sys/class/scsi_host/host?/proc_name</code>   * Find the host bus number<code bash>grep mpt /sys/class/scsi_host/host?/proc_name</code>
     * Example return value:<code bash>/sys/class/scsi_host/host2/proc_name:mptspi</code>     * Example return value:<code bash>/sys/class/scsi_host/host2/proc_name:mptspi</code>
Line 48: Line 42:
     * Example from returned value<code bash>echo "- - -" > /sys/class/scsi_host/host2/scan</code>     * Example from returned value<code bash>echo "- - -" > /sys/class/scsi_host/host2/scan</code>
   * The hyphens represent controller,channel,lun, so – - – indicates all controllers, all channels, and all luns should be scanned.   * The hyphens represent controller,channel,lun, so – - – indicates all controllers, all channels, and all luns should be scanned.
 +
 +==== Expand Disk: Re-Scan SCSI Bus ====
 +
 +If you have expanded an existing disk, rescan the scsi bus<code bash>echo 1 > /sys/class/scsi_device/<device>/rescan</code>
 +
 +Where "<device>" is your disk such as "sda".
  
 ---- ----
Line 88: Line 88:
 pvcreate /dev/sdb1 pvcreate /dev/sdb1
 </code> </code>
 +
 +----
 +
 +**Continue on to either Expanding Storage or Creating New Storage.**
 +
 +----
 +
 +====== Expanding Storage ======
 +
 +Expanding storage steps.
 +
 +===== Expand: Summarized Steps =====
 +
 +To expand storage for a logical volume, the summarized steps are:
 +
 +Performed above in "Expanding or New":
 +  * Add virtual disk to VM
 +  * Re-Scan SCSI Bus (if needed)
 +  * Format the Disk with a partition
 +  * Create physical volume using the new disk's partition
 +
 +Remaining Steps:
 +  * Extend the volume group using the new physical volume
 +  * Extend the logical volume
 +  * Verify new LVM layout
 +  * Grow the file system
 +  * Cleanup (if a pvmove of the logical volume was done to a new disk)
 +    * Verify old physical volume is not used
 +    * Reduce the volume group by removing the physical volume
 +    * Remove the physical volume LVM label
 +    * Delete virtual disk from virtual management UI
  
 ---- ----
Line 102: Line 133:
     - **Option 1(Preferred)**: Move the physical extents of the logical volume to the new disk, so all of it resides on the same VMDK, and then use all of that new disk's space.     - **Option 1(Preferred)**: Move the physical extents of the logical volume to the new disk, so all of it resides on the same VMDK, and then use all of that new disk's space.
       - There may be a performance hit if a logical volume is spanned across multiple VMDKs, so this method is preferred.<code bash>pvmove --name lvhome /dev/sda2 /dev/sdb1       - There may be a performance hit if a logical volume is spanned across multiple VMDKs, so this method is preferred.<code bash>pvmove --name lvhome /dev/sda2 /dev/sdb1
-lvextend /dev/vglocal/lvhome /dev/sdb1</code> +lvextend --resizefs /dev/vglocal/lvhome /dev/sdb1</code> 
-    - Option 2: Give the logical volume all of the space from the newly added physical volume<code bash>lvextend --extents +100%PVS /dev/vglocal/lvhome /dev/sdb1</code> +    - Option 2: Give the logical volume all of the space from the newly added physical volume<code bash>lvextend --resizefs --extents +100%PVS /dev/vglocal/lvhome /dev/sdb1</code> 
-    - Option 3: Give the logical volume a specific amount of additional free space from a specific physical volume<code bash>lvextend --size +10G /dev/vglocal/lvhome /dev/sdb1</code> +    - Option 3: Give the logical volume a specific amount of additional free space from a specific physical volume<code bash>lvextend --resizefs --size +10G /dev/vglocal/lvhome /dev/sdb1</code> 
-    - Option 4: Give the logical volume all of the free space available to the volume group (potentially across multiple physical volumes)<code bash>lvextend --extents +100%FREE /dev/vglocal/lvhome</code>+    - Option 4: Give the logical volume all of the free space available to the volume group (potentially across multiple physical volumes)<code bash>lvextend --resizefs --extents +100%FREE /dev/vglocal/lvhome</code> 
 + 
 +==== Extending a Logical Swap Volume ==== 
 + 
 +Extending a swap volume is slightly different, as the "--resizefs" flag will not work. 
 + 
 +  - Example: Specify the total size of the logical swap volume<code bash>lvextend --size 8G /dev/vglocal/lvswap /dev/sdb1</code> 
 +  - Disable all swap<code bash>swapoff -a</code> 
 +  - Create a new swap area, overwriting the original<code bash>mkswap /dev/vglocal/lvswap</code> 
 +  - Enable swap<code bash>swapon -a</code> 
 +  - Verify<code bash>swapon -s</code>
  
 ---- ----
Line 115: Line 156:
     - Volume Group: <code bash>vgs</code>     - Volume Group: <code bash>vgs</code>
     - Physical Volumes: <code bash>pvs</code>     - Physical Volumes: <code bash>pvs</code>
 +
 +
 +**Logical Volume Location(s) on Physical Volumes**
 +
 +If you would like to see what logical volumes reside where, a nice command to view physical extent to logical volume mappings is:<code bash>pvdisplay -m</code>
  
 ---- ----
  
 ===== Grow File System ===== ===== Grow File System =====
 +
 +**Skip if you used the "--resizefs" flag to lvextend above.**
  
   - Grow the file system   - Grow the file system
Line 153: Line 201:
  
 Login to the virtualization user interface and delete the old disk from inventory. Login to the virtualization user interface and delete the old disk from inventory.
 +
 +\\
 +**Errors During LVM Commands**
 +  * If you see errors during LVM commands like this after a device delete from vmware<code bash>root@llsrlscd01 home $ pvs
 +  /dev/sdc: read failed after 0 of 4096 at 0: Input/output error
 +  /dev/sdc: read failed after 0 of 4096 at 17179803648: Input/output error
 +  /dev/sdc: read failed after 0 of 4096 at 17179860992: Input/output error
 +  /dev/sdc: read failed after 0 of 4096 at 4096: Input/output error
 +  /dev/sdc1: read failed after 0 of 4096 at 17178755072: Input/output error
 +  /dev/sdc1: read failed after 0 of 4096 at 17178812416: Input/output error
 +  /dev/sdc1: read failed after 0 of 4096 at 0: Input/output error
 +  /dev/sdc1: read failed after 0 of 4096 at 4096: Input/output error
 +  PV         VG      Fmt  Attr PSize   PFree
 +  /dev/sda2  vglocal lvm2 a--   19.50g 3.50g
 +  /dev/sdd1  vglocal lvm2 a--  250.00g    0
 +  /dev/sde1  vglocal lvm2 a--   40.00g    0</code>
 +    * Fix by rebooting the system or<code bash>echo 1 > /sys/block/sdX/device/delete</code>
 +      * Where "sdX" is the device, such as 'sdc' in the above example.
  
 ---- ----
  
 ====== Creating New Storage ====== ====== Creating New Storage ======
 +
 +===== Create New: Summarized Steps =====
 +
 +To create new storage for a logical volume, the summarized steps are:
 +
 +Performed above in "Expanding or New":
 +  * Add virtual disk to VM
 +  * Re-Scan SCSI Bus (if needed)
 +  * Format the Disk with a partition
 +  * Create physical volume using the new disk's partition
 +
 +Remaining Steps:
 +  * Create a volume group
 +  * Create a logical volume
 +  * Create a file system on the logical volume
 +  * Mount the logical volume
 +
 +----
  
 ===== Create a Volume Group ===== ===== Create a Volume Group =====
Line 224: Line 308:
 ----- -----
  
-===== LVM Renaming =====+====== LVM Renaming ======
  
 We don't always get a name right the first time. Luckily, LVM allows for easy renaming of logical volumes and volume groups. We don't always get a name right the first time. Luckily, LVM allows for easy renaming of logical volumes and volume groups.
Line 240: Line 324:
 ---- ----
  
-===== LVM Snapshots =====+====== LVM Snapshots ======
  
 LVM allows you to "freeze" the metadata of files. This allows for things like rsync to complete successfully even if files it is trying to sync are modified during the operation. LVM allows you to "freeze" the metadata of files. This allows for things like rsync to complete successfully even if files it is trying to sync are modified during the operation.
  • linux_wiki/logical_volume_management_lvm.1450894933.txt.gz
  • Last modified: 2019/05/25 23:50
  • (external edit)