UNetbootin+PING-3.0.2.iso USB boot documentation and questions

Reece Arnott <[email protected]>
Newsgroups gmane.org.user-groups.linux.dunedin.general
Message-ID <[email protected]>
This is mostly a quick bit of documentation for those who are interested 
in the weird and wonderful world of USB Linux boot processes (and how I 
think of future-proofing) but I also have 3 things I still want to do 
and would like some pointers. So, as thats the quickest to get out of 
the way they are first but may not make sense without reading the rest 
of this...

1. I want to to replace the initrd with rootfs so I don't have to unzip 
and use pivot_root to swap the initial filesystem out(shortcutting steps 
1-3 below and hopefully cutting another 10 or so seconds off the boot 
time) but haven't been able to yet. I can't remember the errors I was 
getting but got the feeling that they seemed to imply that I need to 
look into what linuxrc is doing more as it seems to have some knock-on 
effects on the final ram disk filesystem. The linuxrc script is quite 
long so if anyone else wants to get the PING-3.0.2.iso and go through it 
that would be helpful. And/or if anyone has played with pivot_root and 
has any advice that would be good as well.

2. My wireless is not currently seen by the ifconfig -a command but my 
standard eth0 wired connection is. I don't think *any* wireless are. 
Probably need to add wireless module or get newer kernel (uname -r shows 
the kernel it is using is 3.1.2). Which and how?

3. I don't think it works detecting/mounting when plugged in to USB3 
ports. Again, do I need a newer kernel or an additional module, and if 
so, how do I go about doing it?

On with the show....

The vision
=======
Initially, create a simple USB boot disk I can use to quickly read off 
MAC addresses for initial registration with the University systems (I 
had a USB DOS boot disk that did this 5 years ago but it only did it for 
one type of network card). I also want this to be the start of an easily 
modifiable and expandable set of small scripts that can be run. Pulling 
together a couple of things I did in the past, the way I wanted to do 
this was to have a simple text file that is 'cat'd to stdout that is 
simply the menu with options a,b,c etc. A scripts folder is in the path 
with scripts with one character names, matching the entries in the menu 
text file. This should be able to be edited easily from any machine so 
they are just text files in the root of a normal FAT32 USB drive 
partition. This means I need some way of automating the boot process to 
mount this.

I used PING-3.0.2.iso as it is small (built using the Linux From Scratch 
documentation) and I thought I could trace the boot process relatively 
easily (I started yesterday afternoon around 3pm and had it all more or 
less sorted by 11pm).

It currently boots up in around 30 seconds and takes another 10 to 
shutdown properly (which is needed if you wrote something to the mounted 
USB filesystem due to the use of write buffers - this caught me out a 
few times before I figured out that was the problem). As above, I think 
I can cut another 10 seconds off the first steps of the boot process but 
its still a lot better than the 2 brain-dead ways I've found of getting 
the MAC addresses off a new machine (which as I mentioned is my current 
use for it):
1. Booting up a computer, run through the Windows first use setup, and 
pipe ipconfig to a text file on the USB stick. (slow)
2. Go into BIOS, read the info, and write it down (error-prone).

Onto the documentation....

Startup process
==========

0. The MBR UNetbootin put there with the help of the syslinux program 
loads up just enough to interpret syslinux.cfg

1. syslinux.cfg is a text file that points to the kernel, initial 
ramdisk filesystem (initrd - which can be mounted as a loop device to 
edit it) and the start up process within it (linuxrc). It can 
potentially have multiple options but as I only have the one I've set it 
to just pick the default and not bother with a timeout in choosing one.

(Initially syslinux.cfg pointed to initrd.gz which had to be unzipped 
into ram first. This made it annoying to try and edit and doesn't seem 
to change the time it takes to boot up much so the first thing I did was 
unzip it and point syslinux.cfg at the unzipped version. When I've got 
everything working the way I want it I may look into the timing again 
and see if zipping the initrd is faster or slower in my particular 
circumstance. The initial compressed initrd.gz was 31MB and decompressed 
to 38MB as it contains a 28MB compressed file rootfs.tar.bz anyway - 
exact numbers may be a little off as they are from memory but they were 
in that sort of ballpark.)

2. (initrd)linuxrc finds and un-compresses rootfs.tar.bz2 into ram and 
uses pivot_root to make that the root filesystem and runs standard 
(rootfs)sbin/initrd

3. This (rootfs) initrd runs standard startup scripts and finishes with 
the rc.local script which has been changed to a single line:
  login root

(this was previously a link to the perl script ../../opt/PING/rc.local 
(which waited for you to hit enter before continuing or x to exit which 
threw you to the login prompt).

4. The (rootfs)/root/.bash_profile login script runs which finds the 
device with file Reecesmenu in the root and if it finds it, mounts it as 
/mnt/Reece, sets the path to include the (Reece)/scripts folder, changes 
to the root of the (Reece) USB device and shows the contents of the 
Reecesmenu file.

5. Any scripts are put in the (Reece)/scripts folder with a one letter 
name and described in the Reecesmenu text file. Typing in the letter 
will run the script. Any additional programs that are needed in the path 
can also be put in the scripts folder.

For completeness, here are the additions to the 
(rootfs)/root/.bash_profile login script and the other scripts I have 
created so far:

/root/.bash_profile
-----------------
(more or less copied from the code in linuxrc that finds and mounts the 
device that has the rootfs.tar.bz2 file on it)

mkdir /mnt/Reece
DEV="sda sda1 sda2 sda3 sda4 sdb sdb1 sdb2 sdb3 sdb4 sdc sdc1 sdc2 sdc3 
sdc4 sdd sdd1 sdd2 sdd3 sdd4 sde sde1 sde2 sde3 sde4 sdf sdf1 sdf2 sdf3 
sdf4 sdg sdg1 sdg2 sdg3 sdg4"
for dev in $DEV
do
if mount /dev/$dev /mnt/Reece 1>/dev/null 2>/dev/null; then
     if [ -f /mnt/Reece/Reecesmenu ]; then
         echo "Mounted USB device containing menu: /dev/$dev to /mnt/Reece"
         cd /mnt/Reece
         PATH=/mnt/Reece/scripts:$PATH
         cat Reecesmenu
         break
     else
         umount /mnt/Reece
         continue
     fi
else
     continue
fi
done


/mnt/Reece/Reecesmenu
------------------
a) Get MAC address info and write to file along with user supplied name.
b) PING

s) Safe shutdown. Need to do this if files on USB were changed.

Type 'menu' to repeat

/mnt/Reece/scripts/a
----------------------------
#!/bin/bash
computername=$1
filename=$(dirname $0)/../Documents/ifconfigs.txt
if [ "$computername" == "" ]
then
      echo Alternate Usage: $0 \<computername\>
      echo You need to enter a computer name.
      read computername
      echo Computername: $computername
fi

# Change the field seperator so can read line by line
old_IFS=$IFS
IFS=$'\n'
# This goes through line by line, and prepends the computer name to it 
(the -v means it doesn't show the dummy ones)

for line in $(ifconfig -a | grep "HWaddr" | grep -v "00:00:00:00:00:00" 
| grep -v "dummy0")
do
     echo $computername $line >> $filename
done
IFS=$old_IFS
tail $filename

/mnt/Reece/scripts/b
----------------------------
/opt/PING/rc.local

/mnt/Reece/scripts/s
---------------------------
shutdown -h now

/mnt/Reece/scripts/menu
----------------------------------
cat $(dirname $0)/../Reecesmenu




Scripts for editing the compressed file systems
==============================
(tested on Ubuntu 13.10)
Run loadfs.sh to mount the filesystems. Do your editing and then run 
unloadfs.sh to save the changes. Note that you will need to know the 
mount point for the USB drive as well as two folders that have been 
previously set aside as mount points for the 2 filesystems.

To edit them in Ubuntu the easiest way is to go to the terminal and type 
sudo nautilus so that you can browse and edit the files as root so you 
don't have any issues with file rights as PING has only the root user.

In general you shouldn't need to do this. You should just be able to 
edit the scripts in the scripts folder and the menu in the Reecesmenu file.

loadfs.sh
------------
echo Folder for initrd file?
read initrdpath
echo Folder to mount initrd?
read initrdmount
echo Folder to mount the rootfs?
read rootfsmount

#It is assumed that the mount folders already exist

sudo mount -o loop "$initrdpath/initrd" "$initrdmount"
cd "$rootfsmount"
sudo tar -xvjf "$initrdmount/rootfs.tar.bz2"

unloadfs.sh
---------------
echo Folder for the mounted initrd?
read initrdmount
echo Folder for the mounted rootfs?
read rootfsmount

cd "$rootfsmount"
sudo tar -cvjf "$initrdmount/rootfs.tar.bz2" *
sudo rm -rf "$rootfsmount/*"
sudo umount "$initrdmount"


Replicating the USB boot disk
==================
To copy to a new USB disk on Ubuntu 13.10:
1. Run the simple minded makeiso.sh below.
2. Enter the mount point for the USB disk
3. This will create a file usb.iso from the files on it.
4. Then eject that USB and put in the one you want to copy to.
5. Run UNetbootin and select to write the usb.iso to the new USB drive.
6. This will make it bootable and write the files to the drive.
Repeat steps 4-6 as needed for additional USB drives.

Alternatively use Unetbootin with the PING-3.0.2.iso to create a 
bootable USB drive, delete all the files off it, and replace them with 
the files from the altered drive.

makeiso.sh
----------------
echo Where is the USB drive mounted?
read mountpoint
mkisofs -r -o usb.iso "$mountpoint"




-- 
"Believing men would act in their own interest was not cynicism, it turned out, but sheerest optimism; in reality men do not meet so high a standard."
-- Harry Potter and the Methods of Rationality (Chapter 84)
http://hpmor.com/

Reece Arnott
Dunedin
New Zealand


_______________________________________________
DunLUG mailing list
[email protected]
http://lists.ethernal.org/listinfo/dunlug
DunLUG Wiki - http://dunlug.kallisti.net.nz/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.