Note: question written in 2013, now is 2021, I assume overlayfs
(one of unionfs
filesystems) is supported. This answer is basically merge of two other answers with some things written explicitly, proficient Linux users might see something as obvious (like using sudo
), but not everybody is at that level, I've understood some things along the way and writing complete (IMO) instructions. Texts after #
are comments, no need to copy them, on my system bash
safely ignores them.
cd somefolder # some folder, no need for much free space, enough for modified data only
mkdir fm # for mounting original
mkdir to # for upper unionfs layers
mkdir temp # some overlayfs technical folder
mkdir fin # resulting folders/files would be there
sudo mount /full_path/filesystem.squashfs fm -t squashfs -o loop
sudo mount -t overlay -o lowerdir=fm,upperdir=to,workdir=temp overlay fin
Now can modify/add/delete files/folders in either "to" or "fin" folders.
Changes to them are "mirrored".
To undo deletion of original file delete "deleted" file from "to" with sudo rm path/file
.
After done with modifications to make new squashfs
file in full_path folder, needs to be free space there:
sudo mksquashfs fin /full_path/filesystem.squashfs
When you don't need your working files anymore:
sudo umount fin
sudo umount fm
sudo rm -R fm fin temp to
P.S. After change to quashfs
I wanted to recreate iso
file of modern distro which support both legacy and EFI boot. Why some options to below genisoimage
command are critical, I don't know, for me I was trial-and-error way. Boots both EFI and legacy, however start of iso is different: starts 33 ed 90
instead of 45 52 08
, e.g. mjg59.dreamwidth.org/11285.html hints me Apple support is missing.
mkdir iso,efi
sudo losetup --partscan --show --find original.iso
# if output of previous loop0
sudo mount /dev/loop0p1 iso
sudo mount /dev/loop0p2 efi # not necessary, just to see contents
sudo mount -t overlay -o lowerdir=iso,upperdir=to,workdir=temp overlay fin
Replace what is needed in fin
. Initially did sudo dd if=/dev/loop0p2 fin/EFI/BOOT/usb.efi
to make image for efi, then found out it is already present in grub
folder. If one takes available efi image, than losetup+mount /dev/loop
steps can be replaced by simpler sudo mount original.iso iso
sudo genisoimage -lJr -o new.iso -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 --boot-info-table -eltorito-alt-boot -e boot/grub/efi.img -no-emul-boot fin
sudo isohybrid --uefi new.iso