dpenezic
Posts: 98
Joined: Sat Dec 22, 2012 2:36 pm

Mounting disk image like Linux disk

Wed Oct 09, 2013 3:23 pm

Hi,
today I spent almost 3 hours to find way to mount disk image distribution like Linux disk, A lot of different and not completed information are available on internet. Finally I realize that one switch make big different :D .

Here are basic steps:
1. Get disk image from some source (download from Internet to local disk)

Code: Select all

wget http://downloads.raspberrypi.org/raspbian_latest 
2. unzip disk image (after this action you need to have file with .img extension like 2013-09-25-wheezy-raspbian.img)

Code: Select all

unzip 2013-09-25-wheezy-raspbian.img
3. disk image have 2 partition and is important to found where partition begin for that action use follow command:

Code: Select all

 fdisk -lu 2013-09-25-wheezy-raspbian.img 
command output will be something like :

Code: Select all

You must set cylinders.
You can do this from the extra functions menu.

Disk 2013-09-25-wheezy-raspbian.img: 0 MB, 0 bytes
255 heads, 63 sectors/track, 0 cylinders, total 0 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: 0x0002c262

                         Device Boot      Start         End      Blocks   Id  System
2013-09-25-wheezy-raspbian.img1            8192      122879       57344    c  W95 FAT32 (LBA)
Partition 1 does not end on cylinder boundary.
2013-09-25-wheezy-raspbian.img2          122880     5785599     2831360   83  Linux
Partition 2 does not end on cylinder boundary.
This output show you need to postpone read till 8192 position for first disk, or 122880 position for second disk, size of sector is 512 byte.
4. Mounting second disk you may do with follow command :

Code: Select all

mount -o loop,offset=$(( 512 * 122880)) 2013-09-25-wheezy-raspbian.img /media/rpi
Regards,
Dubravko

Joe Schmoe
Posts: 4277
Joined: Sun Jan 15, 2012 1:11 pm

Re: Mounting disk image like Linux disk

Thu Oct 10, 2013 11:48 am

Good post. Here's another way, using the file command to get the info on the "start sector".

This script will mount both partitions in the image, the first on /mnt, the second on /media. I wrote it a long time ago; haven't messed with it much since then:

Code: Select all

#!/bin/bash
where=/mnt
for i in $(file 2012-12-16-wheezy-raspbian.img|gawk 'BEGIN {RS="startsector"} NR > 1 {
print $0*512}');do
    mount -o ro,offset=$i 2012-12-16-wheezy-raspbian.img $where
    where=/media
done
df
And some folks need to stop being fanboys and see the forest behind the trees.

(One of the best lines I've seen on this board lately)

jannewmarch
Posts: 33
Joined: Thu Jan 17, 2013 12:45 am

Re: Mounting disk image like Linux disk

Sun Mar 16, 2014 9:34 am

Cool. It works for CubieBoard images too. I learnt something from this post

Joe Schmoe
Posts: 4277
Joined: Sun Jan 15, 2012 1:11 pm

Re: Mounting disk image like Linux disk

Sun Mar 16, 2014 1:07 pm

jannewmarch wrote:Cool. It works for CubieBoard images too. I learnt something from this post
Cool. Good to hear.
And some folks need to stop being fanboys and see the forest behind the trees.

(One of the best lines I've seen on this board lately)

Return to “Raspbian”

Who is online

Users browsing this forum: No registered users and 26 guests