Sunday, September 20, 2009

How to retain changes in Backtrack 4 installed on USB

In this article we will describe how we can create a bootable Backtrack 4 USB Drive that will save all the changes we make on the USB itself. In this scenario we will use 2 USB Drives. One USB drive of 1GB and the 2GB USB drive which will hold our changes.

Firstly we need to create a bootable USB Drive on the 1GB USB Drive and boot our machine (A DVD Drive can be used also)

Instructions on how to do this can be found on the following link: http://www.itsolutionskb.com/2009/04/how-to-make-backtrack-4-boot-from-usb

Secondly we will need to to prepare our 2GB USB Drive with 2 partitions, one for the USB Boot with (bt4 and boot folder) FAT32 and the other one EXT2 to keep our changes.

bt4_fdisk_1

As you can see in the above screenshot the two USB devices are listed as /dev/sdb1 for the 1GB bootable USB Drive and /dev/sdc1 for the 2GB drive.

We now need to delete the /dev/sdc1 partition and create 2 new partitions for the /dev/sdc USB Drive:
root@bt:~# fdisk /dev/sdc
Command (m for help): d
Selected partition 1
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-2813, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-2813, default 2813): +1024M
Command (m for help): t
Selected partition 1
Hex code (type L to list codes): b
Changed system type of partition 1 to b (W95 FAT32)
Command (m for help): a
Partition number (1-4): 1
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (1489-2813, default 1489):
Using default value 1489
Last cylinder, +cylinders or +size{K,M,G} (1489-2813, default 2813):
Using default value 2813
Command (m for help): w
The partition table has been altered
We now format the linux partition with mkfs.ext2, mount it and create “changes” folder:
root@bt:/# mkfs.ext2 /dev/sdc2
root@bt:/# mkdir -p /mnt/sdc2
root@bt:/# mount -t ext2 /dev/sdc2 /mnt/sdc2
root@bt:/# mkdir /mnt/sdc2/changes
On the first partition we need to copy BT4 and boot folders from the 1GB USB Drive to our 2GB USB Drive first partition /dev/sdc1:
Format the partition to FAT32
root@bt:/# mkdosfs -F 32 /dev/sdc1
root@bt:/# mkdir -p /mnt/sdc1
root@bt:/# mount -t vfat /dev/sdc1 /mnt/sdc1
root@bt:/# cp -Rf /mnt/sdb1/boot/ /mnt/sdc1/
root@bt:/# cp -Rf /mnt/sdb1/BT4/ /mnt/sdc1/
Now we have to make our 2GB USB Drive bootable and keeping the changes on our second partition:
chmod +Xx /mnt/sdc1/boot/syslinux/lilo
chmod +Xx /mnt/sdc1/boot/syslinux/syslinux
nano /mnt/sdc1/boot/syslinux/syslinux.cfg
Append the changes to reflect the Linux EXT2 partition we created before:
LABEL BT4
MENU LABEL BT4 Beta – Console
KERNEL /boot/vmlinuz
APPEND vga=0×317 initrd=/boot/initrd.gz ramdisk_size=6666 root=/dev/ram0 rw quiet changes=/dev/sdb2
As you can see we had put /dev/sdb2 partition because on the next boot we will remove the 1GB USB drive that it currently has the /dev/sdb partition and our new bootable USB Drive will use /dev/sdb.

The last step is to write our MBR Boot record to make our USB Drive bootable:
As we notice running bootinst.sh on backtrack 4 we get an error as follow
root@bt:/# sh /mnt/sdc1/boot/bootinst.sh
/mnt/sdc1/boot/bootinst.sh: 27: Bad substitution

To fix this we need to force symbolic link the /bin/bash with /bin/sh and reboot the system:
root@bt:/# ln -sf /bin/bash /bin/sh
root@bt:/# sh /mnt/sdc1/boot/bootinst.sh
root@bt:/# reboot
Now you have a full Backtrack 4 installation on your USB Drive that will keep all the changes we make.

No comments:

Post a Comment