当前位置:网站首页>Using LVM to resize partitions
Using LVM to resize partitions
2022-06-30 10:34:00 【Yangxiangrui】
List of articles
1. problem
Before using Windows I think it's amazing that I can adjust the partition size at will , Feeling Linux You should be able to adjust the partition size at will , But does the tool in the built-in graphical interface have the ability to change the partition size . To study the lvm I realized that I had to use the terminal lvm Tools can adjust the size of partitions
2. Main process
First of all, understand PV(Physical)、VG(Volume Group)、LV(Logic Volume) These three concepts .
PV( Physical volume ) Represents the partition on the actual disk , That is to use gdisk、fdisk Partition out of partition .
VG Express PV Partition group composed of , Multiple PV Of storage space VG Storage space of , here VG It's like a new disk .
LV It means that VG Logical partition on disk .
LV When used, it is a virtual disk partition , Can be used to mount .LV The most important difference from a normal physical partition is LV It can be resized , Partitions of ordinary disks cannot be resized . except LV It can be resized VG You can also adjust the size , Just go VG Add a new physical volume to the .
So create LV The process is as follows :

2.1 gdisk Stage
gdisk First create three new physical volumes on the disk , as follows . Last three Linux filesystem Is the newly created physical partition .
Number Start (sector) End (sector) Size Code Name
1 2048 1230847 600.0 MiB EF00 EFI System Partition
2 1230848 3327999 1024.0 MiB 8300
3 3328000 55764991 25.0 GiB 8E00
4 55764992 57862143 1024.0 MiB 8300 Linux filesystem
5 57862144 58886143 500.0 MiB 8300 Linux filesystem
6 58886144 59910143 500.0 MiB 8300 Linux filesystem
About such as The contents of any physical partition
2.2 PV Stage
PV The phase is a bit like the format of the physical partition phase ,gdisk After partitioning, you only need to use the following instructions to create on the physical partition PV that will do .
$ pvcreate /dev/sda{
4,5,6}
Physical volume "/dev/sda4" successfully created.
Physical volume "/dev/sda5" successfully created.
Physical volume "/dev/sda6" successfully created.
Then use the command pvscan View the created partition ( The display will have a 25G Of PV, That was created when I installed the system )
$ pvscan
PV /dev/sda3 VG fedora_localhost-live lvm2 [25.00 GiB / 7.00 GiB free]
PV /dev/sda4 lvm2 [1.00 GiB]
PV /dev/sda5 lvm2 [500.00 MiB]
PV /dev/sda6 lvm2 [500.00 MiB]
Total: 4 [<26.98 GiB] / in use: 1 [25.00 GiB] / in no VG: 3 [<1.98 GiB]
2.3 VG Stage
VG The stage is to create the previously created PV Add a newly created ( Or old )VG.
Use vgcreate Creating VG Join in at the same time PV
$ vgcreate vg /dev/sda4 /dev/sda5 /dev/sda6
Volume group "vg" successfully created
Once created, you can use vgreduce Delete one PV; Or use vgextend Add one PV. In this way, adjustment can be achieved VG The purpose of size .
$ vgreduce vg /dev/sda5
Removed "/dev/sda5" from volume group "vg"
$ vgextend vg /dev/sda5
Volume group "vg" successfully extended
2.4 LV Stage
And then finally in the VG Create logical partitions on LV.
Use lvcreate Create logical partitions , among -L Specify the size of the partition ,-n Specify the name of the logical partition .
$ lvcreate -L 500M -n first_lv vg
Logical volume "first_lv" created.
The next step is to /dev/vg/first_lv Find the logical partition just separated on the . Then you can use the normal steps to format 、 mount .
$ mkfs.ext4 /dev/vg/first_lv
$ mkdir /media/logical1
$ mount /dev/vg/first_lv /media/logical1
$ df -Th /media/logical1
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/vg-first_lv ext4 477M 2.3M 445M 1% /media/logical1
2.5 Resize partition
Expand first first_lv The capacity of , Use lvresize
$ lvresize -L +500M /dev/vg/first_lv
Size of logical volume vg/first_lv changed from 500.00 MiB (125 extents) to 1000.00 MiB (250 extents).
Logical volume vg/first_lv successfully resized.
Successful expansion first_lv The partition cannot be expanded until the partition is unmounted ( There should be a way not to uninstall , But we haven't found it yet )
$ umount /media/logical1/
$ e2fsck -f /dev/vg/first_lv
$ resize2fs /dev/vg/first_lv
$ mount /dev/vg/first_lv /media/logical1/
$ df -Th /media/logical1/
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/vg-first_lv ext4 961M 2.5M 905M 1% /media/logical1
After mounting, you can see that the capacity of the file system has indeed increased to 1000M.
To reduce the use of file systems lvresize. However, according to the above method of extending the file system, I directly destroyed the file system , So a new one is created 1000M Of first_lv, In another way, it is reduced to 500M.
$ umount /media/logical1
$ lvresize --resizefs --size 500M /dev/vg/fist_lv
fsck from util-linux 2.35.2
/dev/mapper/vg-fist_lv: clean, 11/64000 files, 8748/256000 blocks
resize2fs 1.45.5 (07-Jan-2020)
Resizing the filesystem on /dev/mapper/vg-fist_lv to 128000 (4k) blocks.
The filesystem on /dev/mapper/vg-fist_lv is now 128000 (4k) blocks long.
Size of logical volume vg/fist_lv changed from 1000.00 MiB (250 extents) to 500.00 MiB (125 extents).
Logical volume vg/fist_lv successfully resized.
$ mount /dev/vg/fist_lv /media/logical1/
$ df -Th /media/logical1/
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/vg-fist_lv ext4 477M 1.5M 440M 1% /media/logical1
边栏推荐
- 技能梳理[email protected]语音模块+stm32+nfc
- 乡村振兴公益基金启动暨古茶树非遗保护公益行发布
- Implementation of iterative method for linear equations
- Open source! Wenxin large model Ernie tiny lightweight technology, accurate and fast, full effect
- 半钢同轴射频线的史密斯圆图查看和网络分析仪E5071C的射频线匹配校准
- 【Rust日报】2021-01-23 几个新库发布
- Configure Yii: display MySQL extension module verification failed
- I found a wave of "alchemy artifact" in the goose factory. The developer should pack it quickly
- 逸仙电商发布一季报:坚持研发及品牌投入,实现可持续高质量发展
- 技能梳理[email protected]在oled上控制一条狗的奔跑
猜你喜欢

戴森设计大奖,以可持续化设计改变世界

Compétences Comb 27 @ Body sense Manipulator

The latest SCI impact factor release: the highest score of domestic journals is 46! Netizen: I understand if

Getting started with X86 - take over bare metal control

Deployment of efficient and versatile clusters lvs+kept highly available clusters

IPhone address book import into Excel

2022 Season 6 perfect children's model toxon division finals came to a successful conclusion

Get through the supply chain Shenzhen gift show helps cross-border e-commerce find ways to break the situation

ArcGIS Pro脚本工具(6)——修复CAD图层数据源

The performance of arm's new CPU has been improved by 22%, up to 12 cores can be combined, and the GPU is first equipped with hardware optical tracking. Netizen: the gap with apple is growing
随机推荐
Skill sorting [email protected]+adxl345+ Motor vibration + serial port output
MySQL log management, backup and recovery of databases (2)
【Rust日报】2021-01-22 首份Rust月刊杂志邀请大家一起参与
超长干货 | Kubernetes命名空间详解
A brief introduction to database mysql
【Rust日报】2021-01-23 几个新库发布
[ark UI] implementation of the startup page of harmoniyos ETS
Oracle creates a stored procedure successfully, but the compilation fails
Skill combing [email protected] control a dog's running on OLED
mysql数据库基础:TCL事务控制语言
GeoffreyHinton:我的五十年深度学习生涯与研究心法
Dow Jones Industrial Average
KOREANO ESSENTIAL打造气质职场范
The rising star of Goldshell STC box
马斯克推特粉丝过亿了,但他在线失联已一周
Skill combing [email protected] voice module +stm32+nfc
RobotFramework学习笔记:环境安装以及robotframework-browser插件的安装
R language plot visualization: use plot to visualize the prediction confidence of the multi classification model, the prediction confidence of each data point of the model in the 2D grid, and the conf
Getting started with X86 - take over bare metal control
Es common curl finishing