Jump to content

[Guide] Change the casper directory in Ubuntu (BT4)


Recommended Posts

With the release of Back|Track 4 Final, I finally got around to looking into what scripts needed to be modified and in what way they needed to be modified in order to change the casper directory. This guide, as far as I know, will work with any Ubuntu based LiveCD (BT4, SamuraiWTF, Mint, etc.) that uses the casper squashfs files. So, I will be talking about BT4, but it can be applied to any distro.

NOTE: You will need some type of writable media, which means you can't do this by booting from your flash drive and then writing to that same flash drive because BT mounts it as read-only by default. You could, however, boot BT from your flash drive, unmount your hard drive, remount your hard drive as writable, and then write the modified rootfs.gz to your hard drive.

The script found at the bottom of this guide assumes that you have booted into BT4 from either the CD or an ISO (if in a VM). The script is NOT by any means a "good" script, because it is the first script I've ever written, but it gets the job done. You will need to manually change the path you want BT to find the casper directory in, and you may have to change the path that points to the original initrd files.


commands - type this into the terminal windows and press "Enter"

stuff to change - in the command, change this to your desired path

To manually change the casper directory:

01. Boot into Back|Track 4 from either a VM, a CD, or a flash drive.

02. startx

03. Start a new terminal. (Black icon on the bottom left)

04. mkdir tmp

05. cp /cdrom/boot/initrd.gz ./

06. gunzip initrd.gz

07. cd tmp

08. cpio -id < ../initrd

09. mv ../initrd ../initrd.old

10. replace '$path/casper' '$path/.multiboot/BT4-final/casper' '$path/.disk/casper-uuid' '$path/.multiboot/BT4-final/.disk/casper-uuid' '$directory/casper' '$directory/.multiboot/BT4-final/casper' -- scripts/casper

11. find . | cpio -oH newc > ../initrd

12. gzip ../initrd

13. cd ..

14. rm -rf tmp


Now you can copy the .gz files into your 'boot' directory for BT4


Copy and paste this into a file, change where it says "PATH/TO/YOUR/BT4DIRECTORY" to wherever you have Back|Track 4, save it with a .sh file extension, open a terminal window, chmod 777 change_casper.sh, then run it with: ./change_casper.sh

rm -rf /bt4-final_edit/
mkdir -p /bt4-final_edit/tmp/
echo -e "Copying...\c"
cp /cdrom/boot/initrd*.gz /bt4-final_edit/
echo -e "\t\t\t\tDone!"
echo -e "Decompressing (gunzip)...\c"
gunzip /bt4-final_edit/initrd*.gz
echo -e "\t\tDone!"
cd /bt4-final_edit/tmp/
mkdir initrd initrd800 initrdfr

# cpio all
echo -e "Extracting (cpio)...\c"
cd initrd &amp;&amp; cpio --quiet -id &lt; ../../initrd
cd ../initrd800 &amp;&amp; cpio --quiet -id &lt; ../../initrd800
cd ../initrdfr &amp;&amp; cpio --quiet -id &lt; ../../initrdfr
echo -e "\t\t\tDone!"

# replace all strings
cd .. &amp;&amp; rm ../initrd*
echo -e "Replacing all needed strings...\c"
replace -s '$path/casper' '$path/[color="#808080"]PATH/TO/YOUR/BT4DIRECTORY[/color]/casper' '$path/.disk/casper-uuid' '$path/[color="#808080"]PATH/TO/YOUR/BT4DIRECTORY[/color]/.disk/casper-uuid' '$directory/casper' '$directory/[color="#808080"]PATH/TO/YOUR/BT4DIRECTORY[/color]/casper' -- initrd*/scripts/casper
echo -e "\t\tDone!"

# repack all with cpio
echo -e "Repacking (cpio)...\c"
find initrd/ | cpio --quiet -oH newc &gt; ../initrd 
find initrd800/ | cpio --quiet -oH newc &gt; ../initrd800
find initrdfr/ | cpio --quiet -oH newc &gt; ../initrdfr
echo -e "\t\t\tDone!"

# recompress all with gzip
echo -e "Recompressing (gzip)...\c"
gzip ../initrd*
echo -e "\t\t\tDone!"

# cd, cp all to desktop, &amp;&amp; rm tmp files
echo -e "Copying to /root/desktop/ ...\c"
cp /bt4-final_edit/init* .
echo -e "\t\tDone!"
rm -rf /bt4-final_edit/
echo -e "\n\n\n
You can now copy the initrd*.gz files from the  *
Desktop to the 'boot' folder on your multipass! *

If anybody can code a better script where the user can input their desired path and such, please post it!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...