SoFunction
Updated on 2025-03-04

How to add vg size in Linux system

New vg size added to Linux system

Recently, many friends around me asked me how to operate the new vg in Linux, and how to operate the existing vg in Linux expansion. Next, I will take you to see how we add and expand the capacity.

1. Due to limited resources

So I can only add 10G, ah~~, add a 10G data disk.

We can see it after adding the data disk. After I add it, my name is sdb.

[root@localhost ~]# lsblk
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda      8:0    0   20G  0 disk 
├─sda1   8:1    0  300M  0 part /boot
├─sda2   8:2    0    2G  0 part [SWAP]
└─sda3   8:3    0 17.7G  0 part /
sdb      8:16   0   10G  0 disk 
sr0     11:0    1 1024M  0 rom  
[root@localhost ~]# fdisk -l

Disk /dev/sda: 21.5 GB, 21474836480 bytes, 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000dad8d

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048      616447      307200   83  Linux
/dev/sda2          616448     4810751     2097152   82  Linux swap / Solaris
/dev/sda3         4810752    41943039    18566144   83  Linux

Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

[root@localhost ~]# 
2. Create this disk PV
[root@localhost ~]# lsblk
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda      8:0    0   20G  0 disk 
├─sda1   8:1    0  300M  0 part /boot
├─sda2   8:2    0    2G  0 part [SWAP]
└─sda3   8:3    0 17.7G  0 part /
sdb      8:16   0   10G  0 disk 
sr0     11:0    1 1024M  0 rom  
[root@localhost ~]# pvcreate /dev/sdb
  Physical volume "/dev/sdb" successfully created.
[root@localhost ~]# 

3. Create this disk into VG

VG name vgdata1

[root@localhost ~]# vgcreate vgdata1 /dev/sdb
  Volume group "vgdata1" successfully created
[root@localhost ~]# vgs
  VG      #PV #LV #SN Attr   VSize   VFree  
  vgdata1   1   0   0 wz--n- <10.00g <10.00g
[root@localhost ~]# 

4. Create an LV

The name is Lvdata1, and after creation is completed, check it.

[root@localhost ~]# lvcreate -L 9.9G -n Lvdata1 vgdata1 
 Rounding up size to full physical extent 9.90 GiB
  Logical volume "Lvdata1" created.
[root@localhost ~]# cd /dev/mapper/
[root@localhost mapper]# ls
control  vgdata1-Lvdata1
[root@localhost mapper]# 

5. Assign it to the file system with the created vgdata1-Lvdata1

I'm not going to explain much here~~

[root@localhost ~]# mkfs.ext4 /dev/mapper/
control          vgdata1-Lvdata1  
[root@localhost ~]# mkfs.ext4 /dev/mapper/vgdata1-Lvdata1 
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
648960 inodes, 2595840 blocks
129792 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2151677952
80 block groups
32768 blocks per group, 32768 fragments per group
8112 inodes per group
Superblock backups stored on blocks: 
	32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done 

[root@localhost ~]# 

6. At this point, it has been completed

If you need to mount it, you can continue to read it below~~

[root@localhost ~]# lsblk
NAME              MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda                 8:0    0   20G  0 disk 
├─sda1              8:1    0  300M  0 part /boot
├─sda2              8:2    0    2G  0 part [SWAP]
└─sda3              8:3    0 17.7G  0 part /
sdb                 8:16   0   10G  0 disk 
└─vgdata1-Lvdata1 253:0    0  9.9G  0 lvm  
sr0                11:0    1 1024M  0 rom  
[root@localhost ~]# 

7. If you need to mount it

I'll tell you quietly that you need to create a mount path, or mount it on an existing path, and hang wherever you want according to customer needs.

Here I want to mount it in /opt/a

[root@localhost ~]# mkdir /opt/a
[root@localhost ~]# ls /opt
a  rh
[root@localhost ~]# 


It's already installed here,
[root@localhost ~]# mount /dev/mapper/vgdata1-Lvdata1 /opt/a
[root@localhost ~]# df -h
Filesystem                   Size  Used Avail Use% Mounted on
/dev/sda3                     18G  4.3G   14G  24% /
devtmpfs                     471M     0  471M   0% /dev
tmpfs                        487M     0  487M   0% /dev/shm
tmpfs                        487M  8.6M  478M   2% /run
tmpfs                        487M     0  487M   0% /sys/fs/cgroup
/dev/sda1                    297M  147M  151M  50% /boot
tmpfs                         98M   20K   98M   1% /run/user/1000
tmpfs                         98M     0   98M   0% /run/user/0
/dev/mapper/vgdata1-Lvdata1  9.7G   37M  9.1G   1% /opt/a
[root@localhost ~]# 

Summarize

The above is personal experience. I hope you can give you a reference and I hope you can support me more.