DEV Community

Wesley Schwengle
Wesley Schwengle

Posted on • Edited on

Add a disk to an LVM group

This is a small how-to to add an (encrypted) disk to an LVM Volume Group (VG). In this example, we'll add /dev/sda to an existing volume group called howto-vg.

Encrypt the disk and open it:

cryptsetup luksFormat --type luks1 /dev/sda
cryptsetup open /dev/sda sda_crypt
Enter fullscreen mode Exit fullscreen mode

Create the physical volume:

pvcreate /dev/mapper/sda_crypt
Enter fullscreen mode Exit fullscreen mode

Make sure the volume group exists by running vgscan. Alternatively, you can use vgdisplay. Add the physical volume to the volume group:

vgextend howto-vg /dev/mapper/sda_crypt
Enter fullscreen mode Exit fullscreen mode

And create the logical volume:

lvcreate -l 100%FREE howto-vg -n howto-volume
Enter fullscreen mode Exit fullscreen mode

Create the filesystem on the logical volume:

mkfs.ext4 -m 1 /dev/howto-vg/howto-volume
Enter fullscreen mode Exit fullscreen mode

Create the mount point so you can mount the volume:

mkdir -p /path/to/mount
Enter fullscreen mode Exit fullscreen mode

You can now add the volume in /etc/fstab:

/dev/mapper/howto--vg-howto--volume  /path/to/mount ext4    defaults    0   2
Enter fullscreen mode Exit fullscreen mode

Now reload systemd by running systemctl daemon-reload.

Mount the disk by running mount /path/to/disk. The following step isn't needed but cannot hurt either: reboot. After the reboot, you are sure the disk is mounted in the correct place. Yay.

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Dive into an ocean of knowledge with this thought-provoking post, revered deeply within the supportive DEV Community. Developers of all levels are welcome to join and enhance our collective intelligence.

Saying a simple "thank you" can brighten someone's day. Share your gratitude in the comments below!

On DEV, sharing ideas eases our path and fortifies our community connections. Found this helpful? Sending a quick thanks to the author can be profoundly valued.

Okay