KVM Partition Resize?

ejc317

Member
Oct 18, 2012
263
0
16
Hi,

So we create VM with 50GB (corresponding LV is created)

We dd a .raw file that is 20GB into the VM. How do we make it 20GB? Doing qemu-img resize resizes the image but the partition shows 20GB while fdisk -l shows 50gb

thanks all
 
Seems that this will be the dealbreaker for ProxMox for us ... unfortunate. The only workaround I see is to create the LV, mount it, rsync the files, and unmount.

We need to automate it so we can't be booting into GParted manually for each one of them. We need to resize the partition on the KVM that we dd'ed into the iSCSI LV to the maximum size of the VM - parted / cfdisk etc all don't work right ...

Any ideas feel fre to let us know
 
Seems that this will be the dealbreaker for ProxMox for us ... unfortunate. The only workaround I see is to create the LV, mount it, rsync the files, and unmount.

We need to automate it so we can't be booting into GParted manually for each one of them. We need to resize the partition on the KVM that we dd'ed into the iSCSI LV to the maximum size of the VM - parted / cfdisk etc all don't work right ...

Any ideas feel fre to let us know
Hi,
if you use dd to copy an rawfile to another rawfile, or LV, the target has the same size like the source.
For LVs you can use lvextend to resize the VM-disk.
For raw-files you can use also dd - if the extension inside the "disk" work, depends on your guest/partition.

Here is an example to resize an 4GB rawfile with an ext4 filesystem to 10GB (you must be sure to use the right blocksize/seek or you overwrite data on the end of the raw-file):
Code:
# ls -lsa bigdisk 
4194304 -rw-r--r-- 1 admin admin 4294967296 Nov  8 23:08 bigdisk

# dd if=/dev/zero of=bigdisk bs=1G seek=4 count=6

# ls -lsa bigdisk 
10485760 -rw-r--r-- 1 admin admin 10737418240 Nov  8 23:12 bigdisk

# fdisk -l bigdisk

Disk bigdisk: 10.7 GB, 10737418240 bytes
43 heads, 32 sectors/track, 15240 cylinders, total 20971520 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
Disk identifier: 0x9dbffc21

  Device Boot      Start         End      Blocks   Id  System
bigdisk1            2048     8388607     4193280   83  Linux
after that the partition and the filesystem must be extended (delete old and create new partition):
Code:
#fdisk -l bigdisk

Disk bigdisk: 10.7 GB, 10737418240 bytes
40 heads, 32 sectors/track, 16384 cylinders, total 20971520 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
Disk identifier: 0x9dbffc21

  Device Boot      Start         End      Blocks   Id  System
bigdisk1            2048    20971519    10484736   83  Linux

# kpartx -a bigdisk

# e2fsck -f /dev/mapper/loop0p1

# resize2fs /dev/mapper/loop0p1

# mount /dev/mapper/loop0p1 /mnt

# df -k /mnt
Dateisystem         1K-Blöcke Benutzt Verfügbar Verw% Eingehängt auf
/dev/mapper/loop0p1  10320184   75556   9720392    1% /mnt

# umount /mnt; kpartx -d bigdisk
Udo
 
If I understand you correctly, you copied a 20 GB raw image onto an 50 GB LV. That should work, but you need to resize the partition (you seem to have achieved that) AND you need to resize the filesystem on top of it. For instance you need to use resize2fs or xfs_growfs for ext2+ or xfs on the relevant partition, respectively.
 
If I understand you correctly, you copied a 20 GB raw image onto an 50 GB LV. That should work, but you need to resize the partition (you seem to have achieved that) AND you need to resize the filesystem on top of it. For instance you need to use resize2fs or xfs_growfs for ext2+ or xfs on the relevant partition, respectively.

So what we've done is

1) Create a 50GB LV on SAN through VM
2) Copy a 20GB .RAW file as a block into the LV
3) LV partitions now show 1.0mb partition, a 20GB partition, and empty space of about 29.9GB at the end.

When I do cfdisk the device, it shows up fine ... BUT when I try to maximize, it doesn't work. Presumably b/c its mounted. And you can't unmount because the iscsi connection will drop.

We try parted - again can't resize and there's no swap - I am thinking the partition starts at the wrong sector? Also, why is there a 1.0MB partition ahead of our regular partition?

We basically need to automate this process - someone requests a VM, we set it up, copy in image, and resize partition. FDISK parameters can be fed in I suppose but this does not seem to work correctly.
 
Thanks Udo, this is what we did (we used qemi-img resize to resize the images) - is this where we may have gone wrong?
 
So what we've done is

1) Create a 50GB LV on SAN through VM
2) Copy a 20GB .RAW file as a block into the LV
3) LV partitions now show 1.0mb partition, a 20GB partition, and empty space of about 29.9GB at the end.

When I do cfdisk the device, it shows up fine ... BUT when I try to maximize, it doesn't work. Presumably b/c its mounted. And you can't unmount because the iscsi connection will drop.

We try parted - again can't resize and there's no swap - I am thinking the partition starts at the wrong sector? Also, why is there a 1.0MB partition ahead of our regular partition?

We basically need to automate this process - someone requests a VM, we set it up, copy in image, and resize partition. FDISK parameters can be fed in I suppose but this does not seem to work correctly.
Well. Please show us the exact error messages you see, and an sfdisk -l <device> would also be useful.
 

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!