vgcreate

The vgcreate command in Linux is used to create a new volume group (VG) in the Logical Volume Manager (LVM). A volume group is a collection of physical volumes (PVs) that can be used to create logical volumes (LVs). You use this command to allocate space from the available physical volumes and create a volume group that can be further used to create logical volumes.

Syntax

vgcreate [Options] VolumeGroupName PhysicalVolumePath [...]
  • VolumeGroupName: The name of the volume group you want to create.

  • PhysicalVolumePath: The path to one or more physical volumes (e.g., /dev/sda1, /dev/sdb1, etc.) to include in the new volume group.

Options

  • -s, --size: Specifies the physical extent (PE) size for the volume group. If not specified, the default PE size is used.

  • -n, --name: This option is not used directly with vgcreate, but could be relevant in more complex LVM configurations.

  • -p, --physicalextents: Specifies the number of physical extents to create for the volume group.

  • --addtag: Add tags to the volume group.

  • --setphysicalvolumesize: Set the physical volume size when creating the volume group.

Example Usage

1. Create a Volume Group from a Single Physical Volume

If you have a physical volume /dev/sda1 and want to create a volume group called vgdata, you would run:

sudo vgcreate vgdata /dev/sda1

This creates a new volume group vgdata using the /dev/sda1 physical volume.

2. Create a Volume Group from Multiple Physical Volumes

You can create a volume group from multiple physical volumes. For example, to create a volume group vgdata using both /dev/sda1 and /dev/sdb1:

sudo vgcreate vgdata /dev/sda1 /dev/sdb1

This command creates the volume group vgdata using the two physical volumes /dev/sda1 and /dev/sdb1.

3. Specify a Physical Extent Size

If you want to specify the size of the physical extents, you can use the -s option. For example, to create a volume group vgdata with a physical extent size of 8 MB, using the physical volume /dev/sda1:

sudo vgcreate -s 8M vgdata /dev/sda1

This sets the physical extent size to 8 MB.

4. Create a Volume Group with Multiple Physical Volumes and Specify Extent Size

You can combine multiple physical volumes and specify the extent size as follows:

sudo vgcreate -s 8M vgdata /dev/sda1 /dev/sdb1

This will create a volume group vgdata with physical extents of 8 MB, using /dev/sda1 and /dev/sdb1 as the physical volumes.

Example Output

When you successfully run the vgcreate command, you should see output similar to the following:

  Volume group "vgdata" successfully created

This indicates that the volume group vgdata was created successfully.

Key Points

  • Volume Group: A container for logical volumes. It is created from one or more physical volumes.

  • Physical Extents: The basic units of allocation in LVM. The size of the physical extent can be customized during volume group creation.

  • Multiple Physical Volumes: A volume group can span multiple physical devices (disks), and you can add more physical volumes to the volume group later.

  • Flexibility: LVM provides flexibility by allowing you to expand or shrink your volume groups and logical volumes dynamically.

Conclusion

The vgcreate command is essential when setting up LVM on Linux. It allows you to create volume groups from physical volumes, which are the building blocks for creating logical volumes. Logical volumes are used to manage storage more flexibly, enabling you to resize volumes or add new ones without needing to partition or format the underlying disks.

Last updated