Differences
This shows you the differences between two versions of the page.
linux_wiki:logical_volume_management_lvm [2018/03/07 09:33] billdozor [Add Disk: Scan SCSI Bus] |
linux_wiki:logical_volume_management_lvm [2019/05/25 23:50] |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Logical Volume Management (LVM) ====== | ||
- | **General Information** | ||
- | |||
- | LVM provides a way to create virtual disks and containers in order to provide flexibility with parition sizes and extending/ | ||
- | |||
- | **Checklist** | ||
- | * 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 or New ====== | ||
- | |||
- | Whether expanding or creating new storage, the summarized steps are: | ||
- | * Add virtual disk to VM | ||
- | * Scan SCSI Bus (if needed) | ||
- | * Format the Disk with a partition | ||
- | * Create physical volume using the new disk's partition | ||
- | |||
- | ---- | ||
- | |||
- | ===== Add/Expand Disk ===== | ||
- | |||
- | Add or expand the disk to the system either physically or virtually if a VM. | ||
- | |||
- | ---- | ||
- | |||
- | ==== Add Disk: Scan SCSI Bus ==== | ||
- | |||
- | If adding a disk to a virtual machine and the new disk does not show up: | ||
- | |||
- | \\ | ||
- | **One Liner Method**< | ||
- | |||
- | \\ | ||
- | **Manual Method** | ||
- | * Find the host bus number< | ||
- | * Example return value:< | ||
- | * " | ||
- | * Used the returned host# to scan the SCSI bus<code bash> | ||
- | * Example from returned value< | ||
- | * The hyphens represent controller, | ||
- | |||
- | ==== Expand Disk: Re-Scan SCSI Bus ==== | ||
- | |||
- | If you have expanded an existing disk, rescan the scsi bus<code bash> | ||
- | |||
- | Where "< | ||
- | |||
- | ---- | ||
- | |||
- | ===== Format the disk ===== | ||
- | |||
- | /dev/sdb is used in this example. | ||
- | |||
- | Use gdisk in order for GPT instead of MBR. (seriously, don't use fdisk...let MBR die already) | ||
- | <code bash> | ||
- | gdisk /dev/sdb | ||
- | </ | ||
- | |||
- | ==== Create a New Empty GUID Partition Table ==== | ||
- | |||
- | Once in gdisk: | ||
- | * Use option " | ||
- | * " | ||
- | |||
- | ==== Create the LVM Partition ==== | ||
- | |||
- | * Go back into gdisk. (gdisk /dev/sdb) | ||
- | * " | ||
- | * Choose the defaults for partition number, start, and end blocks to fill the entire disk | ||
- | * Use code " | ||
- | * " | ||
- | |||
- | ---- | ||
- | |||
- | ===== Create a Physical Volume ===== | ||
- | |||
- | About: Think of physical volumes as your " | ||
- | |||
- | Create a physical volume using the parition that the LVM is on. | ||
- | |||
- | pvcreate < | ||
- | |||
- | Example: | ||
- | <code bash> | ||
- | pvcreate /dev/sdb1 | ||
- | </ | ||
- | |||
- | ---- | ||
- | |||
- | **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 " | ||
- | * 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 | ||
- | |||
- | ---- | ||
- | |||
- | ===== Extend the Volume Group ===== | ||
- | |||
- | - Add the new physical disk to the existing volume group< | ||
- | |||
- | ---- | ||
- | |||
- | ===== Extend Logical Volume ===== | ||
- | |||
- | - Extend the logical volume that needs the space (/home will be used in this example) | ||
- | - **Option 1(Preferred)**: | ||
- | - There may be a performance hit if a logical volume is spanned across multiple VMDKs, so this method is preferred.< | ||
- | lvextend --resizefs / | ||
- | - Option 2: Give the logical volume all of the space from the newly added physical volume< | ||
- | - Option 3: Give the logical volume a specific amount of additional free space from a specific physical volume< | ||
- | - Option 4: Give the logical volume all of the free space available to the volume group (potentially across multiple physical volumes)< | ||
- | |||
- | ==== Extending a Logical Swap Volume ==== | ||
- | |||
- | Extending a swap volume is slightly different, as the " | ||
- | |||
- | - Example: Specify the total size of the logical swap volume< | ||
- | - Disable all swap< | ||
- | - Create a new swap area, overwriting the original< | ||
- | - Enable swap< | ||
- | - Verify< | ||
- | |||
- | ---- | ||
- | |||
- | ===== Verify New LVM Layout ===== | ||
- | |||
- | - Verify LVM Allocation | ||
- | - Logical Volume: <code bash> | ||
- | - Volume Group: <code bash> | ||
- | - Physical Volumes: <code bash> | ||
- | |||
- | |||
- | **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> | ||
- | |||
- | ---- | ||
- | |||
- | ===== Grow File System ===== | ||
- | |||
- | **Skip if you used the " | ||
- | |||
- | - Grow the file system | ||
- | - Ext2/ | ||
- | - XFS<code bash> | ||
- | - Verify filesystem space< | ||
- | |||
- | ---- | ||
- | |||
- | ===== Cleanup ===== | ||
- | |||
- | If you have just moved all of the data of a logical volume off of an old physical volume, the old physical volume can go away if it is no longer in use. | ||
- | |||
- | Examples below: You have just moved everything off of /dev/sdc1 to a new disk and can now remove the old disk (/dev/sdc). | ||
- | |||
- | ==== Verify Old Physical Volume Not Used ==== | ||
- | |||
- | <code bash> | ||
- | pvs -o +pv_used | ||
- | </ | ||
- | ==== Reduce Volume Group ==== | ||
- | |||
- | vgreduce vgname olddisk | ||
- | <code bash> | ||
- | vgreduce vglocal /dev/sdc1 | ||
- | </ | ||
- | ==== Remove Physical Volume ==== | ||
- | |||
- | pvremove olddisk | ||
- | <code bash> | ||
- | pvremove /dev/sdc1 | ||
- | </ | ||
- | ==== Delete Virtual Disk ==== | ||
- | |||
- | Login to the virtualization user interface and delete the old disk from inventory. | ||
- | |||
- | ---- | ||
- | |||
- | ====== Creating New Storage ====== | ||
- | |||
- | ===== Create New: Summarized Steps ===== | ||
- | |||
- | To create new storage for a logical volume, the summarized steps are: | ||
- | |||
- | Performed above in " | ||
- | * 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 ===== | ||
- | |||
- | About: Volume groups aggregate physical volumes into a usable pool of disk space. | ||
- | |||
- | vgcreate < | ||
- | |||
- | Example: | ||
- | <code bash> | ||
- | vgcreate vgstorage /dev/sdb1 | ||
- | </ | ||
- | |||
- | ---- | ||
- | |||
- | ===== Create a Logical Volume ===== | ||
- | |||
- | About: Logical volumes use the disk space made available via a volume group. | ||
- | |||
- | lvcreate --size < | ||
- | |||
- | Example: Create a 100G logical volume | ||
- | <code bash> | ||
- | lvcreate --size 100G --name lvbackups vgstorage | ||
- | </ | ||
- | |||
- | Example: Create a logical volume that uses 100% of the volume group free extents | ||
- | <code bash> | ||
- | lvcreate --extents 100%FREE --name lvbackups vgstorage | ||
- | </ | ||
- | ---- | ||
- | |||
- | ===== Create the file system on the logical volume ===== | ||
- | |||
- | About: So far, the only things being created were pretty much containers. Create the actual file system below. | ||
- | |||
- | mkfs -t < | ||
- | |||
- | Example: | ||
- | <code bash> | ||
- | mkfs -t ext4 -L Backups / | ||
- | </ | ||
- | |||
- | ---- | ||
- | |||
- | ===== Mount the logical volume by uuid ===== | ||
- | |||
- | ==== Find the UUID with blkid ==== | ||
- | <code bash> | ||
- | blkid | ||
- | / | ||
- | </ | ||
- | |||
- | ==== Add entry to /etc/fstab by UUID ==== | ||
- | <code bash> | ||
- | vim /etc/fstab | ||
- | UUID=d89744ad-133c-452b-98d8-9480ef18fe77 / | ||
- | </ | ||
- | |||
- | ==== Mount the fstab entries and check to see if it mounted with df ==== | ||
- | |||
- | <code bash> | ||
- | mount -a | ||
- | df -h | ||
- | </ | ||
- | |||
- | ----- | ||
- | |||
- | ====== 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. | ||
- | |||
- | Rename a Volume Group (vgrename vg-oldname vg-newname) | ||
- | <code bash> | ||
- | vgrename vgbackupmirror vgredusb | ||
- | </ | ||
- | |||
- | Rename a Logical Volume (lvrename vgname lv-oldname lv-newname) | ||
- | <code bash> | ||
- | lvrename vgredusb lvbackupmirror lvredbackups | ||
- | </ | ||
- | |||
- | ---- | ||
- | |||
- | ====== LVM Snapshots ====== | ||
- | |||
- | LVM allows you to " | ||
- | |||
- | |||
- | {TODO} |