System and processes

The vgcreate command

Creates a volume group (VG) by joining one or more PVs into one pool.

Syntax

sudo vgcreate <grupo> <dispositivo...>Try it in the terminal →

Most useful options

-s, --physicalextentsize <tamaño>Physical extent (PE) size of the group. It must be a power of 2 (of at least one sector) or at least 128 KiB; changing it later is hard
-l, --maxlogicalvolumes <número>Maximum number of logical volumes (LVs) the group can hold
-p, --maxphysicalvolumes <número>Maximum number of PVs in the group. 0 means no limit
-A, --autobackup y|nKeeps a copy of the metadata after each change. The manual strongly advises leaving it enabled
-Z, --zero y|nZeroes the first 2048 bytes of each device being initialized. By default it does, unless --uuid or --restorefile is used
--addtag <etiqueta>Adds a tag to the group. It can be repeated to add several
-f, --forceSkips confirmations and some checks. Use it with extreme care

Copy-ready examples

$ lsblkchecks the disks before deciding which one joins the group.
$ sudo vgcreate datos /dev/sdccreates the group on one disk. Destructive: if the disk is not a PV yet, vgcreate initializes it and may erase what it held.

Example output

Volume group "datos" successfully created
$ sudo vgcreate -s 8m almacen /dev/sdd /dev/sdecreates a group with two disks and 8 MiB extents. Same warning as above.
$ sudo pvs -o pv_name,vg_namechecks which PV has joined each group.

You can try them in the browser terminal: it does not touch your computer.

Common errors

MessageCauseFix
A volume group called datos already exists.A group with that name already exists, on this machine or on a disk LVM detects.List the groups with vgs and pick another name, or extend the existing one with vgextend.
Physical volume '/dev/sdc' is already in volume group 'datos'That disk is already a PV in another group, and vgcreate does not reassign it.Use another disk, or first take the PV out of its group with vgreduce.

Typical mistakes

  • The VG pools the space of all its PVs into one: you will not see each disk separately, only a single free space.
  • The extent size (-s) is hard to change later. Set it when you create the group, unless no extents need moving.
  • An existing PV keeps its metadata size and its pe_start even if you pass other values to vgcreate. To change them, run pvremove first.
  • vgcreate initializes the disks that are not PVs yet: if you pass a disk that holds data, that data can be lost.

Differences from similar commands

  • pvcreate: prepares disks as PVs without forming any group. vgcreate does that step only when needed.
  • vgextend: adds PVs to a group that already exists. vgcreate creates the group from scratch.
  • lvcreate: creates logical volumes inside the group. It is done after vgcreate.

FAQ

Do I need to run pvcreate before vgcreate?

No: vgcreate initializes the devices that are not PVs yet. Use pvcreate only if you want to prepare the disks first or check them separately.

Can I extend the group later?

Yes, with vgextend, which adds new PVs to an existing VG.

What extent size should I use?

If you do not set it, LVM uses the default, which is 4 MiB. Change it with -s only if you have a specific reason.

More System and processes commands

Learn to actually use it

The basic Linux course takes you from zero to console fluency with 24 self-grading lessons.

Start the free course