Answers
Got a burning question about open source or the kernel? Whatever your level, email it to answers@linuxformat.com
Neil Bothwick
has the Linux kernel running through his wetware.
Q Sticky computer
I have a device that records data to a USB stick. I cannot change this, it is a ‘black box’. It works fine except that in order to access the data, I have to stop the devices, change sticks and start a new session. Is there a way to connect a Linux box to the USB ports on the device so that it sees the Linux box as a USB storage device and records the data to its hard drive? I have not heard of such a thing, but it would mean I could access the data while it was running.
Alex
Bennett
A There is a solution using the Linux kernel gadget class, but it has a couple of drawbacks. The first is that the kernel module used for this, g_mass_ storage, is not normally enabled on distribution kernels, so you most likely need to install the distro’s kernel source package, enable the CONFIG_USB_ MASS_STORAGE option, then recompile it. The other drawback is that the filesystem you use to receive the data is mounted on the other device, so any changes to it from your computer will probably cause corruption. However, most devices that record to USB storage expect a FAT filesystem and split the output into files of 1GB or 2GB. Provided you only read from these files, and do not touch the one currently being written to, you should be OK, but no promises.
Once you have compiled the kernel and rebooted, you create somewhere for the data to be written, called the backing storage. This can be either a hard disk partition or a file. A partition is easiest – all you need to do is format the partition with an appropriate filesystem and tell the module to use it, for example:
If you want to use a file as the backing storage, create and format it with:
This creates a 16GB (bs x count) file – give this as the file option for the module. Now you can connect your USB cable, and your black box device should see the ‘USB stick’ you have created. To avoid any chance of data corruption, when you need to access the backing storage, you should mount it read-only, like this: