9

I state I am asking if it is possible and HOW. I note many forum answers are 'you can't' or 'you don't need to on Linux cause it is perfect and wonderful' - none of these answers will help.

Firstly, the HDD in question is SATA 163 GB and contains ONLY backup data like music, video and NO windows programs or installations. I have had a HDD failure in second HDD that is completely FUBAR so have lost my windows installation, this HDD had linux and windows dual boot, HDD is undetectable in BIOS.

The working HDD is 130GB full with capacity of 163GB (it is badly fragmented due to excessive use...). I intend to defrag this drive using USB linux OS (bootable USB with installation files and 'trial') and any other programs that will enable this task. Once this is done I intend to locate which data areas are free (the end of HDD data storage area), create a new partition on this free space, install linux full version and get things working.

+++

I understand fully the following:

I can buy a new HDD for install.

I can get an external hard drive, back up the data.

I also understand that copying off backup hdd and then copying back will do the same as defrag.

I ask this question to find out how to complete this action I have requested and NOT to complete it using the methods unavailable to me at this time.

Thanks

Alvar
  • 17,058
mike
  • 103
  • 1
  • 1
  • 4
  • you don't hvae to defrag a ext filesystem, so no you can't do it. – Alvar Jul 13 '13 at 16:48
  • 1
    Well, to add to "you can't" and "you don't need", I think you don't even want to. Defragmentation won't make a large area of free space. It will only defragment individual files - so they can still be scattered over the whole area. Secondly, if you succeed in moving files to the start of end of the current partition then it will take you the same amount of time as letting the partition shrink and have the resize process take care of that for you. (both methods require the same data to be moved). – gertvdijk Jul 13 '13 at 16:48
  • however, I have one partition on this HDD. To create a new partition now would surely not allocate space fairly and keep all data. Surely I am right in saying partitioning this drive will involve data loss?? This is my issue... I wish to defrag only so I can safely 'move' data to a smaller area so it will read that 'HDD area from 130GB to 160GB is free' therefore a partition would be possible. – mike Jul 13 '13 at 16:56
  • 2
    Alvar, it is not ext filesystem it is NTFS, and aswell as that linux can become fragmented and at times a defrag could be useful (except on new drives etc) despite what linux users say about allocation of HDD space by linux. This question asks: is this action possible and how would i do it, NOT should i do it. – mike Jul 13 '13 at 16:58
  • 2
    well you never said what file system was used on the HDD – Alvar Jul 13 '13 at 17:01
  • Please offer details of either USB defrag program or alternatively suitable linux software that would enable defrag of NTFS from linux OS. I want the answer not just to do it but to find out how to allocate space on HDD using linux and creating partitions in tricky situations. – mike Jul 13 '13 at 17:01
  • If you want to resize the partition, that has nothing to do with defragging. You can resize in the Ubuntu installer or with gparted. – psusi Jul 13 '13 at 17:50
  • @Alvar, while it is true that you generally do not need to, you can: http://launchpad.net/e2defrag – psusi Jul 13 '13 at 18:03
  • @psusi my point isn't that you can't. It's that you wont gain anything doing it. So it's pointless. He wants to defrag it from Ubuntu, it's impossible so you have resize it as a solution. – Alvar Jul 13 '13 at 20:41

1 Answers1

5

Personally I wouldn't bother to defrag the NTFS partition of the HDD since if you install Ubuntu on the spare part it will only use that amount as a hard drive and the rest will not be affected. Then just mount the NTFS on Ubuntu and access the files there.

An ext4 file system doesn't have the problems with empty slots as NTFS or FAT32. The problems with NTFS and FAT32 are that the storage is based on data being put in slots and if a files on fills up 15 slots but are assigned 16 slots then one slot will be empty.

Here is where defrag comes in and moves the data around so that the data is used in each slot and the empty slots are declared as empty instead of used by this and that file. This saves space and makes access times shorter since you don't have to search the whole HDD for a file.

In ext4 files are divided throughout the disk and the fields where the data is stored is linked to the original file, so a file can be stored in row 1 field 2, row 3 field 12, etc.

So moving files around to save space doesn't work in ext4, you will make no more room on the hard drive. it will be just as easy to access files as it was before. This is just an example of the principle, explaining it in detail seemed too complex right now.

Is it possible to defrag an NTFS from Ubuntu
What I've found out by searching on this topic is that there is no program to defrag an NTFS HDD from Ubuntu. The best solution is to:

  1. Mount the HDD under Ubuntu
  2. Copy the files to another HDD
  3. Re-format the HDD (preferably with ext4)
  4. Move back the files

If you don't have another drive I would

  1. Create a ext4 partition on the empty space and move some files to there
  2. Remove those files from the NTFS partition
  3. Resize the NTFS partition to make it smaller
  4. Make the ext4 partition larger

Do this procedure until all files are moved and the NTFS partition is gone.

Alvar
  • 17,058
  • 1
    I am not trying to create 'more' space, I am trying to compress the files in one section of the HDD so I can manually create the space for a possible new partition. As I said before the question is how can you do this, please refer to the question. – mike Jul 13 '13 at 17:04
  • Unless I am wrong a defrag can allow files to be stored in sections 0-130 GB with the rest empty. Im trying to make a new partition that is all. – mike Jul 13 '13 at 17:07
  • @mike, you can make a new partition without defragging. – Alaa Ali Jul 13 '13 at 17:08
  • thanks mate for the quick response. What about USB defrag software? – mike Jul 13 '13 at 17:09
  • @mike Really, just shrink the partition. You can leave space unpartitioned very well which you can use to create new partition at a later time. It does not make much sense to "move files" to a specific spot on the hard drive - that's what filesystems for in the first place; to not have to worry about that! Shrinking the partition will move the data for you. – gertvdijk Jul 13 '13 at 17:11
  • Alaa - But this will either likely or definitely delete files would it not. Surely a partition editor will fail if there is mass fragmentation and data on all parts of the disk with no free area of data 'in one chunk'? unless I am missing something the only way to ensure no data loss is to have this free chunk of space? – mike Jul 13 '13 at 17:11
  • @mike added another way to do it. – Alvar Jul 13 '13 at 17:12
  • 2
    @mike No. Read up on how filesystems work. Your continuing repeated question about to control the physical spot on the hard drive does not make sense for what you're trying to achieve. Shrinking a filesystem (and partition) should not delete any files. – gertvdijk Jul 13 '13 at 17:13
  • gertvdijk - ok. Will investigate this option. – mike Jul 13 '13 at 17:16
  • @mike The filesystem will make sure that your files are there even if you shrink the partition, the empty space on a HDD will always be empty.. – Alvar Jul 13 '13 at 17:17
  • 1
    Just wanted to add that the order of shrinking the filesystem and then shrinking the partition is important. Otherwise you will lose data. And yes, a filesystem is different from a partition, in case you are frowning upon this comment. – gertvdijk Jul 13 '13 at 17:19
  • gertvdijk - well! I feel a little silly now... Thanks! I was not aware of the location of the details of the technical operations of shrinking the partition, therefore I did not think it would allow me without likely data loss. I thank you for enlightening me on this issue. I STILL want to know how to do it though. If anyone can offer a program that defrags on linux it would be great - even if it were merely a bootable (FREE) usb stick with the software. This problem is not unfixable - I just wanted to learn the operation and save buying a new HDD for 3 weeks and not lose files. – mike Jul 13 '13 at 17:20
  • @mike you can't defrag a NTFS filesystem on Ubuntu (I've siad that a couple of times now!) do one of the methods I suggested. That will be faster than trying find something that doesn't exist. – Alvar Jul 13 '13 at 17:22
  • gertvdijk - how do you shrink the filesystem? please explain any technicalities. I believed shrinking the partition without 'making space' (ie from 130 GB to 166GB) would overwrite. I have Gparted and it will allow me to resize/shrink partition and states how much would be left over. I wish to avoid data loss that is my MAIN CONCERN, payday is weeks away and USB linux is a pain – mike Jul 13 '13 at 17:23
  • @mike this question explains how you install UBuntu via a live usb and creates a sperate partition on an HDD. http://askubuntu.com/q/6328/10698 – Alvar Jul 13 '13 at 17:25
  • alvar, well I guess the question is 'Can I shrink the partition to it's minimum (as suggested amount by - in my case Gparted - and be 100% sure of no data loss. (I'm guessing the answer is yes and I have approached this task from the wrong angle and this is in fact and easy task to complete... at least I hope so) – mike Jul 13 '13 at 17:35
  • @Mike well yes shrink the partition to what size is used (no data loss) then with the free space install Ubuntu on that and then make a backup of the important files when you get a new HDD. shrink it with gparted first then try the live usb and select the free space in the install. – Alvar Jul 13 '13 at 17:37
  • cool. Thanks Alvar. I guess I did not know the full functionality and limitations properly. in short, silly question!! Well thanks again, now you can go and wrestle with more important questions like: who's getting the beers in tonight, and shall I have sex with her before we go out or after? Keep well. My stupid! – mike Jul 13 '13 at 17:40