This document guides you through the steps for adding a new disk space to your Linux system or increasing an existing volume.
This is a “copy & paste” how-to. The easiest way to follow this tutorial is to use a command line SSH client (like putty) and simply copy and paste the commands (except where you have to provide your own information.
Adding a new disk
First add a new disk to your virtual machine within you virtualization environment.
1 | Get a list of your current disk/partition table.You can compare this output after adding the new disk. |
In the output you will find your current disk(s), for example something like:
|
2 | Re-scan the SCSI bus for the disk changes. |
|
3 | Now get again the list of the disks/partition table. You will see the disk change(s) with its size. |
In the output you will find the added disk, for example something like:
|
In case of a disk increasement, it can be that disk change is not updated, then run following command for the increased disk (sdb). |
|
|
4 | Creating a new partition on the new disk, in this case, the disk is: /dev/sdb |
you will get the message below:
|
5 | Create a new partition |
|
6 | Choose Primary partition |
|
7 | Partition number. Accept the default values for the other questions. Just press enter. |
|
8 | Write table to disk and exit |
|
9 | New partition now created, with PhysicalDevicePath: |
|
10 | Initialize the new physical volume. |
Output:
|
11 | Create a volume group on the physical volume. | vgcreate VolumeGroupName PhysicalDevicePath
Output:
|
12 | Check the results by displaying physical volumes. |
|
13 | Now create a (10 gigabyte) logical volume named LV_01 from the free extents in volume group VG_02 |
Output:
|
14 | List Logical Volumes path, needed for next step. |
|
15 | Create a file system on the logical volume. |
|
Mounting the Logical Volume
16 | Create a mount folder |
|
17 | Activating and Mounting the new Logical Volume. |
|
18 | To mount the Logical Volume on system startup. |
Insert following line:
|
19 | To get a list of your mounted Logical Volumes |
|
Extending a Logical Volume
First increase the disk size of your virtual machine.
Then follow the same steps from above, adding a new disk, until step 10. The only difference is:
Step 4. | Create an additional partition on the existing disk. So you must use here the existing disk. |
Step 7. | Partition can’t be 1. After step 4, first type p to view the existing partition(s). Increase the number with 1. |
Now follow the steps below to extend the Logical Volume:
11 | Get VG names needed for next step |
|
12 | Extend the Volume Group to include the new physical volume |
|
13 | Get LV path needed for next step |
|
14 | Extend the LogicalVolume with the available/remaining space. Or: |
|
15 | extends the logical volumne /dev/myvg/homevol to (for example) 12 gigabytes. Or: |
|
16 | adds (for example) 10 gigabyte to the logical volume from the free extents in the volume group. |
|
17 | Resize the File system |
|
If you get the error below, first install e4fsprogs to support the ext4dev file system.
resize2fs: Filesystem has unsupported feature(s) while trying to open /dev/vg_u01/lv_u01 |
|
|
18 | Verify the results |
|
Removing a Logical Volume
1 | A logical volume must be closed before it can be removed. |
|
2 | Remove logical volume(s) from the system. |
|
LVM Commands
Some other useful Logical Volume Management Commands:
lvdisplay | Display information about a logical volume |
lvmdiskscan | List devices that may be used as physical volumes |
lvreduce | Reduce the size of a logical volume |
lvrename | Rename a logical volume |
lvresize | Resize a logical volume |
lvs | Display logical volumes |
pvresize | Resize physical volume(s) |
pvck | Check the consistency of physical volume(s) |
pvdisplay | Display various attributes of physical volume(s) |
pvremove | Remove LVM label(s) from physical volume(s) |
vgdisplay | Display volume group information |
vgextend | Add physical volumes to a volume group |
vgmerge | Merge volume groups |
vgreduce | Remove physical volume(s) from a volume group |
vgremove | Remove volume group(s) |
vgrename | Rename a volume group |
vgsplit | Move physical volumes into a new or existing volume group |