解决linux系统下因无法创建新分区导致不能扩容lvm和文件系统的问题

实战侠近期处理一个磁盘扩容需求,虚拟化工程师扩容时直接将/dev/sdc磁盘进行了扩容,登录linux操作系统以后检查发现,已经扩容的/dev/sdc的盘上已经划分了3个主分区/dev/sdc1-3和1个扩展分区/dev/sdc4,并在该分区下划分了一个/dev/sdc5。这种情况意味着已经扩容到/dev/sdc磁盘上的容量没有办法创建新的分区使用更别说扩容文件系统了。当时,能想到的解决方案只有一个扩容该磁盘的最后1个分区/dev/sdc5,但是该分区使用的是扩展分区/dev/sdc4的容量,最终需要扩容的分区有/dev/sdc4和/dev/sdc5两个分区。

解决方案

如果在虚拟化环境中,我们首选一定要记得做个快照。很多的时候,这个快照是你最后的机会。
1.扩容虚拟化磁盘
我们在虚拟化环境中,将/dev/sdc的盘从10G增大到12G并保存配置。解决linux系统下因无法创建新分区导致不能扩容lvm和文件系统的问题
2.操作系统识别磁盘
重新扫描/dev/sdc的磁盘,并且识别到12G。

[root@shizhanxia.com ]# echo 1 > /sys/class/scsi_device/0\:0\:2\:0/device/rescan

3.卸载分区
卸载/dev/sdc5挂载,这个分区的挂载目录是/sdc5,卸载命令为:

[root@shizhanxia.com ]# umount  /sdc5

4.删除分区
我们需要删除并重新划分/dev/sdc4和sdc5分区

[root@shizhanxia.com ]# fdisk /dev/sdc  #分区/dev/sdc
Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help): p  #打印分区信息
Disk /dev/sdc: 12.9 GB, 12884901888 bytes, 25165824 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
Disk label type: dos
Disk identifier: 0x00076296
Device Boot Start End Blocks Id System
/dev/sdc1 2048 4194303 2096128 8e Linux LVM
/dev/sdc2 4194304 8388607 2097152 8e Linux LVM
/dev/sdc3 8388608 12582911 2097152 8e Linux LVM
/dev/sdc4 12582912 20971519 4194304 5 Extended
/dev/sdc5 12584960 20971519 4193280 8e Linux LVM
Command (m for help): d #删除分区
Partition number (1-5, default 5): 5  #删除分区5
Partition 5 is deleted
Command (m for help): d #删除分区
Partition number (1-4, default 4): 4 #删除分区4
Partition 4 is deleted
Command (m for help): n  #创建分区
Partition type:
p primary (3 primary, 0 extended, 1 free)
e extended
Select (default e): e  #创建扩展分区
Selected partition 4  #创建分区4
First sector (12582912-25165823, default 12582912):
Using default value 12582912
Last sector, +sectors or +size{K,M,G} (12582912-25165823, default 25165823):
Using default value 25165823
Partition 4 of type Extended and of size 6 GiB is set
Command (m for help): n  #创建分区
All primary partitions are in use
Adding logical partition 5
First sector (12584960-25165823, default 12584960):
Using default value 12584960
Last sector, +sectors or +size{K,M,G} (12584960-25165823, default 25165823):
Using default value 25165823
Partition 5 of type Linux and of size 6 GiB is set
Command (m for help): w  #保存所有修改
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
End

扩展阅读:

声明:本网站刊载的所有内容,包括文字、图片、音频、视频、软件、程序、以及网页版式设计等如无特殊说明或标注,均在网上搜集。仅供访问者个人学习、研究或欣赏,禁止商业性或盈利性用途,访问者应遵守著作权法的规定,在使用时征得本站和原著作权人的同意并支付许可使用费。本网站刊登内容,如有侵权请权利人予以告知,本站将立即予以删除。

给TA打赏
共{{data.count}}人
人已打赏
笔记

redis-sentinel service does not start after upgrading to SLES 15 SP4

2023-3-29 17:29:22

笔记

Linux不能挂载windows共享文件夹的解决方案

2023-4-4 15:30:03

2 条回复 A文章作者 M管理员
  1. guan

    不错

  2. 保哥

    测试

今日签到
有新私信 私信列表
搜索