vgcreate
Create a new volume group
TLDR
Create a new volume group called vg1 using the /dev/sda1 device
Create a new volume group called vg1 using multiple devices
SYNOPSIS
vgcreate [OPTIONS] VolumeGroupName PhysicalVolumePath [PhysicalVolumePath...]
PARAMETERS
-s, --physicalextentsize Size[B|K|M|G|T|P|E]
Sets the size of physical extents for the new volume group. This is a crucial setting as all logical volumes within the VG will be allocated in multiples of this size. The default is 4MiB.
-c, --clustered {y|n}
Configures the volume group for use in a clustered LVM environment. Set to 'y' for clustered setups.
-l, --maxlogicalvolumes Number
Sets the maximum number of logical volumes that can be created in this volume group. A value of 0 means no limit. Defaults to 0.
-p, --maxphysicalvolumes Number
Sets the maximum number of physical volumes that can be added to this volume group. A value of 0 means no limit. Defaults to 0.
-A, --autobackup {y|n}
Controls automatic metadata backup for the volume group. 'y' (default) enables automatic backup to /etc/lvm/backup, 'n' disables it.
-f, --force
Forces the creation of the volume group, even if it appears unsafe or if the physical volumes already contain LVM metadata. Use with caution as it can overwrite existing data.
-y, --yes
Assumes 'yes' to all questions; useful for scripting.
-v, --verbose
Increases verbose output, showing more details about the command execution.
--addtag Tag
Adds a tag to the newly created volume group. Tags are arbitrary strings that can be used to group and filter LVM objects.
--metadatasize Size[B|K|M|G|T|P|E]
Specifies the size of the metadata area on the physical volume(s). This is rarely needed as LVM usually handles it automatically.
--pvmetadatacopies Number
Sets the number of copies of LVM metadata to store on each physical volume. Default is 1 or 2, depending on the metadata area type.
--systemid SystemID
Assigns a unique system ID to the volume group. This is relevant in environments where VGs might be shared or moved between systems.
--readonly
Creates the volume group in a read-only state. This prevents any writes to the volume group or its logical volumes.
DESCRIPTION
vgcreate is a fundamental command in Logical Volume Management (LVM) on Linux systems. It is used to create a new volume group (VG) from one or more physical volumes (PVs). A volume group acts as a container for logical volumes (LVs) and aggregates the storage space from multiple physical volumes, allowing for flexible storage management, including resizing, snapshotting, and striping. Before creating a VG, you must first initialize physical volumes using pvcreate. vgcreate takes the name of the new volume group and the names of the physical volumes to include. Once created, logical volumes can be allocated from the VG's free space using lvcreate. The command writes LVM metadata to the specified physical volumes, marking them as part of the new volume group.
CAVEATS
Important Considerations:
1. Before creating a volume group, the underlying devices must first be initialized as physical volumes using the pvcreate command.
2. Ensure that the chosen physical volumes have sufficient free space and are not already part of another active LVM volume group (unless using --force, which is not recommended without understanding the risks).
3. The VolumeGroupName must be unique on the system and adhere to LVM naming conventions.
4. Using the --force option can lead to data loss if used incorrectly, as it can overwrite existing LVM metadata or other filesystem structures.
LVM HIERARCHY
LVM organizes storage in a three-tier hierarchy:
1. Physical Volumes (PVs): These are physical disk partitions or entire disks initialized for LVM use via pvcreate.
2. Volume Groups (VGs): Created using vgcreate, VGs aggregate one or more PVs into a single storage pool.
3. Logical Volumes (LVs): Created using lvcreate, LVs are virtual partitions carved out of a VG's free space. Filesystems are then created on LVs.
VOLUME GROUP NAMING
When choosing a VolumeGroupName, it is best practice to use descriptive names (e.g., 'vg_data', 'vg_root'). Names should typically consist of alphanumeric characters, hyphens, and underscores, avoiding spaces or special characters. They must be unique across the system.
HISTORY
vgcreate, along with other core LVM commands, has been a cornerstone of Linux's Logical Volume Manager since its early development. LVM (specifically LVM2, which is the current mainstream version) evolved to provide more robust and flexible storage management capabilities than traditional fixed-size partitions. The command's fundamental function of aggregating physical storage into logical units has remained consistent, adapting to new storage technologies and requirements like clustering and thin provisioning over time.