![]() |
Create Bootable USB image
Hi,
I need to create a bootable image file (like .iso) for for USB drive. I have all the contents ready (initrd, vmlinux, grub.conf etc) and I can create a bootable USB connecting the USB drive into the machine. But now I need a way to create an Image of the contents (just like iso using mkisofs) so that the same can be written into any USB drive later. So, is there any command/program/way to achieve that? Also, if it there, how shall I write the image into USB? Any recommendation/information/pointer regarding this would be much appreciated. TIA |
So if I understand you correctly you want to make a backup ISO of a bootable USB drive. I would use dd.
Quote:
|
Create your ISO as usual, then use the hybridiso tool on the created ISO. This will convert it to a hybrid-ISO file, which either can be used to burn a CD/DVD or can be copied directly to USB with the dd or cat commands.
|
"so that the same can be written into any USB drive later." Kind of trick question.
The dd command is used normally. An .img file is common for this. The extension .iso tends to be an optical drive but any name is fine for your use. Different OS's may try to burn a cd from a wrong name. Be very careful with the dd command. I'd boot to some other media like live cd or full install to use to copy this usb drive. Then maybe it might be /dev/sdb or such. You'd want the entire disk. I guess you can try to make it a hybrid iso but that may involve some drastic change. Dunno what you have so I can't say how easy it would be. It is also possible that you could use some other means like partimage or clonezilla. The trick to the deal is that clones may have issues with different hardware. Generally if you have a 2G drive you need to have a 2G to use or larger. Lastly is exactly how this thing works. It may be that you are talking about a usb hard drive and have grub booting and using a disk by name or disk by id to tell it how to boot. Those specific issues need to be generic. |
Thanks guys for your replies.
Since this is for client delivery I cannot go for some complex method. (I need to deliver the output as well as the procedure) btw, I have found a way of what I need, but still not working yet. :) Steps I had followed Code:
mkfs.msdos /tmp/myImage.img -C 300000Edited syslinux.cfg as Code:
default linuxAfter this, I can boot from the USB. (partially though :D) It shows vmlinuz loading. It takes lots of time to load initrd, but after sometime the machine reboots without showing up anything. Any idea what may be I am doing wrong? TIA. |
One more query..
Do I need to install grub into the .img? I am not very confident with these grub, syslinux things. (I am asking because, while I creating the bootable USB - without the img file, I had used grub-install in that) TIA. |
Update
I have tried installing GRUB into a disk image. Below is what I have done Code:
Copy boot/grub/{stage1,stage2,menu.lst & grub.conf} Then I ran grub Code:
grub --device-map=/dev/nullBut it stuck during loading initrd. It threw some error Code:
Kernel panic : vfs unable to mount root fs on unknown-block... |
Better off making the usb as you wish then the dd command to the device would create a copy. Why do you need to install grub?
It may be easier to use a virtual machine instead of trying a loop mount. |
Solved the problem with kernel panic. It was because I was because I gave wrong root (hd1,0) for in the grub.conf.
btw, solved the complete issue. Created an Image file with GRUB in it. Now it can be burnt to any USB using any USB writer. Steps I followed - Step 1: Creating the image Using 'dd' command first create a image file with null bytes. Code:
dd if=/dev/zero of=/tmp/disk.img bs=1024 count=250000Step 2: Next we need a loopback device which would be attached to the disk image so that other applications can use the image file as block device. Code:
losetup -fCode:
losetup /dev/loop0 /tmp/disk.imgCode:
fdisk /dev/loop0(I gave n->p->1->Enter->Enter->t->c->w to create a FAT32 partition in the image) Step 4: Next we need another loopback device for the partition we have just created to make the partition available for other applications as device. Now the loopback device /dev/loop0 is similar to /dev/sda. What we need a loopback device attached to the partition, for example a device like /dev/sda1. Code:
fdisk -ul /dev/loop0Code:
losetup -o 32256 /dev/loop1 /dev/loop0Step 5: Now we need to format and mount the partition attached to the device /dev/loop1 Code:
mkfs.vfat /dev/loop1(here a message may show up as "Loop device does not match a floppy size, using default hd params" but which seems fine as the image worked.) Next create a temporary directory and mount the partition to it Code:
mkdir /mnt/tmpStep 7: Copy GRUB related stuffs. Code:
mkdir -p /mnt/tmp/boot/grubCode:
timeout=5Step 8: Install GRUB. The following command will take to the grub console Code:
grub --device-map=/dev/nullCode:
device (hd0) /tmp/disk.imgCode:
umount /mnt/tmpCode:
losetup -d /dev/loop1Wrote a blog post with these. HERE ps: thread can be marked SOLVED. |
| All times are GMT -5. The time now is 12:59 AM. |