114 - How to make an Easy2Boot (grub4dos) USB Flash drive using linux
This is how to make a grub4dos Easy2Boot USB MultiBoot USB Flash drive under linux.
Once you have made the E2B USB drive, you can boot pretty much any number of linux LiveCD ISOs just by copying them to the E2B drive!
Make an E2B USB drive using the E2B linux script
Look in the Easy2Boot download files in the \_ISO\docs\linux_utils folder for bootlace and defragfs. There is also a fmt.sh script which will format a USB partition as FAT32, copy over E2B and install the bootloader (see the ReadMe_fmt.sh.txt file for details).
1. Download any ISO or payload files you may need.
3. cd into the folder from the extracted files called /_ISO/docs/linux_utils.
Tip: If you like, you can copy the payload files into the correct folders now, so that they will always be copied across and contiguous when you run the fmt.sh script.
4. In the linux_utils folder, now run the following two commands:
sudo chmod 777 *
Then follow the instructions. Make sure you specify the correct drive for the USB drive! Note: fmt.sh is a bash shell script. If it fails to run try sudo bash ./fmt.sh.
5. Finally copy your ISO and other payload files into /_ISO/Linux on the USB drive (or any suitable menu folder at the 2nd level). It is best to copy the files one by one to avoid 'file not contiguous' errors, especially if defragfs does not work or is very slow.
6. (optional) Use the defragfs utility to make all files contiguous on the FAT32 USB drive (this may not always work though!). Do this if you delete any files from the USB drive and then add different files. The utility (defragfs) does NOT work on NTFS, that is why the script file only makes a FAT32 partition.
Tip: If the USB drive starts to get full and you need to delete and replace with other payload files, to avoid 'file not contiguous' errors, it is often quicker to remake the USB drive and start from the beginning again.
Here is how to do it the harder way...
1. A system running linux
2. (optional) gparted (or boot from a gparted ISO)
3. bootlace.com (can be found inside the latest grub4dos 0.4.5c download here - (use version 0.4.5c, NOT 0.4.6a) - Note: on Easy2Boot v1.53 and later versions, bootlace.com and defragfs are included in the E2B download \_ISO\docs\linux_utils folder.
So before you begin, copy the bootlace.com file (if not in the E2B download) and the Easy2Boot.zip file to somewhere accessible on your linux system (e.g. to another spare USB drive or a folder on your hard disk)
I tested this by using two USB drives, one containing a bootable linux OS + the bootlace.com+Easy2Boot.zip files, and the other USB drive was the one I wanted to prepare as my E2B drive.
I booted from the linux OS USB drive and then partitioned and formatted the other USB drive under linux.
Due to a lack of linux defrag utilities, I strongly recommend that you format the partition using FAT32 so that you can make the files contiguous using the linux defragfs utility.
Steps to make an E2B USB drive under linux:
1. Format your USB Flash Drive to use a Single Partition (FAT32 type 0C - or if possible add a small 2nd partition too, to help bootability - some systems will not boot from USB Flash correctly unless it has 2 or more partitions so it is always best to add a tiny (hidden) partition) use gparted- or do it the hard way using fdisk as follows:
Open a terminal and type sudo su
Type fdisk -l (and note which device is your USB Drive)
Type fdisk /dev/sdx (replacing x with your actual usb device)
Type d (to delete the existing partition) (press d again to delete the next partition, etc.)
Type n (to create a new partition)
Type p (for primary partition)
Type 1 (to create the first partition)
Press Enter (to use the first cylinder)
Press Enter again (to use the default value as the last cylinder)
Type a (for active)
Type 1 (to mark the first partition active "bootable")
Type t (for partition type)
Type c (to use fat32 partition)
Type w (to write the changes and close fdisk)
Create a Fat32 Filesystem on the USB Flash Drive:
fdisk -l (check which device is the USB Flash drive)
umount /dev/sdx1 (to unmount the mounted partition if it is mounted)
sudo mkfs.vfat -F 32 -n MULTIBOOT /dev/sdx1 (to format the partition as fat32)
2. Check you can access the drive that has bootlace.com and the Easy2Boot zip file on it using ls, e.g. ls /mnt/yyyy/ (where yyy is the name of the device - tip: type mount to see what mounted devices are present)
If you cannot access the drive that contains bootlace.com, then mount it using the commands:
mount /dev/sdb1 /mnt/mysrc
and then you will be able to use /mnt/mysrc/bootlace.com to run bootlace (see step 3)
If you cannot access the empty, newly formatted USB drive, then mount it using these commands:
fdisk -l (check which device is the USB Flash drive) OR try... sudo fdisk -l /dev/sdX (where X is a or b or c or d, etc, until you find the ISB drive)
sudo mkdir /mnt/newusb
sudo mount /dev/sdx1 /mnt/newusb (where x is the letter for the USB Flash drive)
3. Install grub4dos onto the USB Flash Drive:
Assuming that the bootlace.com executable is on /mnt/mysrc and the USB drive is sdx, use the following command to install grub4dos to the MBR with 0 seconds timeout
sudo /mnt/mysrc/bootlace.com --time-out=0 /dev/sdX (note that we specify the whole disk sdx)
If you have formatted the drive as NTFS using gparted, you may need to add the --ntfs parameter to the command line Note: Use 0.4.5c version (0.4.6a is Beta and may give a segmentation fault when run).
If you use the files from the Easy2Boot download, it may not have execute permissions, run a bash shell and cd to the same folder as the bootlace.com file...
sudo cp boot* / (copy bootlace.com and bootlace64.com to /) sudo chmod +rwx /boot* (change permissions to execute,read,write) sudo /bootlace.com --time-out=0 /dev/sdX (where X is a or b or c or d, etc.) - or try sudo /bootlace64.com --time-out=0 /dev/sdX
you should see the response
4. Extract the Easy2Boot files from the E2B zip file and copy it onto the USB Flash drive
5. Copy all your linux livecd ISOs to the \_ISO\MAINMENU or \_ISO\LINUX folder using the GUI File Manager in linux.
For other ISOs or for linux ISOs+Persistence, follow the instructions in the Easy2Boot tutorial.
6. Make all files contiguous
After adding any files to the E2B USB drive you need to ensure that all files are contiguous. 'danboid' suggests using defragfs - you may need to omit the .pl file extension depending on what version of defragfs you have.
sudo perl defragfs.pl /mnt/newusb/ -f
This is reported to only work on FAT32 volumes (TBC) but not on NTFS volumes. ext2/3/4 volumes seem to contain non-contiguous files after running this, so it does not seem to actually defrag files on ext2/3/4 partitions!
Note: To defrag files on FAT32 and NTFS, you could boot from the E2B USB drive to a mini-Windows OS (such as Mini-XP on a Hirens ISO or even a Windows Install ISO) and run RMPrepUSB - Ctrl+F2 to run WinContig under Mini-Windows. Copy over the portable version of RMPrepUSB (or just WinContig) to the USB drive first.
To run RMPrepUSB from WinPE or WINE, you may need to copy the msvbvm60.dll file from the RMPrepUSB\WINPE_EXTRA folder to the same folder as RMPrepUSB.exe. Also, if WinPE does not include a variety of different fonts and so you cannot see any text on the controls when RMPrepUSB runs, select English204 as the language.
Checking last sector is accessible...
Some BIOSes may hang or go very slowly when booting to E2B. This can usually be fixed by reducing the size of the partition by a few MBs. The actual problem is caused by the BIOS code being asked for a sector which is past the end of the USB drive and therefore does not exist. A good BIOS will just return the data and an error, a bad BIOS will hang!
You can shrink the size of the last partition on the USB drive using a suitable tool - e.g. gparted.
Creating files containing ext2/3/4 filesystems
For persistence , you often need to create a file on the E2B USB drive which is formatted as an ext2/3/4 filesystem (instructions are always inside the .mnu file). To do this under linux AND have it contiguous (which is required for E2B) - see the thread here.
Use cd to get to the directory where you have mounted the USB drive - e.g. /media/USBDrive, then create a file as follows (example uses 1GB mint-rw, volume name is normally casper-rw)
dd if=/dev/zero of=mint-rw bs=1M count=1024
mkfs -t ext2 mint-rw -L casper-rw
or for ext3
mkfs.ext3 -F mint-rw -L casper-rw
Making a sparse file using dd may be faster, try this...