大网数据广告活动
服务器运维问答

How can increase root partition on KVM guest

· 52CE 我爱测

I have a kvm guest,as follow, The guest disk /dev/vda actually is a qcow2 file in Host [root@guest ~]# cat /etc/redhat-release CentOS Linux release 7.2.1511 (Core) [root@guest ~]# uname -a Linux guest 3.10.0-327.28.3.el7.x86_64 #…

问题原文

原帖链接 · jython.li · CC BY-SA 3.0

I have a kvm guest,as follow, The guest disk /dev/vda actually is a qcow2 file in Host

[root@guest ~]# cat /etc/redhat-release
CentOS Linux release 7.2.1511 (Core)

[root@guest ~]# uname -a
Linux guest 3.10.0-327.28.3.el7.x86_64 #1 SMP Thu Aug 18 19:05:49 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux

[root@guest ~]# parted -l
Model: Virtio Block Device (virtblk)
Disk /dev/vda: 64.4GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:

Number  Start   End     Size    Type     File system  Flags
 1      1049kB  8590MB  8589MB  primary  xfs          boot

But I only see 8G with dfcommand, How can I increase the root partition to 64G? I have try xfs_growfs /dev/vda1, but doesn't work

[root@guest ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/vda1       8.0G  1.1G  6.9G  14% /
devtmpfs        1.9G     0  1.9G   0% /dev
tmpfs           1.9G     0  1.9G   0% /dev/shm
tmpfs           1.9G   17M  1.9G   1% /run
tmpfs           1.9G     0  1.9G   0% /sys/fs/cgroup
tmpfs           380M     0  380M   0% /run/user/0

已采纳解答

原帖链接 · EnzoR · CC BY-SA 3.0

First of all, this could be not related to virtualization at all. I think you are using a single partition of 8GB on a 64GB disk, as reported by parted.

If you really need to enlarge that partition, then you'd run it to enlarge the one and only partition you have. I normally use fdisk, not just for historical reasons. But with parted should be something like this:

parted /dev/vda1 resizepart 1 64G

Only later you'd run xfs_growfs to take advantage of the extra room. As an option, you could run it interactively, issuing first a command to display sectors:

(parted) unit s

then a command to display the drive size in sectors (the actual size of the drive):

(parted) print
...
Disk /dev/vda: (the number of sectors here)

and finally the command to resize the partition #1 to that number.

If parted doesn't provide for a resize command, then you have only one option: you take note of the starting block number, partition type (primary), partition id (should be 83), then you delete the partition and recreate it with exactly the same starting block, type and ID, while the ending block is to be set as the last one available (as reported by the parted command).

As an option you could use fdisk, provided that the tool is available. In that case you should run:

sudo fdisk /dev/vda

and give the command p in order to print the current partition table. For example:

Disk /dev/sda: 111,8 GiB, 120034123776 bytes, 234441648 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
Disklabel type: dos
Disk identifier: 0x00070c95

Device     Boot Start       End   Sectors  Size Id Type
/dev/sda1  *     2048 218028031 218025984  104G 83 Linux

With fdisk you simply delete the partition and recreate it: it will propose you to make it as large as possible.

Command (m for help): d
Selected partition 1
Partition 1 has been deleted.

Command (m for help): n
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): p
Partition number (1-4, default 1): 
First sector (2048-234441647, default 2048): 
Last sector, +sectors or +size{K,M,G,T,P} (2048-234441647, default 234441647): 

Created a new partition 1 of type 'Linux' and of size 111,8 GiB.

Command (m for help): p
Disk /dev/sda: 111,8 GiB, 120034123776 bytes, 234441648 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
Disklabel type: dos
Disk identifier: 0x00070c95

Device     Boot Start       End   Sectors   Size Id Type
/dev/sda1        2048 234441647 234439600 111,8G 83 Linux

Then you'd issue a command w to write the changes to the disk. A reboot is highly recommended before enlarging the file system.

Finally, I'd suggest you to use df -H instead of df -h so the numbers shown would match the ones by parted -l.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-10-10)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。