1.环境准备
环境配置,安装ARM64 Linux 5.4.34
下载qemu
apt-get install build-essential zlib1g-dev pkg-config libglib2.0-dev binutils-dev libboost-all-dev autoconf libtool libssl-dev libpixman-1-dev libpython-dev python-pip python-capstone virtualenv
wget https://download.qemu.org/qemu-4.2.1.tar.xz
tar xvJf qemu-4.2.1.tar.xz
cd qemu-4.2.1
./configure --target-list=x86_64-softmmu,x86_64-linux-user,arm-softmmu,arm-linux-user,aarch64-softmmu,aarch64-linux-user --enable-kvm
make
sudo make install
配置arm64环境
在linux-5.3.34文件夹中,配置内核编译选项:
make defconfig ARCH=arm64
make menuconfig ARCH=arm64
在menuconfig中完成以下更改
Kernel hacking --->
Compile-time checks and compiler options --->
[*] Compile the kernel with debug info
[*] Provide GDB scripts for kernel debugging
[*] Kernel debugging
# 关闭KASLR,否则会导致调试的时候打断点失败
Processor type and features ---->
[] Randomize the address of the kernel image (KASLR)
更改后开始编译:
export ARCH=arm64
export CROSS_COMPILE=aarch64-linux-gnu-
make Image -j$(nproc)
制作跟文件系统:
与上个实验类似,下载busybox并解压:
wget https://busybox.net/downloads/busybox-1.36.0.tar.bz2
tar -jxvf busybox-1.36.0.tar.bz2
cd busybox-1.36.0
编译前需要设置:
export ARCH=arm64
export CROSS_COMPILE=aarch64-linux-gnu-
然后配置:
make menuconfig
Settings --->
[*] Build static binary (no shared libs)
之后就可以编译:
make -j$(nproc) && make install
/rootfs目录下添加init脚本:
#!/bin/sh
mount -t proc none /proc
mount -t sysfs none /sys
echo "Wellcome TryOS!"
echo "--------------------"
cd home
/bin/sh
并加上运行权限:
chmod +x init
打包成镜像文件存放在与rootfs的同级目录下:
find . -print0 | cpio --null -ov --format=newc | gzip -9 > ~/linux_lab4/rootfs.cpio.gz
启动内核:
qemu-sys