02-16-2020, 08:02 PM
As a learning experience, I've been trying to roll my own Arch Linux image. I've been cobbling together bits and pieces from the following locations while adding some bits of my own:
Its worth noting that when I write the official manjaro image to the SD card, it does boot that successfully.
- anarsoul's build scripts
- Blutkoete's manual setup
- hku2's manual setup
- enospc's mostly upstream uboot
Code:
#!/usr/bin/env bash
set -x
set -euo pipefail
IFS=$'\n\t'
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# Manual Steps
##############
#
# Install dirmngr
#
# trust arch linux arm key
# gpg --recv-keys 68B3537F39A313B3E574D06777193F152BDBE6A6
WORKSPACE=$(mktemp -d -t "arch-pinebook-pro-build-XXXXXXX")
cleanup() {
if [ -d "$MOUNT" ]; then
umount -R "$MOUNT" || true
fi
if [ -z "$LOOP_DEVICE" ]; then
losetup -d "$LOOP_DEVICE"
fi
if [ -d "$WORKSPACE" ]; then
rm -rf "$WORKSPACE"
fi
}
trap cleanup EXIT
DOWNLOADS="$WORKSPACE/downloads"
mkdir -p "$DOWNLOADS"
ROOT="$WORKSPACE/root"
mkdir -p "$ROOT"
MOUNT="$WORKSPACE/mount"
mkdir -p "$MOUNT"
IMAGE_FILE="$WORKSPACE/archlinux.img"
IMAGE_SIZE="$(( 1024*1024*1024*6 ))" # bytes
archroot() {
CHROOT="$1"
shift 1
CMD="$@"
mount -o bind /tmp "$CHROOT/tmp"
mount -o bind /dev "$CHROOT/dev"
chroot "$CHROOT" mount -t proc proc /proc
chroot "$CHROOT" mount -t sysfs sys /sys
chroot "$CHROOT" "$CMD"
chroot "$CHROOT" umount /sys
chroot "$CHROOT" umount /proc
umount "$CHROOT/dev"
umount "$CHROOT/tmp"
}
wget -O "$DOWNLOADS/base.tar.gz.sig" http://os.archlinuxarm.org/os/ArchLinuxARM-aarch64-latest.tar.gz.sig
wget -O "$DOWNLOADS/base.tar.gz" http://os.archlinuxarm.org/os/ArchLinuxARM-aarch64-latest.tar.gz
gpg --verify "$DOWNLOADS/base.tar.gz.sig" "$DOWNLOADS/base.tar.gz"
# Disk positions (in bytes)
sector_size=512
boot_start=$((1024*1024*20))
boot_size=$((1024*1024*1024*1))
main_start=$((boot_start + boot_size + sector_size))
dd if=/dev/zero of="$IMAGE_FILE" bs=1 count=0 seek=$IMAGE_SIZE
fdisk "$IMAGE_FILE" <<EOF
o
n
p
1
$((boot_start/sector_size))
+$((boot_size/sector_size))
t
c
n
p
2
$((main_start/sector_size))
t
2
83
a
2
w
EOF
LOOP_DEVICE=$(losetup -f)
losetup -P $LOOP_DEVICE $IMAGE_FILE
dd if="$DIR/idbloader.img" of=$LOOP_DEVICE seek=64 conv=notrunc
dd if="$DIR/u-boot.itb" of=$LOOP_DEVICE seek=16384 conv=notrunc
mkfs.vfat -n BOOT -F32 ${LOOP_DEVICE}p1
mkfs.ext4 -L ARCH ${LOOP_DEVICE}p2
mount ${LOOP_DEVICE}p2 "$MOUNT"
mkdir "$MOUNT/boot"
mount ${LOOP_DEVICE}p1 "$MOUNT/boot"
# bsdtar too old on base pinebook install
#bsdtar -xpf "$DOWNLOADS/base.tar.gz" -C "$MOUNT"
tar -xpf "$DOWNLOADS/base.tar.gz" -C "$MOUNT"
# no genfstab on base pinebook install, do in chroot instead
# genfstab -U "$MOUNT" >> "$MOUNT/etc/fstab"
mv "$MOUNT/etc/resolv.conf" "$MOUNT/etc/resolv.conf.bak"
cp /etc/resolv.conf "$MOUNT/etc/resolv.conf"
cat > "$MOUNT/chroot_commands" <<EOF
#!/usr/bin/env bash
set -x
set -euo pipefail
IFS=$'\n\t'
pacman-key --init
pacman-key --populate archlinuxarm
killall -KILL gpg-agent
pacman -Syu --noconfirm
# wget to fetch manjaro packages
# arch-install-scripts for genfstab
pacman -S --noconfirm wget arch-install-scripts
mkdir /manjaro_packages
pushd .
cd /manjaro_packages
wget "http://ftp-nyc.osuosl.org/pub/manjaro-arm/repo/stable/aarch64/core/linux-pinebookpro-5.5.0-3-aarch64.pkg.tar.xz"
wget "http://ftp-nyc.osuosl.org/pub/manjaro-arm/repo/stable/aarch64/core/uboot-pinebookpro-2020.01-4-aarch64.pkg.tar.xz"
wget "http://ftp-nyc.osuosl.org/pub/manjaro-arm/repo/stable/aarch64/community/pinebookpro-post-install-20200203-1-any.pkg.tar.xz"
wget "http://ftp-nyc.osuosl.org/pub/manjaro-arm/repo/stable/aarch64/community/ap6256-firmware-2020.01-1-aarch64.pkg.tar.xz"
pacman -U linux-pinebookpro-5.5.0-3-aarch64.pkg.tar.xz
pacman -U uboot-pinebookpro-2020.01-4-aarch64.pkg.tar.xz
pacman -U pinebookpro-post-install-20200203-1-any.pkg.tar.xz
pacman -U ap6256-firmware-2020.01-1-aarch64.pkg.tar.xz
popd
genfstab -U / >> /etc/fstab
# clean up
#yes | pacman -Scc
EOF
chmod +x "$MOUNT/chroot_commands"
archroot "$MOUNT" "/chroot_commands"
rm "$MOUNT/chroot_commands"
mv "$MOUNT/etc/resolv.conf.bak" "$MOUNT/etc/resolv.conf"
sync
umount -R "$MOUNT"
losetup -d "$LOOP_DEVICE"
cp $IMAGE_FILE "$DIR/archlinux.img"
Its worth noting that when I write the official manjaro image to the SD card, it does boot that successfully.