Tag:Linux fdisk expansion
Category:system(linuxwindows)
Article From:https://www.cnblogs.com/liujiacai/p/9059777.html

Original: http://blog.51cto.com/qicheng0211/1620171

9818Human reading

 

One, a brief introduction to LVM

    LVMIt is the abbreviation of Logical Volume Manager (logical volume management). It is a mechanism for managing disk partitions in Linux environment. LVM takes one or more disk partitions (PV) as a volume group (VG), which is equivalent to a large hard disk.You can divide a number of logical volumes (LV) on it. When the space of the volume group is not enough, new disk partitions can be added. We can also divide some spaces from the volume group space to use logical volumes that are not enough for space.

 

    LVMThe model is as follows:

wKiom1UCozqRFqxeAAG7GUxEGiI294.jpg

Two, LVM add hard disk and dilatancy

    Test environment: CentOS7 64 bit (KVM virtual machine)

    LVMVersion: lvm2-2.02.105-14.el7.x86_64

    1、Add a hard disk (8GB) to the system

wKioL1UCppmhSdIjAAKV8ioaU_8847.jpg

    Use the fdisk -l to see the new disk as /dev/vdb:

1
shell# fdisk -l

wKiom1UCpifTBblUAAQ82M1Bf5g201.jpg

    2、New zoning

    Using the fdisk command to partition the new disk, a primary partition, /dev/vdb1, the size 8GB, is used to reread the partition table with the partprobe command.

1
2
shell# fdisk /dev/vdb
shell# partprobe

 wKioL1UCp5GxyGZaAA4mZCbd6zI957.jpg

    In the partition process, note that the format is 8e, which is the partition format of LVM.

    3、Create a physical volume (PV)

    Use the command pvcreate to create the physical volume, pvdisplay see the physical volume information:

1
2
shell# pvcreate /dev/vdb1
shell# pvdisplay

wKioL1UCqNqxGdtnAALlubh9ZfU693.jpg

    4、Add PV to the volume group (VG)

    Using volume vgdisplay to see the volume group information, the following figure shows that the volume group name is CentOS, and the idle size is 0.

1
shell# vgdisplay

wKioL1UCqauTF4K3AAHZNsqkEPU128.jpg

    Use the command vgextend to add /dev/vdb1 to CentOS:

1
shell# vgextend centos /dev/vdb1

wKioL1UCqieTRfuIAAB8vhFL7c4900.jpg

    We re examined the volume information and found that the free space is 8GB, indicating that /dev/vdb1 has been successfully added.

wKioL1UCqqjCkyMAAAHAR-pYI4Q174.jpg

    5、Create a logical volume (LV)

    Using the lvcreate command to divide a new logical volume from the volume group, a logical volume partition named Newlv, the size 4GB is created, and the logical volume information is viewed with the lvdisplay.

1
2
shell# lvcreate -L 4G -n newlv centos
shell# lvdisplay

 wKiom1UCqguxHgiGAAW2XNw9-gQ507.jpg

    Let’s take a look at the volume group information and regroup the remaining 4GB space:

wKiom1UCqszySmcfAAHjPD9topM757.jpg

    6、Formatting logical volumes and mounting

    The new logical volume can be mounted to the system to store data after formatting. The XFS file system is formatted as CentOS7 using mkfs.xfs.

1
shell# mkfs.xfs /dev/centos/newlv

wKioL1UCreviNJTmAAHP5wDGs_I570.jpg

    Mount to the /mnt directory (you can mount to the directory you want). After mounting, you see the capacity is 4GB:

1
2
shell# mount -t xfs /dev/centos/newlv /mnt/
shell# df -Th

wKiom1UCrPijc-QwAAISB0kRF4Q420.jpg

    Set up auto mount, edit /etc/fstab file, add the last line:

1
/dev/centos/newlv       /mnt                    xfs     defaults        1 2

wKiom1UCru2h4j7zAAD5xdCy684180.jpg

    7、Logical volume expansion

    Use the lvextend command for logical volume expansion. I allocated all the remaining space to Newlv and increased to 8GB, as follows:

1
shell# lvextend -l +100%FREE /dev/centos/newlv

wKioL1UCsGmCLO6tAADG8q0WDxs285.jpg

 

#Extend lvdata to 5G using the lvextend command

1
2
3
[root@node01 ~]# lvextend -L 5G /dev/vgdata/lvdata
  Size of logical volume vgdata/lvdata changed from 4.00 GiB (1024 extents) to 5.00 GiB (1280 extents).
  Logical volume lvdata successfully resized.

Note: if new 5G is added, use lvextend -L +5G /dev/vgdata/lvdata.

   

 Use xfs_growfs command to adjust the size of the XFS file system online (CentOS6 uses resize2fs):

1
shell# xfs_growfs /dev/centos/newlv

wKiom1UCr1OCExEnAAQhpLMXn8g840.jpg

    Finally, we see that the logical volume partition has been dynamically expanded to 8GB:

wKioL1UCsIbTUjAUAAHFG4bUKDE852.jpg

Leave a Reply

Your email address will not be published. Required fields are marked *