扩容image文件方法:
我们使用qemu-img 工具

使用下面命令给img文件追加50G空间:

qemu-img resize $img +50G
Image resized.

You can mount the image and check that it has the correct size:

用kpartx工具挂载img文件:
kpartx -v -a $img
add map loop0p1 (254:13): 0 195318207 linear /dev/loop0 63
查看挂载后的信息:

parted /dev/loop0 print

Model:  (file)
Disk /dev/loop0: 215GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number  Start   End    Size   Type     File system  Flags
 1      32.3kB  100GB  100GB  primary  ext3
..
删掉当前分区表分区1
parted /dev/loop0 rm 1
重新按照新空间大学创建分区表(上面信息中有新大小和开始字节数)
parted /dev/loop0 mkpart primary ext3 32.3kB 215GB
重新打印分区检查分区信息
parted /dev/loop0 print
重新挂载镜像:
kpartx -d $img
loop deleted : /dev/loop0
kpartx -v -a $img
add map loop0p1 (254:13): 0 419430337 linear /dev/loop0 63
扩容新增空间到最后一个分区
检查后扩容的分区
e2fsck -f /dev/mapper/loop0p1
e2fsck 1.42.5 (29-Jul-2012)
/dev/mapper/loop0p1: recovering journal
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/mapper/loop0p1: 41753/6111232 files (9.1% non-contiguous), 23479003/24414775 blocks
扩容分区
resize2fs /dev/mapper/loop0p1
resize2fs 1.42.5 (29-Jul-2012)
Resizing the filesystem on /dev/mapper/loop0p1 to 52428792 (4k) blocks.
The filesystem on /dev/mapper/loop0p1 is now 52428792 blocks long.
卸载镜像,重新挂载,mount 分区到系统,用df查看空间
mount /dev/mapper/loop0p1 /mnt
df -h /mnt
Filesystem           Size  Used Avail Use% Mounted on
/dev/mapper/loop0p1  197G   89G  109G  45% /mnt
卸载img文件收工
umount /mnt
kpartx -d $img
loop deleted : /dev/loop0

发表评论

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据

Advertisment ad adsense adlogger