ubuntu18.04扩容操作笔记(lvm)

ubuntu18.04扩容操作笔记(lvm)

分区扩容扩展步骤

1> parted扩容分区
unit s 
设置以扇区(sector)为单位
print free
查看空闲空间
resizepart [partition number] [end]
扩展分区大小
quit
退出
2> partprobe 刷新分区
3> pvresize /dev/sda3
4> lvextend -l +100%FREE /dev/mapper/ubuntu--vg-root
对 VG(volume group 卷组)中的 LV(logical volume 逻辑卷)进行扩充
5> resize2fs /dev/mapper/ubuntu--vg-root
重置 LV(logical volume 逻辑卷)的空间大小

添加分区扩容步骤

1> fdisk dev/sd[x]
通过 n 命令创建一个新主分区
2> pvcreate /dev/sd[x][n]
创建 PV(physical volume 物理卷)
3> vgextend ubuntu-vg /dev/sd[x][n]
将 PV(physical volume 物理卷)扩到 VG(volume group 卷组)中
4> lvextend -l +100%FREE /dev/mapper/ubuntu--vg-root
对 VG(volume group 卷组)中的 LV(logical volume 逻辑卷)进行扩充
5> resize2fs /dev/mapper/ubuntu--vg-root
重置 LV(logical volume 逻辑卷)的空间大小

提示,三个命令帮助你理解过程

pvdisplay: 查看 PV(physical volume 物理卷)列表信息
vgdisplay: 查看 VG(volume group 卷组)列表信息
lvdisplay: 查看 LV(logical volume 逻辑卷)列表信息

以下内容是我上次扩容失败的笔记,仅做参考


参考帖子

https://blog.csdn.net/jacky128256/article/details/123442981

查看根分区空间

在这里插入图片描述
可以看到,现在已经100%,用不成了。

查看磁盘分区列表

看一下运维给添加空间没有
在这里插入图片描述
没有问题,已经从原来的30G添加到80G空间了。

查看lv信息

root@ubuntu:~# lvdisplay 
  --- Logical volume ---
  LV Path                /dev/ubuntu-vg/ubuntu-lv
  LV Name                ubuntu-lv
  VG Name                ubuntu-vg
  LV UUID                AR3mwc-rmRp-eq47-BCRP-OMdq-Lymk-FvG5zl
  LV Write Access        read/write
  LV Creation host, time ubuntu-server, 2021-09-08 13:51:17 +0800
  LV Status              available
  # open                 1
  LV Size                29.50 GiB
  Current LE             7552
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0

增加根分区

此处用到四个命令
lvextend 扩充
lvreduce 减少
lvresize 重新大小
resize2fs 重新大小
文章附录有help信息

在另外搜了一下怎么添加所有空间

root@ubuntu:~# lvextend -l +100%FREE -r /dev/ubuntu-vg/ubuntu-lv
  Size of logical volume ubuntu-vg/ubuntu-lv changed from 29.50 GiB (7552 extents) to <59.00 GiB (15103 extents).
  Logical volume ubuntu-vg/ubuntu-lv successfully resized.
resize2fs 1.44.1 (24-Mar-2018)
Filesystem at /dev/mapper/ubuntu--vg-ubuntu--lv is mounted on /; on-line resizing required
old_desc_blocks = 4, new_desc_blocks = 8
The filesystem on /dev/mapper/ubuntu--vg-ubuntu--lv is now 15465472 (4k) blocks long.
root@ubuntu:~# lvdisplay 
  --- Logical volume ---
  LV Path                /dev/ubuntu-vg/ubuntu-lv
  LV Name                ubuntu-lv
  VG Name                ubuntu-vg
  LV UUID                AR3mwc-rmRp-eq47-BCRP-OMdq-Lymk-FvG5zl
  LV Write Access        read/write
  LV Creation host, time ubuntu-server, 2021-09-08 13:51:17 +0800
  LV Status              available
  # open                 1
  LV Size                <59.00 GiB
  Current LE             15103
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0
root@ubuntu:~# df -H
Filesystem                         Size  Used Avail Use% Mounted on
udev                               4.2G     0  4.2G   0% /dev
tmpfs                              837M  869k  836M   1% /run
/dev/mapper/ubuntu--vg-ubuntu--lv   63G   30G   31G  50% /
tmpfs                              4.2G     0  4.2G   0% /dev/shm
tmpfs                              5.3M     0  5.3M   0% /run/lock
tmpfs                              4.2G     0  4.2G   0% /sys/fs/cgroup
/dev/sda2                          1.1G  302M  649M  32% /boot
tmpfs                              837M     0  837M   0% /run/user/0

感觉有些不对,怎么是小于59GB。先不管,继续走流程

重置大小

root@ubuntu:~# resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv 
resize2fs 1.44.1 (24-Mar-2018)
The filesystem is already 15465472 (4k) blocks long.  Nothing to do!
root@ubuntu:~# lvdisplay 
  --- Logical volume ---
  LV Path                /dev/ubuntu-vg/ubuntu-lv
  LV Name                ubuntu-lv
  VG Name                ubuntu-vg
  LV UUID                AR3mwc-rmRp-eq47-BCRP-OMdq-Lymk-FvG5zl
  LV Write Access        read/write
  LV Creation host, time ubuntu-server, 2021-09-08 13:51:17 +0800
  LV Status              available
  # open                 1
  LV Size                <59.00 GiB
  Current LE             15103
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0
root@ubuntu:~# df -H
Filesystem                         Size  Used Avail Use% Mounted on
udev                               4.2G     0  4.2G   0% /dev
tmpfs                              837M  869k  836M   1% /run
/dev/mapper/ubuntu--vg-ubuntu--lv   63G   30G   31G  50% /
tmpfs                              4.2G     0  4.2G   0% /dev/shm
tmpfs                              5.3M     0  5.3M   0% /run/lock
tmpfs                              4.2G     0  4.2G   0% /sys/fs/cgroup
/dev/sda2                          1.1G  302M  649M  32% /boot
tmpfs                              837M     0  837M   0% /run/user/0

Nothing to do 什么鬼,不管了,没有加到预期的大小,

在琢磨一下

root@ubuntu:~# fdisk -l
GPT PMBR size mismatch (125829119 != 167772159) will be corrected by w(rite).
Disk /dev/sda: 80 GiB, 85899345920 bytes, 167772160 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 3226BCAC-57EC-4BD9-A9D5-EEE0E4B33A50

Device       Start       End   Sectors Size Type
/dev/sda1     2048      4095      2048   1M BIOS boot
/dev/sda2     4096   2101247   2097152   1G Linux filesystem
/dev/sda3  2101248 125827071 123725824  59G Linux filesystem


Disk /dev/mapper/ubuntu--vg-ubuntu--lv: 59 GiB, 63346573312 bytes, 123723776 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

问题好像出在分区上,/dev/sda3只有59G空间,不太对,咋办,先重启。
不管用

修复分区

网上查的,需要修复分区

root@ubuntu:~# parted -l
Model: VMware Virtual disk (scsi)
Disk /dev/sda: 85.9GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 

Number  Start   End     Size    File system  Name  Flags
 1      1049kB  2097kB  1049kB                     bios_grub
 2      2097kB  1076MB  1074MB  ext4
 3      1076MB  64.4GB  63.3GB


Model: Linux device-mapper (linear) (dm)
Disk /dev/mapper/ubuntu--vg-ubuntu--lv: 63.3GB
Sector size (logical/physical): 512B/512B
Partition Table: loop
Disk Flags: 

Number  Start  End     Size    File system  Flags
 1      0.00B  63.3GB  63.3GB  ext4
 
root@ubuntu:~# fdisk -l
GPT PMBR size mismatch (125829119 != 167772159) will be corrected by w(rite).
Disk /dev/sda: 80 GiB, 85899345920 bytes, 167772160 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 3226BCAC-57EC-4BD9-A9D5-EEE0E4B33A50

Device       Start       End   Sectors Size Type
/dev/sda1     2048      4095      2048   1M BIOS boot
/dev/sda2     4096   2101247   2097152   1G Linux filesystem
/dev/sda3  2101248 125827071 123725824  59G Linux filesystem


Disk /dev/mapper/ubuntu--vg-ubuntu--lv: 59 GiB, 63346573312 bytes, 123723776 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

没有鸟用

分区扩容

不管了,直接给/dev/sda3扩容

root@ubuntu:~# fdisk /dev/sda

Welcome to fdisk (util-linux 2.31.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

GPT PMBR size mismatch (125829119 != 167772159) will be corrected by w(rite).
GPT PMBR size mismatch (125829119 != 167772159) will be corrected by w(rite).

Command (m for help): m

Help:

  Generic
   d   delete a partition
   F   list free unpartitioned space
   l   list known partition types
   n   add a new partition
   p   print the partition table
   t   change a partition type
   v   verify the partition table
   i   print information about a partition

  Misc
   m   print this menu
   x   extra functionality (experts only)

  Script
   I   load disk layout from sfdisk script file
   O   dump disk layout to sfdisk script file

  Save & Exit
   w   write table to disk and exit
   q   quit without saving changes

  Create a new label
   g   create a new empty GPT partition table
   G   create a new empty SGI (IRIX) partition table
   o   create a new empty DOS partition table
   s   create a new empty Sun partition table

Command (m for help): p

Disk /dev/sda: 80 GiB, 85899345920 bytes, 167772160 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 3226BCAC-57EC-4BD9-A9D5-EEE0E4B33A50

Device       Start       End   Sectors Size Type
/dev/sda1     2048      4095      2048   1M BIOS boot
/dev/sda2     4096   2101247   2097152   1G Linux filesystem
/dev/sda3  2101248 125827071 123725824  59G Linux filesystem


放弃了,加30G先用着,剩下的20G不知道怎么加了。

附录

lvextend --help

root@ubuntu:~# lvextend --help
  lvextend - Add space to a logical volume // 添加空间到一个逻辑卷

  Extend an LV by a specified size. // 扩展一个LV通过一个明确的大小
  lvextend -L|--size [+]Size[m|UNIT] LV
	[ -l|--extents [+]Number[PERCENT] ]
	[ -r|--resizefs ]
	[ -i|--stripes Number ]
	[ -I|--stripesize Size[k|UNIT] ]
	[    --poolmetadatasize [+]Size[m|UNIT] ]
	[ COMMON_OPTIONS ]
	[ PV ... ]

  Extend an LV by specified PV extents.// 扩展一个LV通过PV扩展(不懂)
  lvextend LV PV ...
	[ -r|--resizefs ]
	[ -i|--stripes Number ]
	[ -I|--stripesize Size[k|UNIT] ]
	[ COMMON_OPTIONS ]

  Extend a pool metadata SubLV by a specified size. // 扩展一个子LV池通过具一个具体的大小(不懂)
  lvextend --poolmetadatasize [+]Size[m|UNIT] LV_thinpool
	[ -i|--stripes Number ]
	[ -I|--stripesize Size[k|UNIT] ]
	[ COMMON_OPTIONS ]
	[ PV ... ]

  Extend an LV according to a predefined policy. // 扩展一个LV按照一个预定的策略(不懂)
  lvextend --usepolicies LV_snapshot_thinpool
	[ -r|--resizefs ]
	[ COMMON_OPTIONS ]
	[ PV ... ]

  Common options for command:
	[ -A|--autobackup y|n ]
	[ -f|--force ]
	[ -m|--mirrors Number ]
	[ -n|--nofsck ]
	[    --alloc contiguous|cling|cling_by_tags|normal|anywhere|inherit ]
	[    --nosync ]
	[    --noudevsync ]
	[    --reportformat basic|json ]
	[    --type linear|striped|snapshot|mirror|raid|thin|cache|thin-pool|cache-pool ]

  Common options for lvm:
	[ -d|--debug ]
	[ -h|--help ]
	[ -q|--quiet ]
	[ -v|--verbose ]
	[ -y|--yes ]
	[ -t|--test ]
	[    --commandprofile String ]
	[    --config String ]
	[    --driverloaded y|n ]
	[    --longhelp ]
	[    --profile String ]
	[    --version ]

  Use --longhelp to show all options and advanced commands.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值