Skip to content

af1381/Create-LVM-Partition

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 

Repository files navigation

Create-LVM-Partition

Step 1: Prepare the disk

First you need to identify the new disk you want to use for LVM. Use the following command to view the disks:

 lsblk

Step 2: Create LVM partition:

Create a new partition using the fdisk or parted tool. For example:

sudo fdisk /dev/sdb

In the fdisk environment, follow these steps:

  • Press the {n} key to create a new partition.
  • Select the partition type (Primary or Extended). Usually Primary.
  • Specify the partition size.
  • Then change the partition type with {t} and enter the code {8e} (LVM).
  • Save the changes with {w}

Step 3: Set the partition as a Physical Volume (PV):

To use LVM, you need to convert the partition to a physical volume (PV):

sudo pvcreate /dev/sdb1

Step 4: Create Volume Group (VG):

Create a Volume Group and add your physical volume to it:

sudo vgcreate my_vg /dev/sdb1
  • Here my_vg is the name of the volume group, which you can change.

Step 5: Create Logical Volume (LV):

Now you can create one or more Logical Volumes within your volume group. For example, to create a 10GB Logical Volume:

sudo lvcreate -L 10G -n my_lv my_vg
  • -L 10G: Specifies the logical volume size.
  • -n my_lv: Logical volume name (here my_lv).
  • my_vg: Volume group name.

Step 6: Format the logical volume:

To use a logical volume, you must format it. For example, with the ext4 file system:

sudo mkfs.ext4 /dev/my_vg/my_lv

Step 7: Mount the logical volume :

To use a logical volume, you must mount it:

  • Create a directory for the mount:

    sudo mkdir /mnt/my_lv
    
  • Mount the logical volume:

    sudo mount /dev/my_vg/my_lv /mnt/my_lv
    
  • For permanent mount, add it to the fstab file. Edit the /etc/fstab file and add the following line:

     /dev/my_vg/my_lv /mnt/my_lv ext4 defaults 0 0
    

Step 8: Check the settings:

To check the LVM status, use the following commands:

  • Viewing physical volumes:

    sudo pvs
    
  • View volume groups:

     sudo vgs
    
  • Viewing logical volumes:

      sudo lvs
    

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published