At this point, we assume that the server already has the following:
Software installation and information viewing
First check whether the software is installed:
[root@Candy ~]# rpm -qa | grep lvm lvm2-libs-2.02.118-2.el6.x86_64 lvm2-2.02.118-2.el6.x86_64 [root@Candy ~]# lv lvchange lvextend lvmdiskscan lvmsar lvresize lvconvert lvm lvmdump lvreduce lvs lvcreate lvmchange lvmetad lvremove lvscan lvdisplay lvmconf lvmsadc lvrename [root@Candy ~]# rpm -qa | grep parted parted-2.1-29.el6.x86_64
After the software is ready, check the VM hardware:
[root@Candy ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/vg_candy-root 7.3G 231M 6.7G 4% / tmpfs 1.9G 0 1.9G 0% /dev/shm /dev/sda1 477M 30M 422M 7% /boot /dev/mapper/vg_candy-home 3.9G 8.0M 3.7G 1% /home /dev/mapper/vg_candy-usr 3.9G 382M 3.3G 11% /usr /dev/mapper/vg_candy-var 3.9G 63M 3.6G 2% /var [root@Candy ~]# fdisk -l Disk /dev/sda: 21.5 GB, 21474836480 bytes 255 heads, 63 sectors/track, 2610 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x0006e71c Device Boot Start End Blocks Id System /dev/sda1 * 1 64 512000 83 Linux Partition 1 does not end on cylinder boundary. /dev/sda2 64 2611 20458496 8e Linux LVM Disk /dev/sdb: 4398.0 GB, 4398046511104 bytes 255 heads, 63 sectors/track, 534698 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00000000 Disk /dev/mapper/vg_candy-root: 8061 MB, 8061452288 bytes 255 heads, 63 sectors/track, 980 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00000000 Disk /dev/mapper/vg_candy-usr: 4294 MB, 4294967296 bytes 255 heads, 63 sectors/track, 522 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00000000 Disk /dev/mapper/vg_candy-var: 4294 MB, 4294967296 bytes 255 heads, 63 sectors/track, 522 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00000000 Disk /dev/mapper/vg_candy-home: 4294 MB, 4294967296 bytes 255 heads, 63 sectors/track, 522 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00000000 [root@Candy ~]# ls /dev/sd* /dev/sda /dev/sda1 /dev/sda2 /dev/sdb
At this point we can see that CentOS already knows there is a disk called sdb, but it is not mounted or partitioned.
Use Parted to partition before expansion
Now suppose that all partitions except /boot are full! We need to partition first and use the 4TB hard disk (/dev/sdb).
[root@Candy ~]# parted /dev/sdb GNU Parted 2.1 Using /dev/sdb Welcome to GNU Parted! Type 'help' to view a list of commands. (parted) mklabel New disk label type? gpt (parted) mkpart Partition name? []? File system type? [ext2]? ext4 Starting point? 0T Ending point? 4T (parted) p Model: VMware, VMware Virtual S (scsi) Disk /dev/sdb: 4398GB Sector size (logical/physical): 512B/512B Partition Table: gpt Number Start End Size File system Name Mark 1 1049kB 4398GB 4398GB (parted)set 1 lvm on (parted)p Model: VMware, VMware Virtual S (scsi) Disk /dev/sdb: 4398GB Sector size (logical/physical): 512B/512B Partition Table: gpt Number Start End Size File system Name Flag 1 1049kB 4398GB 4398GB lvm (parted)q [root@Candy ~]# ls /dev/sd* /dev/sda /dev/sda1 /dev/sda2 /dev/sdb /dev/sdb1
Now let's explain the operation:
Next, we check to see what our LVM group is called:
[root@Candy ~]# vgs VG #PV #LV #SN Attr VSize VFree vg_candy 1 4 0 wz--n- 19.51g 0 [root@Candy ~]# vgdisplay --- Volume group --- VG Name vg_candy System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 5 VG Access read/write VG Status resizable MAX LV 0 Cur LV 4 Open LV 4 Max PV 0 Cur PV 1 Act PV 1 VG Size 19.51 GiB PE Size 4.00 MiB Total PE 4994 Alloc PE / Size 4994 / 19.51 GiB Free PE / Size 0 / 0 VG UUID Gcm5Ml-fc88-Xk5q-xuPC-Kj7Y-alfK-i770Gc [root@Candy ~]# lvscan ACTIVE '/dev/vg_candy/usr' [4.00 GiB] inherit ACTIVE '/dev/vg_candy/var' [4.00 GiB] inherit ACTIVE '/dev/vg_candy/home' [4.00 GiB] inherit ACTIVE '/dev/vg_candy/root' [7.51 GiB] inherit [root@Candy ~]#
Knowing that the lvm volume group is called 'vg_candy', we use vgextend to add members to the lvm 'vg_candy' volume group.
[root@Candy ~]# vgextend vag_candy /dev/sdb1 Physical volume "/dev/sdb1" successfully created Volume group "vg_candy" successfully extended
Now let's use the vgs command to check the number of pvs:
[root@Candy ~]# vgs VG #PV #LV #SN Attr VSize VFree vg_candy 2 4 0 wz--n- 4.02t 4.00t
Have you seen that the number of PVs has changed from 1 to 2 by comparing the vgs before adding it?
Now let's use vgdisplay to see the current partition capacity.
[root@Candy ~]# vgdisplay --- Volume group --- VG Name vg_candy System ID Format lvm2 Metadata Areas 2 Metadata Sequence No 6 VG Access read/write VG Status resizable MAX LV 0 Cur LV 4 Open LV 4 Max PV 0 Cur PV 2 Act PV 2 VG Size 4.02 TiB PE Size 4.00 MiB Total PE 1053569 Alloc PE / Size 4994 / 19.51 GiB Free PE / Size 1048575 / 4.00 TiB VG UUID Gcm5Ml-fc88-Xk5q-xuPC-Kj7Y-alfK-i770Gc
Comparing the unadded vgdiplay command again, we find that the value of FreePE changes from 0 / 0 to 1048575 / 4.00 TiB. This means that Candy has successfully added the 4TB lvm partition to the vg_candy logical volume group.
Now before we expand all logical partitions, we can use df -h to see which partitions there are.
[root@Candy ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/vg_candy-root 7.3G 231M 6.7G 4% / tmpfs 1.9G 0 1.9G 0% /dev/shm /dev/sda1 477M 30M 422M 7% /boot /dev/mapper/vg_candy-home 3.9G 8.0M 3.7G 1% /home /dev/mapper/vg_candy-usr 3.9G 382M 3.3G 11% /usr /dev/mapper/vg_candy-var 3.9G 63M 3.6G 2% /var
Now that the hassle is done, all that remains is to expand the capacity of the partition.
Expand the disk capacity
Assume: We need to add 500G capacity to these partitions: /
, /home
, /usr
, /var
[root@Candy ~]# lvextend -L +500G /dev/mapper/vg_candy-root Size of logical volume vg_candy/root changed from 7.51 GiB (1922 extents) to 507.51 GiB (129922 extents). Logical volume root successfully resized [root@Candy ~]# lvextend -L +500G /dev/mapper/vg_candy-home Size of logical volume vg_candy/home changed from 4.00 GiB (1024 extents) to 504.00 GiB (129024 extents). Logical volume home successfully resized [root@Candy ~]# lvextend -L +500G /dev/mapper/vg_candy-usr Size of logical volume vg_candy/usr changed from 4.00 GiB (1024 extents) to 504.00 GiB (129024 extents). Logical volume usr successfully resized [root@Candy ~]# lvextend -L +500G /dev/mapper/vg_candy-var Size of logical volume vg_candy/var changed from 4.00 GiB (1024 extents) to 504.00 GiB (129024 extents). Logical volume var successfully resized
Please note that this step is irreversible! It's OK if you enter the wrong partition name! If you add it to other partitions, you have to repeat the process N times to shrink the capacity, which is quite troublesome! I suggest you check the FileSystem above carefully. Remember...
The expansion is successful! Let's use the above command again to view the LVM information:
[root@Candy ~]# vgs VG #PV #LV #SN Attr VSize VFree vg_candy 2 4 0 wz--n- 4.02t 2.05t [root@Candy ~]# lvscan ACTIVE '/dev/vg_candy/usr' [504.00 GiB] inherit ACTIVE '/dev/vg_candy/var' [504.00 GiB] inherit ACTIVE '/dev/vg_candy/home' [504.00 GiB] inherit ACTIVE '/dev/vg_candy/root' [507.51 GiB] inherit [root@Candy ~]# vgdisplay --- Volume group --- VG Name vg_candy System ID Format lvm2 Metadata Areas 2 Metadata Sequence No 10 VG Access read/write VG Status resizable MAX LV 0 Cur LV 4 Open LV 4 Max PV 0 Cur PV 2 Act PV 2 VG Size 4.02 TiB PE Size 4.00 MiB Total PE 1053569 Alloc PE / Size 516994 / 1.97 TiB Free PE / Size 536575 / 2.05 TiB VG UUID Gcm5Ml-fc88-Xk5q-xuPC-Kj7Y-alfK-i770Gc [root@Candy ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/vg_candy-root 7.3G 231M 6.7G 4% / tmpfs 1.9G 0 1.9G 0% /dev/shm /dev/sda1 477M 30M 422M 7% /boot /dev/mapper/vg_candy-home 3.9G 8.0M 3.7G 1% /home /dev/mapper/vg_candy-usr 3.9G 382M 3.3G 11% /usr /dev/mapper/vg_candy-var 3.9G 63M 3.6G 2% /var
You may be surprised to see this! Why hasn't df -h changed?
Refresh disk information and write
We need to use resize2fs to resize the partition so that df -h can also take effect.
The time required for resize2fs is linearly superimposed with the capacity you provide. In other words, the more capacity you provide, the more time resize2fs will take.
[root@Candy ~]# resize2fs /dev//mapper/vg_candy-root resize2fs 1.41.12 (17-May-2010) Filesystem at /dev//mapper/vg_candy-root is mounted on /; on-line resizing required old desc_blocks = 1, new_desc_blocks = 32 Performing an on-line resize of /dev//mapper/vg_candy-root to 133040128 (4k) blocks. The filesystem on /dev//mapper/vg_candy-root is now 133040128 blocks long. [root@Candy ~]# resize2fs /dev//mapper/vg_candy-usr resize2fs 1.41.12 (17-May-2010) Filesystem at /dev//mapper/vg_candy-usr is mounted on /usr; on-line resizing required old desc_blocks = 1, new_desc_blocks = 32 Performing an on-line resize of /dev//mapper/vg_candy-usr to 132120576 (4k) blocks. The filesystem on /dev//mapper/vg_candy-usr is now 132120576 blocks long. [root@Candy ~]# resize2fs /dev//mapper/vg_candy-var resize2fs 1.41.12 (17-May-2010) Filesystem at /dev//mapper/vg_candy-var is mounted on /var; on-line resizing required old desc_blocks = 1, new_desc_blocks = 32 Performing an on-line resize of /dev//mapper/vg_candy-var to 132120576 (4k) blocks. The filesystem on /dev//mapper/vg_candy-var is now 132120576 blocks long. [root@Candy ~]# resize2fs /dev//mapper/vg_candy-home resize2fs 1.41.12 (17-May-2010) Filesystem at /dev//mapper/vg_candy-home is mounted on /home; on-line resizing required old desc_blocks = 1, new_desc_blocks = 32 Performing an on-line resize of /dev//mapper/vg_candy-home to 132120576 (4k) blocks. The filesystem on /dev//mapper/vg_candy-home is now 132120576 blocks long. [root@Candy ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/vg_candy-root 500G 245M 474G 1% / tmpfs 1.9G 0 1.9G 0% /dev/shm /dev/sda1 477M 30M 422M 7% /boot /dev/mapper/vg_candy-home 496G 16M 471G 1% /home /dev/mapper/vg_candy-usr 496G 390M 471G 1% /usr /dev/mapper/vg_candy-var 496G 71M 471G 1% /var
Conclusion
By the way, I’ll show you a picture of the system automatically mounting after restarting!
The Linux system is quite smart. In fact, it can be used with or without restarting. I just want to show you the effect after restarting.
The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.
environment
| ||||||||
<<: How to solve the problem of ERROR 2003 (HY000) when starting mysql
>>: Summary of 10 advanced tips for Vue Router
This article example shares the specific code of ...
GitHub address, you can star it if you like it Pl...
Table of contents Overview Code Implementation Si...
Content Detail Tags: <h1>~<h6>Title T...
Preface Index Condition Pushdown (ICP) is a new f...
In centos7, the permissions of the /etc/rc.d/rc.l...
Preface “When it comes to image processing, we of...
1. Introduction Recently, I helped a friend to ma...
In MySQL, databases correspond to directories wit...
This article mainly introduces how to implement l...
1. Query process show processlist 2. Query the co...
Problem background: When using docker to deploy t...
Create a simple Spring boot web project Use the i...
location / { index index.jsp; proxy_next_upstream...
1. Basic use <!DOCTYPE html> <html lang=...