How to find and access the USB device and then get the image (USB ready) to the Drive entirely within Linux.
I have found lots of different instruction sets, but none seemed to work entirely within Linux - there was always a Windows hitch to it. I have collected a bunch of different instructions from around the 'net to get this to work. My target OS was BackTrack Linux, but I think that this should work with any USB ready ISO image. There are other steps required to take a standard ISO image and get it USB ready - your on your own for that.
*Of course, insert the USB first!*
First step was to open terminal and type sudo su - the command had no prompt (but maybe because I had already issued sudo before and so was already 'logged in') and had no discernible output.
Next fdisk -l (Lowercase L) - lists partitions. Without the su command previous, I was unable to open and view the partitions. Now I am able to identify the primary partition on the USB flash drive. In this case, the drive is /dev/sdb with the primary partition /dev/sdb1 .
next mkdir -p /mnt/distroname This creates a directory (with parents as necessary) that the iso image will be attached to with the next command.
mount -o loop bt3final_usb.iso /mnt/backtrack
This command was issued from within the folder where the iso image was stored (being lazy - did not want to mess with relative pathnames as well). -o sets options, in this case the loop option. At this point unclear what it (loop) does, but it is consistantly mentioned in instructions, so I am using it here to be safe. Now the ISO image appears as a folder which can be viewed and accessed normally.
uh-oh.......here is where Linux gets screwy - poor instructions that leave out the little things. The next command is
cfdisk /dev/sdb - which is a semi-graphical utility for viewing and modifying disk partitions. I DON'T KNOW WHAT THE HELL TO DO HERE! The instructions just said use this command, not what to do once I am in here. My guess was to change to bootable and make it a Linux filesystem (changed the 'type') and 'Write' to commit changes.
*Update* - What a wrong choice that was. As long as the USB is formatted FAT32, everything is just fine. No need to make bootable, as this is done later. On an already working drive, it is possible that this step may be skipped.
*reminder* - uh....make sure when using cfdisk to change partition information you are looking at the correct device. Otherwise you might overwrite the MBR on you HDD (hypothetically, of course :)
mkfs.ext2 -b1024 -m0 -L'Linux Live USB' -O sparse_super /dev/sdb1
This next command was actually to make a filesystem, but I have one, and when I tried to execute the command, it tells me the device is mounted, and basically, beat it. so I tried umount except that tells me the device is busy, and I have no way of shutting it down now. So, I skipped that step.
*Update* - See above - no need to do this, and it seems to me that FAT32 is the better option anyway......
Next, tune the file system I couldn't create. That didn't work either.
tune2fs -c0 -i0 /dev/sdb1
Next is the process of creating another target directory in mnt for the usb drive - mkdir -p /mnt/bt_usb where bt was short for the distro I was copying, and usb, well, that should be self explanatory.
Now, mount the usb drive - mount /dev/sdb1 /mnt/bt_usb
• went without a hitch.
Now, since the iso image that I have is ready for usb, I am just going to copy the files in the image directly to the usb stick and hope that it works with no further modifications (see references on the web to syslinux & isolinux.) However, my copy process
cp -avR /mnt/distroname/* /mnt/bt_usb/
(archive, verbose, recursive)
is barking after every file that it cannot 'preserve ownership' for the files. Don't know if this will be a deal breaker. Only time will tell..........but I am counting on trying this again real soon.
(follow up: the files all exist on the drive, despite the barking)
I think that I may need to go in through the gui filemanager and unmount the usb from there. Maybe then I can get all of the other functions to work correctly. For now, I will hope that this just works.
*Update and Resolution*
After much trial and more error, I have finally succeeded, and hope that these instruction will follow for any USB.ISO.
Once the FAT32 partition is there (no need to specify bootable, as this is accomplished later), just copy over the files from the ISO image to the usb (mounted as above).
Here was another one of those tricky situations....My distro had a file in the Boot folder called Bootinst.sh, which is the executable to make the filesystem (and O.S.) bootable. Unfortunately, as a DOS/Windows chump and Linux n00b, I kept trying to just type the command and kept getting the same result - no such command. Turns out to launch the program, it needs to be proceeded by "dot slash" - e.g. ./bootinst.sh - just like when running configure to create executables (which I have done maybe twice). Once I figured out how to actually execute the damn program, it was all smooth sailing.
I now have a fully bootable Linux USB key - created entirely within Linux - no Windows required.

No comments:
Post a Comment