O'Reilly Hacks
oreilly.comO'Reilly NetworkSafari BookshelfConferences Sign In/My Account | View Cart   
Book List Learning Lab PDFs O'Reilly Gear Newsletters Press Room Jobs  



Backdooring Knoppix
Remastering Knoppix (see Knoppix Hacks #94) remains pretty uneasy and time consuming. Here is a way to backdoor your Knoppix so that you'll be able to add a few new functionnalities (eg : add a script, aliases, even add new programs) in a snapshot... This hack won't keep you from remastering : it will help you in remastering a smartest way...

Contributed by:
Endrazine
[07/08/05 | Discuss (0) | Link to this hack]

By allowing the execution of a few generic scripts outside the big 700 Mo KNOPPIX file, one can actually "Backdoor Knoppix" in order to fasten up further modifications. I used this hack to build a Knoppix Remaster I could publish, and then tuned to my own needs so that I could automatically mount a remote drive via samba : this way, I kept my remote disk IP private (for obvious security reasons) and did not have to rebuild the whole Remaster. This trick can also be used to perform more complex tasks, like adding new scripts, modifying aliases or even adding new apps to your remaster in no time.

The first thing you need to do is backdooring this big annoying 700++ Mo compressed file so that an external script located at the cdrom root (and therefore *NOT COMPRESSED*, ie editable) will be launched at boot time. You may think in backdooring your .profile or .bashrc files... I choosed to modify my /etc/skel/.fluxbox/startup instead because it will only be run once (as opposite to the ~/.bashrc that will be used any time a new shell is started).

If you use Kde instead, you can do the same with /etc/skel/.kde/Autostart/Presentation.sh. Icewm lovers will need to edit /etc/skel/.icewm/startup, etc...

Here is my /etc/skel/.fluxbox/startup file after modification :


#!/bin/sh
#
#############################################################################
#
#                        BACKDOORING KNOPPIX
#
#  Concept and code : Jonathan Brossard (jonathan at messel d0t emse d0t fr)
#
#
#############################################################################
#
# Initializing Desktop :
#
rox-snapshot --pinboard=MonPunaiseur &
#
# Launching the main CDRom html page (usually some help file) :
#
mozilla /cdrom/index.html &
#
# BACKDOORING !!
#
#
# 1) We can directly execute uncompressed (ie: editable :) scripts :
#           (I use this one for aliases)
#
sudo /cdrom/initscript1.sh &
#
#
#
# 2) We can copy and then execute scripts :
#        (I use this to mount remote disk space)
#
sudo cp /cdrom/initscript2.sh /home/knoppix/ &
sudo chmod 777 /home/knoppix/*.sh &
sudo /home/knoppix/initscript2.sh &
#
# 3) We can of course add regular commands :
#
# For compatibility with most GUI programs when
# launched from command line :
#
echo "export DISPLAY=localhost:0.0" >> /home/knoppix/.bashrc &
#
#eof



As you can see, the first trick allows the execution of /cdrom/initscript1.sh when launching fluxbox. The second one copies /cdrom/initscript2.sh to /home/knoppix/ and runs it.

Now you can simply finish up your remastering process (see hack #94) to generate the backdoored 700++ Mo KNOPPIX file. When you're done, don't forget to create /cdrom/initscript1.sh and /cdrom/initscript2.sh to customize your Remaster. The next time you'll want to modify your distribution, simply edit one of those two scripts to have your modifications automatically applied. Here is my initscript1.sh :


#!/bin/sh
########################################################################
#
#                         BACKDOORING KNOPPIX
#
#  Concept and code : Jonathan Brossard (jonathan at messel d0t emse d0t fr)
#
#
########################################################################
#
#This is script is only used to easily add new aliases
#Wa actually add a line to ~/.bashrc to have it permanently
#
echo "#">>/home/knoppix/.bashrc
echo "#Dynamically added using Jonathan Brossard's">>/home/knoppix/.bashrc
echo "#KNOPPIX BACKDOOR HACK">>/home/knoppix/.bashrc
echo "#">>/home/knoppix/.bashrc
echo "alias cree-usb-disk='/usr/sbin/knoppix-mkimage'" >>/home/knoppix/.bashrc

I found that one very usefull when a friend of mine asked me for a version of my remaster adapted to his aliases habbits :) Now, let's do something a little bit harder : allow users to mount a remote disk via samba with a simple command (change the IPs and hostnames to fit your needs. Those are intranet IPs, but internet IPs will work fine too) :


#!/bin/sh
##########################################################################
#
#                         BACKDOORING KNOPPIX
#
#
#   Concepts and code : Jonathan Brossard (jonathan at messel d0t emse d0t fr)
#
#
##########################################################################
#
#
#Check if testflag exist : if not, shell account WASN'T mounted...
#
if (test -e /home/knoppix/foo/.testflag)
then
#
#Remote disk already mounted...
#
echo "Don't forget to save your files to /home/knoppix/foo/ :)"
else
#
#Remote disk not mounted...
#
clear
echo "Trying to mount remote disk via Samba..."
echo ""
#
#Request login...
#
echo "Please enter your login :"
read mylogin
export mylogin
#
#Create the appropriate directory and attempt to mount the remote disk...
#
cd /home/knoppix
sudo mkdir ./foo
sudo chmod 777 foo
sudo smbmount //10.0.1.2/${mylogin} foo -o username=${mylogin}, ip=10.0.1.2 rw
#
#Create the flag file (.testflag)
#
cd foo
echo "This is a test file for a Backdoored Knoppix" >.testflag
#
#List mounted rep content
#
clear
pwd
ls -a
pwd
#
#This is it :)
#
fi
#eof


What the script does is looking for a file named .testflag in /home/knoppix/foo/ if found, then the partition is already mounted : print a nice warning message. Otherwise : prompt for a login, mount the partition to /home/knoppix/foo/ and create a .testflag there.

Conclusion : This trick can be used to quickly modify a pre-remastered Knoppix, but deep changes like changing the windows manager or removing programs via apt-get can't be done that way :( If you want to add a new app to your Knoppix, you can link to a bin placed in /cdrom/some.prog or even copy it if it's small enougth.

See also:


  • Last section of Knoppix Hacks ( Knoppix Remastered) including Hack #94


O'Reilly Home | Privacy Policy

© 2007 O'Reilly Media, Inc.
Website: | Customer Service: | Book issues:

All trademarks and registered trademarks appearing on oreilly.com are the property of their respective owners.