6

I duplicated a hard disk to a new larger one using the method suggested in Full DD copy from hdd to hdd.

After doing that df -h reports the original and smaller partition sizes from the original disk and gparted highlights the disparity and offers to fix them, though it seems unwise as they are mounted. If you look closely at the image you can see that Used + Unused < Size for the partitions with the yellow warning signs.

What command line tools can be used to fix the issue, and will it be safe for gparted to do it on mounted partition live? Ideally I should have done that before switching over to the target disk and rebooting from it. Gparted Snapshot

Below is the information dialog from gparted about the discrepancy and I edited the title to describe it better.

Gparted information dialog

1
  • extendfs /dev/sda6 ? You might need to specify an ext4 filesystem.
    – Archemar
    Jun 11, 2016 at 8:44

4 Answers 4

6
  • If gparted only has to extend the partition or filesystem into unused space (immediately following the partition), then it should be safe to let it extend the partition and/or fs.

  • If, however, it has to MOVE any partitions around to make space for resizing, you'll have to boot with a gparted Live CD

  • See the man page for resize2fs (which is the command-line tool gparted will use to grow an ext2, ext3, and ext4 filesystem) for more details about resizing those filesystems.

    For ext2/3/4, growing a filesystem is generally not a problem and can safely be done while the fs is mounted.

    Shrinking a filesystem, however, is more troublesome and should be done while the fs is unmounted. If it's the rootfs, that means booting to a rescue CD/USB/PXE etc.


BTW, both dd and cat are amongst the worst ways to copy a linux system to another hard disk. Use Clonezilla, that's what it's for.

4
  • I have edited the question to indicate that it is about extending the file system to use the unallocated space within the partition. Is it safe for gparted to do it while the partitions are mounted? Both / and /home are in use. PS. I used the pv command suggested by Clive
    – vfclists
    Jun 11, 2016 at 5:36
  • I already answered that in my first sentence - yes, it should be safe (I hesitate to say "definitely will be safe" only because there may be some weird and rare situations where it isn't entirely safe. Unless the fs or partition table is already corrupted, it's extremely unlikely to be a problem). BTW, see man resize2fs (which is the command-line tool gparted will use to grow an ext2/3/4 filesystem) for more details.
    – cas
    Jun 11, 2016 at 5:47
  • Also BTW, pv is no better than using dd or cat alone. making exact bit-for-bit copies of a partition or dissk is the problem...copying the files in the partition is the best method (e.g. using cp or rsync or tar or cpio amongst many other tools). Clonezilla can and will use these and other tools to perform backup, restore, and cloning of disks and/or partitions. It's the best tool for the job.
    – cas
    Jun 11, 2016 at 5:49
  • As you suggested resize2fs before Clive's answer, if you add it to the answer I can select yours as the correct one.
    – vfclists
    Jun 14, 2016 at 7:36
5
sudo resize2fs /dev/sda6 

will solve your problem.

4
  • We prefer answers with a bit of explanation.  Also, your answer is essentially the same as the one given a year ago, except yours explicitly includes sudo (which is implicit) and gets the disk name right. Aug 1, 2017 at 4:44
  • This happened to be the most precise answer for my situation.
    – yclian
    Apr 5, 2018 at 2:40
  • This happened to be the only available option in my case. Thanks. Sep 21, 2020 at 13:42
  • Amazing, this actually helps me, just one line of command! Mar 8, 2021 at 8:48
2

If I understand correctly, your partitions are already filling up the new disk, but your filesystems aren't filling up the partitions. Since they're ext3 or ext4 filesystems, you can simply run resize2fs /dev/sda1 etc. as root, even while the filesystem is mounted, to grow it to the partition size.

0

I have solved the exact same issue, both on sda6 and sda7, by resizing the partitions with DISKS! First I have shrinked sda6 by 16GB (not 40GB as I wanted and needed), then I checked in GParted and the "unallocated space" at the end of sda6 was GONE COMPLETELY! Why? Because DISKS did some partition fixing when it shrinked sda6 by 16GB. After this I have enlarged sda6 back, by the same 16GB. I did the same steps with sda7.

Now everything is OK!

So: when GParted fails, DISKS can also be used to fix!!

Edit: Unfortunately, "sudo resize2fs /dev/sda6" did absolutely nothing in my case!

You must log in to answer this question.

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