1

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
1

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.

6
  • parted /dev/vda1 resizepart 1 125829120 seem not work. my parted version:parted (GNU parted) 3.1
    – jython.li
    Oct 10 '16 at 7:32
  • @jython.li I added a few more details
    – EnzoR
    Oct 10 '16 at 7:37
  • Seem parted 3.1 can't use resize or resizepart How do I resize partitions and filesystems on them?
    – jython.li
    Oct 10 '16 at 7:50
  • @jython.li I added some details to overcome that lack.
    – EnzoR
    Oct 10 '16 at 11:47
  • @jython.li Reword the question as it's not related to KVM or any virtualization environment. This is "generic" Linux system administration.
    – EnzoR
    Oct 10 '16 at 11:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.