更改KVM虚拟机的磁盘大小 ;挂载虚拟机磁盘到宿主机上。

来源:互联网 发布:目前常见软件架构 编辑:程序博客网 时间:2024/06/05 04:35

原先创建的kvm镜像磁盘不够用了怎么办?可以用如下方法进行扩展

1、用qemu-img resize更改磁盘大小。

qemu-img info XXX.img  可以查看原来镜像的信息。

然后用qemu-img resize XXX.img  +2G来更改大小

qemu-img info resize  XXX.img查看更改后的信息。

可能只支持raw格式的。若qcow2格式的不行,用qemu-img convert 进行转换。

2、 更改后,进入虚拟机,就可以用fdisk命令对新增加的容量进行划分了。


   当宿主机要访问虚拟机里的文件时,可以将虚拟机镜像直接挂载到宿主机上。

1.       查看磁盘文件信息

# fdisk -lu T-MXW-centos.raw
…………………
Units = sectors of 1 * 512 = 512 bytes
……….
           Device Boot      Start         End      Blocks   Id  System
T-MXW-centos.raw1   *          63      208844      104391   83  Linux
T-MXW-centos.raw2          208845    12787739     6289447+  82  Linux swap / Solaris
T-MXW-centos.raw3        12787740    62910539    25061400   83  Linux
Partition 3 has different physical/logical endings:
     phys=(1023, 254, 63) logical=(3915, 254, 63)

2.       如同上面,raw1boot分区,raw3是根分区;

如果需要挂载根分区的话,需要设置mount的偏移量,offset12787740*512

# mount -o loop,offset=$((12787740*512)) T-MXW-centos.raw /mnt

3.       end ,测试

# ls /mnt
bin  boot  data  dev  etc  halt  home  lib  lib64  lost+found  media  misc  mnt  net  opt  proc  root  sbin  selinux  srv  sys  tftpb

出处http://fifeapple.blog.51cto.com/1566225/1064099


0 0
原创粉丝点击