Building Release Images

From Manjaro-Arm Building
Jump to: navigation, search

Manjaro-Arm makes all releases in the form of Images .img to ease in the installation across all platforms. Most people with imbedded boards are already familiar with installing images so this aligns with their prior knowledge and makes it easier on them






To create the image, you can dump your current SDCard contents or use the rootfs. Either way works however, it is easiest to dump it from the SDCard and truncate after all the editing needed from the device is finished.

From SDCard

If you installed the rootfs properly, you will may have one or two partitions on the SDCard. The benefit of using images is that the partitions stay intact and can be transferred directly to the SDCard upon installation. To begin, first dump the contents of the SDCard to your filesystem

# dd if=/dev/mmcblk0 of=Manjaro-Arm.img 

This will dump an image the size of your SDCard into a file. Since we don't need images that are 4,8,16,++ GB, we need to first shrink the filesystem and partitions to only be as large as the data and then truncate the image to fit the partitions. The easiest way to do this is using gparted or a similar disk utility and a loop device.

Setup the image to loop device

Enable loop in the kernel

# modprobe loop

Create the blank /dev/loop0 device

# losetup -f

Create the loop0 device out of the image

# losetup /dev/loop0 Manjaro-Arm.img

You may need to re-probe the partitions

# partprobe /dev/loop0

Once mounted, you can start gparted for loop0 and shrink the partition to a few hundred MB larger than the end of data

$ gksu gparted /dev/loop0

After the filesystem and partition are shunk, you can remove the loop mount and prepare for truncating

# losetup -d /dev/loop0

Truncate the Image

Truncating the Image shrinks it down to remove all the empty space at the end (after the last partition). It essentially creates an image that is exactly the size of the partitions which saves space and download time.

Check the last sector of the last partition.

  1. fdisk -l Manjaro-Arm.img
Disk Manjaro-Arm_Minimal_rpi2_16.05.img: 1.6 GiB, 1691353600 bytes, 3303425 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: 0x9f5f861a
Device                                                      Boot     Start            End     Sectors       Size    Id    Type
Manjaro-Arm_Minimal_rpi2_16.05.img1                                   2048         206847      204800       100M     c    W95 FAT32 (LBA)
Manjaro-Arm_Minimal_rpi2_16.05.img2                                 206848        3303423     3096576       1.5G    83    Linux

Use the END sector and add one (which is the first of the free space) from the output to truncate the .img. The above example has already been truncated but its the same principle.

# truncate --size=$[(3303424+1)*512] Manjaro-Arm.img

Notice that we are technically adding 2 to the end sector. This allows there to be a one sector buffer so that nothing gets cut off and damages the partition table.

When it is all finished you should have a bootable image that is just the size of the contents. fdisk should show the same end sector and ls -ahl should show a smaller than 2gb size.

From Rootfs

Creating the image from a rootfs is a bit more complicated. It is necessary to create a blank image, dump the rootfs in place, and then all of the steps above to shrink the filesystem and truncate the image. Plus, you will still need to edit the image and do it again once the final setup is finished. It is always recommended to create the image from a working SDCard as stated above.

Creating The Image

Create a 2gb blank image, we will truncate the size down later

# dd if=/dev/zero of=Manjaro-Arm.img bs=1M count=2048

Setup the image to loop device Enable loop in the kernel

# modprobe loop

Create the blank /dev/loop0 device

# losetup -f

Create the loop0 device out of the image

# losetup /dev/loop0 Manjaro-Arm.img

Partition the Image for what is needed

The following is an example for the Raspberry Pi 2. It differs per device so change accordingly.

Create a 100mb /boot partition and the rest can be /root

# fdisk /dev/loop0
          o  --> new partition table
          n  --> new partition
          p  --> primary partition
          1  --> partition 1
       enter --> default start sector
       +100M --> End after 100MB
          t  --> Change type
          c  --> select type fat32
          n  --> new partition
          p  --> primary partition
      enter  --> default partition number (2)
      enter  --> default start sector
      enter  --> default end sector
          w  --> save changes and exit

Reload the partitions

# partprobe /dev/loop0

Create filesystems

Vfat on /boot

# mkfs.vfat /dev/loop0p1

Ext4 on /root

# mkfs.ext4 /dev/loop0p2

Mount filesystems and copy the rootfs over

We need to first mount the paritions on the machine so that we can edit the contents

# mount /dev/loop0p1 boot/
# mount /dev/loop0p2 root/

Copy the contents of the rootfs into the proper directories

# cp -ra rpi-rootfs/* root/
# mv root/boot/* boot/

Unmount the partitions once everything is finished copying

# umount root boot

Shrinking and truncating the Image

Once you have the data in place, you have the same setup as above except instead of dumping from the SDCard, you used the rootfs. Continue with editing the image in gparted, and finally truncating the image to fit.

Ziping the New Image into a zip file

Archiving the image can be done several different ways but for simplicity and compatibility across platforms, zip is probably the save choice. To zip it into the smallest possible size:

$ zip -9 Manjaro-Arm.img       //the -9 flag triggers more compression