3

If we are using initrd for, say in live usb, why would we also need squashfs?

Ciro Santilli OurBigBook.com
  • 26,663
  • 14
  • 108
  • 107
user285825
  • 153
  • 2
  • 6

2 Answers2

2

Initrd is deprecated and replaced by Initramfs (and to some extent upstart).

What is the difference between initrd and initramfs?

The initramfs is more a part of the booting process and is a minimal file system used to bootstrap the kernel and initialize your hardware.

suqashfs is a compression tool and takes a large (5 Gb) file system and compresses it into a much smaller size, but it is ro.

squashfs is thus used for the entire file system, / and all the binaries and libs necessary to be Ubuntu live.

See also:

https://help.ubuntu.com/community/LiveCDCustomizationFromScratch

https://wiki.ubuntu.com/Initramfs

Initramfs is used as the first root filesystem that your machine has access to. It is used for mounting the real rootfs which has all your data. The initramfs carries the modules needed for mounting your rootfs.

Here is the initramfs I built http://blog.bodhizazen.com/linux/initramfs/

And

http://squashfs.sourceforge.net/

Squashfs is a compressed read-only filesystem for Linux. Squashfs is intended for general read-only filesystem use, for archival use (i.e. in cases where a .tar.gz file may be used), and in constrained block device/memory systems (e.g. embedded systems) where low overhead is needed.

Panther
  • 100,877
  • 19
  • 193
  • 283
  • 1
    Awesome answer. I have two questions. first: if the the squashfs contains the same filesystem paths like /etc, /tmp, etc as in initramfs, then how does the kernel resolve the conflict. Second: I want to customize the live usb but I don't want to modify the initramfs or vmkernel. I want to be able to run some init script upon boot. Hence then initramfs will be constant and it will kind of delegate the control to some user defined scripts (kind of like chain loading. I mean initramfs will have a pointer to the user script which can be modifed at will). Can I accomplish this using squashfs? – user285825 Jun 06 '13 at 08:13
  • first: squashfs during bootup will define its own path and these are usually FIXED and immutable after booting up (reason is because you cannot afford to recompress the-entire-filesyste back ALL the time for each single byte change) . so what is done is a softlink for anything that is immutable. and these softlink will point to another partition where files are kept, and the partition itself is also mounted read-writeable, unlike the one for squashfs (RO). – Peter Teoh Jul 20 '18 at 02:56
  • second: customization is possible: just extract out in another machine, insert the new file, recompress it back (using mksquashfs command) and then generate your image file from there. Lots of wifi router images are made this way. – Peter Teoh Jul 20 '18 at 02:58
1

squashfs vs compressed initramfs

It is also interesting to note that initramfs can also be compressed: https://unix.stackexchange.com/questions/2221/can-the-initramfs-image-use-a-compression-format-other-than-gzip/429880#429880

I think that the advantage of squashfs is that you don't have to do a full decompression on every boot for a huge image, which would be slow.

This is what initramfs does, as it is just a zipped .cpio.

Instead, squashfs allows you to only decompresses files on the fly as you go, since it must separately compress individual files and disk data structures.

Ciro Santilli OurBigBook.com
  • 26,663
  • 14
  • 108
  • 107
  • Yes, according to https://www.kernel.org/doc/Documentation/filesystems/squashfs.txt, files and directories are individually compressed. So directly accessing any specific files are possible, without the need to decompress other files. But changes to any single files, even though it changes only contiguously that specific modified file, will have consequences on locating other files, and so per file changes are not easy, recompressing with "mksquashfs" is needed. – Peter Teoh Jul 20 '18 at 03:18