CentOS调整LVM分区

0x00 前言

打算把/dev/mapper/VolGroup00-LogVol03逻辑卷的2.5T空间重新分配给/dev/mapper/VolGroup00-LogVol00。

0x01 查看磁盘空间

$ df -lh
Filesystem                       Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00   99G   96G     0 100% /
devtmpfs                          63G     0   63G   0% /dev
tmpfs                             63G     0   63G   0% /dev/shm
tmpfs                             63G   25M   63G   1% /run
tmpfs                             63G     0   63G   0% /sys/fs/cgroup
/dev/sda1                        240M   86M  138M  39% /boot
/dev/mapper/VolGroup00-LogVol01   40G  365M   37G   1% /var
/dev/mapper/VolGroup00-LogVol02  976M   19M  891M   2% /tmp
/dev/mapper/VolGroup00-LogVol03  2.6T   89M  2.5T   1% /da1
tmpfs                             13G     0   13G   0% /run/user/448376178

可以看到根目录已经没有可用空间了,而/da1这个目录还有2.5T可用。

0x02 卸载要缩减的目录/da1

umount /da

如果提示target is busy. 可以用fuser命令解除占用

0x04 调整分区大小

resize2fs -p /dev/mapper/VolGroup00-LogVol03 90M

输出

resize2fs 1.42.9 (28-Dec-2013)
Please run 'e2fsck -f /dev/mapper/VolGroup00-LogVol03' first.

按照提示运行

e2fsck -f /dev/mapper/VolGroup00-LogVol03

输出

e2fsck 1.42.9 (28-Dec-2013)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
/lost+found not found.  Create<y>? yes
Pass 4: Checking reference counts
Pass 5: Checking group summary information

/dev/mapper/VolGroup00-LogVol03: ***** FILE SYSTEM WAS MODIFIED *****
/dev/mapper/VolGroup00-LogVol03: 11/173842432 files (0.0% non-contiguous), 10970219/695369728 blocks

再执行一遍分区命令

resize2fs -p /dev/mapper/VolGroup00-LogVol03 90M

输出

resize2fs 1.42.9 (28-Dec-2013)
resize2fs: New size smaller than minimum (1434844)

0x05 挂载目录/da1

mount /da1/

查看磁盘大小

df -lh

输出

Filesystem                       Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00   99G   96G     0 100% /
devtmpfs                          63G     0   63G   0% /dev
tmpfs                             63G     0   63G   0% /dev/shm
tmpfs                             63G   25M   63G   1% /run
tmpfs                             63G     0   63G   0% /sys/fs/cgroup
/dev/sda1                        240M   86M  138M  39% /boot
/dev/mapper/VolGroup00-LogVol01   40G  365M   37G   1% /var
/dev/mapper/VolGroup00-LogVol02  976M   19M  891M   2% /tmp
tmpfs                             13G     0   13G   0% /run/user/448376178
/dev/mapper/VolGroup00-LogVol03  2.6T   89M  2.5T   1% /da1

没有看到变化

0x06 释放留出来的空间

lvreduce -L 90M /dev/mapper/VolGroup00-LogVol03

输出

  Rounding size to boundary between physical extents: 96.00 MiB
  WARNING: Reducing active and open logical volume to 96.00 MiB
  THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce LogVol03? [y/n]: y
  Size of logical volume VolGroup00/LogVol03 changed from 2.59 TiB (84884 extents) to 96.00 MiB (3 extents).
  Logical volume LogVol03 successfully resized.

看下逻辑卷信息

vgdisplay

输出

  --- Volume group ---
  VG Name               VolGroup00
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  6
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                4
  Open LV               4
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               2.73 TiB
  PE Size               32.00 MiB
  Total PE              89416
  Alloc PE / Size       4515 / 141.09 GiB
  Free  PE / Size       84901 / 2.59 TiB
  VG UUID               olDTte-CLOQ-leom-Efev-UiGF-PLOI-gdIeSI

free的部分已经变成了2.59T

0x07 扩展新空间

lvextend -L +2.5T /dev/mapper/VolGroup00-LogVol00

输出

  Size of logical volume VolGroup00/LogVol00 changed from 100.00 GiB (3200 extents) to 2.60 TiB (85120 extents).
  Logical volume LogVol00 successfully resized.

更新文件系统

resize2fs -p /dev/mapper/VolGroup00-LogVol00

输出

resize2fs 1.42.9 (28-Dec-2013)
Filesystem at /dev/mapper/VolGroup00-LogVol00 is mounted on /; on-line resizing required
old_desc_blocks = 13, new_desc_blocks = 333
The filesystem on /dev/mapper/VolGroup00-LogVol00 is now 697303040 blocks long.

0x08 查看磁盘空间

df -lh

输出

Filesystem                       Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00  2.6T   96G  2.4T   4% /
devtmpfs                          63G     0   63G   0% /dev
tmpfs                             63G     0   63G   0% /dev/shm
tmpfs                             63G   25M   63G   1% /run
tmpfs                             63G     0   63G   0% /sys/fs/cgroup
/dev/sda1                        240M   86M  138M  39% /boot
/dev/mapper/VolGroup00-LogVol01   40G  365M   37G   1% /var
/dev/mapper/VolGroup00-LogVol02  976M   19M  891M   2% /tmp
tmpfs                             13G     0   13G   0% /run/user/448376178
/dev/mapper/VolGroup00-LogVol03  2.6T   89M  2.5T   1% /da1

可以看到/dev/mapper/VolGroup00-LogVol00 已经变成2.4T了。

这里有个问题,/dev/mapper/VolGroup00-LogVol03居然还是2.5T,磁盘信息没有更新,实际上只有100M。

0x09 小结

LVM的磁盘灵活性比较高,可以方便的调整分区大小,方便docker使用。

0x10 参考文献

https://yq.aliyun.com/articles/140963

你可能感兴趣的:(centos,docker)