Saturday 1 June 2013

Creating Dummy file system on Linux

USB mass storage gadget can read a block device or a normal file. This normal file or block device is called the backing storage for the gadget.

The steps to create a backing storage file for testing with USB mass storage gadget driver, are as below. USB gadget driver can read the MBR from the backing storage file.

root@victorBox:/home/victor# dd bs=1M count=1 if=/dev/zero of=/home/victor/backing_file
1+0 records in
1+0 records out
1048576 bytes (1.0 MB) copied, 0.00331003 s, 317 MB/s


root@victorBox:/home/victor# fdisk /home/victor/backing_file
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x8544f2df.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
You must set cylinders.
You can do this from the extra functions menu.
Command (m for help): x
Expert command (m for help): s
Number of sectors (1-63, default 63): 8
Expert command (m for help): h
Number of heads (1-256, default 255): 16
Expert command (m for help): c
Number of cylinders (1-1048576): 16
Expert command (m for help): r
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4, default 1):
Using default value 1
First sector (1-2047, default 1): 1
Last sector, +sectors or +size{K,M,G} (1-2047, default 2047):
Using default value 2047
Command (m for help): t
Selected partition 1
Hex code (type L to list codes): b
Changed system type of partition 1 to b (W95 FAT32)
Command (m for help): p
Disk /home/victor/backing_file: 1 MB, 1048576 bytes
16 heads, 8 sectors/track, 16 cylinders, total 2048 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x8544f2df
                    Device Boot      Start     End        Blocks   Id  System
/home/victor/backing_file1            1        2047        1023+   b  W95 FAT32

Command (m for help): w
The partition table has been altered!

WARNING: If you have created or modified any DOS 6.x
partitions, please see the fdisk manual page for additional
information.
Syncing disks.

root@victorBox:/home/victor# fdisk -lu /home/victor/backing_file
Disk /home/victor/backing_file: 1 MB, 1048576 bytes
16 heads, 8 sectors/track, 16 cylinders, total 2048 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x8544f2df
                    Device Boot    Start     End        Blocks  Id  System
/home/victor/backing_file1          1        2047       1023+   b   W95 FAT32

root@victorBox:/home/victor# losetup -o 512 /dev/loop0 /home/victor/backing_file 
root@victorBox:/home/victor# mkdosfs /dev/loop0
mkdosfs 3.0.9 (31 Jan 2010)
Loop device does not match a floppy size, using default hd params
root@victorBox:/home/victor# mount -t vfat /dev/loop0 /mnt/
root@victorBox:/home/victor# cp examples.desktop /mnt/
root@victorBox:/home/victor# ls /mnt/
examples.desktop
root@victorBox:/home/victor# umount /dev/loop0
root@victorBox:/home/victor# losetup -d /dev/loop0

No comments:

Post a Comment