当前位置:网站首页>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
边栏推荐
- What is the real performance of CK5, the king machine of CKB?
- Who should the newly admitted miners bow to in front of the chip machine and the graphics card machine
- 乡村振兴公益基金启动暨古茶树非遗保护公益行发布
- Guolin was crowned the third place of global popularity of perfect master in the third quarter of 2022
- Gd32 RT thread RTC driver function
- KOREANO ESSENTIAL打造气质职场范
- Questions about cookies and sessions
- Foster design method
- Leetcode question brushing (III) -- binary search (go Implementation)
- L'activité "Kunming City coffee map" a rouvert
猜你喜欢

Go -- maximum heap and minimum heap

Koreano essential creates a professional style

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

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

mysql数据库基础:存储过程和函数

IPhone address book import into Excel

我在鹅厂淘到了一波“炼丹神器”,开发者快打包

著名画家史国良《丰收时节》数字藏品上线长城数艺

Configure Yii: display MySQL extension module verification failed

郭琳加冕 2022第三季完美大师 全球人气季军
随机推荐
ArcGIS Pro + PS 矢量化用地规划图
KOREANO ESSENTIAL打造气质职场范
ArcGIS Pro脚本工具(5)——排序后删除重复项
Dow Jones Industrial Average
Who should the newly admitted miners bow to in front of the chip machine and the graphics card machine
透过华为军团看科技之变(五):智慧园区
Yixian e - commerce publie un rapport trimestriel: adhérer à la R & D et à l’investissement de la marque, réaliser un développement durable et de haute qualité
Leetcode question brushing (II) -- sorting (go Implementation)
移植完整版RT-Thread到GD32F4XX(详细)
技能梳理[email protected]在oled上控制一条狗的奔跑
Launch of Rural Revitalization public welfare fund and release of public welfare bank for intangible cultural heritage protection of ancient tea tree
GD32 RT-Thread PWM驱动函数
Jump table introduction
Guolin was crowned the third place of global popularity of perfect master in the third quarter of 2022
Koreano essential creates a professional style
转卡通学习笔记
半钢同轴射频线的史密斯圆图查看和网络分析仪E5071C的射频线匹配校准
GD32 RT-Thread OTA/Bootloader驱动函数
技能梳理[email protected]体感机械臂
著名画家史国良《丰收时节》数字藏品上线长城数艺