How to resize / enlarge / grow a non-LVM ext4 partition
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
Solution 1:
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.
Solution 2:
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: msdosNumber 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 precaution. I recommend to do the same.
Use the following command to find the process which is stopping the unmounting of /boot if it fails:
lsof /boot
Good luck!