近期处理一个磁盘扩容需求,虚拟化工程师扩容时直接将/dev/sdc磁盘进行了扩容,登录linux操作系统以后检查发现,/dev/sdc的盘上已经划分了3个主分区和1个扩展分区,并在扩展分区下划分了一个/dev/sdc5。这种情况意味着已经扩容到/dev/sdc磁盘上的容量没有办法创建新的分区使用更别说扩容文件系统了。本文将引导您完成扩容操作。
一、先决条件
1.正常的Linux操作系统,并使用lvm管理磁盘
2.在单一分区上已经划分了3主分区和1个扩展分区
3.扩容容量的磁盘已经无法创建新分区
二、解决方案
如果在虚拟化环境中,我们首选一定要记得做个快照。很多的时候,这个快照是你最后的机会。
1.扩容虚拟化磁盘
我们在虚拟化环境中,将/dev/sdc的盘从10G增大到12G并保存配置。
2.操作系统识别磁盘
重新扫描/dev/sdc的磁盘,并且正常识别到12G。
[root@yunweixia.com ]# echo 1 > /sys/class/scsi_device/0\:0\:2\:0/device/rescan
3.卸载分区
卸载将分区/sdc5从分区/dev/sdc5上卸载,卸载命令为:
[root@yunweixia.com ]# umount /sdc5
4.删除分区
我们需要删除并重新划分/dev/sdc4(扩展分区)以及扩展分区上划分的/dev/sdc5分区。
[root@yunweixia.com ]# umount /sdc5
4.删除分区
我们需要删除并重新划分/dev/sdc4和sdc5分区
[root@yunweixia.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
扩展阅读
如上这个操作需要记录分区起始位置的sectors(通过fdisk -l查看 ),创建新分区的时候起始sectors要和已删除分区保持一致。只有这样数据才不会丢失。
5.扩容lvm
接着需要扩容lvm(有可能需要重启服务器)。
[root@yunweixia.com ]# pvs #查看pv信息 PV VG Fmt Attr PSize PFree /dev/sda2 rhel lvm2 a– 15.51g 0 /dev/sdb swapvg lvm2 a– 8.00g 0 /dev/sdc1 sdc_1 lvm2 a– 2.00g 0 /dev/sdc2 sdc_1 lvm2 a– 2.00g 0 /dev/sdc3 sdc_1 lvm2 a– 2.00g 0 /dev/sdc5 sdc_1 lvm2 a– 4.00g 0 [root@yunweixia.com ]# pvresize /dev/sdc5 #重置pv容量 Physical volume “/dev/sdc5” changed 1 physical volume(s) resized / 0 physical volume(s) not resized [root@yunweixia.com ]# pvs #查看pv信息 PV VG Fmt Attr PSize PFree /dev/sda2 rhel lvm2 a– 15.51g 0 /dev/sdb swapvg lvm2 a– 8.00g 0 /dev/sdc1 sdc_1 lvm2 a– 2.00g 0 /dev/sdc2 sdc_1 lvm2 a– 2.00g 0 /dev/sdc3 sdc_1 lvm2 a– 2.00g 0 /dev/sdc5 sdc_1 lvm2 a– 6.00g 2.00g [root@yunweixia.com ]# vgs #查看vg信息 VG #PV #LV #SN Attr VSize VFree rhel 1 1 0 wz–n- 15.51g 0 sdc_1 4 1 0 wz–n- 11.98g 2.00g swapvg 1 1 0 wz–n- 8.00g 0 [root@yunweixia.com ]# lvextend -l +100%free /dev/sdc_1/sdc1 #扩容lvm Size of logical volume sdc_1/sdc1 changed from 9.98 GiB (2556 extents) to 11.98 GiB (3068 extents). Logical volume sdc1 successfully resized [root@yunweixia.com ]# e2fsck -f /dev/sdc_1/sdc1 #检查分区 e2fsck 1.42.9 (28-Dec-2013) Pass 1: Checking inodes, blocks, and sizes Pass 2: Checking directory structure Pass 3: Checking directory connectivity Pass 4: Checking reference counts Pass 5: Checking group summary information /dev/sdc_1/sdc1: 402/655360 files (0.0% non-contiguous), 83136/2617344 blocks [root@yunweixia.com ]# resize2fs /dev/sdc_1/sdc1 #扩容文件系统,如果是xfs文件系统需要使用命令xfs_growfs命令扩容文件系统。 resize2fs 1.42.9 (28-Dec-2013) Resizing the filesystem on /dev/sdc_1/sdc1 to 3141632 (4k) blocks. The filesystem on /dev/sdc_1/sdc1 is now 3141632 blocks long.
6.扩容完成,挂载检查。
[root@yunweixia.com ]# mount /dev/sdc_1/sdc1 /sdc5 [root@yunweixia.com ]# ll /sdc5 total 20 drwxr-xr-x. 21 root root 4096 Jul 25 09:48 dev drwx——. 2 root root 16384 Jul 25 09:50 lost+found
三、方案总结
以上就是在3个主分区一个扩展分区下,如何扩容lvm的全部步骤。感谢@袁麟技术指导。
原创文章,作者:运维侠,如若转载,请注明出处:https://www.yunweixia.com/solutions/linux-single-disk-partition-creation-failure-preventing-lvm-expansion-solution.html