When cloning ext4 partition with the "dd" command to a bigger partition free space doesn't increase [duplicate]
Possible Duplicate:
Drive reporting incorrect free space
Recently I've been trying to clone my hd using dd tool. Everything was ok, as cloning ntfs partitions but when it comes to ext4 - dd does a strange thing. Eg. Having 12GB partition with 4GB of free space, when im trying to clone it on the new 25GB partition it does clone it, but the data that previously was 12GB, now are 21GB with 4GB(the same amount of free space still as it was on the old partition). It happens everytime im cloning my home and root partitions (ext4). I was also trying to lower the size of the new partition, to the size of the old one, but then dd ends with error saying that there's not enough of space, which should be enough...
Anyone? What's going on?
Solution 1:
I assume you are doing something like:
sudo dd if=/dev/sda98 of=/dev/sda99
where /dev/sda98 has a size of 12GB and /dev/sda99 is 25GB in size.
Obviously these names are wrong, but you get the idea.
What you have done is to move not just the data but the entire file system, including all of its metadata describing what's free and what's used, to the new partition. It has lot's of free space but that free space hasn't been incorporated into the file system on /dev/sda99 so its hidden at the end of the partition and completely unusable.
The solution is to resize the file system located in the partition:
sudo resize2fs /dev/sda99
it works on EXT2, EXT3, and EXT4 file systems.
I'd encourage you to make a backup first, but I assume you still have the data in the original partition.
This will tell the file system to expand into all available space on the partition, incorporating the new space into the file systems's metadata so files can be stored in it.
You can't copy a bigger partition to a smaller partition with dd
unless you tell it to only copy so much with the count parameter. dd
does a bit for bit copy of everything in the source partition to the target partition, in this case it tries to copy all of the hidden/invisible space to the smaller partition along with the original contents. It has no idea or care about what it is copying--it needn't be a valid file system at all.