LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 04-28-2018, 02:42 AM   #1
qrange
Senior Member
 
Registered: Jul 2006
Location: Belgrade, Yugoslavia
Distribution: Debian stable/testing, amd64
Posts: 1,061

Rep: Reputation: 47
consolidate free space on ext4


I need to consolidate free space on ext4.
thanks.
 
Old 04-28-2018, 03:39 AM   #2
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,126

Rep: Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120
Shouldn't be too hard.
 
Old 04-28-2018, 06:38 AM   #3
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,307
Blog Entries: 3

Rep: Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721
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?
 
Old 04-28-2018, 07:03 AM   #4
_roman_
Member
 
Registered: Dec 2017
Location: _Austro_Bavaria_
Distribution: gentoo / linux mint
Posts: 433

Rep: Reputation: 29
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.
 
1 members found this post helpful.
Old 04-28-2018, 11:32 AM   #5
qrange
Senior Member
 
Registered: Jul 2006
Location: Belgrade, Yugoslavia
Distribution: Debian stable/testing, amd64
Posts: 1,061

Original Poster
Rep: Reputation: 47
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.
 
Old 04-28-2018, 11:58 AM   #6
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,779

Rep: Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212
Quote:
Originally Posted by qrange View Post
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.
 
1 members found this post helpful.
Old 04-28-2018, 12:04 PM   #7
qrange
Senior Member
 
Registered: Jul 2006
Location: Belgrade, Yugoslavia
Distribution: Debian stable/testing, amd64
Posts: 1,061

Original Poster
Rep: Reputation: 47
thank you.
in that case could you please recommend a better filesystem for / (xubuntu64 guest) ?
 
Old 04-28-2018, 04:47 PM   #8
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,779

Rep: Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212
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.
 
Old 04-29-2018, 01:25 AM   #9
qrange
Senior Member
 
Registered: Jul 2006
Location: Belgrade, Yugoslavia
Distribution: Debian stable/testing, amd64
Posts: 1,061

Original Poster
Rep: Reputation: 47
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.
 
Old 04-29-2018, 02:42 AM   #10
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,126

Rep: Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120
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.
 
1 members found this post helpful.
Old 04-29-2018, 02:51 AM   #11
qrange
Senior Member
 
Registered: Jul 2006
Location: Belgrade, Yugoslavia
Distribution: Debian stable/testing, amd64
Posts: 1,061

Original Poster
Rep: Reputation: 47
thanks for the lesson. yes, I've already used /dev/zero and --compact.
 
Old 04-30-2018, 02:05 PM   #12
jefro
Moderator
 
Registered: Mar 2008
Posts: 21,980

Rep: Reputation: 3624Reputation: 3624Reputation: 3624Reputation: 3624Reputation: 3624Reputation: 3624Reputation: 3624Reputation: 3624Reputation: 3624Reputation: 3624Reputation: 3624
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.
 
1 members found this post helpful.
Old 04-30-2018, 02:33 PM   #13
hydrurga
LQ Guru
 
Registered: Nov 2008
Location: Pictland
Distribution: Linux Mint 21 MATE
Posts: 8,048
Blog Entries: 5

Rep: Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925
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
 
1 members found this post helpful.
Old 04-30-2018, 03:57 PM   #14
qrange
Senior Member
 
Registered: Jul 2006
Location: Belgrade, Yugoslavia
Distribution: Debian stable/testing, amd64
Posts: 1,061

Original Poster
Rep: Reputation: 47
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.

Last edited by qrange; 04-30-2018 at 03:59 PM.
 
Old 04-30-2018, 10:34 PM   #15
AwesomeMachine
LQ Guru
 
Registered: Jan 2005
Location: USA and Italy
Distribution: Debian testing/sid; OpenSuSE; Fedora; Mint
Posts: 5,524

Rep: Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015
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.

Last edited by AwesomeMachine; 04-30-2018 at 10:36 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
ext4 partition free space wrongly reported by df -h (ubuntu 14.04 64bit) trancephorm Linux - Software 16 01-16-2018 10:27 PM
Debian squeeze will not show free and used disk space on EXT4 formatted hard drives sillas2001 Debian 5 03-06-2011 06:56 AM
Help removing free space to create Raw free space nightmare55 Linux - Newbie 11 10-01-2009 03:07 AM
Not enough free space on hard drive with 50g of free space??? auoq SUSE / openSUSE 5 10-13-2004 08:21 PM
Formating free space: WinXP pro and RH9 dualboot with free space on 3rd drive Vermicious Linux - General 2 03-22-2004 05:10 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 10:53 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration