LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   consolidate free space on ext4 (https://www.linuxquestions.org/questions/linux-software-2/consolidate-free-space-on-ext4-4175628577/)

qrange 04-28-2018 02:42 AM

consolidate free space on ext4
 
I need to consolidate free space on ext4.
thanks.

syg00 04-28-2018 03:39 AM

Shouldn't be too hard.

Turbocapitalist 04-28-2018 06:38 AM

You might look at e4defrag, but for the most part EXT4 avoids fragmentation rather well until you start to run out of space.

What problem are you trying to solve?

_roman_ 04-28-2018 07:03 AM

Most binary "newbie" distros setup the system in a bad way.

you may look into

Quote:

tune2fs - adjust tunable filesystem parameters on ext2/ext3/ext4 filesystems
To read defrag again after year 2000 has passed, sigh.

I'd also helps when you would rephrase waht you want to do in the first place.

qrange 04-28-2018 11:32 AM

nah, I just want to consolidate free space, not defrag. admittedly, those two are somewhat similar.
no need for sarcasm (if i understood some replies well, otherwise sorry).

I use 'dynamic' .vdi and try to keep image size small on ssd. presumably a lot of scattered small files are bad for dynamic-vdi/sparse.
anyway, why I want it shouldn't matter *that* much.

I don't want to copy the whole thing or something like that.

thanks.

rknichols 04-28-2018 11:58 AM

Quote:

Originally Posted by qrange (Post 5848337)
I use 'dynamic' .vdi and try to keep image size small on ssd. presumably a lot of scattered small files are bad for dynamic-vdi/sparse.

It probably doesn't help. However, ext2/3/4 deliberately distribute files across all the block groups in the filesystem. Directories and the files they contain tend to be allocated in the same or nearby block groups, and keeping the free space scattered means there will likely be nearby free space to do that. None of that makes any sense for a dynamic .vdi or SSD, but you will be constantly fighting against the filesystem to do anything else.

qrange 04-28-2018 12:04 PM

thank you.
in that case could you please recommend a better filesystem for / (xubuntu64 guest) ?

rknichols 04-28-2018 04:47 PM

Sorry, but I don't know of any filesystem designed to keep free space consolidated in normal operation. And anyway, defragmenting the filesystem visible to the guest OS doesn't have much bearing on how fragmented the virtual disk image might be. It's like defragmenting your virtual address space in a program. The physical memory pages could, and probably will, still be scattered all over the processor's physical address space. Conversely, consecutive physical memory pages could map to scattered virtual addresses.

qrange 04-29-2018 01:25 AM

the thing is, .vdi is about 5Gb, and 'du' says there's 4Gb of data. I've already used 'tune2fs -m 0'
can't figure out where the missing space is.

syg00 04-29-2018 02:42 AM

The initial post contained no relevant information - my reply was to highlight that fact. Had the later info been included in the original post, better answers would have arrived earlier.

This is a virtualbox issue, not a filesystem issue. Dynamic vdi only increases as required - (last I looked) it doesn't automatically shrink as files are deleted. If it did, the performance would be abysmal. And --compact only works if the data has been erased to zeroes on file deletion. ext4 is aware of SSD characteristics and supports trim to advise the hardware about unneeded space.

qrange 04-29-2018 02:51 AM

thanks for the lesson. yes, I've already used /dev/zero and --compact.

jefro 04-30-2018 02:05 PM

The issue is still if it is a problem with the file containing the virtual hard drive or the actual use of the virtual hard drive in the VM or the files on the filesystem.

Tar used to be the way to compact files and still works today. This would only help your real filesystem and not the actual growable virtual hard drive.

hydrurga 04-30-2018 02:33 PM

Boot up into the VM. Install the zerofree package.

Reboot the VM to recovery mode (shift key while booting to get Grub screen; root shell->maintenance).

Run df to determine the root partition. Then run the following commands (assumes root partition at /dev/sda1; replace systemctl poweroff with alternative if required):

Code:

mount -n -o remount,ro -t ext4 /dev/sda1 /

zerofree -v /dev/sda1

systemctl poweroff

In the host, determine the VM's UUID with vboxmanage list hdds. Then run the following command, replacing "UUID" with the actual UUID:

Code:

vboxmanage modifyhd UUID --compact

qrange 04-30-2018 03:57 PM

well, I just did all that, no change.
in past, I used the old: 'cat /dev/zero >zero.tmp; sync; rm zero...'

however, zerofree output this (presumably) summary:
62646/4025006/5242368

seems that 4025006 is used space and 5242368 is occupied space.

thanks all.

AwesomeMachine 04-30-2018 10:34 PM

As syg00 said, the size of the drive in the setup is not the actual size of the drive, because virtual drives are sparse files that grow as you need more capacity, unless you specifically tell the program to reserve all allotted space.

OH, and for defrag--if such a thing ever becomes necessary--I just rsync everything to a different drive and then put it all back.


All times are GMT -5. The time now is 07:48 AM.