Quick remastering of a Ubuntu based Live iso


/ Published in: Bash
Save to your folder(s)

This is a simple script for testing changes in a live iso created with squashfs filesystem for the compression.
It will take the iso path as a parameter and it will open it up with unionfs to let you modify its content (into a chroot enviroment) and when you get out, it will create a new iso file with the new content.

It's pretty simple and easy stuff but useful for every day testing.


Copy this code and paste it in your HTML
  1. #!/bin/bash
  2.  
  3. # variables
  4. sqhs_file_tmp="/tmp/filesystem.squashfs"
  5.  
  6. # checks
  7. if [ `id -u` != 0 ]; then
  8. echo "ERROR: You need be a root."
  9. echo "Use: sudo $(basename $0)"
  10. exit
  11. fi
  12.  
  13. if [ -z "$1" ]; then
  14. echo "ERROR: You must pass an iso name as argument"
  15. exit
  16. elif [ ! -f "$1" ]; then
  17. echo "ERROR: ${1} does not exist"
  18. exit
  19. else
  20. original_iso="$1"
  21. fi
  22.  
  23. if [ ! -d "/tmp/master" ]; then
  24. mkdir /tmp/master
  25. fi
  26.  
  27. if [ ! -d "/tmp/unionfs" ]; then
  28. mkdir /tmp/unionfs
  29. fi
  30.  
  31. if [ ! -d "/tmp/changes" ]; then
  32. mkdir /tmp/changes
  33. else
  34. rm -f /tmp/changes/*
  35. fi
  36.  
  37. if [ ! -d "/tmp/rw" ]; then
  38. mkdir /tmp/rw
  39. else
  40. rm -f /tmp/rw/*
  41. fi
  42.  
  43. if [ ! -d "/tmp/ro" ]; then
  44. mkdir /tmp/ro
  45. fi
  46.  
  47. # mount the iso file
  48. mount -o loop -t iso9660 $original_iso /mnt/ || ( echo "error: mount iso" && exit )
  49.  
  50. # mount the squashfs image
  51. mount -o loop -t squashfs /mnt/casper/filesystem.squashfs /tmp/ro || ( echo "error: mount squashfs" && exit )
  52.  
  53. # mount sources from squashfs image with unionfs
  54. mount -t unionfs -o dirs=/tmp/rw=rw:/tmp/ro=ro: unionfs /tmp/unionfs || ( echo "error: mount unionfs" && umount /tmp/unionfs && exit )
  55.  
  56. # prepare the chroot enviroment
  57. mount --bind /proc /tmp/unionfs/proc
  58.  
  59. # enter into the sources with chroot
  60. chroot /tmp/unionfs /bin/bash
  61.  
  62. # umount the chroot enviroment
  63. umount /tmp/unionfs/proc
  64.  
  65. # regeneration of the squashfs image
  66. test -f $sqhs_file_tmp && rm -f $sqhs_file_tmp
  67. mksquashfs /tmp/unionfs $sqhs_file_tmp
  68.  
  69. # mount the iso file content with unionfs
  70. mount -t unionfs -o dirs=/tmp/changes=rw:/mnt/=ro: unionfs /tmp/master || ( echo "error: mount master" && exit )
  71.  
  72. # copy the squashfs file to the right dir
  73. cp -f $sqhs_file_tmp /tmp/master/casper/ || ( echo "error: copying $sqhs_file_tmp" && exit )
  74.  
  75. # copy the kernel and initrd files to the right dir
  76. #cp -f /tmp/unionfs/boot/vmlinuz-2.6.20-15-generic /tmp/master/casper/vmlinuz || ( echo "error: copying vmlinuz" && exit )
  77. #cp -f /tmp/unionfs/boot/initrd.img-2.6.20-15-generic /tmp/master/casper/initrd.gz || ( echo "error: copying initrd" && exit )
  78.  
  79. # create the new iso file
  80. mkisofs -r -V "Live test" -cache-inodes -J -l -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -o /tmp/live-test.iso /tmp/master/ || ( echo "error: mkisofs" )
  81.  
  82. # umount iso stuff
  83. umount /tmp/master
  84. umount /mnt/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.