Gparted won’t shrink an NTFS partition with a bad sector

February 12th, 2011  |  Published in Random computer how-tos  |  33 Comments

Hopefully someone might find this useful. I searched many forums and could never find a solution to this problem, apart from “run chkdsk /r”. Hopefully this might help you, but be warned its very dangerous, make sure you have a backup of everything on your disk!

While trying to shrink an NTFS partition on my laptop, to make room for Ubuntu, I discovered that GParted (running from Ubuntu cd)  will not let you shrink the partition if it has a bad sector. It has a exclamation mark in a triangle next to the disk, and you can’t get proper information about the usage in the partition. Because of this, you can only move it, or increase its size (operations that don’t require knowledge of whats already in there).

I tried fixing any errors on the disk using CHKDSK from Windows, but it never seemed to actually solve the problem. I believe the reason was that the problem was something that CHKDSK refuses to touch, or there was never really a problem.

The interesting thing is that the ntfsresize program (part of ntfsprogs package) will let you re-size the partition if you use the –bad-sectors option. However when I did this manually, it doesn’t seem to do everything correctly and the partition is not actually reduced in size.

Turns out that gparted actually calls ntfsresize to get information about the drive, and then do the resizing. The problem is ntfsresize keeps reporting there are errors on the disk, so gparted gives up. Gparted itself does not provide an equivalent to the –bad-sectors option.

Solution

[WARNING: Only try this if you have backed up all your data. Since its essentially bypassing a fail-safe feature of gparted, its inherently dangerous
[EDIT: See Miguel's comment below about moving the partition aswell]]

Trick Gparted :)

I just moved /usr/bin/ntfsresize to /usr/bin/ntfsresize.orig

I then created (and chmod’d to be executable) /usr/bin/ntfsresize and put the following in it:


#!/bin/bash
exec ntfsresize.orig --bad-sectors "$@"

I was then able to run gparted without any problems.

Print This Post

Responses

  1. avatar stlouisubntu says:

    July 24th, 2011 at 6:21 am (#)

    Hey friend, thanks so much for this post and for leaving it up. I would not have been able to help a friend set up a dual boot linux install without it. Windows XP Media Center was installed on an NTFS partition that would not resize. Gparted would give apparently accurate information on this partition provided it was mounted, but would give no information on it when unmounted (and would not resize it marking it with an “!”.) Your work around did the trick with the only difference being that ntfsresize was found in /usr/sbin instead of /usr/bin (on a Puppy Linux live CD loaded into RAM.)

    Thanks again.

    Kind Regardd,

    stlouisubntu

  2. avatar Dave says:

    September 9th, 2011 at 6:24 pm (#)

    Thanks for this, this will save me stacks of time in the future, disks with bad sectors are the bane of my life when repairing customers computers and now using Clonezilla to clone them and Gparted with this fix to resize them, I can save myself the occassional windows reinstall. Good work.

  3. avatar Miguel says:

    September 13th, 2011 at 3:06 am (#)

    Thanks for this tip :)

    But be careful when doing this.

    Although you will be able to resize the NTFS partition, if you ask GParted to move it while resizing (it’s done in the same window for resize/move), GParted won’t be able to move the partition after resizing if the bad sectors are still uncorrected in the disk.

    Only if the bad sectors have been previously corrected on the disk (by using the manufacturer program, or using badblocks…) the move operation will be ok.

    And if you have corrected the disk bad sectors, you can reset the NTFS bad blocks by using CHKDSK /B (only available on Windows Vista or Windows 7).

  4. avatar Luís says:

    February 8th, 2012 at 10:08 pm (#)

    Wow!

    It did allow me to shrink an ntfs partition with bad blocks!

    Thanks for sharing!

  5. avatar m00dymark says:

    February 10th, 2012 at 4:52 am (#)

    Thanks for this very useful tip. I thought I was going crazy when I couldn’t resize the partition. It’s been a year or so since I done the last one and thought my memory was failing me. I mean my own personal on board brain memory ;)

    A good example of how a Linux system can be so flexible.

  6. avatar Tone says:

    February 12th, 2012 at 1:44 am (#)

    Nice. This worked for me, too.

    Just to spell it out in case someone wants to see:

    cd /sbin
    sudo mv ntfsresize ntfsresize.orig
    sudo touch ntfsresize
    sudo vi ntfsresize

    #!/bin/bash
    exec ntfsresize.orig –bad-sectors “$@”

    sudo chmod 777 ntfsresize

  7. avatar Mark Conger says:

    March 27th, 2012 at 2:44 am (#)

    Just to confirm that this worked for me as well.

    Great tip!

    Please note that the correct syntax for the bad sector option in the ntfsresize command is either:

    -b

    -OR-

    –bad-sectors

    Note the additional hyphen before the full word. This caused me an extra hour of fidgeting to figure it out.

  8. avatar Mark Conger says:

    March 27th, 2012 at 2:46 am (#)

    Ok. I guess the commenting system on this site removes additional hyphens as it stripped it from my comment too.

    If you use “bad-sectors” instead of “b” be sure to put TWO hyphens.

  9. avatar Dzec says:

    April 19th, 2012 at 1:31 am (#)

    Hello, I’d like to try this. I guess this info gets entered from the command prompt but I get invalid switch /sbin. Please put me out of my misery

  10. avatar anthony says:

    April 20th, 2012 at 3:53 pm (#)

    Dzec:
    Not sure why you would be getting an invalid switch error.
    You need to backup the ntfsresize file, and then replace it with a ascii file with the contents of:

    #!/bin/bash
    exec ntfsresize.orig –bad-sectors “$@”

    The ntfsresize file might be in /usr/bin/ or in /usr/sbin/

    (Sorry about comments needing approval – they shouldn’t; I thought I’d fixed that)

  11. avatar Anton says:

    June 9th, 2012 at 5:35 pm (#)

    Hi Could you please help me with the following:
    I get e319 error when I tried to create the ntfs resize file in VI editor, I am completely new to linux, on the website they advised reinstall the following but it says the package is not available
    # apt-get install vim-gui-common

    # apt-get install vim-runtime
    can you please help me step by step how can i get the advanced VI editor, any help is much appreciated. Thanks.

  12. avatar anthony says:

    June 10th, 2012 at 7:14 pm (#)

    Anton: First off, if you are new to linux, I would be very careful following my instructions, since it is bypassing a safety feature of gparted. If you still want to to do it, read on:

    Just “sudo apt-get install vim” should be sufficient. You do not specifically need to use vim, you can use any editor. I have not encountered that error. The page at
    http://tiny.cc/foranton
    looks like it might help.

    For now, I would suggest doing the following instead to avoid using an editor:

    cd /usr/bin/
    sudo mv ntfsresize ntfsresize.orig
    sudo echo ‘#!/bin/bash’ >> ntfsresize
    sudo echo ‘exec ntfsresize.orig –bad-sectors “$@”‘ >> ntfsresize
    sudo chmod u+x,g+x,o+x ntfsresize

    That should (hopefully) put the require file in place and make it executable. Note that that is a double-hyphen before bad-sectors, but the commenting system might not be showing it as such.

  13. avatar Anton says:

    June 11th, 2012 at 6:53 am (#)

    Thanks for your quick response Anthony, I will try it tomorrow and let you know how it went.

  14. avatar Andy386 says:

    January 9th, 2013 at 5:11 pm (#)

    Thank you so much!
    Tried first by hand with ntfsresize, it told about fdisk, but unfortunatly fdisk wont let my fist partion start at 62… Now I did it in a nice GUI with some error-catching by gparted – everything is fine.

  15. avatar Jimmi says:

    January 13th, 2013 at 9:55 am (#)

    Wow, Anthony! You da man! You have just saved me boatloads of grief!

    I’m in the process of transferring and virtualizing my old IDE XP machine, with a failing controller, over to a new Win8 machine. The controller has wreaked havoc on both the Master and Slave, in addition to truly bad physical sectors on the Slave. Clonzilla worked great but the copy of the Master indicated bad physical sectors which Clonzilla had copied dutifully from the original, still marking them as bad on the virtualized image. gParted of course wouldn’t let me resize the drive since bad physical sectors were indicated. Your little tricked saved my rear!

    Thanks for sharing!

  16. avatar John says:

    February 1st, 2013 at 2:23 am (#)

    Let me too say thanks Anthony! Your method worked like a charm.

    The question arises though, why does ntfsresize/gparted behave this way. It’s hard for me to believe Linux is too stupid to handle bad sectors properly and that we’re therefore in some kind of danger.

  17. avatar Signs of Success » Blog Archive » Drives with bad sectors says:

    February 15th, 2013 at 12:29 pm (#)

    [...] to resize partitions with bad sectors. I searched for weeks to find a solution to this one, and here it is. This is a really dangerous fix, so don’t mess about with your only copy of a disk, clone it [...]

  18. avatar manu says:

    February 18th, 2013 at 12:36 am (#)

    Thanks very much for the trick !

  19. avatar Lazydog says:

    March 9th, 2013 at 2:03 am (#)

    Thank you a lot for the trick. Finally I’ve managed to solve the resizing the partition after so many hours of trying various methods.

  20. avatar vexorian says:

    April 16th, 2013 at 11:22 am (#)

    This is a total life saver. Wish there was an easy –bad-sectors gparted option.

  21. avatar Patrick Verner says:

    June 16th, 2013 at 11:42 pm (#)

    I patched GParted to resize with bad sectors. The patched and unpatched version are kept separate. Download Parted Magic and look in:

    Panel Menu –> System –> Resize NTFS with Bad Sectors

    Hope this helps everybody out a little bit.

  22. avatar Cloter says:

    June 28th, 2013 at 9:49 pm (#)

    Just to confirm it worked for me too!

    Thanks Miguel, great tip.

  23. avatar Markus S says:

    August 13th, 2013 at 5:57 pm (#)

    Thank you for the trick. I was a little bit scary but it worked for me!

  24. avatar Stonefeather Grubbs says:

    August 20th, 2013 at 7:28 am (#)

    Using Anthony’s method to do this (response 12) I was able to run the first two lines successfully, in the first line replacing the directory with /sbin, where ntfsresize lives on my machine, in the first line. Copying and pasting the third line, got “event not found, then realized the site had changed straight single quotes with curly equivalent, switched them back but got “bash: ntfsresize: Permission denied.” If anyone can figure out why, let me know. I may just try using a text editor, saving it a chmoding it. I am a total Linux newbie, btw, though I’ve microsofted for years.

  25. avatar Stonefeather Grubbs says:

    August 20th, 2013 at 8:08 am (#)

    Okay, Tone’s approach (response 6) seemed to work, just had to look up how to use vi is all. Now to see if it works.

  26. avatar Stonefeather Grubbs says:

    August 20th, 2013 at 9:01 am (#)

    And yes, works like a charm! Thank you all!

  27. avatar Maxi Vacation says:

    June 7th, 2014 at 5:58 am (#)

    Maxi Vacation…

    Gparted won’t shrink an NTFS partition with a bad sector :: Unfinished Teleporter…

  28. avatar Recommended Web page says:

    June 7th, 2014 at 2:37 pm (#)

    Recommended Web page…

    Gparted won’t shrink an NTFS partition with a bad sector :: Unfinished Teleporter…

  29. avatar Luxury Toy Stores In London England says:

    June 23rd, 2014 at 11:02 am (#)

    Luxury Toy Stores In London England…

    Gparted won’t shrink an NTFS partition with a bad sector :: Unfinished Teleporter…

  30. avatar free kids clothes catalogs says:

    July 4th, 2014 at 12:05 am (#)

    free kids clothes catalogs…

    Gparted won’t shrink an NTFS partition with a bad sector :: Unfinished Teleporter…

  31. avatar visit the website says:

    July 4th, 2014 at 10:30 am (#)

    visit the website…

    Gparted won’t shrink an NTFS partition with a bad sector :: Unfinished Teleporter…

  32. avatar amazing website for says:

    August 20th, 2014 at 11:29 pm (#)

    amazing website for…

    Gparted won’t shrink an NTFS partition with a bad sector :: Unfinished Teleporter…

  33. avatar Anonmouse says:

    December 3rd, 2014 at 3:07 pm (#)

    Thanks for the tut, saved me hours of head scratching.

Leave a Response