Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have a dynamically expanding VDI file which is 14 GB big while the partition itself is only 2 GB.

The files are too spread out over the disk so zero-ing the free space and compacting the VDI didn't help, if I can get the files too be together on the disk like MyDefrag can do on Windows I can spare out 12 GB.

Steps taken so far:

  • Made root partition as small as possible. (NCurses Disk Usage shows only 2 GB left)
  • Used zerofree on the root partition.
  • Used the VirtualBox tools to compact the VDI file. (It went from 16 GB -> 14 GB)

The file should be half the size of what it is now...

Info about the disk:

Disk /dev/sda: 536.9 GB, 536870912000 bytes  
255 heads, 63 sectors/track, 65270 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: 0x837d7521  

   Device Boot      Start         End      Blocks   Id  System  
/dev/sda1               1           5       40131   83  Linux  
/dev/sda2               6          71      530145   82  Linux swap / Solaris  
/dev/sda3              72       65270   523710967+  83  Linux


Model: ATA VBOX HARDDISK (scsi)
Disk /dev/sda: 537GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number  Start   End     Size    Type     File system     Flags
 1      32.3kB  41.1MB  41.1MB  primary  ext2
 2      41.1MB  584MB   543MB   primary  linux-swap(v1)
 3      584MB   537GB   536GB   primary  ext3


Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/sda3            515492812   2443136 486864128   1% /

I'm currently trying to defragment it, then I'll do the zerofree and compact steps again.

This might work...

Total Files:                    178174
Fragmented Files:               25881
File Fragmentation Rate:        14.5256883720408%
Avg File Fragments(1 is best):  1.16055653462346

But does it?

Done!
Now lets see the results...
Statistics for /
Total Files:                    0
Fragmented Files:               0
Illegal division by zero at /usr/sbin/defragfs line 193.

Ouch, fail... It broke my install (kernel panic), I think I still have a back-up of a month ago.

Don't worry about it, I only have to emerge --sync; emerge -Du world; svn up on the back-up...
I currently use it for native Linux developing only, that's why I need it to be 3 GB and not 14 GB.

share|improve this question
    
Updated question with the steps taken so far, next time I boot the system I'll check the size of the boot and swap partition and then I will try the defragmenter that harrymc mentions. –  Tom Wijsman Aug 7 '10 at 11:27

3 Answers 3

up vote 0 down vote accepted
+50

If your problem is the layout of the partitions, you can use any partitioning product.
Just download the image of the boot CD of any partitioning product and boot with it as you would with a real physical computer. GParted is one possible choice.

If the partitions won't resize, defragmentation might be required. Although the file system on Linux is organized more efficiently than on Windows, it is not immune to this need. Linux File System Defragmenter is one possible solution.

EDIT

Sorry about losing the kernel.

Weird: Having a file-system with 1% used that can't resize is really weird.
Did you have on it some large files that you deleted?

In any case, defragmenters for ext3 are rare, unlike ext4 which is planned to eventually include an online defragmentation utility. However, here are some utilities that may play nicer with your disk. Be sure to read well the README files.

Shake is a defragmenter that runs in userspace, without the need of patching the kernel and while the system is used (for now, on GNU/Linux only).

Defrag the first is a shell-level script.

Defrag the second is another shell-level script.

share|improve this answer
    
The lay-out of partition is the default one, first the boot partition, then the swap partition and then the root partition. My root partition contains 2 GB and I'm sure the other two together are not 12 GB. So I think that the reason the VDI doesn't compact more is that there are a lot of blocks that contain used and free together, so I want to force the used together so that the free ones are apart and thus can be compacted I will try to see if your second link helps me to do this... –  Tom Wijsman Aug 7 '10 at 11:24
    
@TomWij: Try first to get an over-all view of the disk to understand the problem better. See cyberciti.biz/faq/… . You might also post this info. –  harrymc Aug 7 '10 at 11:59
    
Updated, trying the defragmenter now. –  Tom Wijsman Aug 10 '10 at 19:06
    
The defragmenter makes me have a kernel panic during the boot, why does that happen? See the answer for details about the failed defragmentation process. –  Tom Wijsman Aug 10 '10 at 20:41
    
Is it possible that my file system got corrupt? Can I troubleshoot or remedy that? I'll try Shake tomorrow if I still have a back-up, will make a back-up copy too so I don't have to go trough the restore feature of my back-up software. Maybe my back-up doesn't show up corruption... –  Tom Wijsman Aug 11 '10 at 22:42

May not be the best solution, but an easy way would be to copy the filesystem on the partition to a new partition, using copy -a to preserve the file attributes.

A quick edit of fstab to mount the new partition in place of the old one and away you go...

share|improve this answer
    
But then I would need to resize, which makes me think: Can I resize the current partition to 3 GB somehow? –  Tom Wijsman Aug 10 '10 at 20:50

How to effectively compact Linux Virtual Machine: http://kb.parallels.com/en/5683

In Parallels Desktop version 3:

  • Click Hard Disk 1
  • Advanced
  • click Compact

In Parallels Desktop version 4:

  • Start Parallels Image Tools from Applications/Parallels
  • Select Disk to compact pointing to Virtual Machine pvm
  • Click "Choose" button
  • Click "Continue"
  • Select "Compact Disk"
  • Click "Start"
share|improve this answer
    
I've already used the zerofree utility... I'm using VirtualBox so these instructions do not help me, I've already chosen to compact using VirtualBox and that only made it go from 16 GB to 14 GB. Hmm, I just realized I didn't check the space the boot and swap partition uses, but that doesn't count up to 12 GB so I still need to force the partition files together to get rid of the free space in between. (Force together as MyDefrag calls it, but that's a Windows utility) –  Tom Wijsman Aug 7 '10 at 8:49

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.