Here I'm trying to create a squashfs filesystem but the resulting image is bigger than the original version and not because I added a file or anything as I only modified some configuration files.

What I'm trying to do is modify the existing squashfs filesystem on a live usb and delete some info to start the OS in a login shell. Since I fixed an amount of space to the EXT4 partition I need the modified squashf to have the same size as the original. I can do the changes while the live system is running but since I'm making a script to automate this process I need to do it before creating the live usb itself. The problem comes when recreating the image as the resulting file is about 400mb larger than the original and when I use the -b 4096/1Mbyte option the image is about 800mb larger when the original file is about 2.2gb.

I did the same before to add my script to the filesystem and it worked great but now I can't understand what happen this time. I searched my backup of .bash_history but with no luck

How can I reduce the image size?? What I'm doing wrong, anyone??


# Create Directories
mkdir /mnt/kali-iso
mkdir /mnt/squash
mkdir /tmp/squash_mod

# Mount ISO And Squashfs Image
mount /root/kali.iso /mnt/kali-iso
mount /mnt/kali-iso/live/filesystem.squashfs /mnt/squash -o loop

# Copy All Files To A Temp Directory To Modify Them
cp -rf /mnt/squash/* /tmp/squash_mod
cp /root/foo.sh /tmp/squash_mod/root/Desktop/

# Create Squashfs
mksquashfs /tmp/squash_mod filesystem.squashfs 


# mksquashfs /tmp/squash_mod filesystem.squashfs -b 4096 # or 1Mbyte

Results from "du" command:

du -ch /mnt/squash | grep "total"  =  6.6G total

du -ch /tmp/squash_mod | grep "total"  =  7.2G total

There are some discrepancies between the same folders, their size are different:

"/tmp/squash_mod/sbin = 8.8mb" "/mnt/squash/sbin = 8.5mb"

"/tmp/squash_mod/var = 309mb" "/mnt/squash/var = 282mb"

"/tmp/squash_mod/bin = 7.0mb" "/mnt/squash/bin = 6.8mb"

  • Can you provide the full command you're using to generate the file?
    – phemmer
    Commented Nov 12, 2013 at 4:33
  • Check my edit for complete process but by only copying a file instead of modifying a file
    – DarkXDroid
    Commented Nov 12, 2013 at 5:21
  • Your cp -rf won't preserve hardlinks, so hard linked files will take up twice as much space as before. Not sure if this is the issue, but worth trying. Use rsync -Ha /mnt/squash/. /tmp/squash_mod/ instead. You can also use du to compare /mnt/squash with /tmp/squash_mod to see where the difference in space is.
    – phemmer
    Commented Nov 12, 2013 at 15:25
  • Well I did as you said but the size of the 2 directories are way too different. I'll post the results for a better understanding.
    – DarkXDroid
    Commented Nov 13, 2013 at 1:18

1 Answer 1


Cannot comment so I'm writing an answer:

1) I agree with Patrick that the most probably source of your problems is hardlink 'multiplication'. With a normal cp you create as many copies of a hardlinked file as the hardlink count was. Use rsync or cp -a instead.

2) An even better solution would be to simply unsquashfs the image so you can skip the loop mount step.

3) Digging even deeper, you can play around with aufs or unionfs :)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .