Create a block device in RAM
Solution 1:
Just use brd and create one brd device (ram0). Use that device in place of your usb drive. You can partition it using sfdisk, use the partitions and then use dd to dump its contents to file.
There is no need to use one filesystem per brd device.
Or (though little hacky) you can use tmpfs, create image file and use that as loop device. That might be the easiest way to accomplish what you want. As a bonus, you have that image ready and can upload it straight away. No need to dd.
# Create mountpoint for tmpfs
mkdir /tmp/tmpfs
# Mount tmpfs there
mount -t tmpfs none /tmp/tmpfs
# Create empty file of 600MB
# (it creates 599MB hole, so it does not
# consume more memory than needed)
dd if=/dev/zero of=/tmp/tmpfs/img.bin bs=1M seek=599 count=1
# Partition the image file
cfdisk /tmp/tmpfs/img.bin
# Create loop block device of it (-P makes kernel look for partitions)
losetup -P /dev/loop0 /tmp/tmpfs/img.bin
# Create filesystems
mkfs.vfat /dev/loop0p1
mkfs.ext4 /dev/loop0p2
# Now it's your turn:
# mount loop0p1 and loop0p2 and copy whatever you want and unmount it
# detach the loop device
losetup -d /dev/loop0
# May i present you with your image ...
ls -al /tmp/tmpfs/img.bin
Modify to suit your needs.
Solution 2:
This is an analog to Fox's answer, but ramfs is used instead of tmpfs. In my tests with vdbench, ramfs shows higher IOPS than tmpfs (33k IOPS vs 29k IOPS on my machine in three consecutive tests, i.e. 6 tests overall), and it is easier to setup too.
# the following creates 1 device /dev/ram0 of size 600M. More elaborate parameters
# description you can see with `modinfo brd | grep parm`, ATM there's just three.
modprobe brd rd_nr=1 rd_size=614400
# Partition the image file. The following creates two GPT partitions: one of size
# 300M, and the other one takes all space that's left
sgdisk -Z --new 1::+300M --new 2 /dev/ram0
# Create filesystems
mkfs.vfat /dev/ram0p1
mkfs.ext4 /dev/ram0p2
# Now you can mount ram0p1 and ram0p2 as you would with a usual block device and copy
# your stuff there. After you `umount` it, you get a partitioned `/dev/ram0` block
# device with your files. You can make an image of it with `dd if=/dev/ram0 of=img.bin`
# for example. After you're done, to remove the ram device execute `rmmod brd`.