Making your own persistent USB bootable Ubuntu Distro: the easy way

I had a recent Ubuntu install with customizations that I wanted to be able to put it on a USB, boot into it on another machine and be able to modify its contents by, installing new packages, editing files, etc…

PinguyBuilder to the rescue

So after a number of false starts. I stumbled upon PinguyBuilder. I followed the excellent instructions at maketecheasier, with the slight modification of checking the PinguyBuilder site for the the latest version. I used the backup option to get all the tweaks on home directory, and my none deb packages in. My Ubuntu was a derivative the standard Xubuntu 16.04 distro.

Moving the ISO to the USB

The generated iso file could then be installed usb-creator-gtk, or if are working on windows, Rufus. At this point I could nicely boot using my USB stick. I could not, however, write anything persistently on the USB. If I create some file, and then reboot, it would be gone!

Making the USB persistent

First I need to create casper-rw file that would be identified by boot-loader as space to write on. I was happy with 2GB, so this what I did by adopting the instructions on StackExchange post:

I created an empty 2GB file

dd if=/dev/zero of=casper-rw bs=1M count=2048

You can changed count to whatever size of persistent storage you want. I then had to format that space into something that Linux would be able to read

mkfs.ext4 -F casper-rw

The next step was to change /boot/grub/grub.cfg file on the USB to have the following menu-entry at the beginning.

menuentry "Xubuntu in persistent mode" {
    set gfxpayload=keep
    linux   /casper/vmlinuz  file=/cdrom/preseed/custom.seed boot=casper persistent iso-scan/filename=${iso_path} quiet splash --
    initrd  /casper/initrd.gz

Finally, I modified /isolinux/isolinux.cfg to include the extra label

label persistent 
  menu label live - boot the Live System
  kernel /casper/vmlinuz
  append  file=/cdrom/preseed/custom.seed boot=casper persistent initrd=/casper/initrd.gz quiet splash --

et voilĂ !


Mutating your MAC address

Recently I was at an airport that offered free WiFi for the first 15 minutes, afterwards the system asked you pay. I knew that they must be checking identity via MAC address, so I wrote this little nifty python script that changes it to some random value each time you call it. This would only work on Linux (or maybe a MAC) OS.
I am not suggesting that you violate any laws, I put this up for educational purposes. Use it at your own risk.
For obtaining the MAC address through python, I used synthesizerpatel‘s code snippet. Alternatively the MAC address could have been obtained via a system call ifconfig using “subprocess.Popen”, as described in here.

 import fcntl, socket, struct, random  
 from subprocess import call  
 def getHwAddr(ifname):  
   s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)  
   info = fcntl.ioctl(s.fileno(), 0x8927, struct.pack('256s', ifname[:15]))  
   return ''.join(['%02x:' % ord(char) for char in info[18:24]])[:-1]  
 print "Changing from "+a+" to "+b  
 call(["sudo ifconfig wlan0 down"],shell=True)  
 call(["sudo ifconfig wlan0 hw ether "+b],shell=True)  
 call(["sudo ifconfig wlan0 up"],shell=True)