Bulding the SD card imge for Arch

For this part of the process, and as a follow-up to my previous post, I will be using the beautifully clear and concise post at http://serverfault.com/questions/281628/combine-partitions-to-one-disk-image.

I have two filesystem images that I want to combine into a single 16G image file. The above post mentions kpartx and I made the mistake of thinking that it was a KDE version of parted (!) except that it doesn’t work with the -av options.

A wee bit of digging hinted at kpartx being part of the multipath-tools package, but pacman couldn’t find it.

A quick word with one of my kids (who is more of an Arch whizz than I) suggested that the problem was that multipath-tools is part of the AUR (Arch Use Repository) and can be installed using the command,

$ yaourt -S multipath-tools

Note, as a unprivileged user. So we continue with the process.

# truncate --size 16G r-pi-16gb.img
# fdisk r-pi-16gb.img

With two partitions: 100M and 15.9 G.

# kpartx -av r-pi-16gb.img 
add map loop2p1 (254:0): 0 204800 linear /dev/loop2 2048
add map loop2p2 (254:1): 0 33347584 linear /dev/loop2 206848
# dd if=rpi-arch-root.img of=/dev/mapper/loop2p1 bs=1M
100+0 records in
100+0 records out
# dd if=rpi-arch-ext4.img of=/dev/mapper/loop2p2 bs=1M
dd: error writing ‘/dev/mapper/loop2p2’: No space left on device
16284+0 records in
16283+0 records out
17073963008 bytes (17 GB) copied, 509.39 s, 33.5 MB/s

Not what I was expecting. I have checked my sums and they all seem to match up: the ext4 image is 15.9 GiB (16284 M) and the combined size should match the 16G image file.

A closer check of fdisk does seem to highlight a discrepancy:

  • r-pi-16gb.img2 has 33347584 sectors for 15.9G
  • rpi-arch-ext4.img: 15.9 GiB, 17075011584 bytes with 33349632 sectors

So, perhaps the problem here is because there is an offset at the start, but extending the 16G disk image won’t work because that is then bigger than the size of the SD card. Back to the drawing board and out with the calculator.


2 thoughts on “Bulding the SD card imge for Arch

  1. julianrawcliffe Post author

    It would appear that 16284 is 1M bigger than the 15.9G on the combined image, so I tried creating an ext4 partition consisting of 16283M, but it still errors:

    # dd if=rpi-arch-ext4.img of=/dev/mapper/loop2p2 bs=1M
    dd: error writing ‘/dev/mapper/loop2p2’: No space left on device
    16283+0 records in
    16282+0 records out
    17073946112 bytes (17 GB) copied, 1329.25 s, 12.8 MB/s

    It really doesn’t want this to work. All the numbers match up, except they don’t. I really can’t see what I’m doing wrong and probably ought to give up.

  2. julianrawcliffe Post author

    And as an experiment I create the target disk fo rthe SD image to be the same size of the ext4 disk and I get the same error!
    I create two disk images: one with 100M, one with 16284M. I create a second disk of 16384M partitoned up as 100M and 16284M. A dd of the 100M image to the partition is fine, but a dd of the 16284M disk into the 16284M partition fails: no space left on device!
    But, there’s an another way:
    # mount /dev/mapper/loop2p2 arch-linux-r-pi/root/
    # mount rpi-root-ext4.img /mnt
    # cd /mnt
    # tar cpf – . | (cd /path/to/arch-linux-r-pi/root; tar xmpf -)


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s