VM Config
VM Specifications:
- CPU: 1vCPU (4 cores)
- RAM: 8 GB
- HD: 100 GB (OS)
- HD: 200 GB (File Server
Change the hostname:
Update the IP:
LVM Concepts and Commands
Logical Volume Manager (LVM) is a way to span multiple drives or partitions together to build redudancies or performance bennefits. In the beginning they can be very confusing. I have tried to give basic descriptions/defintions below. In our example, we have a virtual machine that has two drives. One drive is for the Operating System. The other drive is for a NFS file server. We will also cover a few ways to increase the size of the NFS volume.
Physical Volume (PV)
Defintion: Think of this a physcial volume such as a disk or partition.
Command: The command to list the physcial volumes is: pvscan
Volume Group (VG))
Defintion: An agreages of of PVs put together.
Command: The command to list the volume groups is: vgscan
Logical Volume (LV)
Defintion: Think of this as a virtual partion. A VG still requires formatting. A VG can be resized.
Command: The command to list the logical volumes is: lvscan
Addtional Commands
List block devices in table format: lsblk
List all LVM block devices: lvmdiskscan
List the partiontions for sdb: fdisk -l /dev/sdb
List the sizes of partiontions: df -h
List the size of LVM: df -h /mnt/nfs
List the partition table for sdb: parted /dev/sdb print
Create a Partition
While there are many partitioning tools out there, for this, we will be using parted. Create new GPT partition and set the ID type to 8E for System Linux LVM. Create partition interactivly, type:
Select the disk
Show current table
Make the partition GPT
Create pirmary partition that starts at 1 and used the whole disk (by using the -1).
Source: http://www.troubleshooters.com/linux/parted_cheat.htm
Make partition LVM
Check if the first partition is correctly aligned
To quit parted
Create LVM
Create a PV for the following partiontions
Create a volume group
Syntanx: vgcreate name device
Create LV from VG
Syntanx: lvcreate -n name -l size vgNameSource
Some engineers use -l which stands for extents.
Format LVM
Format using XFS
To display the existing label for an unmounted XFS file system and then apply a new label:
To change the xfs label
Mount LVM
Create the mount points.
Mount the LVMs.
Create the folders in the mount. Assuming they do not already exist AFTER they have been mounted.
Appeend the following items to the fstab config file so that the LVMs are mounted after reboots.
Mount anything that is in the fstab that isn't mounted
LVM Expansion - Notes
When it comes to LVM, there are two options on how to increase disk space.
1. Add more disk space to the VMDK. Create a new partition on the disk. You will need to partition it then create a pv out of it. Then add the new pv to the lv. The VG will recognize the changes automagically.
The upside to this is that it is easier to expand an LVM while still online.
The difficulty with this that it adds extra layers of complexity and a drive can only handle four primary partitions. If more room is needed, a new VMDK drive will need to be created. Then you can repeat the steps above.
2. Add more disk space to the VMDK. Unmount the LVM, delete the partition and recreate it with the new size. Then update the PV and LV. The VG will recognize the changes automagically.
The upside here is that it keeps things simple. It is assumed that at this point, there is only one PV in the LVM. This process can repeated as many times as required.
The downside to this is that things need to be taken offline and it is scary as all get out deleteing a partition. Don't worry, if done correctly, there will not be any data loss ;)
Bottomline: in my humble opinion, keep things simple. Use option 2.
LVM Expansion - Pre-Requirements
Resize drive that is to be extended in the vCenter. With modern version of Linux, this can often be done on the fly. If the text box to increase the drive size is greyed out, a shutdown will be required.
When expanding the drive in VMware vCenter, do not use TB. Use GB based on the conversions below.
Example:
- 1 TB = 1024 GB
- 2 TB = 2048 GB
- 4 TB = 4096 GB
- 6 TB = 6144 GB
- 8 TB = 8192 GB
- 10 TB = 10240 GB
- 12 TB = 12288 GB
- 14 TB = 14336 GB
- 16 TB = 16384 GB
- 18 TB = 18432 GB
- 20 TB = 20480 GB
For a hirearchy view of the drive and partition layout, run the following command.
Run the following command to see the size used/available for each drive/partition.
Run the following command to see the physical volumes.
Run the following command to see the volume groups.
Run the following command to see the logical volumes.
Example:
- LV Path: /dev/vg-nfs/lv-nfs
- LV Name: lv-nfs
- VG Name: vg-nfs
You can view the XFS volume details as follows.
If new size is not visible from the lsblik command, re-scan of iscsi bus.
Before you can umount the LVM, services that use the LVM must be stopped other wise you will get an error message: "umount: /mnt/nfs: target is busy."
Assuming you are making changes to a non-OS LVM, unmount the LVM. This is a safe way to avoid any writes to the LVM during changes.
LVM Expansion - Add new PV (Option 1)
After the the drive has has been expaned (the VMDK), we will use this space to create a new partition.
Print the partition table.
Create a new partition.
Choose the partition number. Remeber you can only have a maximum of four primary partitions.
Choose where you would like the disk to begin. You can normally hit enter to start at the end of the last partition.
Choose where you would like the disk to end. If you want to use the new maximum size, just hit <enter>.
Set the partition type.
Select the newly created partition. I think 2 is selected as the "default" partition because that is what we worked with last.
If you type L during the wizard, a long list of partition types is provided. We want 31 which is the Linux LVM type.
Write the config and exit.
After you have created your new partition, you may get a message about the kernel still using the old partition table, and to reboot to use the new table. The reboot is not needed as you can also rescan for those partitions using partprobe. Run the following to scan for the newly created partition.
If that does not work, you can try to use partx command to rescan the device and add the new partitions. For example: partx -v -a /dev/sdb
Convert new partition to physical volume.
Add the new PV to the VG.
Extend the logical volume to use all of the remaining disk space.
Remount the LVM for the next step.
For xfs, force the OS to see the extended space:
For ext3/ext4, force the OS to see the extended space.
It is probably wise to do a good ol' reboot.
LVM Expansion - Resize PV (Option 2)
!!!IMPORTANT!!!
Delete and recreate the partition. Don't freak out, we will recreate it with new geometry. No data will be lost during this process.
The encrypted partitions signature will be detected and you will be prompted to remove the signature, DO NOT REMOVE THE SIGNATURE OR YOUR DATA WILL BE IRRECOVERABLE, enter 'n'.
If you do not get the question about the removal of the LVM signature there is something wrong and you should abort without writing by pressing 'q'.
Print the partition table.
Delete the partition. If there is only one partition, it will be automatically selected.
Create a new partition.
Match the same beginning sector. It is assumed it is the only partition on the disk.
Make BLOODY POSITIVE that the start of the disk is as shown in the printed partition table.
If this is the only partition on the disk, you can safely hit <enter>.
See !!!IMPORTANT!!! above.
Set the partition type. In this case, we will use Linux LVM which is 31 if you type L in the wizard.
Write the config and exit.
After you have created your new partition, you may get a message about the kernel still using the old partition table, and to reboot to use the new table. The reboot is not needed as you can also rescan for those partitions using partprobe. Run the following to scan for the newly created partition.
If that does not work, you can try to use partx command to rescan the device and add the new partitions. For example: partx -v -a /dev/sdb
Apply the partition changes to the PV.
Extend the logical volume to use all of the remaining disk space.
Remount the LVM for the next step.
For xfs, force the OS to see the extended space:
For ext3/ext4, force the OS to see the extended space.
It is probably wise to do a good ol' reboot.
References
Most of this material is based on previous progjects and from iterations of Linux NFS servers.