2

I'm following this guide to install a virtual ARM environment on Ubuntu.

  • I installed linaro and qemu packages:

sudo add-apt-repository ppa:linaro-maintainers/tools
sudo apt-get install linaro-image-tools qemu-user-static qemu-system

  • Cross compilers:

sudo apt-get install gcc-arm-linux-gnueabi g++-arm-linux-gnueabi

  • Downloaded a Linaro release and hardware pack:

wget http://releases.linaro.org/platform/linaro-n/nano/alpha-3/linaro-natty-nano-tar-20110302-0.tar.gz
wget http://releases.linaro.org/platform/linaro-n/hwpacks/alpha-3/hwpack_linaro-vexpress_20110302-0_armel_supported.tar.gz

  • Created a VM disk image:

linaro-media-create --image_file vexpress.img --dev vexpress \
--binary linaro-natty-nano-tar-20110302-0.tar.gz \
--hwpack hwpack_linaro-vexpress_20110302-0_armel_supported.tar.gz

I'm failing at Extracting the kernel and initrd. The instructions say to run:

sudo mount -o loop,offset="$(file vexpress.img | awk 'BEGIN { RS=";"; } /partition 2/ { print $7*512; }')" \
-t auto vexpress.img /mnt/tmp

But I'm getting the error:

mount: failed to parse mount options

There's a note in the guide that says:

The actual names of the files might vary slightly in your build.

So does anyone know how to modify this last line to fit on Ubuntu?

2
  • Break down the components and see if they're giving you reasonable values. Run file vexpress.img; run the awk command.
    – Jeff Schaller
    Nov 1 '16 at 15:11
  • vexpress.img exists and file vexpress.img returns data. awk is found and awk <command in post> just hangs
    – Alaa M.
    Nov 1 '16 at 15:17
2
sudo mount -o loop,offset="$(file vexpress.img | awk 'BEGIN { RS=";"; } \
/partition 2/ { print $7*512; }')" \
-t auto vexpress.img /mnt/tmp

What the above command is doing is actually simple: It finds the starting sector of partition 2 of the image vexpress.img, multiply it by 512, and take the result as offset to mount as a loop device.

The mount command accepts offset value in byte. Each sector has 512 bytes, so multiplying start sector offset by 512 will yield the start offset in bytes.

Here's an alternative way to do this: (I take a raw raspbian image as example)

  1. Find the offset:

    $ fdisk -lu 2016-09-23-raspbian-jessie-lite.img 
    Disk 2016-09-23-raspbian-jessie-lite.img: 1.3 GiB, 1389363200 bytes, 2713600 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: 0x5a7089a1
    
    Device                               Boot  Start     End Sectors  Size Id Type
    2016-09-23-raspbian-jessie-lite.img1        8192  137215  129024   63M  c W95 FAT32 (LBA)
    2016-09-23-raspbian-jessie-lite.img2      137216 2713599 2576384  1.2G 83 Linux
    

The start offset of partition two is 137216. Like your vexpress.img, partition 2 is the root partition that we are interested in.

  1. Simple math:

    $ perl -e "print 137216*512"
    70254592
    
  2. Mount it:

    sudo mount -o loop,offset=70254592 vexpress.img /mnt/tmp
    
2
  • fdisk -lu vexpress.img gives me only up to I/O size .... I don't get Start / End / Sectors
    – Alaa M.
    Nov 2 '16 at 5:55
  • file vexpress.img is supposed to return something like DOS/MBR boot sector; partition 1 .... partition 2 ..... Since it returns data in your case, this means your vexpress.img is essentially broken. Please try to generate it again. Nov 2 '16 at 6:11

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.