aboutsummaryrefslogtreecommitdiff
path: root/partitions/managing_lvm.md
diff options
context:
space:
mode:
authorIbrahim Mkusa <ibrahimmkusa@gmail.com>2024-08-11 20:05:54 -0400
committerIbrahim Mkusa <ibrahimmkusa@gmail.com>2024-08-11 20:05:54 -0400
commit19b68bb3cd69e6e7d238bc3db5e764ea626a7686 (patch)
treefc2599737be05837bf2bd498761f435031040aa1 /partitions/managing_lvm.md
parentd3478ddfc778ad5ad64e161f1017af765b243d3d (diff)
using lvm tools to create and extend logical volumes aka lvm partitions
Diffstat (limited to 'partitions/managing_lvm.md')
-rw-r--r--partitions/managing_lvm.md39
1 files changed, 39 insertions, 0 deletions
diff --git a/partitions/managing_lvm.md b/partitions/managing_lvm.md
new file mode 100644
index 0000000..fd7f6a7
--- /dev/null
+++ b/partitions/managing_lvm.md
@@ -0,0 +1,39 @@
+To work with lvm make sure lvm packages are installed on your system. If you
+are adding an lvm partition manually follow the steps below.
+Make sure there's enough unallocated space. Figure out the extent size, lets
+say ==8M== chunks and we'll go for ==100== of these at least. Extents are the smallest
+divisible units in a lvm file system.
+
+*** Create LVM volume group and a logical volume from a normal partition ***
+```
+lsblk # identify device and partition
+fdisk /dev/sda # '/dev/sda' is the device we'll be working with
+# use n flag to create new partition
+# use t flag to designate the new partition as 'lvm'
+# use w to sync all changes to disk
+
+vgcreate -s 8M volume_name /dev/sda6 # -s specifies the extent size of 8M
+lvcreate -n scratch -l 100 /dev/volume_name # -n for name, -l Num of Extents
+mkfs.ext4 /dev/volume_name/scratch # formats the logical volume to ext4
+```
+
+After volume is created, it needs to be mounted. You can simply create
+a mountpoint `mkdir /scratch` or wherever, then edit ==/etc/fstab== to append
+the volume likes so:
+```
+/dev/volume_name/scratch /scratch ext4 defaults 0 0
+
+```
+
+If there any doubts, man vgcreate or man lvcreate are super helpful. The beauty
+of lvm is its flexibility to resize beyond the restrictions of one or many
+physical volumes
+physical volumes -> volume group -> logical volumes
+
+We can use lvextend to add space to logical volume like so:
+```
+lvextend -r -L +1G /dev/volume_name/scratch
+
+```
+==lvresize== adds more flexibility allowing you to shrink the volume.
+