One of my day-to-day tasks is to create a bootable image of a USB pendrive with our software on it. The image must consist of two partitions, first one formatted with FAT32 and second with EXT3. On the first we put Linux kernel and a small startup script that the bootloader on the device we are going to boot with reads on startup.
On the second partition we put our rootfs.
Now, here's how I do it:
insert a USB pendrive into my Linux comp. Figure out its device file (here let's assume /dev/sdx)
zero out the first 600 MB of it: dd if=/dev/zero of=/dev/sdx bs=1M count=600
Create the two partitions, first 10 MB and second 500 MB: sfdisk /dev/sdx --unit S << EOF ,20000,c ,1000000,83 EOF
mkfs.vfat /dev/sdx1 mkfs.ext3 /dev/sdx2
(that's assuming sector size is 512 bytes!)
- copy the kernel and startup script to /dev/sdx1
- Unpack pre-compiled RootFS to /dev/sdx2
- Copy the ready-made image from USB pendrive back to our HDD: dd if=/dev/sdx of=usb.img bs=1M count=520
- Compress it and send to the people who test this software.
- the people then uncompress, flash their USB disks with dd if=usb.img of=/dev/sdx insert into their devices and test.
Now, all of this works. The obvious improvement is to create a script that would do this all automatically. This can also be done, but one manual step will still remain: insert the USB pendrive.
I am thinking instead of the actual USB disk we could use a block device in RAM. This not only would eliminate the manual step of inserting the USB disk, but would also be faster.
So what I need is a plain block device in RAM. One that can be split into partitions just like a physical USB pendrive can.
I just researched this topic and seems like the only options are
- tmpfs and ramfs, which obviously don't suit me
- ramdisk and the 'brd' kernel module, which, when loaded, creates a number of 'partitions': /dev/ram[0-15]
and each of them can individually be formatted and used, but like I said - I want a plain block device in RAM which I would then split into two partitions of 10MB and 500MB myself, and from where I would be then able to dd an image to a file on my HDD.
What are my options?