How to add a startup script in live persistant ubuntu and lubuntu linux

I installed Lubuntu on a stick as my main operating system, used it for about 4 months now maybe less. It works perfectly as a full on operating system. As long as you have hard drives in your computer you can save big files to such as downloads or such then you are fine.

Lubuntu is much faster than Ubuntu linux, which is why i chose it.

Problem is, now you installed your nice Ubuntu or Lubuntu operating system on a stick, you managed to get persistance and everything saves fine now. Thats cool until you run into a problem.

I wanted a persistant linux but I also wanted a custom hosts file so I could block just about everything i dont like on the internet such as Facebook and tracker domains.

Not hard to do this normally but the problem was, everytime I rebooted my hosts file would reset. This was absolutely annoying.

So, to have a custom hosts file on a livecd or persistant usb linux installation I had to modify a few things.

First. I created a script called I placed this file on my desktop because I frequently edit it. You can probably place it wherever you want.

The script on the desktop says the following:


cp /home/evl/Desktop/hosts /etc/

Now I have my custom hosts file on my desktop. This script takes that file and replaces it in my /etc/

The problem is I want that to happen automatically and as root. Everytime I start up Ubuntu I want that script to run as root.

The solution is easy.

In /etc/ I have a file called rc.local and in that file I just go:

#!/bin/sh -e
sh ‘/home/evl/Desktop/’
exit 0

The things in this file runs when you boot your computer. As far as I know they run as root.

Thus, I have a script replacing my hosts file everytime I start my computer.