【Linux】定制Linux系统

文章目录

  • [1. 制作尽可能小的Linux系统](#1. 制作尽可能小的Linux系统)
    • [1.1. 环境准备](#1.1. 环境准备)
      • [1.1.1 Linux内核编译相关](#1.1.1 Linux内核编译相关)
      • [1.1.2. bash-static](#1.1.2. bash-static)
    • [1.2. 具体步骤](#1.2. 具体步骤)
      • [1.2.1. 编译内核镜像](#1.2.1. 编译内核镜像)
      • [1.2.2. 加入bash-static](#1.2.2. 加入bash-static)
  • 其他
    • [fish shell](#fish shell)
      • [fish shell相关依赖安装](#fish shell相关依赖安装)
      • [静态编译fish shell](#静态编译fish shell)

1. 制作尽可能小的Linux系统

参考资料:https://www.bilibili.com/video/BV1gtfbYWEui

1.1. 环境准备

1.1.1 Linux内核编译相关

bash 复制代码
sudo apt install build-essential libncurses-dev bison flex libssl-dev libelf-dev bc flex -y
  • 安装qemu
bash 复制代码
sudo apt install qemu-system-x86 -y
  • 安装镜像构建依赖
bash 复制代码
sudo apt install syslinux isolinux genisoimage -y

1.1.2. bash-static

bash 复制代码
sudo apt install bash-static -y

1.2. 具体步骤

1.2.1. 编译内核镜像

  • 解压文件
bash 复制代码
tar -xvf linux-6.17.5.tar.xz
cd linux-6.17.5/
  • 创建tinyconfig
bash 复制代码
make tinyconfig
  • 手动调整内核配置

    bash 复制代码
    make menuconfig
    • 启用
      • 64-bit kernel
      • General setup > Initial RAM filesystem and RAM disk (initramfs/initrd) support
        • 禁用
          • Support initial ramdisk/ramfs compressed using gzip
          • Support initial ramdisk/ramfs compressed using bzip2
          • Support initial ramdisk/ramfs compressed using LZMA
          • Support initial ramdisk/ramfs compressed using XZ
          • Support initial ramdisk/ramfs compressed using LZO
          • Support initial ramdisk/ramfs compressed using LZ4
      • General setup > Configure standard kernel features (expert users) > Enable support for printk
      • Device Drivers > Character devices > Enable TTY
      • Executable file formats > Kernel support for ELF binaries
  • 编译内核

bash 复制代码
make -j$(nproc)
  • qemu使用编译的内核尝试启动可以发现缺少初始化模块
bash 复制代码
qemu-system-x86_64 -kernel arch/x86/boot/bzImage
  • 查看内核镜像大小
bash 复制代码
ls -lh arch/x86/boot/bzImage

1.2.2. 加入bash-static

bash 复制代码
cd ~
mkdir output
cd output
cp  ~/linux-6.17.5/arch/x86/boot/bzImage .
cp /usr/bin/bash-static .
mv bash-static init
echo init | cpio -H newc -o > init.cpio
cd ~/linux-6.17.5
make isoimage FDARGS="initrd=/init.cpio" FDINITRD=~/output/init.cpio
qemu-system-x86_64 -cdrom arch/x86/boot/image.iso

其他

fish shell

fish shell相关依赖安装

  • 下载fish shell linux源码:https://github.com/fish-shell/fish-shell/releases/download/4.1.2/fish-4.1.2.tar.xz

  • 安装rust环境

    • 设置镜像源
    bash 复制代码
    export RUSTUP_DIST_SERVER=https://mirrors.ustc.edu.cn/rust-static
    export RUSTUP_UPDATE_ROOT=https://mirrors.ustc.edu.cn/rust-static/rustup
    • 下载安装脚本安装
    bash 复制代码
    curl https://sh.rustup.rs -sSf | sh
    source "$HOME/.cargo/env.fish"
    • 检查cargo是否安装成功
    bash 复制代码
    cargo --version
  • 安装gettext(rust-pcre2的依赖)

bash 复制代码
sudo apt install -y gettext

静态编译fish shell

  • 解压文件
bash 复制代码
tar -xvf fish-4.1.2.tar.xz
cd fish-4.1.2
  • 替换GitHub源

  • 静态编译

bash 复制代码
mkdir build
cd build
cmake .. \
  -DCMAKE_BUILD_TYPE=Release \
  -DCMAKE_EXE_LINKER_FLAGS="-static" \
  -DCMAKE_FIND_LIBRARY_SUFFIXES=".a"
make -j$(nproc)
相关推荐
赵民勇2 小时前
Linux/Unix中install命令全面用法解析
linux·shell
苏宸啊4 小时前
Linux指令篇(一)
linux·运维·服务器
睡不醒的猪儿4 小时前
nginx常见的优化配置
运维·nginx
我要升天!5 小时前
Linux中《网络基础》
linux·运维·网络
国强_dev5 小时前
在数据库开发和运维中的“错误信息误导(Red Herring)”
运维·adb·数据库开发
安科瑞刘鸿鹏175 小时前
工业自动化系统中抗晃电保护的协同控制研究
运维·网络·嵌入式硬件·物联网
ZStack开发者社区5 小时前
ZStack Cloud 5.5.0正式发布
运维·服务器·网络
草莓熊Lotso5 小时前
脉脉独家【AI创作者xAMA】|当豆包手机遭遇“全网封杀”:AI学会操作手机,我们的饭碗还保得住吗?
运维·开发语言·人工智能·智能手机·脉脉
鸽芷咕5 小时前
【2025年度总结】时光知味,三载同行:落笔皆是沉淀,前行自有光芒
linux·c++·人工智能·2025年度总结
羑悻的小杀马特5 小时前
指尖敲代码,笔尖写成长:2025年度总结与那些没说出口的碎碎念
linux·c++·博客之星·2025年度总结