0

I'm experimenting with repartitioning in a KVM virtual. I have created a new qcow2 disk and mounted in a virtual. I'm experimenting with resizing the filesystem and repartitioning. I had previously unmounted and shrunk the filesystem using e2fsk -f and then resize2fs -M down to around 30k blocks. From what I've read online, to shrink the partition I now need to delete it, and then recreate it with a smaller block count (no less than the size of my file system) at the same starting sector. When I use fdisk to delete partition 1, and then recreate it, my lowest starting sector is 2048. As you can see in the output below, partition 1 originally starts at sector 8. What am I doing incorrectly?

pphan@www-dev1:~$ mount -l -t ext3
/dev/vdb1 on /wsrv type ext3 (rw)
pphan@www-dev1:~$ sudo umount /wsrv
pphan@www-dev1:~$ sudo fdisk -u -c -l /dev/vdb

Disk /dev/vdb: 1073 MB, 1073741824 bytes
9 heads, 8 sectors/track, 29127 cylinders, total 2097152 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: 0xad16440c

   Device Boot      Start         End      Blocks   Id  System
/dev/vdb1               8     2097143     1048568   83  Linux

Ubuntu 10.04.2 host and guest. I have tagged libvirt-KVM because I am not sure if this problem is specific to disk images.

TIA

2
  • Next time, just make each partition into its own virtual disk. virtual disks are basically free, and can be resized at will without messing about with partitioning.
    – Dan Pritts
    Mar 18, 2013 at 19:37
  • That's what I've got going on. At some point I may want to grow/shrink the image.
    – Pete
    Jun 6, 2013 at 20:39

1 Answer 1

1

This happens with physical disks as well. To be able to specify a lower initial sector, launch fdisk with the -cu options. You can also go to expert menu ('x') and use "move beginning of data in a partition" ('b') command.

3
  • After i delete the partition (d) I then recreate a new primary partition 1 (n,p,1). I'm given the option of entering a first sector, but limited to 2048 as a minimum. Entering the expert menu (x) and then trying to 'move beginning of data in a partition' (b) will only let me move a minimum of 2048. I'm assuming its not possible move the beginning of data in a partition to outside the partitions sector range.
    – Pete
    May 3, 2012 at 1:23
  • You may want to check also SU: superuser.com/questions/352572/…
    – S19N
    May 3, 2012 at 15:27
  • Just tried doing this in a new 12.04 virtual and it worked
    – Pete
    Aug 8, 2014 at 23:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .