Linux disk volume expansion

First identify the disk will appear under / dev After successfully

[root@oracle01 ~]# fdisk /dev/sda

## / dev / sda of view by fdisk -l physical disk (first row)

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.

The Command (m for Help): n- ## n-create a new partition
the Partition type: ## here need to select or create a primary partition extended partition, you can be, directly selected from primary partition where
p primary (2 primary, 0 extended , 2 Free) 
E Extended
the select (default P): P ## choose to create a primary partition, the primary partition can have four, numbered 1-4, all of the following direct the transport like, with the remainder automatically space is created
the Partition Number (3,4-, default. 3): 
First a SECTOR (104857600-209715199, default 104857600): 
the Using default value 104857600
Last a SECTOR, sectors or + size + {K, M, G} (104857600-209715199, default 209 715 199): 
the Using default value 209 715 199
Partition 3 of Linux and of the type of size 50 GiB the SET IS

The Command (m for Help): T ## T to modify the partition type
the Partition Number (1-3, default. 3):. 3 ## just created for the section number. 3
Hex code (type L to List All Codes): 8E ## 8e lvm partition is formatted
Changed type of partition 'Linux' to 'Linux LVM'

The Command (m for Help): W ## W stored and written to disk.
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.

 

Here, after saving, you will find an error may occur, display busy to re-read the partition information. Here are solutions. It can be used to restart or perform partprobe or kpartx. So, here performed directly partprobe

[root@oracle01 ~]# partprobe

 

2. Create a physical partition, you need to create a physical partition physical volume:

## 3 physical partitions to create physical volumes, where the / dev / sda3 is the first step in creating a physical partition by fdisk -l can see
## is the first partition on a physical disk / dev / sda below ( a disk can have multiple partitions), had been / dev / sda1, / dev / sda2
## generated by the first step in creating / dev / sda3 partition, and then create the partition as a physical volume

[root@oracle01 ~]# pvcreate /dev/sda3
Physical volume "/dev/sda3" successfully created.
[root@oracle01 ~]# pvdisplay ## 查看物理卷
--- Physical volume ---
PV Name /dev/sda2
VG Name centos
PV Size 49.51 GiB / not usable 3.00 MiB
Allocatable yes 
PE Size 4.00 MiB
Total PE 12674
Free PE 11
Allocated PE 12663
PV UUID 8T9dpf-SrDj-maVi-IlAb-tpPb-Lzyt-WLeRHG

"/dev/sda3" is a new physical volume of "50.00 GiB"
--- NEW Physical volume ---
PV Name /dev/sda3
VG Name 
PV Size 50.00 GiB
Allocatable NO
PE Size 0 
Total PE 0
Free PE 0
Allocated PE 0
PV UUID uRRJtJ-Ds7J-dvqs-y5Lb-W95H-FXeh-C2QNtl

 


3. Physical volume Once created, you need to add a physical volume to the volume group, so as to be distributed in the volume group.

[root@oracle01 ~]# vgdisplay ## 查看卷组
--- Volume group ---
VG Name centos
System ID 
Format lvm2
Metadata Areas 1
Metadata Sequence No 3
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 1
Act PV 1
VG Size <49.51 GiB
PE Size 4.00 MiB
Total PE 12674
Alloc PE / Size 12663 / 49.46 GiB
The PE as Free / Size . 11 / 44.00 MiB volume group ## can see only the remaining space of 44M, the other logical volumes are divided into a similar partitioned 
VG of the UUID 3TMbc1 -A7aP-DAMv-QtUU-VTjC- 4tOf- iAxDkc 

 

[oracle01 the root @ ~] # the vgextend CentOS / dev / sda3 physical volume ## is added to the volume group 
volume group " CentOS " successfully Extended 
[oracle01 the root @ ~ ] # vgdisplay ## after the addition, check again the volume group
 - - Volume Group --- 
VG of the Name CentOS 
the System ID 
the Format LVM2 
the Metadata Areas 2 
the Metadata Sequence No . 5 
VG of Access Read / Write 
VG of the Status resizable 
MAX the LV 0 
the Cur the LV 2 
the Open the LV 2 
Max the PV 0 
the Cur the PV 2 
Act the PV 2 
VG of Size 99.50 GiB 
the PE Size 4.00 MiB 
the Total the PE 25473 
of Alloc the PE / Size 12663 / 49.46 GiB 
as Free the PE / Size 12810 / < 50.04 GiB ## can be seen, added after the success of the remaining space in the volume group becomes large, so there is more space can be allocated, or create new new logical volume 
VG UUID 3TMbc1 -A7aP-DAMv-QtUU-VTjC-4tOf-iAxDkc

 


4. add to the volume group, logical volume is the remaining space for expansion.

[root @ oracle01 ~ ] # ## to see the lvdisplay logical
 --- --- the Logical Volume 
LV Path / dev / CentOS / root ## Logical Volume Name 
LV the Name root 
VG the Name CentOS 
LV UUID RaEygR -53tg-UaJQ-5dJs- by51--e8V4 fcp1DQ 
the LV the Write Access Read / Write 
the LV Creation Host, Time localhost.localdomain, 2017 - 09 - 30  . 19 : 12 is : 05 + 0800 
the LV the Status Available 
# Open . 1 
the LV size 45.46 front GiB ## increases, the size of the logical volume 
LE Current 11639 
Segments. 1 
Allocation the inherit 
the Read Ahead sectors Auto
 - Currently SET to 8192 
Block Device 253 : 0 

[oracle01 the root @ ~] # the lvextend -l + 100 % the FREE / dev / CentOS / the root ## and the remaining space is added to the logical volume hundred percent the 
Size of Logical Volume CentOS / changed from the root 45.46 GiB ( 11639 extents) to 95.50 GiB ( 24449 extents). 
the Logical Volume CentOS / the root Resized successfully. 
[oracle01 the root @ ~ ] # the lvdisplay
 --- --- the Logical Volume 
the LV the Path / dev / CentOS / root 
LV the Name root
VG Name centos
LV UUID RaEygR-53tg-UaJQ-5dJs-e8V4-by51-fcp1DQ
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2017-09-30 19:12:05 +0800
LV Status available
# open 1
LV Size 95.50 GiB ## 增加后,逻辑卷大小
Current LE 24449
Segments 3
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:0

5. recognize it and then re-partition size, you can see the new -h capacity by df

[oracle01 the root @ ~] # xfs_growfs / dev / CentOS / the root ## command, followed by the logical volume with the path 
Meta -data = / dev / Mapper / CentOS an array of lSize = the root- 256 agcount = . 4 , agsize = 2979584 BLKS
 = sectsz = 512 attr = 2 , projid32bit = . 1 
= CRC = 0 finobt = 0 
Data = BSIZE = 4096 Blocks = 11,918,336 , imaxpct = 25 
= SUnit = 0 SWidth = 0 BLKS 
Naming = Version 2 BSIZE = 4096 ASCII-CI = 0 FTYPE = 0
log =internal bsize=4096 blocks=5819, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 11918336 to 25035776

[root@oracle01
~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/centos-root 96G 32G 64G 34% / ## 这里可以看到,已成功扩容 devtmpfs 1.9G 0 1.9G 0% /dev tmpfs 1.9G 0 1.9G 0% /dev/shm tmpfs 1.9G 17M 1.9G 1% /run tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup /dev/sda1 497M 125M 372M 26% /boot tmpfs 379M 0 379M 0% /run/user/0

 

OK, this, the expansion is complete. And without rebooting, easy to use.

Guess you like

Origin www.cnblogs.com/poov/p/11949008.html