I used below 2 scripts to configure cross compiling on arm64 , I tried to search a lot on error end Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(0,0)
but I couldn’t fix it
I seem to be enforced on some tools and versions to use but I managed to write the 2scripts of building kernel and running qemu but after searching the error and reviewing many questions I couldn’t figure what I done wrong
the below the script manual-linux.sh
for building kernel and busybox
set -e
set -u
OUTDIR=/tmp/aeld
KERNEL_REPO=git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git
KERNEL_VERSION=v5.1.10
BUSYBOX_VERSION=1_33_1
FINDER_APP_DIR=$(realpath $(dirname $0))
ARCH=arm64
CROSS_COMPILE=aarch64-none-linux-gnu-
CC_SYSROOT=$(${CROSS_COMPILE}gcc -print-sysroot)
if [ $# -lt 1 ]
then
echo "Using default directory ${OUTDIR} for output"
else
OUTDIR=$1
echo "Using passed directory ${OUTDIR} for output"
fi
mkdir -p ${OUTDIR}
cd "$OUTDIR"
if [ ! -d "${OUTDIR}/linux-stable" ]; then
#Clone only if the repository does not exist.
echo "CLONING GIT LINUX STABLE VERSION ${KERNEL_VERSION} IN ${OUTDIR}"
git clone ${KERNEL_REPO} --depth 1 --single-branch --branch ${KERNEL_VERSION}
fi
if [ ! -e "${OUTDIR}/linux-stable/arch/${ARCH}/boot/Image" ]; then
cd linux-stable
CURRENT_VERSION=$(git describe --tags --exact-match)
if [ "${CURRENT_VERSION}" != "${KERNEL_VERSION}" ]; then
echo "Checking out version ${KERNEL_VERSION}"
git checkout ${KERNEL_VERSION}
curl -s -o e33a814e772cdc36436c8c188d8c42d019fda639.patch https://github.com/torvalds/linux/commit/e33a814e772cdc36436c8c188d8c42d019fda639.patch
git apply e33a814e772cdc36436c8c188d8c42d019fda639.patch
else
echo "Already on version ${KERNEL_VERSION}"
curl -s -o e33a814e772cdc36436c8c188d8c42d019fda639.patch https://github.com/torvalds/linux/commit/e33a814e772cdc36436c8c188d8c42d019fda639.patch
git apply e33a814e772cdc36436c8c188d8c42d019fda639.patch
fi
echo "hel1"
make ARCH=arm64 CROSS_COMPILE=aarch64-none-linux-gnu- mrproper
echo "e1"
make ARCH=arm64 CROSS_COMPILE=aarch64-none-linux-gnu- defconfig
echo "e2"
make -j4 ARCH=arm64 CROSS_COMPILE=aarch64-none-linux-gnu- all
echo "e3"
fi
echo "Adding the Image in outdir"
cp ${OUTDIR}/linux-stable/arch/${ARCH}/boot/Image ${OUTDIR}
echo "Creating the staging directory for the root filesystem"
cd "$OUTDIR"
if [ -d "${OUTDIR}/rootfs" ]
then
echo "Deleting rootfs directory at ${OUTDIR}/rootfs and starting over"
sudo rm -rf ${OUTDIR}/rootfs
fi
mkdir -p rootfs
cd "${OUTDIR}/rootfs"
# TODO: Create necessary base directories
mkdir -p bin dev etc home lib lib64 proc sbin sys tmp usr var
mkdir -p usr/bin usr/lib usr/sbin
mkdir -p var/log
cd "$OUTDIR"
if [ ! -d "${OUTDIR}/busybox" ]
then
git clone git://busybox.net/busybox.git
cd busybox
git checkout ${BUSYBOX_VERSION}
# TODO: Configure busybox
make -j4 distclean
make -j4 defconfig
else
cd busybox
fi
pwd
make -j4 distclean
make -j4 defconfig
# TODO: Make and install busybox
echo "b1sy"
make -j4 ARCH=${ARCH} CROSS_COMPILE=${CROSS_COMPILE}
echo "b2sy"
make -j4 CONFIG_PREFIX=${OUTDIR}/rootfs ARCH=${ARCH} CROSS_COMPILE=${CROSS_COMPILE} install
echo "Library dependencies"
${CROSS_COMPILE}readelf -a busybox | grep "program interpreter"
${CROSS_COMPILE}readelf -a busybox | grep "Shared library"
# TODO: Add library dependencies to rootfs
cp ${CC_SYSROOT}/lib64/libm.so.6 ${OUTDIR}/rootfs/lib64
cp ${CC_SYSROOT}/lib64/libresolv.so.2 ${OUTDIR}/rootfs/lib64
cp ${CC_SYSROOT}/lib64/libc.so.6 ${OUTDIR}/rootfs/lib64
cp -r ${CC_SYSROOT}/lib/ld-linux-aarch64.so.1 ${OUTDIR}/rootfs/lib
# TODO: Make device nodes
sudo mknod -m 666 ${OUTDIR}/rootfs/dev/null c 1 3
sudo mknod -m 600 ${OUTDIR}/rootfs/dev/console c 5 1
sudo mknod -m 660 ${OUTDIR}/rootfs/dev/sda b 8 0
sudo mknod -m 660 ${OUTDIR}/rootfs/dev/sda1 b 8 1
sudo mknod -m 660 ${OUTDIR}/rootfs/dev/sda2 b 8 2
sudo mknod -m 660 ${OUTDIR}/rootfs/dev/sda3 b 8 3
sudo mknod -m 660 ${OUTDIR}/rootfs/dev/sda4 b 8 4
# TODO: Clean and build the writer utility
cd ${FINDER_APP_DIR}
make -j4 clean
make -j4 CROSS_COMPILE=${CROSS_COMPILE}
# TODO: Copy the finder related scripts and executables to the /home directory
# on the target rootfs
cd ${FINDER_APP_DIR}
cp -r * ${OUTDIR}/rootfs/home/
# TODO: Chown the root directory
sudo chown -R root:root ${OUTDIR}/rootfs/*
# TODO: Create initramfs.cpio.gz
cd "$OUTDIR/rootfs"
find . | cpio -H newc -o --owner root:root > ${OUTDIR}/initramfs.cpio
cd "$OUTDIR"
gzip -f initramfs.cpio
the below script of start-qemu-terminal
# !/bin/bash
# Script to open qemu terminal.
set -e
OUTDIR=$1
if [ -z "${OUTDIR}" ]; then
OUTDIR=/tmp/aeld
echo "No outdir specified, using ${OUTDIR}"
fi
KERNEL_IMAGE=${OUTDIR}/Image
INITRD_IMAGE=${OUTDIR}/initramfs.cpio.gz
if [ ! -e ${KERNEL_IMAGE} ]; then
echo "Missing kernel image at ${KERNEL_IMAGE}"
exit 1
fi
if [ ! -e ${INITRD_IMAGE} ]; then
echo "Missing initrd image at ${INITRD_IMAGE}"
exit 1
fi
echo "Booting the kernel"
# See trick at https://superuser.com/a/1412150 to route serial port output to file
qemu-system-aarch64 -m 2048M -M virt -cpu cortex-a53 -nographic -smp 1 -kernel ${KERNEL_IMAGE}
-chardev stdio,id=char0,mux=on,logfile=${OUTDIR}/serial.log,signal=off
-serial chardev:char0 -mon chardev=char0
-append "rdinit=/bin/sh" -initrd ${INITRD_IMAGE} -append " init=/sbin/init"