Monday, January 11, 2010

BackTrack With Ubuntu USB Key

I have a USB key with several Linux distro: BackTrack, Ubuntu, Slax, some recovery distros, ... All Working with persistent changes.
It's quite easy to have pleinty of distro on one USB key with a syslinux start menu to boot them. But some like Ubuntu and BackTrack 4 are using squashfs filesystem in a casper folder, and it is more difficult to make them work together.
For ubuntu, the Live Initrd has an option to specify the location of the casper folder. Since i decompressed ubuntu live cd in an ubuntu folder on my usb key, i added these options to syslinux:

ignore_uuid live-media-path=/ubuntu/casper

BackTrack's initrd does not support this parameter so you must have to patch it:

mkdir tmp
# put initrd.gz from BackTrack iso to tmp folder
cd tmp
gzip -dc initrd.gz | cpio -id
rm initrd.gz
patch -u scripts/casper < ../casper.patch
find . | cpio --quiet --dereference -o -H newc | gzip -9 > ../initrd-patched.gz

Then in your syslinux entry, use the new initrd-patched.gz instead of the original one.

The patched initrd image can be downloaded here. You can then use these parameters in your syslinux entry for BackTrack:

ignore_uuid live-media-path=/backtrack/casper

casper.patch:

--- tmp/scripts/casper 2010-01-11 22:15:21.464236536 -0500
+++ casper 2010-01-11 22:19:23.039237990 -0500
@@ -5,6 +5,7 @@
export PATH=/usr/bin:/usr/sbin:/bin:/sbin

mountpoint=/cdrom
+LIVE_MEDIA_PATH=casper

root_persistence="casper-rw"
home_persistence="home-rw"
@@ -44,6 +45,10 @@
export STATICIP ;;
ignore_uuid)
IGNORE_UUID="Yes" ;;
+ live-media-path=*)
+ LIVE_MEDIA_PATH="${x#live-media-path=}"
+ export LIVE_MEDIA_PATH
+ echo "export LIVE_MEDIA_PATH=\"$LIVE_MEDIA_PATH\"" >> /etc/casper.conf ;;
esac
done
if [ "${UNIONFS}" = "" ]; then
@@ -53,10 +58,10 @@

is_casper_path() {
path=$1
- if [ -d "$path/casper" ]; then
- if [ "$(echo $path/casper/*.squashfs)" != "$path/casper/*.squashfs" ] ||
- [ "$(echo $path/casper/*.ext2)" != "$path/casper/*.ext2" ] ||
- [ "$(echo $path/casper/*.dir)" != "$path/casper/*.dir" ]; then
+ if [ -d "$path/$LIVE_MEDIA_PATH" ]; then
+ if [ "$(echo $path/$LIVE_MEDIA_PATH/*.squashfs)" != "$path/$LIVE_MEDIA_PATH/*.squashfs" ] ||
+ [ "$(echo $path/$LIVE_MEDIA_PATH/*.ext2)" != "$path/$LIVE_MEDIA_PATH/*.ext2" ] ||
+ [ "$(echo $path/$LIVE_MEDIA_PATH/*.dir)" != "$path/$LIVE_MEDIA_PATH/*.dir" ]; then
return 0
fi
fi
@@ -106,10 +111,10 @@
mount_images_in_directory() {
directory="$1"
rootmnt="$2"
- if match_files_in_dir "$directory/casper/*.squashfs" ||
- match_files_in_dir "$directory/casper/*.ext2" ||
- match_files_in_dir "$directory/casper/*.dir"; then
- setup_unionfs "$directory/casper" "$rootmnt"
+ if match_files_in_dir "$directory/$LIVE_MEDIA_PATH/*.squashfs" ||
+ match_files_in_dir "$directory/$LIVE_MEDIA_PATH/*.ext2" ||
+ match_files_in_dir "$directory/$LIVE_MEDIA_PATH/*.dir"; then
+ setup_unionfs "$directory/$LIVE_MEDIA_PATH" "$rootmnt"
else
:
fi
@@ -415,11 +420,11 @@

if [ -n "${SHOWMOUNTS}" ]; then
for d in ${rofslist}; do
- mkdir -p "${rootmnt}/casper/${d##*/}"
+ mkdir -p "${rootmnt}/${LIVE_MEDIA_PATH}/${d##*/}"
case d in
- *.dir) # do nothing # mount -o bind "${d}" "${rootmnt}/casper/${d##*/}"
+ *.dir) # do nothing # mount -o bind "${d}" "${rootmnt}/${LIVE_MEDIA_PATH}/${d##*/}"
;;
- *) mount -o move "${d}" "${rootmnt}/casper/${d##*/}"
+ *) mount -o move "${d}" "${rootmnt}/${LIVE_MEDIA_PATH}/${d##*/}"
;;
esac
done


2009-01-18 Update request

I was requested to give as example my syslinux config files. Here is the root filesystem of my usb key:

kha@box:/media/usbsys$ ls
backtrack clonezilla g4l gparted other slax slitaz syslinux sysrescue ubcd ubuntu
kha@box:/media/usbsys$

I have setup syslinux hidden boot file into the syslinux folder. The content of my syslinux folder can be downloaded from here.

Here is a preview of my bootable syslinux menu:

7 comments:

  1. Salut
    je trouve tres interressant mais bon tu t'adresse à des experts car je j' ai beaucoup de mal à tout comprendre
    pourrais tu etre plus explicite sur la maniere de mettre toutes ces distros sur la clé
    comment tu la rends bootable ?
    sinon c' est super dans l'idée

    ReplyDelete
  2. Désolé mais cet article n'a pas pour objectif d'expliquer comment faire ta clé USB multi-distro. Pour ça tu as plein de tutoriels si tu recherches dans Google.

    L'objectif de cet article est de régler le problème de comatibilité quand il s'agit de mettre sur la même clé 2 distribution utilisant le système Casper, comme BackTrack et Ubuntu.

    C'est ce problème que tu va voir justement sur ce
    genre de tuto, et c'est pour ca que les tutos qui te montrent comment faire des clés USB multiboot prennent en principe des distributions qui vont bien ensemble, comme DSL, Slax, Ubuntu. Mais tu ne verras pas de tuto avec Ubuntu + backTrack 4 je pense...

    En passant, si tu as cherché un peu sur le net, tu n'aurais meme pas posé cette question car j'ai mis à jour l'article récemment pour fournir le détail de mon implémentation et même tout le dossier syslinux !

    Donc tu as la tout ce qu'il te faut et meme plus car le travail de config t'as été maché !

    ReplyDelete
  3. Can you upload your configuration files?

    ReplyDelete
  4. Hi,

    Links are already there in there article for that.

    ReplyDelete
  5. HI,
    I use this method below on my backtrack 4 final:
    http://www.infosecramblings.com/backtrack/backtrack-4-usbpersistent-changesnessus/#persistent

    And I like to add the ff. distro: Slax, Linux Mint 8 (base on Ubuntu 9.10), and Hiren's Boot CD 10.2

    My question are:
    1. the casper-rw that I made on /dev/sdb2 can be use as with Linux Mint 8? meaning can both BT4 and Linux Mint 8 share one(same) casper-rw for persistent change?

    therefore i will only have 2 partition on my usb:
    1st partition = /dev/sdb1 vfat (distros and syslinux)
    2nd partition = /dev/sdb2 ext3 (casper-rw) for both BT4 and Linux Mint 8

    2. is it possible also that both BT4 and Linux Mint 8 could shared common home directory? so that i will save more space on my usb. no more redundant file.

    your help are very much appriciated. thanks!

    ReplyDelete
  6. Hi,

    I don't think they can share the same casper-rw image. Event if it is possible, a lot of things may not work since you will load the profile of another distro.

    On my 1TB portable hard drive, i've made one fat partition at the beginning containing all distros, and i've made 3 partitions for slaz-save, one ubuntu-rw and one bt-rw for backtraq.

    Then i've updated all initrd images to change the value of:

    root_persistence="casper-rw"

    to

    root_persistence=""

    Note: on some recent distro, this parameter can event be passed to the syslinux config, so no need to modify the initrd image.

    ReplyDelete
  7. can we use this patched on the latest release of Backtrack 4 R2?

    ReplyDelete