0

So I'm using this SD Card image for my raspberry pi downloaded from Ubiquity Robotics. It has ROS preinstalled and runs Ubuntu OS. The problem is I'm missing a few dependencies missing and because of those missing dependencies I can't seem to install libraries from the internet. So if someone could walk me through on the process of installing dependencies directly onto the SD Card image, that would be great. Thank you.

1

You can mount the partitions -- there are probably two (Raspbian), possibly more but not less -- in a Pi SD card image pretty much the same way you would1 mount the partitions on a card created from such an image.

How can I mount a Raspberry Pi Linux distro image?

Any changes you make while the image partitions are so mounted are real, meaning if you unmount it and mount it again later they will still be so, and if you create a card using that image, they will be part of that too.

The OS that's in the image is obviously not running (exactly the same as if you put a Pi SD card in another computer), so you can't use the distro package manager2, but this may not be necessary on what your dependencies are and how you intended to install them.

As per the footnote, chroot is likely to be an important tool here, and that will require another Pi or other similar ARM system to do the work on. To summarize:

  • If the changes you want to make do not require you to run software from inside the image (such as a package manager), then you can work on the mounted image directly.
  • If you do need to run software that's inside the image, use chroot on another ARM based linux system (such as a Pi).

  1. Maybe "you could" makes more sense than "you would" there.

  2. As far as I know, that is. But IMO it should be possible, presuming you can run the same package manager (PM) software (eg. apt) on the host system -- it just requires explicit capabilities in the PM, presuming all the PM does is unpack an archive, copy files, and apply changes to text files or databases that are architecture agnostic.

    I doubt that has been implemented though, which means your best bet is to do the whole thing using another Pi (and USB SD card adapter) with chroot.

    https://en.wikipedia.org/wiki/Chroot

    In case that was a bit confusing, you can only use chroot this way on a system that has the same ISA as the software in the image, which is ARMv6. Most normal computers are not that, they are x86 or x86-64.

| improve this answer | |
1

You can loop mount the image file on a linux system (including the Pi itself).

This lets you examine and modify the image.

I use the following script (not mine - sourced from https://raspberrypi.org/forums/viewtopic.php?p=1528736).

This works with Raspbian, and should work with any normal image with 2 partitions. It could be modified for any image by determining the offsets of the partition within the image.

image-mount mounts a standard 'raw' image file to allow it to be read or written as if it were a device. Usage is:

image-mount imagefile mountpoint [W95|Linux]

where W95 mounts the BOOT partition and Linux mounts the ROOT partition. If neither is specified, Linux is assumed.

#!/bin/bash

errexit()
{
  echo ""
  echo "$1"
  echo ""
  exit 1
}

usage()
{
  errexit "Usage: $0 imagefile mountpoint [W95|Linux]"
}

if [ $(id -u) -ne 0 ]; then
  errexit "$0 must be run as root user"
fi

IMG="$1"
MNT="$2"
PART="$3"

if [[ "${IMG}" = "" || "${MNT}" = "" ]]; then
  usage
fi

if [ ! -f "${IMG}" ]; then
  errexit "${IMG} not found"
fi

if [ ! -d "${MNT}" ]; then
  errexit "${MNT} is not a directory"
fi

if [ "${PART}" = "" ]; then
  PART="type=83"
else
  PART="$(tr [A-Z] [a-z] <<< "${PART}")"
  if [ "${PART}" = "w95" ];then
    PART="type=c"
  elif [ "${PART}" = "linux" ];then
    PART="type=83"
  else
    usage
  fi
fi

echo ""
echo -n "Mount ${IMG} on ${MNT} (y/n)? "
while read -r -n 1 -s answer; do
  if [[ "${answer}" = [yYnN] ]]; then
    echo "${answer}"
    if [[ "${answer}" = [yY] ]]; then
      break
    else
      errexit "Aborted"
    fi
  fi
done
echo ""

INFO="$(sfdisk -d "${IMG}")"
START=$(grep "${PART}" <<< "${INFO}" | sed -n 's|^.*start=\s\+\([0-9]\+\).*$|\1|p')
SIZE=$(grep "${PART}" <<< "${INFO}" | sed -n 's|^.*size=\s\+\([0-9]\+\).*$|\1|p')
LOOP="$(losetup -f --show -o $((${START} * 512)) --sizelimit $((${SIZE} * 512)) "${IMG}")"
if [ $? -ne 0 ]; then
  errexit "Unable to create loop device"
fi
if [ "${PART}" = "type=c" ]; then
  dosfsck "${LOOP}"
else
  FS_TYPE=$(blkid "${LOOP}" | sed -n 's|^.*TYPE="\(\S\+\)".*|\1|p')
  if [ "${FS_TYPE}" = "f2fs" ]; then
    fsck.f2fs "${LOOP}"
  else
    fsck.ext4 -f "${LOOP}"
  fi
fi
if [ $? -ne 0 ]; then
  losetup -d "${LOOP}"
  errexit "Filesystem appears corrupted"
fi
mount "${LOOP}" ${MNT}
echo ""
echo "${IMG} mounted on ${MNT}"
echo ""
echo "When done, run:"
echo "umount ${MNT}"
echo "losetup -d ${LOOP}"
echo ""
| improve this answer | |

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.