您的位置:首页 > 运维架构 > Linux

CentOS7.1 KVM虚拟化之虚拟机根分区扩容(8)

2016-03-16 13:34 671 查看
注:适用于未使用KVM管理的分区,要求根分区为最后一个分区

一、扩展虚拟机磁盘

1.关闭虚拟机

virsh shutdown vm1-clone


2.查看虚拟机磁盘当前大小

[root@kvm01 ~]# qemu-img info /vm-images/vm1-clone.img
image: /vm-images/vm1-clone.img
file format: qcow2
virtual size: 10G (11206127360 bytes)
disk size: 1.7G
cluster_size: 65536
Format specific information:
compat: 1.1
lazy refcounts: true


3.扩展磁盘大小

qemu-img resize /vm-images/vm1-clone.img +5G


4.再次查看虚拟机磁盘当前大小

[root@kvm01 ~]# qemu-img info /vm-images/vm1-clone.img
image: /vm-images/vm1-clone.img
file format: qcow2
virtual size: 15G (16106127360 bytes)
disk size: 1.7G
cluster_size: 65536
Format specific information:
compat: 1.1
lazy refcounts: true


二、扩展虚拟机根分区

1.查看当前分区状况,可以看到磁盘/dev/vda大小变化

[root@localhost ~]#
fdisk -l

Disk /dev/vda: 16.1 GB, 16106127360 bytes

255 heads, 63 sectors/track, 1958 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System

/dev/vda1 * 1 25 200781 83 Linux

/dev/vda2 26 156 1052257+ 82 Linux swap / Solaris

/dev/vda3 157 1305 9229342+ 83 Linux #注意这里起始cylinder 是157,起始cylinder 绝对不可以改,否则会破坏原分区的数据。

2.扩展根分区

[root@localhost ~]#
fdisk /dev/vda

The number of cylinders for this disk is set to 1958.

There is nothing wrong with that, but this is larger than 1024,

and could in certain setups cause problems with:

1) software that runs at boot time (e.g., old versions of LILO)

2) booting and partitioning software from other OSs

(e.g., DOS FDISK, OS/2 FDISK)

Command (m for help): p

Disk /dev/vda: 16.1 GB, 16106127360 bytes

255 heads, 63 sectors/track, 1958 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System

/dev/vda1 * 1 25 200781 83 Linux

/dev/vda2 26 156 1052257+ 82 Linux swap / Solaris

/dev/vda3 157 1305 9229342+ 83 Linux

Command (m for help): d

Partition number (1-4): 3
#根/分区是多少就输入几,这里是/dev/vda3

Command (m for help): p

Disk /dev/vda: 16.1 GB, 16106127360 bytes

255 heads, 63 sectors/track, 1958 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System

/dev/vda1 * 1 25 200781 83 Linux

/dev/vda2 26 156 1052257+ 82 Linux swap / Solaris

Command (m for help): n

Command action

e extended

p primary partition (1-4)

p

Partition number (1-4): 3
#之前是多少,这里还输入多少

First cylinder (157-1958, default 157):

Using default value 157

Last cylinder or +size or +sizeM or +sizeK (157-1958, default
1958): #由之前1305,扩为1958

Using default value 1958

Command (m for help): w

The partition table has been altered!

Calling ioctl() to re-read partition table.

The kernel still uses the old table.

The new table will be used at the next reboot.

Syncing disks.

三、重启虚拟机,完成根分区扩容

执行如下命令,重启系统

[root@localhost ~]#reboot

重启后执行如下命令,完成根分区扩充

[root@localhost ~]#resize2fs /dev/vda3

resize2fs 1.39 (29-May-2006)

Filesystem at /dev/vda3 is mounted on /; on-line resizing required

Performing an on-line resize of /dev/vda3 to 3618641 (4k) blocks.

The filesystem on /dev/vda3 is now 3618641 blocks long.

四、验证

查看当前磁盘状态

[root@localhost ~]# df -h

文件系统 容量 已用 可用 已用% 挂载点

/dev/vda3 14G 1.3G 12G 11% /

/dev/vda1 190M 12M 169M 7% /boot

tmpfs 379M 0 379M 0% /dev/shm

如上,完成根分区扩容
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: