当前位置:网站首页>How to expand disk space on AWS host
How to expand disk space on AWS host
2022-06-24 15:39:00 【Exclusive rainy days】
The purpose is to : In the existing EC2 Insufficient disk space on the host , how Expand aws Disk space on the host ?
Overview of Logic Volume Manager(LVM)
And I saw LVM( Logical volume group management ). Using logical volumes can easily expand the size of partitions .

- Physical Volume(PV):This can be created on a whole physical disk (think /dev/sda) or a Linux partition.( Physical volume – Disk partition )
- Volume Group (VG): This is made up of at least one or more physical volumes.( Logical volume group )
- Logical Volume (LV): This is sometimes referred to as the partition, it sits within a volume group and has a file system written to it.( Logic volume )
- File System: A file system such as ext4 will be on the logical volume.( file system )
A mounted disk , It should correspond to this one Physical Volume.
How to increase or expand LVM
First we start with aws The console in is ready for the new EBS volume (create Volume), And mount (attached). And then go to the terminal .
[email protected]:~$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
loop0 7:0 0 91M 1 loop /snap/core/6350
loop1 7:1 0 18M 1 loop /snap/amazon-ssm-agent/930
loop2 7:2 0 89.3M 1 loop /snap/core/6673
loop3 7:3 0 17.9M 1 loop /snap/amazon-ssm-agent/1068
loop4 7:4 0 89.4M 1 loop /snap/core/6818
xvda 202:0 0 8G 0 disk
└─xvda1 202:1 0 8G 0 part /
######### The bottom one is the newly added two pieces EBS volume #########
xvdf 202:80 0 2G 0 disk
xvdg 202:96 0 2G 0 disk
secondly , We use pvcreate The order will Physical hard disk (disk) Initialize to Physical volume (Physical Volume).
[email protected]:~$ sudo pvcreate /dev/xvdf /dev/xvdg
Physical volume "/dev/xvdf" successfully created.
Physical volume "/dev/xvdg" successfully created.
Use sudo pvscan -n Available physical volumes can be viewed
[email protected]:~$ sudo pvscan -n
WARNING: only considering physical volumes in no volume group
PV /dev/xvdf lvm2 [2.00 GiB]
PV /dev/xvdg lvm2 [2.00 GiB]
Again using pvdisplay You can see , Two new ones “/dev/xvdf” and “/dev/xvdg” It doesn't belong to any one yet Volume Group.(VG Name It's empty )
[email protected]:~$ sudo pvdisplay
"/dev/xvdf" is a new physical volume of "2.00 GiB"
--- NEW Physical volume ---
PV Name /dev/xvdf
VG Name
PV Size 2.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID Cxcn22-4gxj-eJP1-E94R-MiPs-Rrm0-a4leFY
"/dev/xvdg" is a new physical volume of "2.00 GiB"
--- NEW Physical volume ---
PV Name /dev/xvdg
VG Name
PV Size 2.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID giplCK-pQjh-cN66-d8Vr-J2lN-dDyp-cHdCQa
pvscan、pvcreate、pvdisplay It's all about pv start , Said to Physical Volume The operation of
Use vgdisplay Can show all of Volume Group Group information .( Since no new logical volume group has been created , So it's empty )
[email protected]:~$ sudo vgdisplay
[email protected]:~$
Use vgcreate Command to create Volume Group. For example, create a new one named vgdata Logical volume group of , And the physical volume /dev/xvdf Add to volume group .
[email protected]:~$ sudo vgcreate vgdata /dev/xvdf
Volume group "vgdata" successfully created
[email protected]:~$ sudo vgdisplay
--- Volume group ---
VG Name vgdata
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 1
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 0
Open LV 0
Max PV 0
Cur PV 1
Act PV 1
VG Size <2.00 GiB
PE Size 4.00 MiB
Total PE 511
Alloc PE / Size 0 / 0
Free PE / Size 511 / <2.00 GiB
VG UUID gW1oil-0JwD-YD16-BO8m-oPo5-1Fe3-tLP2rr
How do we want to dynamically add physical volumes to volume groups , You can use commands vgextend. such as , I want to initialize the newly initialized physical volume /dev/xvdg Also join the newly created logical volume group (vgdata) in .
[email protected]:~$ sudo vgextend vgdata /dev/xvdg
Volume group "vgdata" successfully extended
[email protected]:~$ sudo vgdisplay
--- Volume group ---
VG Name vgdata
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 2
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 0
Open LV 0
Max PV 0
Cur PV 2
Act PV 2
VG Size 3.99 GiB
PE Size 4.00 MiB
Total PE 1022
Alloc PE / Size 0 / 0
Free PE / Size 1022 / 3.99 GiB
VG UUID gW1oil-0JwD-YD16-BO8m-oPo5-1Fe3-tLP2rr
You can see VG Size It has been expanded by half . But now the whole path
The biggest benefit of this expansion is , Without interrupting application access to logical volumes . The whole extension process , For applications , It's completely transparent .
Now comes logic Volume The operation of . You need to generate logical volumes based on logical volume groups . such as :
sudo lvcreate -n lvname1 -L 512M vgdata
sudo lvcreate -n lvname2 -l 100%FREE vgdata
among :
-nIndicates the specified... Of the display logic volume name;-LIndicates the allocated size , use M、G Equivalent unit of measure ;-lIt also indicates the allocated size , But as a percentage ;vgdataIndicates the logical volume group to which it belongs
see logic Volume Summary information for ( In the same way pvs、gvs、lvs)
[email protected]:~$ sudo lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
lvname1 vgdata -wi-a----- 512.00m
lvname2 vgdata -wi-a----- 3.49g
Created Logic Volume after , You also need to specify File System. such as , Designated as ext4 File format .
[email protected]:~$ sudo mkfs.ext4 /dev/vgdata/lvname1
mke2fs 1.44.1 (24-Mar-2018)
Creating filesystem with 131072 4k blocks and 32768 inodes
Filesystem UUID: 27ee34cc-d587-45a9-8e83-1c928ea8d532
Superblock backups stored on blocks:
32768, 98304
Allocating group tables: done
Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done
Resizing Logical Volumes and Extending Volume Groups
Reduce or increase logic Volume The capacity of
sudo lvreduce -L -2.5G -r /dev/vgdata/lvname2
sudo lvextend -l +100%FREE -r /dev/vgdata/lvname1
Execution results
[email protected]:~$ sudo lvreduce -L -2.5G -r /dev/vgdata/lvname2
fsck from util-linux 2.31.1
/dev/mapper/vgdata-lvname2: clean, 11/228928 files, 34338/915456 blocks
resize2fs 1.44.1 (24-Mar-2018)
Resizing the filesystem on /dev/mapper/vgdata-lvname2 to 260096 (4k) blocks.
The filesystem on /dev/mapper/vgdata-lvname2 is now 260096 (4k) blocks long.
Size of logical volume vgdata/lvname2 changed from 3.49 GiB (894 extents) to 1016.00 MiB (254 extents).
Logical volume vgdata/lvname2 successfully resized.
[email protected]:~$ sudo lvextend -l +100%FREE -r /dev/vgdata/lvname1
fsck from util-linux 2.31.1
/dev/mapper/vgdata-lvname1: clean, 11/32768 files, 6353/131072 blocks
Size of logical volume vgdata/lvname1 changed from 512.00 MiB (128 extents) to 3.00 GiB (768 extents).
Logical volume vgdata/lvname1 successfully resized.
resize2fs 1.44.1 (24-Mar-2018)
Resizing the filesystem on /dev/mapper/vgdata-lvname1 to 786432 (4k) blocks.
The filesystem on /dev/mapper/vgdata-lvname1 is now 786432 (4k) blocks long.
Mounting Logical Volumes on Boot and on Demand
First get each Logic Volume Of UUID. Use blkid command ,( Here I found that I would do a mapping , take /dev/vgdata/lvname1 → /dev/mapper/vgdata-lvname1)
[email protected]:~$ sudo blkid /dev/vgdata/lvname1
/dev/vgdata/lvname1: UUID="27ee34cc-d587-45a9-8e83-1c928ea8d532" TYPE="ext4"
[email protected]:~$ sudo blkid /dev/vgdata/lvname2
/dev/vgdata/lvname2: UUID="0dbc839f-a67a-4861-afe9-37b2e627f70e" TYPE="ext4"
For each Logic Volume Create mount point ( I only have one attached here )
sudo mkdir /padata
Insert the corresponding entry into /etc/fstab in .
LABEL=cloudimg-rootfs / ext4 defaults,discard 0 0
UUID=27ee34cc-d587-45a9-8e83-1c928ea8d532 /pgdata ext4 defaults 0 0
Save the file above , And start mounting LV
[email protected]:~$ sudo mount -a
[email protected]:~$ sudo mount | grep pgdata
/dev/mapper/vgdata-lvname1 on /pgdata type ext4 (rw,relatime,data=ordered)
Deleting a Logic Volume
Before deleting a logical volume , We need to make sure we delete Volume Has been Unmounted. And then use lvremove.
[email protected]:~$ sudo lvremove /dev/vgdata/lvname2
Do you really want to remove and DISCARD active logical volume vgdata/lvname2? [y/n]: y
Logical volume "lvname2" successfully removed
Space to be deleted , Add to logical volume lvname1 On .
[email protected]:~$ sudo lvextend -l+100%FREE /dev/vgdata/lvname1
Size of logical volume vgdata/lvname1 changed from 3.00 GiB (768 extents) to 3.99 GiB (1022 extents).
Logical volume vgdata/lvname1 successfully resized.
Reference material :
边栏推荐
- leetcode 139. Word break word split (medium)
- 熬夜整理出的软件测试【高频】面试题大全(2022最新)
- QTreeWidget作为单例模式以dll返回的两个问题
- "Industry foresight" future development trend of intelligent security monitoring industry
- Working with collections
- Tencent cloud native intelligent data Lake Conference will be held, revealing the panoramic matrix of Tencent cloud data Lake products for the first time
- Universal file online preview project, open source!
- Is it safe to open an account for stock speculation in the top ten securities app rankings in China
- Xingxinghai, it is said that the new generation can fight better?
- CVPR2022 | 可精簡域適應
猜你喜欢
Oracle RAC configuration multipathing
Record the range of data that MySQL update will lock

【我的OpenGL学习进阶之旅】OpenGL的坐标系的学习笔记

Wi-Fi 7 来啦,它到底有多强?

MongoDB入門實戰教程:學習總結目錄
![clang: warning: argument unused during compilation: ‘-no-pie‘ [-Wunused-command-line-argument]](/img/f0/42f394dbc989d381387c7b953d2a39.jpg)
clang: warning: argument unused during compilation: ‘-no-pie‘ [-Wunused-command-line-argument]

Linux记录-4.22 MySQL5.37安装(补充)

如何扩展aws主机上的磁盘空间

FreeRTOS新建任务不执行问题解决办法

熬夜整理出的软件测试【高频】面试题大全(2022最新)
随机推荐
The security market has entered a trillion era, and the security B2B online mall system has been accurately connected to deepen the enterprise development path
FPGA based analog I ² C protocol system design (medium)
Very exciting! 12000 words summarized the theory of network technology, reviewing the old and learning the new
leetcode 139. Word break word split (medium)
How to allow easydss online classroom system to upload an on-demand file with a space in the file name?
Firefox browser uses plug-ins to set up proxy
熬夜整理出的软件测试【高频】面试题大全(2022最新)
Is industrial securities reliable? Is it safe to open a securities account?
Mongodb Getting started Practical Tutoriel: Learning Summary Table des matières
如何扩展aws主机上的磁盘空间
CVPR 2022 - Interpretation of selected papers of meituan technical team
asciinema 搭配 asciicast2gif 实现高效的命令行终端录制能力
Which account of Dongfang fortune is safer and better
Istio FAQ: 431 request header fields too large
Do you really know the difference between H5 and applet?
New de debugging
Use dictionary
Allwinner a40i industrial Internet gateway design scheme, smart site, smart city core gateway
MongoDB入門實戰教程:學習總結目錄
Is it safe to open an account in flush? What preparation is needed