Live usb with interactive shell script autostart

In order to make a catalog of old second hand PCs and get their hardware characteristics as fast as possible, I found a way to do it by creating a custom live usb.

The live cd executes an interactive script on startup. The script reads hardware characteristics, make some tests, make questions to the user and loads all the information it gets on a Google spreadsheet. Here I will cover only the creation of the custom live cd, which has been the most difficult part.

I use a xubuntu virtual machine (virtualbox) to create the live usb, Ubuntu Customization kit 2.4.7 for Xubuntu customization, syslinux package to be able to build final iso file and unetbootin to create live usb.

1. Download and put Xubuntu iso file (xubuntu-14.04.3-desktop-i386.iso) in a directory that is reachable from virtual machine.

2. Install uck and syslinux in Xubuntu virtual machine:
sudo apt-get update
sudo apt-get install uck
sudo apt-get install syslinux
 3. Run System > "Ubuntu Customization Kit" following the wizard and choose "Run console application". Custom pakages will be installed in opened console:

3.1. Packages installed to be able to load data in google spreadsheet:

apt-get update
apt-get install python-pip
pip install gspread oauth2client

3.2. Packages installed to be able to make an audio and video test:

apt-get --yes install smplayer

3.3. Install Xfce4

apt-get --yes install xfce4
apt-get --yes install xfce4-goodies

3.4. Install the custom script by copying script file(s), for example to /home/<virtual machine user>/tmp/remaster-root/usr/bin

cd /home/<virtual machine user>/tmp/remaster-root/
sudo cp -r <path to script>/myscript.sh usr/bin/
sudo chmod 777 usr/bin/myscript.sh

Rights must be assigned in order xubuntu live user can launch the script.

3.5. Make the script runs on startup. In this step, we will create a desktop file inside /home/xubuntu/.config/autostart directory, but due to xubuntu user will be created on the fly in xubuntu live cd, we have to create it before user session is created. So, we will edit xinitrc file this way:

nano /etc/xdg/xfce4/xinitrc
We add the next lines before the line in which xubuntu session is launched (the line with xfce4-session command).

mkdir -p /home/xubuntu/.config/autostart
cat > /home/xubuntu/.config/autostart/terminal.desktop <<MYEOF
[Desktop Entry]
Type=Application
Name=Terminal
Exec=xfce4-terminal -e /usr/bin/myscript.sh
X-GNOME-Autostart-enabled=true
MYEOF
sudo chmod 777 /home/xubuntu/.config/autostart/terminal.desktop

3.6. Exit console and select "continue building".

The process continues and final iso file is created in

/home/<virtual machine user>/tmp/remaster-new-files/livecd.iso

4. Use unetbootin to create usb.


Some links:

- Google spreadsheets:

http://gspread.readthedocs.org/en/latest/oauth2.html
http://alexsavio.github.io/gspread_oauth2client_intro.html
https://github.com/burnash/gspread
http://gspread.readthedocs.org/en/latest/#gspread.Worksheet.append_row

- Autostart in xubuntu live cd

https://www.linux.com/learn/tutorials/739139-roll-your-own-customized-ubuntu-with-uck
https://forum.xfce.org/viewtopic.php?id=10029https://forum.xfce.org/viewtopic.php?id=10029https://forum.xfce.org/viewtopic.php?id=10029
https://help.ubuntu.com/community/LiveCDCustomization


Comentarios