Original Address: https: //www.cnblogs.com/ding2016/p/9680690.html
A brief introduction :
LVM is the logical disk volume management (Logical Volume Manager) short, it is a mechanism to manage disk partitions under Linux, LVM is built on the hard disk and partition a logical layer to increase the flexibility of the disk partition management sex. By LVM system administrator can easily manage disk partitions, such as: the plurality of disk partitions is connected to the volume group (VolumeGroup) of a piece, forming a storage pool. Administrators are free to create the logical volume group (logicalvolumes) on a volume group, and further create a file system on the logical volume group. Administrators can easily resize LVM volume group storage, and disk storage can be named, management and distribution in accordance with the group's way.
Expansion Plan :
① add a new disk, and to mount a new hard disk mount point designated by Mount; (such as a new / data directory, the new hard drive to the loading / data provided use)
② add a new hard disk, LVM by the new hard disk space allocated to the original system disk, dynamic disk expansion system; (you can also turn up the original disk in virtual machine settings, and then expansion)
Here the record about the steps in the program ② under centos7.
Test objectives :
To a virtual machine CentOS7.4 original system disk expansion 10G. (Original system disk 30G, expansion to 40G)
Procedure :
1. virtual machine settings editor to add a new hard disk
2. look
[the root-Server @ 10 ~] # DF -H the Filesystem Size Used Avail the Use% Mounted ON devtmpfs 990M 0 990M 0% / dev tmpfs 1001M 1001M 0 0% / dev / SHM tmpfs 1001M 57M 944M. 6% / RUN tmpfs 1001M 0 1001M % 0 / SYS / FS / a cgroup / dev / Mapper / 5.8G CentOS a 27G 22G-22 is the root% / // after expansion, the look, for comparison / dev / sda1 154M 861m 16% of 10-14m / Boot tmpfs 201M 201M 0 % 0 / RUN / User / 0 [the root-Server @ 10 ~] # lsblk NAME the MAJ: the TYPE MOUNTPOINT the RO SIZE MIN RM SDA. 8: 0 0 0 30G Disk ├─sda1 8:1 0 1G 0 part /boot . 8 └─sda2: Part 2 0 0 29G ├─centos the root-253: 0 0 0 a 27G LVM / └─centos the swap-253: 0. 1 0 2G LVM [the SWAP] SDB 1OG 8:16 0 0 // Added Disk hard disk named sdb, already exists, but not to the system partition can not be used sr0 11: 0 1 1024M 0 rom
3. to create a new hard disk partition (where you create a partition by default)
[root@server-10 ~]# fdisk /dev/sdb Welcome to fdisk (util-linux 2.23.2). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. Command (m for help): n // 添加新分区 Partition type: p primary (0 primary, 0 extended, 4 free) e extended Select (default p): // 回车,默认p,主分区 Using default response p Partition number (1-4, default 1): // 回车,默认1 First sector (2048-20971519, default 2048): // 回车,默认起始位置 Using default value 2048 Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519): // enter, default to the last position of the Using default value 20,971,519 the Partition. 1 of the Linux type and size of 10 IS SET GiB the Command (m for Help): T // change format partition the Selected Partition. 1 Hex code (type L to List All Codes) : L // options View
0 24 Empty 81 the Minix the NEC the DOS / Old the Solaris Lin BF . 1 Hidden the NTFS FAT12 27 82 Win the swap the Linux / So C1 DRDOS / sec (FAT- 2 XENIX the root Plan. 9 83 39 C4 DRDOS the Linux / sec ( FAT- . 3 XENIX. 3C usr 84 PartitionMagic the OS / 2 hidden C: C6 DRDOS / sec (FAT- . 4 the FAT16 <32M 40 85 80286 Venix the Linux Extended C7 Syrinx . 5 Extended the PPC 41 is the NTFS the PReP the Boot Volume 86-Non the FS Data SET DA 6 FAT16 42 SFS 87 NTFS volume set db CP/M / CTOS / . 7 HPFS/NTFS/exFAT 4d QNX4.x 88 Linux plaintext de Dell Utility 8 AIX 4e QNX4.x 2nd part 8e Linux LVM df BootIt 9 AIX bootable 4f QNX4.x 3rd part 93 Amoeba e1 DOS access a OS/2 Boot Manag 50 OnTrack DM 94 Amoeba BBT e3 DOS R/O b W95 FAT32 51 OnTrack DM6 Aux 9f BSD/OS e4 SpeedStor c W95 FAT32 (LBA) 52 CP/M a0 IBM Thinkpad hi eb BeOS fs e W95 FAT16 (LBA) 53 OnTrack DM6 Aux a5 FreeBSD ee GPT f W95 Ext'd (LBA) 54 OnTrackDM6 a6 OpenBSD ef EFI (FAT-12/16/ 10 OPUS 55 EZ-Drive a7 NeXTSTEP f0 Linux/PA-RISC b 11 Hidden FAT12 56 Golden Bow a8 Darwin UFS f1 SpeedStor 12 Compaq diagnost 5c Priam Edisk a9 NetBSD f4 SpeedStor 14 Hidden FAT16 <3 61 SpeedStor ab Darwin boot f2 DOS secondary 16 Hidden FAT16 63 GNU HURD or Sys af HFS / HFS+ fb VMware VMFS 17 Hidden HPFS/NTF 64 Novell Netware b7 BSDI fs fc VMware VMKCORE 18 AST SmartSleep 65 Novell Netware b8 BSDI swap fd Linux raid auto 1b Hidden W95 FAT3 70 DiskSecure Mult bb Boot Wizard hid fe LANstep Hidden W95 FAT3 75 PC 1C / FF IX BE the Boot the Solaris BBT 1E Hidden W95 FAT1 80 Old Minix Hex code (of the type L to List All Codes): Device End the Boot the Start Blocks the System Id8E // to change the partition format LVM Changed of the type of Partition 'Linux' to 'Linux LVM' the Command (m for Help) : the p- // print to see a good change partitions (blocks for the partition size in units of kB) 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 the I / O size (Minimum / Optimal): 512 bytes / 512 bytes Disk label of the type: DOS Disk identifier The: 0xa6e3dd82 / dev / sdb1 2048 20,971,519 10,484,736 8E Linux LVM the Command (m for Help): w // save at The Partition the Table has been the Altered! Calling ioctl () to Re-Partition the Read the Table. Syncing Disks.
4. Review the partition again, the partition just good, did not join the system to mount the root can not be used
[root@server-10 ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 30G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 29G 0 part
├─centos-root 253:0 0 27G 0 lvm /
└─centos-swap 253:1 0 2G 0 lvm [SWAP]
sdb 8:16 0 10G 0 disk
└─sdb1 8:17 0 10G 0 part
sr0 11:0 1 1024M 0 rom
The new partition to the physical volume
[root@server-10 ~]# pvcreate /dev/sdb1 Physical volume "/dev/sdb1" successfully created.
6. Review the existing volume group name here centos
[the root-Server @ 10 ~] # the vgdisplay --- --- Volume Group VG of the Name CentOS // This is the default system in Centos VG Name, RHEL system as a RHEL the System ID the Format LVM2 the Metadata Areas. 1 the Metadata Sequence No. 3 VG of Read Access / Write VG of the Status resizable MAX the LV 0 the Cur the LV 2 the Open the LV 2 Max 0 the PV the Cur the PV. 1 Act. 1 the PV VG of Size <GiB 29.00 // monitor the changes in the value of the PE Size 4.00 MiB the Total the PE 7423 of Alloc the PE / Size 7422 / 28.99 GiB as Free the PE / Size. 1 / 4.00 MiB VG UUID RNpAgN-PLQm-M4vp-E37i-fhhp-mr2z-faLm3A
7. The number of physical volumes and to convert VG (volume group)
[root@server-10 ~]# vgextend centos /dev/sdb1 Volume group "centos" successfully extended
[root@server-10 ~]# vgdisplay
--- Volume group ---
VG Name centos
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 4
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 2
Act PV 2
VG Size 38.99 GiB //对比,变大了约10G
PE Size 4.00 MiB
Total PE 9982
Alloc PE / Size 7422 / 28.99 GiB
Free PE / Size 2560 / 10.00 GiB
VG UUID RNpAgN-PLQm-M4vp-E37i-fhhp-mr2z-faLm3A
8. Check the logical volume, the default system is divided into two, select the corresponding logical path
[root@server-10 ~]# lvdisplay
--- Logical volume ---
LV Path /dev/centos/swap //系统默认分了2G给swap,不用管
LV Name swap
VG Name centos
LV UUID w8yxWk-Qrth-x16P-jVg3-1haX-lZUH-0r1SkV
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2018-03-21 02:10:16 +0800
LV Status available
# open 2
LV Size 2.00 GiB
Current LE 512
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:1
--- Logical volume ---
LV Path /dev/centos/root // 后面扩展该逻辑卷,记住该路径
LV Name root
VG Name centos
LV UUID ECEWl4-0AEW-W1Tn-acE2-GLpe-NxeD-v16tGb
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2018-03-21 02:10:16 +0800
LV Status available
# open 1
LV Size 26.99 GiB
Current LE 6910
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:0
9. A logical extension to the space
[root@server-10 ~]# lvextend /dev/centos/root /dev/sdb1 Size of logical volume centos/root changed from 26.99 GiB (6910 extents) to <36.99 GiB (9469 extents). Logical volume centos/root successfully resized.
10. written to the file system, the expansion to take effect.
[root@server-10 ~]# xfs_growfs /dev/mapper/centos-root meta-data=/dev/mapper/centos-root isize=512 agcount=4, agsize=1768960 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=0 spinodes=0 data = bsize=4096 blocks=7075840, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=1 log =internal bsize=4096 blocks=3455, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 data blocks changed from 7075840 to 9696256
If ext system that can replace xfs_growfs command resize2fs command.
11. Check the expansion effect
[root@server-10 ~]# df -h Filesystem Size Used Avail Use% Mounted on devtmpfs 990M 0 990M 0% /dev tmpfs 1001M 0 1001M 0% /dev/shm tmpfs 1001M 57M 944M 6% /run tmpfs 1001M 0 1001M 0% /sys/fs/cgroup /dev/mapper/centos-root 37G 5.8G 32G 16% / /dev/sda1 1014M 154M 861M 16% /boot tmpfs 201M 0 201M 0% /run/user/0
The initial display contrast, successful expansion.
End.