aeromaxx
Posts: 20
Joined: Sat Jun 11, 2016 11:37 am

Unable to mount raspberry pi image

Wed Sep 05, 2018 10:23 am

I am having major difficulties trying to mount a raspberry pi image in a Linux (Debian 9) VM.

Firstly I have googled and googled some more, searched this forum also, and read most if not all the threads and I still can't do it.

I have tried using kpartx, this gives me various errors, I read that someone mentioned to do fsck check on the image, I couldn't figure out how to do that. I wrote the image to an sd card, put it in my pi and booted it, shut it down cleanly and read the sd card back to a new image file, and tried again but the same error as below happens again.

All commands done below on an image that I created after my pi had successfully booted and was shutdown cleanly from an sd card.

Code: Select all

# file ./my-image-file.img
./my-image-file.img: DOS/MBR boot sector; partition 1 : ID=0xc, start-CHS (0x0,130,3), end-CHS (0x5,213,59), startsector 8192, 85611 sectors; partition 2 : ID=0x83, start-CHS (0x6,30,25), end-CHS (0x18d,189,48), startsector 98304, 6291456 sectors

Code: Select all

# kpartx -av ./my-image-file.img 
read error, sector 0
read error, sector 1
read error, sector 29
read: Input/output error
I also read that someone said you could mount it as a loopback device so I tried this also with kpartx, but same errors as above.

Code: Select all

# losetup -f
/dev/loop0

# losetup -f ./my-image-file.img
# kpartx -av /dev/loop0 
read error, sector 0
read error, sector 1
ead error, sector 29
read: Input/output error
I also tried the -P option with losetup.

Code: Select all

# losetup -f
/dev/loop0

# losetup -P ./my-image-file.img
# kpartx -av /dev/loop0 
read error, sector 0
read error, sector 1
ead error, sector 29
read: Input/output error
I also tried using fdisk and standard mount, this also didn't work although with different errors.

Code: Select all

# fdisk -l ./my-image-file.img
Disk ./my-image-file.img: 3.7 GiB, 3941596672 bytes, 7698431 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
Disklabel type: dos
Disk identifier: 0xb457dd38

Device                                  Boot Start     End Sectors  Size Id Type
./my-image-file.img1       8192   93802   85611 41.8M  c W95 FAT32 (LBA)
./my-image-file.img2      98304 6389759 6291456    3G 83 Linux

Code: Select all

# mount ./my-image-file.img -o loop,offset=$(( 512 * 8192 )) /mnt/pi_img_p1/
mount: /dev/loop0: can't read superblock

# mount ./my-image-file.img -o loop,offset=$(( 512 * 98304 )) /mnt/pi_img_p2/
mount: /dev/loop0: can't read superblock
I also tried

Code: Select all

# mount -v -o offset=$(( 512 * 8192 )) -t vfat ./my-image.img /mnt/pi_img_p1/
mount: /dev/loop0: can't read superblock

# mount -v -o offset=$(( 512 * 98304 )) -t ext4 whatever.img /mnt/pi_img_p2/
mount: /dev/loop0: can't read superblock
It was at this point I was ready to give up and ask for help, the ./my-image-file.img was on the host OS side, and was being shared via Oracle Virtual Box Guest Additions, so I though I would try something different, I shutdown my VM, added a 2nd NTFS formatted hard drive and copied the ./my-image-file.img to it.

I then tried the same commands above again, suprisingly the first one work so I thought I was onto something... then I got another error argh!

Code: Select all

# mount -v -o offset=$(( 512 * 8192 )) -t vfat ./my-image.img /mnt/pi_img_p1
mount: /dev/loop0 mounted on /mnt/pi_img_p1.

mount -v -o offset=$(( 512 * 98304 )) -t ext4 ./my-image.img /mnt/pi_img_p2
mount: ./my-image.img: overlapping loop device exists
So I tried the following after doing losetup -d /dev/loop0 and got a another error albeit different from the last!

Code: Select all

# losetup -d /dev/loop0
# mount -v -o offset=$(( 512 * 8192 )),sizelimit=$(( 512 * 85611 )) -t vfat ./my-image.img /mnt/pi_img_p1
mount: /dev/loop0 mounted on /mnt/pi_img_p1.

# mount -v -o offset=50331648-t ext4 whatever.img /mnt/pi_img_p2
mount: wrong fs type, bad option, bad superblock on /dev/loop2,
       missing codepage or helper program, or other error

       In some cases useful info is found in syslog - try
       dmesg | tail or so.
Seeing as this didn't work, I revisited the commands that I had tried first again to see if these now worked.

Code: Select all

# kpartx -a ./my-image-file.img
add map loop2p1 (254:0): 0 85611 linear 7:2 8192
add map loop2p2 (254:1): 0 6291456 linear 7:2 98304

# mount /dev/loop2p1 /mnt/pi_img_p1/
mount: special device /dev/loop2p1 does not exist

# mount /dev/loop0 -o loop,offset=$(( 512 * 8192 )) /mnt/pi_img_p1/
Killed
Some more googling ensued, and found some new information that I didn't notice the first time I visit a topic right here on this forum!

Code: Select all

# mount /dev/mapper/loop2p1 /mnt/pi_img_p1/

# ls -al /mnt/pi_img_p1/
total 21784
drwxr-xr-x 4 root root    2560 Jan  1  1970 .
drwxr-xr-x 7 root root    4096 Sep  5 08:42 ..
-rwxr-xr-x 1 root root   22264 Apr 23 19:09 bcm2708-rpi-0-w.dtb
-rwxr-xr-x 1 root root   21761 Apr 23 19:09 bcm2708-rpi-b.dtb
-rwxr-xr-x 1 root root   22020 Apr 23 19:09 bcm2708-rpi-b-plus.dtb
-rwxr-xr-x 1 root root   21474 Apr 23 19:09 bcm2708-rpi-cm.dtb
-rwxr-xr-x 1 root root   23044 Apr 23 19:09 bcm2709-rpi-2-b.dtb
-rwxr-xr-x 1 root root   24240 Apr 23 19:09 bcm2710-rpi-3-b.dtb
-rwxr-xr-x 1 root root   24503 Apr 23 19:09 bcm2710-rpi-3-b-plus.dtb
-rwxr-xr-x 1 root root   22952 Apr 23 19:09 bcm2710-rpi-cm3.dtb
-rwxr-xr-x 1 root root   52064 Apr 23 19:09 bootcode.bin
-rwxr-xr-x 1 root root     125 Sep  5 10:15 cmdline.txt
-rwxr-xr-x 1 root root    1684 Mar 23 12:52 config.txt
-rwxr-xr-x 1 root root   18693 Apr 23 19:10 COPYING.linux
-rwxr-xr-x 1 root root    2599 Apr 23 19:09 fixup_cd.dat
-rwxr-xr-x 1 root root    6575 Apr 23 19:09 fixup.dat
-rwxr-xr-x 1 root root    9726 Apr 23 19:09 fixup_db.dat
-rwxr-xr-x 1 root root    9730 Apr 23 19:09 fixup_x.dat
-rwxr-xr-x 1 root root     145 Mar 13 22:53 issue.txt
-rwxr-xr-x 1 root root 4922144 Apr 23 19:09 kernel7.img
-rwxr-xr-x 1 root root 4676016 Apr 23 19:09 kernel.img
-rwxr-xr-x 1 root root    1494 Apr 23 19:09 LICENCE.broadcom
-rwxr-xr-x 1 root root   18974 Mar 13 22:53 LICENSE.oracle
drwxr-xr-x 2 root root   11776 Apr 23 19:15 overlays
-rwxr-xr-x 1 root root  673444 Apr 23 19:09 start_cd.elf
-rwxr-xr-x 1 root root 4968292 Apr 23 19:09 start_db.elf
-rwxr-xr-x 1 root root 2825124 Apr 23 19:08 start.elf
-rwxr-xr-x 1 root root 3912164 Apr 23 19:09 start_x.elf
drwxr-xr-x 2 root root     512 Mar 18 18:53 System Volume Information

Code: Select all

# mount /dev/mapper/loop2p2 /mnt/pi_img_p2/

# ls -al /mnt/pi_img_p2/
total 96
drwxr-xr-x 21 root root  4096 Apr 30 21:23 .
drwxr-xr-x  7 root root  4096 Sep  5 08:42 ..
drwxr-xr-x  2 root root  4096 Mar 13 21:59 bin
drwxr-xr-x  2 root root  4096 Mar 13 22:51 boot
drwxr-xr-x  4 root root  4096 Mar 13 21:43 dev
drwxr-xr-x 90 root root  4096 Apr 23 19:27 etc
drwxr-xr-x  3 root root  4096 Mar 13 21:55 home
drwxr-xr-x 16 root root  4096 Mar 13 22:08 lib
drwx------  2 root root 16384 Mar 13 22:51 lost+found
drwxr-xr-x  2 root root  4096 Mar 13 21:41 media
drwxr-xr-x  3 root root  4096 Mar 23 07:52 mnt
drwxr-xr-x  3 root root  4096 Mar 13 21:55 opt
drwxr-xr-x  2 root root  4096 Dec 13  2017 proc
drwx------  4 root root  4096 Mar 22 09:04 root
drwxr-xr-x  5 root root  4096 Mar 13 21:56 run
drwxr-xr-x  2 root root  4096 Apr 23 19:06 sbin
drwxr-xr-x  2 root root  4096 Mar 13 21:41 srv
drwxr-xr-x  2 root root  4096 Dec 13  2017 sys
drwxrwxrwt  8 root root  4096 Sep  5 09:25 tmp
drwxr-xr-x 10 root root  4096 Mar 13 21:41 usr
drwxr-xr-x 11 root root  4096 Mar 13 22:53 var
Woohoo! It worked! Posting this here so that the pain and time consumed trying to figure this out may help someone maybe in the future who knows.

Sorry for the very very long post!

User avatar
lmarmisa
Posts: 1230
Joined: Thu Feb 14, 2013 2:22 am
Location: Jávea, Spain

Re: Unable to mount raspberry pi image

Wed Sep 05, 2018 3:35 pm

This procedure works fine here:

Code: Select all

mkdir boot root
sudo losetup /dev/loop0 my-image-file.img
sudo kpartx -av /dev/loop0
sudo mount /dev/mapper/loop0p1 boot
sudo mount /dev/mapper/loop0p2 root
http://blog.dustinkirkland.com/2008/10/ ... image.html

aeromaxx
Posts: 20
Joined: Sat Jun 11, 2016 11:37 am

Re: Unable to mount raspberry pi image

Thu Sep 06, 2018 11:34 am

Clearly didn't read all of my post!

I know that works, that's what I said at the end! But it doesn't work if the file is on the host OS system and being shared to the guest OS.

If the file is on the guest OS it works fine!

DirkS
Posts: 9956
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: Unable to mount raspberry pi image

Thu Sep 06, 2018 1:02 pm

aeromaxx wrote:
Thu Sep 06, 2018 11:34 am
Clearly didn't read all of my post!
TBH: you should blame yourself for that.
I can't see you mentioning it in in the title or the first 4 paragraphs of your post.
Meaning that the problem point has drowned somewhere in all the terminal output...

Return to “Beginners”