Sunteți pe pagina 1din 2

#Mounting a squashfs file system in read-only mode

mount filesystem.squashfs /tmp/squashfs/ -o loop


mount -o bind /proc/ /tmp/squashfs/proc/
mount -o bind /dev/ /tmp/squashfs/dev/
mount -o bind /dev/pts /tmp/squashfs/dev/pts/
mount -o bind /sys /tmp/squashfs/sys/
cp /etc/resolv.conf /tmp/squashfs/etc/resolv.conf

chroot /tmp/squashfs /bin/bash

#Mounting a squashfs file system in read-write mode

unsquashfs filesystem.squashfs --> extract all file system to squashfs-root


foder.
cd squashfs-root
mount -o bind /proc/ /images/centos/squashfs-root/proc/
mount -o bind /dev/ /images/centos/squashfs-root/dev/
mount -o bind /dev/pts /images/centos/squashfs-root/dev/pts/
mount -o bind /sys /images/centos/squashfs-root/sys/
chroot /images/centos/squashfs-root/ /bin/bash
--> make changes: install softwares, packages....
exit
--> package new squashfs
mksquashfs squashfs-root filesystem.squashfs -b 1024k -comp xz -Xbcj x86 -e
boot

###
mount -o bind /proc/ /tmp/squashfs/proc/
mount -o bind /dev/ /tmp/squashfs/dev/
mount -o bind /dev/pts /tmp/squashfs/dev/pts/
mount -o bind /sys /tmp/squashfs/sys/
chroot /tmp/squashfs/ /bin/bash

umount /tmp/squashfs/proc/
umount /tmp/squashfs/dev/
umount /tmp/squashfs/dev/pts/
umount /tmp/squashfs/sys/
##
If your system supports some uion-filesystem, such as aufs or overlayfs, you don't
have to extract your original squashfs file.
For example the overlayfs is used( a kernel option to enable it): You can mount
your squashfs.file to /fm or somewhere else first. Prepare a writable filesystem
with 2 directories in it, say /to and /temp. prepare another writable directory
/fin for the merged results. Mount them together as an overlayfs to your system
mount -t overlay -o lowerdir=/fm,upperdir=/to,workdir=/temp overlay /fin
Now you can add/modify files in /fin. Once everything done, you can mksquashfs /fin
to a new squashfs file,
mksquashfs /fin newfile; umount /fin
, then clear/unmount all the other used directories as you will.

The squashfs and some unionfs are commonly used for a live-cd.

####################
Script make squashfs
####################
#!/bin/sh
#
# make a filesystem.squashfs for use in casper liveCD/liveUSB images
# usage sudo ./do_squashfs rootdir

rm filesystem.squashfs
chroot $1 dpkg-query -W --showformat='${Package} ${Version}\n' >
filesystem.manifest
mksquashfs $1 filesystem.squashfs
printf $(sudo du -sx --block-size=1 $1 | cut -f1) > filesystem.size

#############################
Script chroot to folder $1
##############################
#!/bin/sh
#
# chroot into a rootfs for the same architecture
# usage: sudo ./do_chroot rootdir

echo chrooting into $1


mkdir -p $1/proc
mkdir -p $1/sys
mkdir -p $1/dev

cp /etc/resolv.conf $1/etc

mount --bind /proc $1/proc


mount --bind /sys $1/sys
mount --bind /dev $1/dev
mount --bind /dev/pts $1/dev/pts

chroot $1 /bin/bash

umount $1/dev/pts
umount $1/dev
umount $1/sys
umount $1/proc || umount -lf $1/proc

rm $1/etc/resolv.conf
rm $1/var/lib/dbus/machine-id

S-ar putea să vă placă și