1

I add a new virtual hard drive vdb to the KVM guest(centos6.5),like this

[root@centos ~]# fdisk -l | grep vdb
Disk /dev/vdb: 8589 MB, 8589934592 bytes

Then,there are two ways to format the disk

a.

[root@centos ~]# mkfs.ext4 /dev/vdb
[root@centos ~]# mount /dev/vdb /data/

b.

[root@boss ~]# fdisk /dev/sdb 
Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-1044, default 1): 
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-1044, default 1044): 
Using default value 1044

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
[root@centos ~]# mkfs.ext4 /dev/vdb1
[root@centos ~]# mount /dev/vdb1 /data/

The above two ways are working ok,but what diff?

Ren P
  • 105
  • 3
jython.li
  • 84
  • 2
  • 10
  • To increase virtual disk vdb, on KVM host,I use `qemu-img resize centos-vdb.disk +20G`,then I start the guest,but I found the disk vdb does not automatically increase(df -h), I manually increase accroding to this article [link](https://access.redhat.com/articles/1196353), the "a" method is ok,but the "b" method is wrong – jython.li Sep 11 '15 at 17:01
  • In scenario b you have to also resize the partition /dev/vdb1 (don't confuse partitions and filesystems) – Brandon Xavier Sep 11 '15 at 17:08
  • Accroding to scenario "b",I mount the /vdb1 to /data and then shutdown the guest, In KVM host,resize the vdb disk from 20G to 40G, start the guest,but I found the vdb1(/data/) is not 40G, so I manually increase,[How to Grow an ext2/3/4 File System with resize2fs](https://access.redhat.com/articles/1196353) ,but the cmd `resize2fs /dev/vdb1` not work – jython.li Sep 11 '15 at 17:50
  • As I said, don't confuse partitions with fileystems. vdb is a disk (albeit virtual), vdb1 is a partition on vdb, and there's a filesystem on vdb1. You've increased the size of the disk vdb, but have not yet increased the size of the partition, so resize2fs in your 3rd step has no new space to use. In scenario "a" you're not using a partition so the middle step of increasing the partition size doesn't apply. – Brandon Xavier Sep 11 '15 at 21:32

1 Answers1

0

The first command is creating a filesystem on the entire disk, with no possibility to add more partitions. The second is partitioning the disk, with the possibility to add more partitions (assuming sdb1 isn't using the entire disk).

Brandon Xavier
  • 1,942
  • 13
  • 15