Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Move live usb persistent files into compressed squashfs.
#!/bin/bash
if [ -z `which mksquashfs` ]; then
sudo aptitude update
sudo aptitude install squashfs-tools
fi
sudo mount /cdrom -o remount,rw
EXCLUDES='.wh* cdrom etc home lost+found medoa rofs root tmp* var/backups var/cache var/crash var/log var/run var/spool var/tmp'
if [ -e /cdrom/casper/update.squashfs ]; then
if [ -z `which mount.aufs` ]; then
# sudo aptitude update
sudo aptitude install aufs-tools
fi
echo mounting existing image.
cd /
sudo mkdir /tmpsqfs /tmprwfs
sudo mount -t squashfs -o loop /cdrom/casper/update.squashfs /tmpsqfs
sudo mount -t ext3 -o loop /cdrom/casper-rw /tmprwfs
sudo mount -t aufs -o br:/tmprwfs=rw:/tmpsqfs=ro none /mnt
sudo mksquashfs /mnt /cdrom/casper/update-new.squashfs -info -noappend -wildcards -e ${EXCLUDES}
if [ -e /cdrom/casper/update-new.squashfs ]; then
cd /cdrom/casper
echo renaming new squashfs image.
sudo mv update.squashfs update.squashfs.old
sudo mv update-new.squashfs update.squashfs
echo deleting moved files.
cd /tmprwfs
sudo rm -rf bin sbin usr lib var/lib
cd /
sudo sync
fi
sudo umount /mnt
sudo umount /tmpsqfs
sudo umount /tmprwfs
sudo rmdir /tmpsqfs /tmprwfs
else
echo mounting existing image.
cd /
sudo mount -t ext3 -o loop /cdrom/casper-rw /mnt
sudo mksquashfs /mnt /cdrom/casper/update.squashfs -info -noappend -wildcards -e ${EXCLUDES}
if [ -e /cdrom/casper/update.squashfs ]; then
echo deleting moved files.
cd /mnt
sudo rm -rf bin sbin usr lib var/lib
cd /
sudo sync
fi
sudo umount /mnt
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment