1

I have rooted android phone running android 10. I have one ext4 partition created using :

  #  dd if=/dev/zero of=/sdcard/ext1.img bs=1M count=1024
  #  mkfs.ext4 -F /sdcard/ext1.img

which I mount using below commands:

  #  mknod    /dev/block/loop52  b 7 0 
  #  losetup  /dev/block/loop52  /sdcard/ext1.img
  #  mkdir /mnt/ext
  #  mount -t ext4 -o rw,noatime  /dev/block/loop52  /mnt/ext

ext1.img file gets mounted successfully but when I create another ext4 file and try to mount in /mnt/ext2 using following commands. It gets mounted but the contents of ext1.img are shown in /mnt/ext2.

  #  mknod    /dev/block/loop62  b 7 0 
  #  losetup  /dev/block/loop62  /sdcard/ext2.img
  #  mkdir /mnt/ext2
  #  mount -t ext4 -o rw,noatime  /dev/block/loop62  /mnt/ext2

What changes do I need to make to mount multiple ext4 files in android ?

4
  • 1
    You are using the same minor number for both devices. Second time you should do mknod /dev/block/loop62 b 7 1. But why are you doing mknod and losetup manually? Mostly devices have already a few (usually 8) loop devices created on boot (which you might be overwriting by using the same major/minor numbers). And mount command handles losetup on its own. Just do mkdir <mount_point>; mount <img_file> <mount_point>. Apr 29 at 13:01
  • Using mknod /dev/block/loop62 b 7 1. then ` losetup /dev/block/loop62 /sdcard/ext.img` gives error: losetup: /dev/block/loop62=/sdcard/ext2.img: Bad file descriptor. Aren't those loop devices (created on boot) used by the system itself ? Running mount /sdcard/ext2.img /mnt/ext2 shows error: mount: can't setup loop device: No such device or address
    – jonny789
    Apr 29 at 13:29
  • Which losetup and mount binaries are you using? busybox, toybox, standalone? Share strace of both commands. Also do ls -l /dev/block/loop* and grep -H . /sys/block/loop*/loop/backing_file. Apr 29 at 20:22
  • The problem is solved. I used the existing system /dev/block/loop* i.e. /dev/block/loop0 and /dev/block/loop1. Then mounted both ext4 files using : losetup /dev/block/loop0 /sdcard/ext.img ; mkdir /mnt/ext ; mount -t ext4 -o rw,noatime /dev/block/loop0 /mnt/ext ; losetup /dev/block/loop1 /sdcard/ext2.img ; mkdir /mnt/ext2 ; mount -t ext4 -o rw,noatime /dev/block/loop1 /mnt/ext2 .
    – jonny789
    May 3 at 7:30

Your Answer

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

Browse other questions tagged or ask your own question.