当前位置:网站首页>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
边栏推荐
- Musk has more than 100 million twitter fans, but he has been lost online for a week
- Overview of currency
- 逸仙电商发布一季报:坚持研发及品牌投入,实现可持续高质量发展
- 技能梳理[email protected]语音模块+stm32+nfc
- Getting started with X86 - take over bare metal control
- ModuleNotFoundError: No module named ‘_ swigfaiss‘
- 光明行动:共同呵护好孩子的眼睛——广西实施光明行动实地考察调研综述
- "Hackers and painters" -- why not be stupid
- 6. Redis new data type
- The preliminary round of the sixth season of 2022 perfect children's model Hefei competition area was successfully concluded
猜你喜欢

透过华为军团看科技之变(五):智慧园区

记一次实习的经历,趟坑必备(一)

MySQL index, transaction and storage engine of database (1)

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

WGet -- 404 not found due to spaces in URL
[email protected]+阿里云+nbiot+dht11+bh1750+土壤湿度传感器+oled"/>技能梳理[email protected]+阿里云+nbiot+dht11+bh1750+土壤湿度传感器+oled

《锦绣中华》中老年公益文旅游-走进佛山敬老院

CVPR 2022 | Tsinghua & bytek & JD put forward BRT: Bridging Transformer for vision and point cloud 3D target detection

I found a wave of "alchemy artifact" in the goose factory. The developer should pack it quickly

mysql数据库基础:视图、变量
随机推荐
技能梳理[email protected]體感機械臂
Deployment of efficient and versatile clusters lvs+kept highly available clusters
Gd32 RT thread RTC driver function
MySQL log management, backup and recovery of databases (1)
MySQL log management, backup and recovery of databases (2)
Compétences Comb 27 @ Body sense Manipulator
Launch of Rural Revitalization public welfare fund and release of public welfare bank for intangible cultural heritage protection of ancient tea tree
Why can't you rob scientists of NFT
Es common curl finishing
CVPR 2022 | Tsinghua & bytek & JD put forward BRT: Bridging Transformer for vision and point cloud 3D target detection
Test memory read rate
Musk has more than 100 million twitter fans, but he has been lost online for a week
What is the real performance of CK5, the king machine of CKB?
郭琳加冕 2022第三季完美大师 全球人气季军
How to deploy deflationary combustion destruction contract code in BSC chain_ Deploy dividend and marketing wallet contract code
Ant s19xp appeared in 140t, why is it called the computing power ceiling by the world
Leetcode question brushing (IV) -- greedy thought (go Implementation)
GD32 RT-Thread PWM驱动函数
A brief introduction to database mysql
Overview of currency