how do i open/edit a rasberry image?
i have googled the heck out of this so please forgive me if this is a no brainer...
i have downloaded rasberry images from various distributions and would like to
open an image on my laptop to make adjustments before i boot the rasberry itself.
i get the following error when i try to mount an image on my laptop:
mount 2012-08-08-wheezy-armel.img /mnt -o loop
mount: unknown filesystem type '(null)'
mount 2012-08-08-wheezy-armel.img /mnt
mount: unknown filesystem type '(null)'
i get this error across the board with every distribution.
i cant make my edits on a running rasberry because the change i need is to set up the
rasberry serial console from the boot line (i have no keyboard, screen or mouse) so no
rasberry until i get this working.
maybe my kernel needs an option i don’t have? here is my laptop environment:-
cat /etc/issue
Welcome to openSUSE 12.2 "Mantis" - Kernel \r (\l).
uname -a
Linux linux-ywym.site 3.4.6-2.10-desktop #1 SMP PREEMPT Thu Jul 26 09:36:26 UTC 2012 (641c197) i686 i686 i386 GNU/Linux
how do i mount a rasberry image (either on the sd card or as an image) on my laptop??
thanks
andrew.
i have downloaded rasberry images from various distributions and would like to
open an image on my laptop to make adjustments before i boot the rasberry itself.
i get the following error when i try to mount an image on my laptop:
mount 2012-08-08-wheezy-armel.img /mnt -o loop
mount: unknown filesystem type '(null)'
mount 2012-08-08-wheezy-armel.img /mnt
mount: unknown filesystem type '(null)'
i get this error across the board with every distribution.
i cant make my edits on a running rasberry because the change i need is to set up the
rasberry serial console from the boot line (i have no keyboard, screen or mouse) so no
rasberry until i get this working.
maybe my kernel needs an option i don’t have? here is my laptop environment:-
cat /etc/issue
Welcome to openSUSE 12.2 "Mantis" - Kernel \r (\l).
uname -a
Linux linux-ywym.site 3.4.6-2.10-desktop #1 SMP PREEMPT Thu Jul 26 09:36:26 UTC 2012 (641c197) i686 i686 i386 GNU/Linux
how do i mount a rasberry image (either on the sd card or as an image) on my laptop??
thanks
andrew.
Re: how do i open/edit a rasberry image?
Does this help?? - http://en.wikibooks.org/wiki/QEMU/Image ... n_the_host
If that doesn't work then I guess you'll have to flash an SD Card and mount it on the Raspberry PI via a USB memory card reader.
Once you have edited what it required you extract an image file back from the SD Card.
It maybe possible to avoid flashing if you use the image file as a secondary hard drive with Win32 Qemu running Raspberry Pi or a Live Linux distro like Mint.
Richard S.
If that doesn't work then I guess you'll have to flash an SD Card and mount it on the Raspberry PI via a USB memory card reader.
Once you have edited what it required you extract an image file back from the SD Card.
It maybe possible to avoid flashing if you use the image file as a secondary hard drive with Win32 Qemu running Raspberry Pi or a Live Linux distro like Mint.
Richard S.
Re: how do i open/edit a rasberry image?
@redhawk, the problem with that is that you would need to know the offset to the second partition. Theoretically that is not impossible, but I don't know how to do it.
I think the problem you are seeing is that the image includes the partition table and two partitions, whereas the filesystem drivers expect to see single partitions.
Why can you not write the SD card and then mount the filesystems from that on your laptop? (It hot-plugs fine on Linux Mint.) There's the extra step of dd'ing the card back into an image file, but it's not a hardship.
I think the problem you are seeing is that the image includes the partition table and two partitions, whereas the filesystem drivers expect to see single partitions.
Why can you not write the SD card and then mount the filesystems from that on your laptop? (It hot-plugs fine on Linux Mint.) There's the extra step of dd'ing the card back into an image file, but it's not a hardship.
Re: how do i open/edit a rasberry image?
You could DD the file to a USB memory stick or even a hard drive if you don't have the technology to do an SD card
Don't judge Linux by the Pi.......
I must not tread on too many sacred cows......
I must not tread on too many sacred cows......
Re: how do i open/edit a rasberry image?
Hi
After few attempts, I could mount two of partition os raspbian image.
Problem is how to determine offset byte of partitions begins?
Fdisk can show some information, file command also.
From above fdisk information, first partition start on sector 8182, and second on 122880. And each have 512 bytes.
File command show same information.
To get offset in bytes, multiply start sector by 512.
First partition have a offset of 4194304 bytes,
And, second, 62914560 bytes.
To mount,
Make modifications, umount and dump to SD card.
After few attempts, I could mount two of partition os raspbian image.
Problem is how to determine offset byte of partitions begins?
Fdisk can show some information, file command also.
Code: Select all
$ /sbin/fdisk -lu 2012-12-16-wheezy-raspbian.img
Disk 2012-12-16-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: 0x00017b69
Device Boot Start End Blocks Id System
2012-12-16-wheezy-raspbian.img1 8192 122879 57344 c W95 FAT32 (LBA)
2012-12-16-wheezy-raspbian.img2 122880 3788799 1832960 83 Linux
Code: Select all
$ file 2012-12-16-wheezy-raspbian.img
2012-12-16-wheezy-raspbian.img: x86 boot sector; partition 1: ID=0xc, starthead 130, startsector 8192, 114688 sectors; partition 2: ID=0x83, starthead 165, startsector 122880, 3665920 sectors, code offset 0xb8
To get offset in bytes, multiply start sector by 512.
First partition have a offset of 4194304 bytes,
And, second, 62914560 bytes.
To mount,
Code: Select all
mkdir /mnt/img1
mount -t vfat -o loop,offset=4194304 /tmp/rpi/2012-12-16-wheezy-raspbian.img /mnt/img1/
mkdir /mnt/img2
mount -t ext4 -o loop,offset=62914560 /tmp/rpi/2012-12-16-wheezy-raspbian.img /mnt/img2/
Re: how do i open/edit a rasberry image?
For people that are too lazy to do offset calculations (like me):
"sudo umount /mnt" and "sudo kpartx -d your-image.img" when done.
Code: Select all
$ sudo kpartx -av your-image.img
add map loop0p1 (252:5): 0 117187 linear /dev/loop0 1
add map loop0p2 (252:6): 0 3493888 linear /dev/loop0 118784
$ sudo mount /dev/mapper/loop0p2 /mnt
-
- Posts: 4277
- Joined: Sun Jan 15, 2012 1:11 pm
Re: how do i open/edit a rasberry image?
kpartx looks interesting. It is not part of the default instal, though.
FWIW (addressing the main thread topic), I think that for most practical purposes, the sequence:
1) Write image to card (using a Linux system other than the Pi)
2) Make changes on the card (using a Linux system other than the Pi)
3) Boot card (on the Pi)
is going to be easiest and best.
You would only need to modify the image itself if you are planning on writing it to multiple cards.
FWIW (addressing the main thread topic), I think that for most practical purposes, the sequence:
1) Write image to card (using a Linux system other than the Pi)
2) Make changes on the card (using a Linux system other than the Pi)
3) Boot card (on the Pi)
is going to be easiest and best.
You would only need to modify the image itself if you are planning on writing it to multiple cards.
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)
(One of the best lines I've seen on this board lately)
Re: how do i open/edit a rasberry image?
"Why can you not write the SD card and then mount the filesystems from that on your laptop?"rurwin wrote:@redhawk, the problem with that is that you would need to know the offset to the second partition. Theoretically that is not impossible, but I don't know how to do it.
I think the problem you are seeing is that the image includes the partition table and two partitions, whereas the filesystem drivers expect to see single partitions.
Why can you not write the SD card and then mount the filesystems from that on your laptop? (It hot-plugs fine on Linux Mint.) There's the extra step of dd'ing the card back into an image file, but it's not a hardship.
looks like i was over-analyzing everything and the above suggestion did the trick...
burning the image to an sd card and sliding it right back into the laptop makes all partitions visible and editable. dont know why that didnt work when i first tried it.
i am still glad i posted this question-i have received some amazing mount syntaxes that i didnt even know existed....
thanks to all....
andrew.
Re: how do i open/edit a rasberry image?
I combined the information in this thread into the following script:
Code: Select all
IMG_FILE=$(find dist/build/raspbian -name '*.img')
SECTOR_OFFSET=$(sudo /sbin/fdisk -l $IMG_FILE | awk '$6 == "Linux" { print $2 }')
BYTE_OFFSET=$(expr 512 \* $SECTOR_OFFSET)
sudo mount -o loop,offset=$BYTE_OFFSET $IMG_FILE dist/build/mnt
Re: how do i open/edit a rasberry image?
A better method than manually calculating the offsets for the image file is to map the img partitions as devices. This can be done with the following (run as root):
You need to load the loop module before mapping devices. kpartx will tell you the name of the device (it may not be loop0), ala:
Code: Select all
/sbin/modprobe loop
/sbin/kpartx -asv 2014-01-07-wheezy-raspbian.img
mount /dev/mapper/loop0p1 /mnt/rpi
Code: Select all
add map loop0p1 (253:1): 0 196608 linear /dev/loop0 2048
add map loop0p2 (253:2): 0 849920 linear /dev/loop0 198656
-
- Posts: 4
- Joined: Sat Feb 09, 2013 5:02 pm
Re: how do i open/edit a rasberry image?
A bit late to this, but you don't need kpartx in order to get the image file partitions accessible via a loopback - you can just use the -P option to losetup. A little more work, but only needs the util-linux package installed, which you almost certainly have.
First, we need a free loopback device to use:then set it up with the file
fdisk can then show you the partitions on your image
and you can mount whichever partition you want
When you are done, you unmount the file system, then detach the file from the loopback device
First, we need a free loopback device to use:
Code: Select all
sudo losetup -f
/dev/loop0
Code: Select all
sudo losetup -P /dev/loop0 lighting-pi-20140328.img
Code: Select all
sudo fdisk -l /dev/loop0
Code: Select all
sudo mount /dev/loop0p2 /media/spare/
Code: Select all
sudo umount /media/spare/
sudo losetup -d /dev/loop0
Re: how do i open/edit a rasberry image?
What version are you using?
losetup: invalid option -- 'P'
losetup: invalid option -- 'P'
-
- Posts: 4
- Joined: Sat Feb 09, 2013 5:02 pm
Re: how do i open/edit a rasberry image?
losetup from util-linux 2.22.2 (Gentoo)
The man page is dated July 2003, so this isn't exactly the bleeding edge.
The man page is dated July 2003, so this isn't exactly the bleeding edge.
Re: how do i open/edit a rasberry image?
To expand on sonnym's script, this script mounts the image file passed as an argument to /mnt/FILENAME:
Put this in my home dir named mount-image.sh, it works for me:
Code: Select all
#!/bin/sh
IMG_FILE=$1
SECTOR_OFFSET=$(sudo /sbin/fdisk -l $IMG_FILE | awk '$6 == "Linux" { print $2 }')
BYTE_OFFSET=$(expr 512 \* $SECTOR_OFFSET)
IMG_DIR=$(basename "$IMG_FILE")
IMG_DIR="${IMG_DIR%.*}"
echo Mounting at /mnt/$IMG_DIR
sudo mkdir -p /mnt/$IMG_DIR
sudo mount -o loop,offset=$BYTE_OFFSET $IMG_FILE /mnt/$IMG_DIR
Code: Select all
infogulch@vm-xubuntu:~$ chmod 755 mount-image.sh
infogulch@vm-xubuntu:~$ ./mount-image.sh 2013-09-10-wheezy-raspbian.img
[sudo] password for infogulch:
Mounting at /mnt/2013-09-10-wheezy-raspbian
infogulch@vm-xubuntu:~$ ls /mnt/2013-09-10-wheezy-raspbian/
bin dev home lost+found mnt proc run selinux sys usr
boot etc lib media opt root sbin srv tmp var
infogulch@vm-xubuntu:~$
Re: how do i open/edit a rasberry image?
Hi all,
in last post script need to use fdisk -lu instead fdisk -l .
I create script for mount and umount /boot and / from disk image. Code is follow:
in last post script need to use fdisk -lu instead fdisk -l .
I create script for mount and umount /boot and / from disk image. Code is follow:
Code: Select all
#!/bin/sh
# Author: Dubravko Penezic, dpenezic@gmail.com
#
# Credit to valuable answer from few users on Raspberry Pi Forum , http://www.raspberrypi.org/forums/viewtopic.php?f=63&t=28860
#
OPTION=$1
IMG_FILE=$2
MOUNT_POINT=/datacopy/RPI-raspbian-image/Work/Img
IMG_DIR=$(basename "$IMG_FILE")
IMG_DIR="${IMG_DIR%.*}"
if [[ "$#" -lt 2 || ("$1" != "m" && "$1" != "u") ]]
then
echo "Please use script as follow:"
echo ""
echo '> $0 m|u <disk_img_file>'
echo " m - mount"
echo " u - umount"
exit 1
fi
if [[ "$1" == "m" ]]
then
SECTOR_OFFSET=$(sudo /sbin/fdisk -lu $IMG_FILE | awk '$6 == "Linux" { print $2 }')
BYTE_OFFSET=$(expr 512 \* $SECTOR_OFFSET)
SECTOR_OFFSET_BOOT=$(sudo /sbin/fdisk -lu $IMG_FILE | awk '$6 == "W95" { print $2 }')
BYTE_OFFSET_BOOT=$(expr 512 \* $SECTOR_OFFSET_BOOT)
echo Mounting image / at $MOUNT_POINT/$IMG_DIR
echo Sector offset $SECTOR_OFFSET - Byte offset $BYTE_OFFSET
sudo mkdir -p $MOUNT_POINT/$IMG_DIR
sudo mount -t ext4 -o loop,offset=$BYTE_OFFSET $IMG_FILE $MOUNT_POINT/$IMG_DIR
echo Sector offset $SECTOR_OFFSET_BOOT - Byte offset $BYTE_OFFSET_BOOT
echo Mounting image /boot at $MOUNT_POINT/${IMG_DIR}_boot
sudo mkdir -p $MOUNT_POINT/${IMG_DIR}_boot
sudo mount -t vfat -o loop,offset=$BYTE_OFFSET_BOOT $IMG_FILE $MOUNT_POINT/${IMG_DIR}_boot
fi
if [[ "$1" == "u" ]]
then
echo Unmounting image / at $MOUNT_POINT/$IMG_DIR
sudo umount $MOUNT_POINT/$IMG_DIR
sudo rmdir $MOUNT_POINT/$IMG_DIR
echo Unmounting image /boot at $MOUNT_POINT/${IMG_DIR}_boot
sudo umount $MOUNT_POINT/${IMG_DIR}_boot
sudo rmdir $MOUNT_POINT/${IMG_DIR}_boot
fi
Re: how do i open/edit a rasberry image?
sorry if the is an old thread, but I am having a similar issue. to start off I am trying to get a bitcoin miner running but the img file I have is for a model B and I have a B+ and the img file has files I need to get it to run correctly. I can't do the usb or card reader as with the img in question doesn't enable the usb and or lan so I'm stuck something bad.
I am still waiting for support on the bitcoin forums atm but info on this thing is rare as and so hoping I can just extract the files needed to the newer weezy and away i go or ssh into the new weezy to copy the files over into the right directories etc.
please any ideas would be greatly appreciated.
Josh
I am still waiting for support on the bitcoin forums atm but info on this thing is rare as and so hoping I can just extract the files needed to the newer weezy and away i go or ssh into the new weezy to copy the files over into the right directories etc.
please any ideas would be greatly appreciated.
Josh
Re: how do i open/edit a rasberry image?
I found this very useful, and decided to make another useful addition to the script.
I added the ability to do an fsck to the primary partition, as I had several images that became corrupted (well not clean) because of various shutdown and power fail issues ... it happens. So I added an "f" option to fsck the primary and allwo you to correct issues and mske it clean...
I added the ability to do an fsck to the primary partition, as I had several images that became corrupted (well not clean) because of various shutdown and power fail issues ... it happens. So I added an "f" option to fsck the primary and allwo you to correct issues and mske it clean...
Code: Select all
#!/bin/sh
# Author: Dubravko Penezic, dpenezic@gmail.com
# initial script mount and unmount
# Updates: Pete Flahery, cometcoaster@gmail.com
# added fsck capability "f" option
# changed to run from current directory (the one that image is in)
# NOTE: this can be run against a symlinked image file(s)
# Credit to valuable answer from few users on Raspberry Pi Forum , http://www.raspberrypi.org/forums/viewtopic.php?f=63&t=28860
#
OPTION=$1
IMG_FILE=$2
CWD=`pwd`
MOUNT_POINT=$CWD/img
IMG_DIR=$(basename "$IMG_FILE")
IMG_DIR="${IMG_DIR%.*}"
if [[ ( "$#" -lt 2 ) || ( "$1" != "m" && "$1" != "u" && "$1" != "f" ) ]]
then
echo "Please use script as follow:"
echo ""
echo '> $0 m|u <disk_img_file>'
echo " m - mount"
echo " u - umount"
echo " f - fdisk it"
exit 1
fi
if [[ ("$1" == "m" || "$1" == "f") ]]
then
SECTOR_OFFSET=$(sudo /sbin/fdisk -lu $IMG_FILE | awk '$6 == "Linux" { print $2 }')
BYTE_OFFSET=$(expr 512 \* $SECTOR_OFFSET)
SECTOR_OFFSET_BOOT=$(sudo /sbin/fdisk -lu $IMG_FILE | awk '$6 == "W95" { print $2 }')
BYTE_OFFSET_BOOT=$(expr 512 \* $SECTOR_OFFSET_BOOT)
echo Mounting image / at $MOUNT_POINT/$IMG_DIR
echo Sector offset $SECTOR_OFFSET - Byte offset $BYTE_OFFSET
if [[ "$1" == "m" ]];then
sudo mkdir -p $MOUNT_POINT/$IMG_DIR
sudo mount -t ext4 -o loop,offset=$BYTE_OFFSET $IMG_FILE $MOUNT_POINT/$IMG_DIR
echo Sector offset $SECTOR_OFFSET_BOOT - Byte offset $BYTE_OFFSET_BOOT
echo Mounting image /boot at $MOUNT_POINT/${IMG_DIR}_boot
sudo mkdir -p $MOUNT_POINT/${IMG_DIR}_boot
sudo mount -t vfat -o loop,offset=$BYTE_OFFSET_BOOT $IMG_FILE $MOUNT_POINT/${IMG_DIR}_boot
else
sudo losetup -o $BYTE_OFFSET /dev/loop999 $IMG_FILE
sudo fsck -t ext4 /dev/loop999
sudo losetup -d /dev/loop999
fi
fi
if [[ "$1" == "u" ]]
then
echo Unmounting image / at $MOUNT_POINT/$IMG_DIR
sudo umount $MOUNT_POINT/$IMG_DIR
sudo rmdir $MOUNT_POINT/$IMG_DIR
echo Unmounting image /boot at $MOUNT_POINT/${IMG_DIR}_boot
sudo umount $MOUNT_POINT/${IMG_DIR}_boot
sudo rmdir $MOUNT_POINT/${IMG_DIR}_boot
fi
- mahjongg
- Forum Moderator
- Posts: 14785
- Joined: Sun Mar 11, 2012 12:19 am
- Location: South Holland, The Netherlands
Re: how do i open/edit a rasberry image?
all good and well, but the original post is eight years old, and the last post of this thread was five years old. Normally almost noting about your assumptions should still work, please don't do things like this, it only causing confusion, normally post like yours are simply deleted!
als threads older than a couple of years should be locked and marked obsolete, as they are several versions old, even before the introduction of system-D which brought radical changes.
also I see no reason at all top open and edit an image.
als threads older than a couple of years should be locked and marked obsolete, as they are several versions old, even before the introduction of system-D which brought radical changes.
also I see no reason at all top open and edit an image.
Re: how do i open/edit a rasberry image?
I do, but scripts like that make me cringe. losetup -P makes much, much more sense.
As it is apparently board policy to disallow any criticism of anything, as it appears to criticise something is to criticise all the users of that something, I will no longer be commenting in threads which are not directly relevant to my uses of the Pi.
- mahjongg
- Forum Moderator
- Posts: 14785
- Joined: Sun Mar 11, 2012 12:19 am
- Location: South Holland, The Netherlands
Re: how do i open/edit a rasberry image?
Ever heard of the expression "if you only have a hammer all problems look like a nail".
remember this was eight years ago, eight years less experience with linux.
remember this was eight years ago, eight years less experience with linux.
Re: how do i open/edit a rasberry image?
losetup has had -P for as long as I can remember.
As it is apparently board policy to disallow any criticism of anything, as it appears to criticise something is to criticise all the users of that something, I will no longer be commenting in threads which are not directly relevant to my uses of the Pi.