5.3. Splitting a Volume Group
In this example procedure, an existing volume group consists of three physical volumes. If there is enough unused space on the physical volumes, a new volume group can be created without adding new disks.
In the initial set up, the logical volume
mylv
is carved from the volume group myvol
, which in turn consists of the three physical volumes, /dev/sda1
, /dev/sdb1
, and /dev/sdc1
.
After completing this procedure, the volume group
myvg
will consist of /dev/sda1
and /dev/sdb1
. A second volume group, yourvg
, will consist of /dev/sdc1
.
- Use the
pvscan
command to determine how much free space is currently available in the volume group.#
pvscan
PV /dev/sda1 VG myvg lvm2 [17.15 GB / 0 free] PV /dev/sdb1 VG myvg lvm2 [17.15 GB / 12.15 GB free] PV /dev/sdc1 VG myvg lvm2 [17.15 GB / 15.80 GB free] Total: 3 [51.45 GB] / in use: 3 [51.45 GB] / in no VG: 0 [0 ] - Move all the used physical extents in
/dev/sdc1
to/dev/sdb1
with thepvmove
command. Thepvmove
command can take a long time to execute.#
pvmove /dev/sdc1 /dev/sdb1
/dev/sdc1: Moved: 14.7% /dev/sdc1: Moved: 30.3% /dev/sdc1: Moved: 45.7% /dev/sdc1: Moved: 61.0% /dev/sdc1: Moved: 76.6% /dev/sdc1: Moved: 92.2% /dev/sdc1: Moved: 100.0%After moving the data, you can see that all of the space on/dev/sdc1
is free.#
pvscan
PV /dev/sda1 VG myvg lvm2 [17.15 GB / 0 free] PV /dev/sdb1 VG myvg lvm2 [17.15 GB / 10.80 GB free] PV /dev/sdc1 VG myvg lvm2 [17.15 GB / 17.15 GB free] Total: 3 [51.45 GB] / in use: 3 [51.45 GB] / in no VG: 0 [0 ] - To create the new volume group
yourvg
, use thevgsplit
command to split the volume groupmyvg
.Before you can split the volume group, the logical volume must be inactive. If the file system is mounted, you must unmount the file system before deactivating the logical volume.Deactivate the logical volumes with thelvchange
command or thevgchange
command. The following command deactivates the logical volumemylv
and then splits the volume groupyourvg
from the volume groupmyvg
, moving the physical volume/dev/sdc1
into the new volume groupyourvg
.#
lvchange -a n /dev/myvg/mylv
#vgsplit myvg yourvg /dev/sdc1
Volume group "yourvg" successfully split from "myvg"You can use thevgs
command to see the attributes of the two volume groups.#
vgs
VG #PV #LV #SN Attr VSize VFree myvg 2 1 0 wz--n- 34.30G 10.80G yourvg 1 0 0 wz--n- 17.15G 17.15G - After creating the new volume group, create the new logical volume
yourlv
.#
lvcreate -L 5G -n yourlv yourvg
Logical volume "yourlv" created - Create a file system on the new logical volume and mount it.
#
mkfs.gfs2 -p lock_nolock -j 1 /dev/yourvg/yourlv
This will destroy any data on /dev/yourvg/yourlv. Are you sure you want to proceed? [y/n]y
Device: /dev/yourvg/yourlv Blocksize: 4096 Filesystem Size: 1277816 Journals: 1 Resource Groups: 20 Locking Protocol: lock_nolock Lock Table: Syncing... All Done #mount /dev/yourvg/yourlv /mnt
- Since you had to deactivate the logical volume
mylv
, you need to activate it again before you can mount it.#
lvchange -a y /dev/myvg/mylv
#mount /dev/myvg/mylv /mnt
#df
Filesystem 1K-blocks Used Available Use% Mounted on /dev/yourvg/yourlv 24507776 32 24507744 1% /mnt /dev/myvg/mylv 24507776 32 24507744 1% /mnt