Have you ever got sick of mess in your Linux home folder(s)?
The mess is usually caused by countless random dotfiles, generated by multiple applications over time. In Unix world, these dotfiles are also known as hidden files
or hidden folders
.
The dotfile pollution issue exists due to three main reasons: non-standardization of dotfile locations in a home folder, the way software developers treat user home folder locations in their application code and, unlike system-wide application packages, user-specific application files are usually not centrally managed at all.
Table of Contents
Introduction
Several years ago I realized I have a fundamental issue on my Linux desktop computer: home folder management.
Many dotfiles were all over the place and they made navigation between directories and finding files just too troublesome. This dotfile pollution is a well-known issue: for instance, there is a huge Reddit discussion topic just about that (Reddit: I'm tired of .folders littering my home directory – want to do something about it.)
Suggested solutions
People have suggested various solutions for the dotfile pollution, including
direct software code implementation changes to respect FreeDesktop specifications
secondary home folders just for dotfiles
As I can't trust that all developers respect the FreeDesktop standards and I didn't like the idea of a secondary home folder, I attempted to find alternative solutions.
rewritefs - A FUSE filesystem intended to be used like Apache mod_rewrite
Inspired by the Reddit topic, and facts I faced on my Linux desktop, I decided to something, and I found rewritefs on GitHub. It promised to solve the exact issue I had. Wonderful!
So I went ahead and installed & configured rewritefs
on my Linux laptop. You can read more about the project on the project GitHub page (link above).
The project documentation is not the best one for beginners and it took a while to figure out optimal configuration. This is why I have written basic setup instructions below.
Quick set-up instructions
WARNING: Before applying any changes to your Linux system, please read section Likely destroyed my HDD, extensively degrades HDD. If you still want to go ahead, you are welcome to do so.
1) Install rewritefs (AUR: rewritefs-git)
2) Move all your dotfiles and dotfolders from $HOME
to $HOME/.config/
folder (excluding .config
, .cache
& .local
folders). Remove the dot prefix from the names of those moved dotfiles/folders. You should end up of having only three dotfolders in your $HOME
dir: .cache
, .config
and .local
(and no dotfiles at all). All your previous dotfiles/folders are now in $HOME/.config
, without the dot prefix in their name. Right? Good. Go ahead.
3) Add file /etc/rewritefs.conf
with the following contents:
1m#^(?!\.)# .
2m#^\.(cache|config|local)# .
3m#^\.# .config/
4) Uncomment user_allow_other
in /etc/fuse.conf
. According to the rewritefs author, you must do it:
The files are owned by the user of the process that create them, which is rewritefs, not your applications. You have to run rewritefs as [user], not root.
In the following steps (5-7)…
…
<username>
refers obviously to your true username on your system.…I assume that your
$HOME
folder and system are on the same partition.
5) Add the following entry into /etc/fstab
:
1/mnt/home/<username> /home/<username> rewritefs config=/etc/rewritefs.conf,allow_other,uid=<username_UID>,gid=<username_GID> 0 0
NOTE: It is important to set username_UID
and username_GID
bits in /etc/fstab
. Otherwise you may end up creating new files which belong to group root instead of your actual primary group in $HOME
.
NOTE: If you have $HOME
folder in another HDD/SSD, you should use that location instead of /mnt/home/<username>
in the above /etc/fstab
entry. Additionally, you can skip step 6.
For example, I have my $HOME
in a separate HDD partition, which is mounted at /mnt/hdd (I have defined this in /etc/fstab
). Therefore, my true $HOME
folder locates at /mnt/hdd/home/<username>
so I use that location instead in my above rewritefs /etc/fstab
entry.
6) Log out (!), switch to another TTY and login as another user (I'd recommend root) or alternatively unmount the partition where your $HOME
locates at. You should move your /home/<username>
folder to /mnt/home/<username>
.
The fstab entry you added above takes care that you'll have your $HOME
folder at /home/<username>
, too (now via rewritefs
).
7) Reboot the system
Source: Reddit
Likely destroyed my HDD, extensively degrades HDD
I wrote the above set-up instructions ~ two years ago. I used this FUSE filesystem plugin nearly two years. During that time, I got a lot of experience using it in my production environment.
The basic idea & principle behind rewritefs
is extremely good, but the implementation is very bad for HDD lifetime, at least when used with default/recommended settings stated in the project README file. The core problem is, as the name states: rewrite operations.
Analysis
According to my long-term analysis, comparison and findings, rewritefs
, when used with a single HDD…
slows down computer in normal use
degrades HDD in extensive manner due to increased I/O operations. You see a lot of rewritefs entries in
iotop
output, for instance. Rewritefs likely destroyed my 1-year old 1TB WD Blue 2.5” HDD due to rapidly increased & occasionally continous I/O usage.Computer can be rendered unusable for many minutes due to extreme I/O usage in default Linux settings (without limiting HDD usage by process/cgroups), especially if you compile software or do similar work.
leaves multiple
.fuse_hiddenXXXXX
trace files in user's .config directory (in default settings) & sub-directoriesslows down and crashes operations in QEMU virtual environments. For instance, constantly crashing Falkon web browser on virtualized Arch Linux, and I see extensive I/O usage just after the program crash, likely due to process dump file generation.
Conclusions
Because rewritefs
had core implementation issues, I had to drop it from my Linux system.
The mentioned issues/consequences are very expected when you just think about the principle behind rewritefs
. Easy to say now.
I thought it'd be good to write about the issues I encountered, as I don't want anyone else to destroy HDDs due to this FUSE plugin. I would really appreciate giving this information as a warning in project README file for end-users.
What now?
Though I hate dotfiles in my home directory, I have to prioritize things, and tolerate dotfile pollution once again. After rewritefs
uninstallation all sluggishness is gone, I/O usage is in normal levels again and I don't need to worry about increased HDD usage or rapidly decreasing HDD lifetime on my Linux system.
I can wait for better approaches for the dotfile pollution issue.
Just a thought: Instead of rewriting dotfile locations, I'd appreciate an approach where the files could be read and written directly without rewriting. Would this be possible with a kernel module? Possibly. Seen any implementations? Nope.