---
# System prepended metadata

title: smallsys
tags: [linux]

---

# smallsys


## 下載qemu並且編譯
```bash=
git clone git@github.com:qemu/qemu.git
cd qemu
./configure --target-list=i386-softmmu,x86_64-softmmu,aarch64-softmmu,arm-softmmu,riscv32-softmmu,riscv64-softmmu --disable-libssh  --enable-debug --enable-kvm
# 編譯
make
# 製造軟連結
ln -s /qemu_source_code/aarch64-softmmu/qemu-system-aarch64 /usr/bin/qemu-system-aarch64
```

發生錯誤-> make: aarch64-linux-gnu-gcc: Command not found

可能原因為32和64位元相容問題

解法:sudo apt-get install binutils-multiarch-dev  binutils-multiarch lib32ncurses5-dev lib32z1

---

## 下載並且編譯buildroot產生根檔案系統

```bash=
git clone git@github.com:buildroot/buildroot.git
cd buildroot
make menuconfig
# 調整buildroot選單內容
Target options 
     Target Architecture (AArch64 (little endian))
Toolchain
    Toolchain type (External toolchain) 
    Linaro AArch64 2018.05
System configuration 
    Run a getty (login prompt) after boot
     (ttyAMA0) TTY port
Target packages
    Show packages that are also provided by busybox
Filesystem images
    cpio the root filesystem (for use as an initial RAM filesystem) 
# 開始編譯
make
```
## 下載並且編譯linux
```bash=
git clone git@github.com:torvalds/linux.git
cd linux 
make CROSS_COMPILE=aarch64-linux-gnu- ARCH=arm64 menuconfig

General setup
    Initial RAM filesystem and RAM disk (initramfs/initrd) support 
     (/home/liangyu/Desktop/opnsrc/buildroot/output/images/rootfs.cpio) Initramfs source file(s)
Networking support
    Plan 9 Resource Sharing Support (9P2000)
File systems
    Network File Systems
        9P POSIX Access Control Lists
#編譯核心
make CROSS_COMPILE=aarch64-linux-gnu- ARCH=arm64
```
---
使用qemu執行
```bash=
qemu-system-aarch64 -machine virt -cpu cortex-a57 -machine type=virt -nographic -smp 1 -m 2048 -kernel /path to linux source code//arch/arm64/boot/Image  --append "console=ttyAMA0"
```
成功畫面
![](https://i.imgur.com/OQ7AyBv.png)


---
[Running Linux in QEMU’s aarch64 system emulation mode](https://www.bennee.com/~alex/blog/2014/05/09/running-linux-in-qemus-aarch64-system-emulation-mode/)

###### tags: `linux`