0

I have a compiled program that saves files to an SD card. In the system I'm developing there's no SD card. I need the output to be written to the disk.

How can I mount a partition to act as it was an SD card (on /dev/mmcblk0, /dev/mmcblk0p1)?

UPDATE

This helped me achieve it:

touch /dev/mmcblk0p1
mount --bind /dev/mtdblock7 /dev/mmcblk0p1
mknod /dev/mmcblk0 b 179 0
/bin/mount -t jffs2 /dev/mmcblk0p1 /mnt
| improve this question | | | | |
  • I don't get it - do you want to write directly to the device and not to the mountpoint? – Arkadiusz Drabczyk Feb 5 at 12:45
  • @ArkadiuszDrabczyk yes, the problem is the compiled binary is set to write only on the SD card – Yossi Neiman Feb 5 at 12:46
  • Try making /dev/mmcblk0 a symlink to an existing device. But be careful and don't overwrite your own disk. – Arkadiusz Drabczyk Feb 5 at 12:47
1

Bind mount it over your /dev/mmcblk0, either directly the regular file:

# touch /dev/mmcblk0
# mount -B /path/to/disk.img /dev/mmcblk0

or if that program is not fooled by it and expects a block device with partitions and such, through a loop device:

# kpartx -va /path/to/disk.img
add map loop0p1 (254:0): 0 33552384 linear 7:0 2048
# touch /dev/mmcblk0 /dev/mmcblk0p1
# mount -B /dev/loop0 /dev/mmcblk0
# mount -B /dev/loop0p1 /dev/mmcblk0p1

Unmount them and remove the mappings after having finished with it:

# umount /dev/mmcblk0 /dev/mmcblk0p1
# kpartx -d dummy
loop deleted : /dev/loop0

If this is not a one-time action, you may consider using a mount namespace, see unshare(1).

| improve this answer | | | | |
  • Can I just mount it to a different partition (Not an *.img) – Yossi Neiman Feb 5 at 13:08
  • Surely you can, but check twice or thrice, so you don't trash your disk: mount -B /dev/sda17 /dev/mmcblk0p1. It's a MUCH BETTER idea to use a virtual disk image (that you can easily create with truncate) and THEN copy the data to the real partition. – Uncle Billy Feb 5 at 13:09
  • I get this error message when trying to mount the partition mount: mounting /dev/mtdblock7 on /dev/mmcblk0p1 failed: Input/output error – Yossi Neiman Feb 5 at 13:17
  • If I were you, I would just run the whole thing into a vm, instead of risking to have my machine trashed by some dubious program which cannot be told what file/devices to use. – Uncle Billy Feb 5 at 13:18
  • Don't forget the -B or --bind option. – Uncle Billy Feb 5 at 13:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.