My *nix world

Speed-up system by SquashFs

It has been a while since I installed Gentoo. I always searched for new ways to improve the speed my system boot and run. After goggling little bit on net I found something about SquashFs and how to use it to squash your portage tree. But can I use the same technique to squash my entire /usr ? Well, this article says that you can.

Basically SquashFs allows you to create a compressed (zlib, lzo or xz) readonly filesystem. But we need to write to it, do we?

So we need another filesystem designed to allow us to write the filesystem content. That would be AnotherUnionFS (aufs). As Wikipedia says:

"aufs it's an advanced multi layered unification filesystem which implements union mount for Linux filesystem. It aimed to improve reliability and performance, but also introduced some new concepts, like writable branch balancing and other improvements".

So it seems something we can use. Let's speed-up system by SquashFs filesystem!

If you had installed SquashFS and aufs then it is a good time to do some modification in your system:

(in your DISTDIR is located outside of /usr then skip the next two steps below)

  1. define in your /etc/make.conf the path to DISTDIR, which should be outside /usr folder (ex: DISTDIR="/var/portage/distfiles")
  2. make sure you move the above folder from /usr/portage/distfiles location to the new DISTDIR location
  3. squash your /usr folder to a compressed filesystem image:
  1. create the following /etc/init.d/squash_usr init script that will help us to mount/unmount the compressed image filesystem when system starts/stops:
  1. make sure you tell your system to start that script after booting:

That's all, it should works!

A more abstract version for this can be found here.

Note: don't delete the original /usr folder (located on the physical partition) in order to free some space unless you know what you are doing! Keep in mind that a lot of utilities are located on /usr/bin or /usr/sbin, a lot of libraries are located on /usr/lib, some configuration are stored event on /usr/share/.

I had deleted some folders inside the original /usr to free some space (that's why I am using a SquashFS in the first place), BUT I had kept the following folders:

  • bin
  • lib
  • lib64 (or lib32 or both , depending on if you are using multilib Gentoo system or not)
  • sbin
  • share/slim
  • tmp

Well, you are not supposed to keep the entire contents of those folders but only the necessary utilities/libraries/configuration files. So it is a matter of try and error if you want to get dirty on your hands.

Another issue (the biggest one I guess) you have to think about would be: how those utilities/libraries/configuration files from your original /usr folder (used just at boot-time) get updated when you rebuild your system? I'm asking this because you will have mounted the SquashFS image and not the physical /usr folder. So after you are successfully booting your system and your SquashFS image get mounted as /usr, everything you will update on your /usr will be stored inside the SquashFS image (ex: /var/portage/portage-current.sqfs) and not on the original /usr folder.

My advice is to analyze the whole scenario before starting and doing anything. What I have learned from here is that "you can" and "how to do it" but not "whether it can be applied to a particular situation or not".

Warning: before doing anything backup your data ;o)

Note: if you are using a SSD disk drive and not a HDD instead, I am not quite sure that you will gain in performance but for sure you will free some space on your disk.

Now, if you think that this article was interesting don't forget to rate it. It shows me that you care and thus I will continue write about these things.

 
The following two tabs change content below.
Speed-up system by SquashFs

Eugen Mihailescu

Founder/programmer/one-man-show at Cubique Software
Always looking to learn more about *nix world, about the fundamental concepts of math, physics, electronics. I am also passionate about programming, database and systems administration. 16+ yrs experience in software development, designing enterprise systems, IT support and troubleshooting.
Tagged on: , , , , ,

5 thoughts on “Speed-up system by SquashFs

  1. Petros

    How the system is supposed to boot and mount /usr if it squashed?

    After all mount is located in (the squashed) /usr and we face the chicken and egg situation.

    1. Eugen Mihailescu Post author

      Good question. From the manual:

      /usr usually contains by far the largest share of data on a system. Hence, this is one of the most important directories in the system as it contains all the user binaries, their documentation, libraries, header files, etc.... X and its supporting libraries can be found here. User programs like telnet, ftp, etc.... are also placed here. In the original Unix implementations, /usr was where the home directories of the users were placed (that is to say, /usr/someone was then the directory now known as /home/someone). In current Unices, /usr is where user-land programs and data (as opposed to 'system land' programs and data) are. The name hasn't changed, but it's meaning has narrowed and lengthened from "everything user related" to "user usable programs and data". As such, some people may now refer to this directory as meaning 'User System Resources' and not 'user' as was originally intended.

      Basically your system can boot without the user-land programs. All it needs is (love) the system land programs and data which happily are stored somewhere else 🙂

      So your compressed/squashed image will be decompressed as soon the Linux Core components are loaded (before X-Server or other user-lands programs). Please read this to learn how to squash any arbitrary folder.

    1. Eugen Mihailescu Post author

      Yes, squashmount is also a script that does the same thing (including the read-write aspect I mentioned in my post). My goal was to learn how things are done and also I tried to squeeze the Gentoo a bit. There is place for improvements, though 🙂

      I hope it helped and if it did then it was my pleasure 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *

Follow

Get every new post on this blog delivered to your Inbox.

Join other followers: