Greetings -
I am going through some testing steps to expand a logical volume and the corresponding filesystem on a KVM guest and have run across a deficiency in my knowledge. I spent the afternoon yesterday googling for answers, but had have come up blank still. What I am trying to do is resize the file system to use the additional disk space that I added to the logical volume that the guest uses. Here is what I have done and the details of my system.
0. Both my host and guest are running Centos 6.2.
1. My KVM host system has the LVM volume group that is divided into logical volumes which are then presented to the KVM guests as raw space.
2. A guest may use 2 or 3 logical volumes from the host system for its filesystem (/, /var, /data) and I have logical volumes named within the host system by guest and mount point so that I know what each logical volume is assigned to by it's name.
3. I expanded a specific logical volume on the host (/dev/vg/lv_guest1root) that is used by Guest1, and I can see in vgdisplay and lvdisplay that the logical volume was properly expanded.
4. I then issued a resize2fs /dev/vg/lv_guest1root command (on the host) to resize the filesystem to the expanded logical volume. This resulted in a message that it essentially couldn't find a valid filesystem superblock. Well of course then I realized that there is no filesystem on the logical volume from the perspective of the host. The filesystem wasn't set on the logical volume until the guest installation occurred.
5. So then I switched over to the guest system and ran df -h to see the existing filesystem
[root@guest1 jeffb]# df -h Filesystem Size Used Avail Use% Mounted on /dev/vda2 4.5G 2.3G 2.0G 53% / tmpfs 1004M 88K 1004M 1% /dev/shm /dev/vda1 485M 30M 430M 7% /boot /dev/vdb1 2.0G 219M 1.7G 12% /var
6. Then I ran resize2fs /dev/vda2 and got the result that the filesystem is already xx blocks long. Nothing to do!
So here is where I am stuck. Guest1 is my test system so it only has the / and /var logical volumes, whereas the production guest (guest2) that I will be expanding also has /data, which will be the logical volume that I will expand. So two things I did not do where, I did not shut down the guest VM, and I did not unmount the filesystem before asking it to resize. However my research before doing this did not seem to indicate that I had to do either, and the message about nothing to do also seems to indicate that they were not necessary.
So I am missing a hole in my knowledge and additional googling has not helped to fill it. I must be missing something simple. Is this result due to the fact that I am testing on expanding the / filesystem, and it would work properly on a guest system that had /data? Do I need to unmount the filesystem, or shut down the guest VM, or mount the guest from a LiveCD? Or do I need to give it resize2fs /dev/vda rather than specifically /dev/vda2 ? Any clues, or pointers to good documentation is greatly appreciated. Thanks.
Jeff Boyce Meridian Environmental www.meridianenv.com
On Fri, 2012-02-24 at 12:05 -0800, Jeff Boyce wrote:
Greetings -
I am going through some testing steps to expand a logical volume and the corresponding filesystem on a KVM guest and have run across a deficiency in my knowledge. I spent the afternoon yesterday googling for answers, but had have come up blank still. What I am trying to do is resize the file system to use the additional disk space that I added to the logical volume that the guest uses. Here is what I have done and the details of my system.
Both my host and guest are running Centos 6.2.
My KVM host system has the LVM volume group that is divided into logical
volumes which are then presented to the KVM guests as raw space.
- A guest may use 2 or 3 logical volumes from the host system for its
filesystem (/, /var, /data) and I have logical volumes named within the host system by guest and mount point so that I know what each logical volume is assigned to by it's name.
- I expanded a specific logical volume on the host (/dev/vg/lv_guest1root)
that is used by Guest1, and I can see in vgdisplay and lvdisplay that the logical volume was properly expanded.
- I then issued a resize2fs /dev/vg/lv_guest1root command (on the host)
to resize the filesystem to the expanded logical volume. This resulted in a message that it essentially couldn't find a valid filesystem superblock. Well of course then I realized that there is no filesystem on the logical volume from the perspective of the host. The filesystem wasn't set on the logical volume until the guest installation occurred.
- So then I switched over to the guest system and ran df -h to see the
existing filesystem
[root@guest1 jeffb]# df -h Filesystem Size Used Avail Use% Mounted on /dev/vda2 4.5G 2.3G 2.0G 53% / tmpfs 1004M 88K 1004M 1% /dev/shm /dev/vda1 485M 30M 430M 7% /boot /dev/vdb1 2.0G 219M 1.7G 12% /var
- Then I ran resize2fs /dev/vda2 and got the result that the filesystem
is already xx blocks long. Nothing to do!
So here is where I am stuck. Guest1 is my test system so it only has the / and /var logical volumes, whereas the production guest (guest2) that I will be expanding also has /data, which will be the logical volume that I will expand. So two things I did not do where, I did not shut down the guest VM, and I did not unmount the filesystem before asking it to resize. However my research before doing this did not seem to indicate that I had to do either, and the message about nothing to do also seems to indicate that they were not necessary.
So I am missing a hole in my knowledge and additional googling has not helped to fill it. I must be missing something simple. Is this result due to the fact that I am testing on expanding the / filesystem, and it would work properly on a guest system that had /data? Do I need to unmount the filesystem, or shut down the guest VM, or mount the guest from a LiveCD? Or do I need to give it resize2fs /dev/vda rather than specifically /dev/vda2 ? Any clues, or pointers to good documentation is greatly appreciated. Thanks.
The guest put a partition table on the LV. To resize the filesystem, the partition must be resized, as well. There are several ways to do it. I think some people use gparted. To recap the steps, resize the LV, resize the partition, resize the filesystem.
I setup a separate guest with the required tools to resize my guest filesystems and temporarily take down the guest to give the disk space to the utility guest.
Fri, 24-Feb-2012 12:05:55 Jeff Boyce wrote:
- Then I ran resize2fs /dev/vda2 and got the result that the filesystem
is already xx blocks long. Nothing to do!
Before you can resize filesystem, you have to resize partition. If it is only 2 partitions on /dev/vda, you can use one of two ways: 1. Resize partition from host system (I think it is not the best idea for root partition operations): Run fdisk /dev/vg/lv_guest1root, delete second partition and create new one which starts from the same place but takes all available space, after it you can boot guest (in single mode) and run resize2fs. 2. Boot VM from any 3-party (LiveCD or any) with access to virtual disk, and do the same: in fdisk delete existing partition, create new one and run resize2fs on it. Or just use parted to do it in one command.
On 24.2.2012 21:28, Sergiy Yegorov wrote:
Fri, 24-Feb-2012 12:05:55 Jeff Boyce wrote:
- Then I ran resize2fs /dev/vda2 and got the result that the filesystem
is already xx blocks long. Nothing to do!
Before you can resize filesystem, you have to resize partition. If it is only 2 partitions on /dev/vda, you can use one of two ways:
- Resize partition from host system (I think it is not the best idea for root
partition operations): Run fdisk /dev/vg/lv_guest1root, delete second partition and create new one which starts from the same place but takes all available space, after it you can boot guest (in single mode) and run resize2fs. 2. Boot VM from any 3-party (LiveCD or any) with access to virtual disk, and do the same: in fdisk delete existing partition, create new one and run resize2fs on it. Or just use parted to do it in one command.
3. You can repartition from the guest itself Do as in 2. After saving the new partition table fdisk will probably request a reboot for using the new table. reboot, then resize the fs.
On 24.2.2012 21:05, Jeff Boyce wrote:
Greetings -
I am going through some testing steps to expand a logical volume and the corresponding filesystem on a KVM guest and have run across a deficiency in my knowledge. I spent the afternoon yesterday googling for answers, but had have come up blank still. What I am trying to do is resize the file system to use the additional disk space that I added to the logical volume that the guest uses. Here is what I have done and the details of my system.
Both my host and guest are running Centos 6.2.
My KVM host system has the LVM volume group that is divided into logical
volumes which are then presented to the KVM guests as raw space.
- A guest may use 2 or 3 logical volumes from the host system for its
filesystem (/, /var, /data) and I have logical volumes named within the host system by guest and mount point so that I know what each logical volume is assigned to by it's name.
- I expanded a specific logical volume on the host (/dev/vg/lv_guest1root)
that is used by Guest1, and I can see in vgdisplay and lvdisplay that the logical volume was properly expanded.
- I then issued a resize2fs /dev/vg/lv_guest1root command (on the host)
to resize the filesystem to the expanded logical volume. This resulted in a message that it essentially couldn't find a valid filesystem superblock. Well of course then I realized that there is no filesystem on the logical volume from the perspective of the host. The filesystem wasn't set on the logical volume until the guest installation occurred.
- So then I switched over to the guest system and ran df -h to see the
existing filesystem
[root@guest1 jeffb]# df -h Filesystem Size Used Avail Use% Mounted on /dev/vda2 4.5G 2.3G 2.0G 53% / tmpfs 1004M 88K 1004M 1% /dev/shm /dev/vda1 485M 30M 430M 7% /boot /dev/vdb1 2.0G 219M 1.7G 12% /var
- Then I ran resize2fs /dev/vda2 and got the result that the filesystem
is already xx blocks long. Nothing to do!
So here is where I am stuck. Guest1 is my test system so it only has the / and /var logical volumes, whereas the production guest (guest2) that I will be expanding also has /data, which will be the logical volume that I will expand. So two things I did not do where, I did not shut down the guest VM, and I did not unmount the filesystem before asking it to resize. However my research before doing this did not seem to indicate that I had to do either, and the message about nothing to do also seems to indicate that they were not necessary.
So I am missing a hole in my knowledge and additional googling has not helped to fill it. I must be missing something simple. Is this result due to the fact that I am testing on expanding the / filesystem, and it would work properly on a guest system that had /data? Do I need to unmount the filesystem, or shut down the guest VM, or mount the guest from a LiveCD?
I think you must reboot the guest to see the new bigger disk, then you can repartition, and then after another reboot you can resize your fs.