Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have already searched the forums, but couldnt find a good suitable answer:

I have an Ubuntu Server 10.04 as KVM Host and a guest system, that also runs 10.04. The host system uses LVM and there are three logical volumes, which are provided to the guest as virtual block devices - one for /, one for /home and one for swap. The guest had been partitioned without LVM.

I have already enlarged the logical volume in the host system - the guest successfully sees the bigger virtual disk. However, this virtual disk contains one "good old" partition, which still has the old small size.

The output of fdisk -l is

me@produktion:/$ LC_ALL=en_US sudo fdisk -l

Disk /dev/vda: 32.2 GB, 32212254720 bytes
255 heads, 63 sectors/track, 3916 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000c8ce7

   Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *           1        3917    31455232   83  Linux

Disk /dev/vdb: 2147 MB, 2147483648 bytes
244 heads, 47 sectors/track, 365 cylinders
Units = cylinders of 11468 * 512 = 5871616 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000f2bf7

   Device Boot      Start         End      Blocks   Id  System
/dev/vdb1               1         366     2095104   82  Linux swap / Solaris
Partition 1 has different physical/logical beginnings (non-Linux?):
     phys=(0, 32, 33) logical=(0, 43, 28)
Partition 1 has different physical/logical endings:
     phys=(260, 243, 47) logical=(365, 136, 44)

Disk /dev/vdc: 225.5 GB, 225485783040 bytes
255 heads, 63 sectors/track, 27413 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00027f25

   Device Boot      Start         End      Blocks   Id  System
/dev/vdc1               1        9138    73398272   83  Linux

The output of parted print all is

Model: Virtio Block Device (virtblk)
Disk /dev/vda: 32.2GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number  Start   End     Size    Type     File system  Flags
 1      1049kB  32.2GB  32.2GB  primary  ext4         boot


Model: Virtio Block Device (virtblk)
Disk /dev/vdb: 2147MB
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number  Start   End     Size    Type     File system     Flags
 1      1049kB  2146MB  2145MB  primary  linux-swap(v1)


Model: Virtio Block Device (virtblk)
Disk /dev/vdc: 225GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number  Start   End     Size    Type     File system  Flags
 1      1049kB  75.2GB  75.2GB  primary  ext4

What I want to achieve is to simply grow or resize the partition /dev/vdc1 so that it uses the whole space provided by the virtual block device /dev/vdc. The problem is, that when I try to do that with parted, it complains:

(parted) select /dev/vdc                                                  
Using /dev/vdc
(parted) print                                                            
Model: Virtio Block Device (virtblk)
Disk /dev/vdc: 225GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number  Start   End     Size    Type     File system  Flags
 1      1049kB  75.2GB  75.2GB  primary  ext4

(parted) resize 1                                                         
WARNING: you are attempting to use parted to operate on (resize) a file system.
parted's file system manipulation code is not as robust as what you'll find in
dedicated, file-system-specific packages like e2fsprogs.  We recommend
you use parted only to manipulate partition tables, whenever possible.
Support for performing most operations on most types of file systems
will be removed in an upcoming release.
Start?  [1049kB]?                                                         
End?  [75.2GB]? 224GB                                                     
Error: File system has an incompatible feature enabled.  Compatible features are has_journal, dir_index, filetype, sparse_super and large_file.  Use tune2fs
or debugfs to remove features.

So what can I do? This is a headless production system. What is a safe way to grow this partition? I CAN unmount it, though - so this is not the problem.

Edit: Cfdisk showed a small free space unpartitioned space, then the partition (flagged as "boot" and Linux/ext3) and then the rest of the unpartitioned space. After deleting the partition and creating it again using cfdisk - cfdisk shows one big partitioned area (which would be fine with me) and as filesystem type only "Linux"

Resize2fs returns this error resize2fs 1.41.11 (14-Mar-2010) resize2fs: Bad magic number in super-block while trying to open /dev/vdc1 Couldn't find valid filesystem superblock

share|improve this question

3 Answers 3

This page indicates the way to do that is unmount, delete, recreate the partition with the desired size, and use resize2fs to extend the partition. The resize2fs man page agrees.

I know 'delete the partition' sounds scary, but it doesn't change the data at all. It just changes the thing that references the container. As long as you DON'T mkfs.ext4 you should be fine.

Your partition start point needs to be the same as it was or the OS won't know how to interpret what's behind it. The end point can then be further along to make a larger partition.

I think the error in the comment is related to moving the start point. You need to start it at the exact same point as it was started. The end point can move around.

Credit to psusi for suggesting fdisk instead of cfdisk and confirming the start point issue.

share|improve this answer
    
Okay, I deleted the partition with cfdisk and created a new one. But I couldnt resize2fs it then and alsoI cannot mount it anymore. –  Mischa Mar 23 '12 at 13:48
    
resize2fs 1.41.11 (14-Mar-2010) resize2fs: Bad magic number in super-block while trying to open /dev/vdc1 Couldn't find valid filesystem superblock. –  Mischa Mar 23 '12 at 14:02
1  
actually, cfdisk showed a small free space unpartitioned space, then the partition (flagged as "boot" and Linux/ext3) and then the rest of the unpartitioned space. After deleting the partition and creating it again using cfdisk - cfdisk shows one big partitioned area (which would be fine with me) and as filesystem type only "Linux". –  Mischa Mar 23 '12 at 14:04
1  
You need to recreate the partition so that it starts at the exact same sector it did originally. You can't do this with cfdisk. Use fdisk or parted and put them in sector mode. –  psusi Mar 23 '12 at 14:33
1  
is there any way to resize the ext4 partition in a way so that the start of the partition is moved? Because I have free space in front of the current ext4 partition, not at the back... fortunately I do have more space free than the partition is large, so I guess I could do the following: copy the whole partition to the front, remove the one at the back, and then resize the moved one to the whole size? but that seems like a terrible hack to me at the moment... –  RandolphCarter Jun 5 '12 at 12:50

An example:

/dev/sdb2 is the /boot partition. It is 100 MB, which is rather small. To increase this ext4 partition on a running system do (as root, or sudo):

umount /boot

parted /dev/sdb

(parted) print

Model: ATA Patriot Torqx 2 (scsi)
Disk /dev/sdb: 32.0GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number Start End Size Type File system Flags
1 1049kB 12.9GB 12.9GB primary type=83
2 12.9GB 13.0GB 107MB primary ext4 type=83

(parted) rm 2

(parted) mkpart

Partition type? primary/extended? primary
File system type? [ext2]?
Start? 12.9GB
End? 13.4GB

(parted) quit

resize2fs /dev/sdb2

resize2fs 1.42.6 (21-Sep-2012)
Filesystem at /dev/sdb2 is mounted on /boot; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 2
The filesystem on /dev/sdb2 is now 498688 blocks long.

done!

All data remains in place. /boot is ready for use and 472MB big (parted is not that secure with the sizes, read the manual to know why)

All data was backed up before, but only as a precocious. I recommend to do the same.

Use the following command to find the proces which is stopping the unmounting of /boot if it fails:

lsof /boot

Good luck!

share|improve this answer
    
You need to use units of sectors, not GB, to be sure you get it in exactly the same place. –  psusi Feb 27 at 14:44

If you try to delete & recreate a partition, when your partition started below 2048 you might be in for some trouble like I was with resize2fs.

Couldn't find valid filesystem superblock.

From fdisk version 2.17.2, fdisk IIUC forces you to begin from 2048 in order to ensure your hard drive is "aligned correctly". So if your original partition started before 2048, you are in for a bumpy ride trying to recreate the partition.

Best approach is to rsync when cloning a disk.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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