首页 > 系统相关 >Linux LVM扩容

Linux LVM扩容

时间:2023-03-18 18:45:45浏览次数:54  
标签:扩容 sector vg -- Linux dev lv ubuntu LVM

Ubuntu默认安装自带了LVM的结构,可以很方便扩容

root@node3:~# lsblk 
NAME                      MAJ:MIN RM   SIZE RO TYPE MOUNTPOINTS
loop0                       7:0    0 109.6M  1 loop /snap/lxd/24326
loop1                       7:1    0  43.2M  1 loop /snap/snapd/18363
loop2                       7:2    0  59.1M  1 loop /snap/core20/1826
loop3                       7:3    0  59.1M  1 loop /snap/core20/1832
sr0                        11:0    1  1024M  0 rom  
nvme0n1                   259:0    0   100G  0 disk 
├─nvme0n1p1               259:1    0   953M  0 part /boot/efi
├─nvme0n1p2               259:2    0   1.8G  0 part /boot
└─nvme0n1p3               259:3    0  17.3G  0 part 
  └─ubuntu--vg-ubuntu--lv 253:0    0  17.3G  0 lvm  /

需求是在VM中上调大磁盘,在虚拟机中扩大容量

  1. 先用gdisk创建新磁盘
 root@node3:~# gdisk
GPT fdisk (gdisk) version 1.0.8

Type device filename, or press <Enter> to exit: /dev/nvme0n1
Partition table scan:
  MBR: protective
  BSD: not present
  APM: not present
  GPT: present

Found valid GPT with protective MBR; using GPT.

Command (? for help): p

#打印现有分区

Disk /dev/nvme0n1: 209715200 sectors, 100.0 GiB
Model: VMware Virtual NVMe Disk
Sector size (logical/physical): 512/512 bytes
Disk identifier (GUID): 85321C7A-EE62-404B-8273-93113AB86745
Partition table holds up to 128 entries
Main partition table begins at sector 2 and ends at sector 33
First usable sector is 34, last usable sector is 209715166
Partitions will be aligned on 2048-sector boundaries
Total free space is 167776189 sectors (80.0 GiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048         1953791   953.0 MiB   EF00  
   2         1953792         5623807   1.8 GiB     8300  
   3         5623808        41940991   17.3 GiB    8300 
Command (? for help): n
Partition number (4-128, default 4): 
First sector (34-209715166, default = 41940992) or {+-}size{KMGTP}: 
Last sector (41940992-209715166, default = 209715166) or {+-}size{KMGTP}: 
Current type is 8300 (Linux filesystem)
Hex code or GUID (L to show codes, Enter = 8300): 
Changed type of partition to 'Linux filesystem'
# 全部默认即可

按w保存

Command (? for help): w

Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!

Do you want to proceed? (Y/N): Y
OK; writing new GUID partition table (GPT) to /dev/nvme0n1.
Warning: The kernel is still using the old partition table.
The new table will be used at the next reboot or after you
run partprobe(8) or kpartx(8)
The operation has completed successfully.

重启

  1. 扩大PV
root@node3:~# vgextend ubuntu-vg /dev/nvme0n1p4
Physical volume "/dev/nvme0n1p4" successfully created.
Volume group "ubuntu-vg" successfully extended
  1. 扩大LV
root@node3:~# lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lv
Size of logical volume ubuntu-vg/ubuntu-lv changed from <17.32 GiB (4433 extents) to 97.31 GiB (24912 extents).
Logical volume ubuntu-vg/ubuntu-lv successfully resized.
  1. 扩大文件系统(ext4)
root@node3:~# resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv
resize2fs 1.46.5 (30-Dec-2021)
Filesystem at /dev/mapper/ubuntu--vg-ubuntu--lv is mounted on /; on-line resizing required
old_desc_blocks = 3, new_desc_blocks = 13
The filesystem on /dev/mapper/ubuntu--vg-ubuntu--lv is now 25509888 (4k) blocks long.

综上三步

vgextend ubuntu-vg /dev/nvme0n1p4
lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lv
resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv


root@node3:~# df -Th
Filesystem                        Type   Size  Used Avail Use% Mounted on
...
/dev/mapper/ubuntu--vg-ubuntu--lv ext4    96G   11G   81G  12% /
...

可以看到已经成功扩容

标签:扩容,sector,vg,--,Linux,dev,lv,ubuntu,LVM
From: https://www.cnblogs.com/y-ming/p/17231460.html

相关文章

  • linux系统离线安装docker(分步法&一键法)
    https://blog.csdn.net/chexlong/article/details/127932711 1前言在有的项目场景中,服务器是不允许连接外网的。此时若想在服务器上安装部署docker容器,就不能采用在......
  • linux ESP32开发环境(idf可选择5.0/4.4.4...)
    1、 下载VMware17pro虚拟机下载地址:https://www.vmware.com/cn/products/workstation-pro/workstation-pro-evaluation.html  2、下载ubuntu推荐下载地址:http......
  • Linux安装Nacos
    nacos安装版本:v2.1.1#获取压缩包、解压wgethttps://github.com/alibaba/nacos/releases/download/2.1.1/nacos-server-2.1.1.zipunzipnacos-server-2.1.1.zip###......
  • Linux day1
    配置源curl-s-o/etc/yum.repos.d/CentOS-Base.repohttp://mirrors.163.com/.help/CentOS7-Base-163.repocurl-s-o/etc/yum.repos.d/CentOS-Base.repohttp://mirror......
  • linux环境下部署mysql环境
    一、部署步骤1、将安装包上传到Linux服务器上(目录随意),然后解压缩2、进入到解压后的目录下,分别执行以下命令安装四个包(严格按照顺序执行)rpm-ivhmysql-community-com......
  • Linux下安装jdk的步骤与bug
    Linux下安装jdk的步骤与bug步骤:先在/opt/下创建一个software文件,用于存放压缩包进入opt下:cd/opt创建software文件:sudovimsoftware在software/下用......
  • Linux进程调度的思考
    a.进程怎么载入到CPU中运行?b.当前进程正在运行,怎么确定是否要切换下一个进程?c.怎么选出下一个进程?d.选择进程的算法和优先级?e.介绍一下常用的算法调度逻辑?f.从......
  • [linux][uvc]YUV格式编码的图片
    YUV格式编码的图片,在Linux下需要安装ffmpeg。#安装ffmpeg$sudoaptinstallffmpeg#查看图片,需要注意的是YUV图像的信息中并没有存储宽和高,所以在打开时需要指定图像......
  • [linux][uart] open uart error
    questionExitcode2-cannotopendevice/dev/ttyUSB0microcom-s115200-p/dev/ttyUSB0Usage:microcom[options][options]include:-p,--port=<devfil......
  • [linux]uvc摄像头调试
    uvc摄像头调试改分辨率:源码中v412fmt.fmt.pix.width图像宽度v412fmt.fmt.pix.height图像高度/**capturingfromUVC*platform:rk3568*/#include<stdi......