From b1356c1b65390dbeb31751260d7b0985f69245b5 Mon Sep 17 00:00:00 2001 From: superconvert Date: Fri, 14 Oct 2022 13:15:23 +0000 Subject: [PATCH] update script --- 01_build_src.sh | 21 ++++++++++++++++++--- 02_build_img.sh | 21 +++++++++++++-------- 03_run_qemu.sh | 6 +++--- mk_xfce.sh | 18 ++++++++++++++++++ 4 files changed, 52 insertions(+), 14 deletions(-) diff --git a/01_build_src.sh b/01_build_src.sh index e68c5ef..b84b179 100755 --- a/01_build_src.sh +++ b/01_build_src.sh @@ -20,6 +20,7 @@ LINUX_SRC_URL=https://mirror.bjtu.edu.cn/kernel/linux/kernel/v5.x/linux-5.8.6.ta #GLIBC_SRC_URL=https://ftp.gnu.org/gnu/glibc/glibc-2.32.tar.bz2 GLIBC_SRC_URL=https://mirrors.ustc.edu.cn/gnu/glibc/glibc-2.27.tar.xz BUSYBOX_SRC_URL=https://busybox.net/downloads/busybox-1.34.1.tar.bz2 +PCIUTILS_SRC_URL=http://mj.ucw.cz/download/linux/pci/pciutils-3.8.0.tar.gz #GCC_SRC_URL=https://ftpmirror.gnu.org/gcc/gcc-7.5.0/gcc-7.5.0.tar.xz GCC_SRC_URL=https://mirrors.ustc.edu.cn/gnu/gcc/gcc-7.5.0/gcc-7.5.0.tar.xz #BINUTILS_SRC_URL=https://ftp.gnu.org/gnu/binutils/binutils-2.36.tar.xz @@ -37,6 +38,7 @@ cd source LINUX_SRC_NAME=$(download_src ${LINUX_SRC_URL}) GLIBC_SRC_NAME=$(download_src ${GLIBC_SRC_URL}) BUSYBOX_SRC_NAME=$(download_src ${BUSYBOX_SRC_URL}) +PCIUTILS_SRC_NAME=$(download_src ${PCIUTILS_SRC_URL}) GCC_SRC_NAME=$(download_src ${GCC_SRC_URL}) BINUTILS_SRC_NAME=$(download_src ${BINUTILS_SRC_URL}) cd .. @@ -51,6 +53,7 @@ mkdir -pv ${build_dir} LINUX_SRC_DIR=$(unzip_src ".tar.xz" ${LINUX_SRC_NAME}); echo "unzip ${LINUX_SRC_NAME} source code" GLIBC_SRC_DIR=$(unzip_src ".tar.xz" ${GLIBC_SRC_NAME}); echo "unzip ${GLIBC_SRC_NAME} source code" BUSYBOX_SRC_DIR=$(unzip_src ".tar.bz2" ${BUSYBOX_SRC_NAME}); echo "unzip ${BUSYBOX_SRC_NAME} source code" +PCIUTILS_SRC_DIR=$(unzip_src ".tar.gz" ${PCIUTILS_SRC_NAME}); echo "unzip ${PCIUTILS_SRC_NAME} source code" GCC_SRC_DIR=$(unzip_src ".tar.xz" ${GCC_SRC_NAME}); echo "unzip ${GCC_SRC_NAME} source code" BINUTILS_SRC_DIR=$(unzip_src ".tar.xz" ${BINUTILS_SRC_NAME}); echo "unzip ${BINUTILS_SRC_NAME} source code" @@ -297,18 +300,29 @@ if [ ! -d "glibc_install" ]; then --disable-werror \ --disable-werror \ CFLAGS="$CFLAGS" - make -j8 && make install -j8 DESTDIR=${glibc_install} && cd .. && cd .. + make -j8 && make install -j8 DESTDIR=${glibc_install} + cd .. && cd .. fi # 编译 busybox if [ ! -d "busybox_install" ]; then mkdir -pv busybox_install && cd ${BUSYBOX_SRC_DIR} && make distclean && make defconfig + # 屏蔽掉 lspci 这个自带的太简单 + sed -i "s/CONFIG_LSPCI=y/# CONFIG_LSPCI is not set/" .config # 静态编译 sed -i "s/# CONFIG_STATIC is not set/CONFIG_STATIC=y/g" .config sed -i "s|.*CONFIG_SYSROOT.*|CONFIG_SYSROOT=\"${glibc_install}\"|" .config sed -i "s|.*CONFIG_EXTRA_CFLAGS.*|CONFIG_EXTRA_CFLAGS=\"-I${linux_install}/include -I${glibc_install}/include -L${glibc_install}/usr/lib64 $CFLAGS\"|" .config # 环境变量 PATH 的设定,因为 busybox 的 init 会覆盖用户设置的 PATH,只能源码进行编译 sed -i "s|#define BB_ADDITIONAL_PATH \"\"|#define BB_ADDITIONAL_PATH \":/usr/local/sbin:/usr/local/bin\"|" include/libbb.h - make busybox -j8 && make CONFIG_PREFIX=${busybox_install} install && cd .. + make busybox -j8 && make CONFIG_PREFIX=${busybox_install} install + cd .. +fi + +# 编译 pciutils ( busybox 的 lspci 太简单 ) +if [ ! -d "pciutils_install" ]; then + mkdir -pv pciutils_install && cd ${PCIUTILS_SRC_DIR} + CFLAGS="-L${glibc_install}/lib64 $CFLAGS" make -j8 && make install -j8 DESTDIR=${pciutils_install} PREFIX=/usr + cd .. fi # 编译 gcc @@ -323,7 +337,8 @@ fi if [ ! -d "binutils_install" ]; then mkdir -pv binutils_install && cd ${BINUTILS_SRC_DIR} && make distclean ./configure --prefix=/usr - CFLAGS="-L${glibc_install}/lib64 $CFLAGS" make -j8 && make install -j8 DESTDIR=${binutils_install} && cd .. + CFLAGS="-L${glibc_install}/lib64 $CFLAGS" make -j8 && make install -j8 DESTDIR=${binutils_install} + cd .. fi cd .. diff --git a/02_build_img.sh b/02_build_img.sh index cd15728..9f00ae3 100755 --- a/02_build_img.sh +++ b/02_build_img.sh @@ -95,6 +95,9 @@ echo "${CYAN}--- build initrd ---${NC}" # 这种方法也可以 mkinitramfs -k -o ./${diskfs}/boot/initrd 4.14.9 # 利用 Busybox 采用脚本制作 init 脚本 https://blog.csdn.net/embeddedman/article/details/7721926 +# 光驱挂载 : /dev/cdrom 是 /dev/sr0 的软连接,也就是说 /dev/sr0 才是实际意义上的光驱。所以没有软连接, +# 照样可以挂载光驱。使用命令"mount /dev/sr0 /mnt/cdrom"便可以实现挂载。 + make_init() { cat<<"EOF">init @@ -110,7 +113,7 @@ mount -t ext3 /dev/sda1 /mnt # 关闭内核烦人的输出信息 echo 0 > /proc/sys/kernel/printk # 热插拔处理都交给 mdev -echo /sbin/mdev > /proc/sys/kernel/hotplug +# echo /sbin/mdev > /proc/sys/kernel/hotplug echo -e "\n\e[0;32mBoot took $(cut -d' ' -f1 /proc/uptime) seconds\e[0m" mkdir -p /dev/pts mount -t devpts devpts /dev/pts @@ -121,7 +124,7 @@ mount --move /proc /mnt/proc mount --move /tmp /mnt/tmp # 切换到真正的磁盘系统上 rootfs ---> diskfs export LD_LIBRARY_PATH="/lib:/lib64:/usr/lib:/usr/lib64:/usr/local/lib:/usr/local/lib64:/usr/lib/x86_64-linux-gnu" -exec switch_root -c /dev/console /mnt /sbin/init +exec switch_root /mnt /sbin/init EOF # /sbin/init [switch_root 执行] ---> /etc/inittab [定义了启动顺序] ---> @@ -169,6 +172,14 @@ cd .. #-------------------------------------------------------------- echo "${CYAN}--- build diskfs ---${NC}" cp rootfs/* ${diskfs} -r + +# 单独的 pciutils +cp ${pciutils_install}/* ${diskfs} -r +if [ -f "${diskfs}/usr/share/pci.ids.gz" ]; then + mkdir -pv ${diskfs}/usr/local/share + mv ${diskfs}/usr/share/pci.ids.gz ${diskfs}/usr/local/share/pci.ids.gz +fi + # 带有 gcc 编译器 if [ "${with_gcc}" = true ]; then echo "${RED} ... build with-gcc${NC}" @@ -177,12 +188,6 @@ if [ "${with_gcc}" = true ]; then fi rm -rf ${diskfs}/init ${diskfs}/lost+found -# lspci 显示厂商 ( 下面的是 ubuntu 的 ) -if [ -f "/usr/share/misc/pci.ids" ]; then - mkdir -p ${diskfs}/usr/share/misk - cp /usr/share/misc/pci.ids ${diskfs}/usr/share/misk/pci.ids -fi - # 测试用户登陆模式: root/123456 if [ "${with_login}" = true ]; then echo "${RED} ... build with-login${NC}" diff --git a/03_run_qemu.sh b/03_run_qemu.sh index 55cc7c6..df00ecd 100755 --- a/03_run_qemu.sh +++ b/03_run_qemu.sh @@ -92,7 +92,7 @@ else fi # 指定内存 -memory="-m 4G" +memory="-m 8G" # 主磁盘 disk="-drive format=raw,file=disk.img" @@ -105,10 +105,10 @@ logfile="-serial file:./qemu.log" network="-netdev tap,id=nd0,ifname=tap0,script=no,downscript=no -device e1000,netdev=nd0" # 显卡参数 需要编译 xf86-video-vmware, see mk_xfce.sh -display="-vga vmware" +display="-vga qxl" # 启动镜像 网络对应 run_nat.sh 里面的配置 ( -enable-kvm : vmware 里面 CPU 设置需要支持虚拟化 Intel VT-x/EPT 或 AMD-V/RVI ) # 命令 qemu-system-x86_64 -device help 可以查看支持哪些设备 -qemu-system-x86_64 -enable-kvm ${display} ${memory} ${disk} ${sdb_img} ${network} ${logfile} +qemu-system-x86_64 ${display} -device qxl ${memory} ${disk} ${sdb_img} ${network} ${logfile} # stop nat stop_nat diff --git a/mk_xfce.sh b/mk_xfce.sh index af1bf69..445f8db 100755 --- a/mk_xfce.sh +++ b/mk_xfce.sh @@ -142,12 +142,15 @@ XSERVER_SRC_URL=https://www.x.org/releases/individual/xserver/xorg-server-21.1.4 FONTUTIL_SRC_URL=https://www.x.org/releases/individual/font/font-util-1.3.3.tar.xz FONTMISC_SRC_URL=https://www.x.org/releases/individual/font/font-misc-misc-1.1.2.tar.bz2 XF86INPUT_SRC_URL=https://www.x.org/releases/individual/driver/xf86-input-libinput-1.2.1.tar.xz +XF86VIDEOATI_SRC_URL=https://www.x.org/releases/individual/driver/xf86-video-ati-19.1.0.tar.bz2 XF86VIDEOVESA_SRC_URL=https://www.x.org/releases/individual/driver/xf86-video-vesa-2.5.0.tar.bz2 +XF86VIDEOINTEL_SRC_URL=https://www.x.org/releases/individual/driver/xf86-video-intel-2.99.917.tar.bz2 XF86VIDEOQXL_SRC_URL=https://www.x.org/releases/individual/driver/xf86-video-qxl-0.1.5.tar.bz2 XF86VIDEOAMD_SRC_URL=https://www.x.org/releases/individual/driver/xf86-video-amd-2.7.7.7.tar.bz2 XF86VIDEOFBDEV_SRC_URL=https://www.x.org/releases/individual/driver/xf86-video-fbdev-0.5.0.tar.bz2 XF86VIDEOVMWARE_SRC_URL=https://www.x.org/releases/individual/driver/xf86-video-vmware-13.3.0.tar.bz2 XF86VIDEOAMDGPU_SRC_URL=https://www.x.org/releases/individual/driver/xf86-video-amdgpu-21.0.0.tar.bz2 +XF86VIDEODUMMY_SRC_URL=https://www.x.org/releases/individual/driver/xf86-video-dummy-0.4.0.tar.xz XKBDATA_SRC_URL=https://www.x.org/releases/individual/data/xkbdata-1.0.1.tar.bz2 XKBDCFG_SRC_URL=https://www.x.org/releases/individual/data/xkeyboard-config/xkeyboard-config-2.36.tar.xz @@ -264,7 +267,10 @@ LIBWACOM_SRC_NAME=$(download_src ${LIBWACOM_SRC_URL}) LIBINPUT_SRC_NAME=$(download_src ${LIBINPUT_SRC_URL}) SPICEPROT_SRC_NAME=$(download_src ${SPICEPROT_SRC_URL}) XF86INPUT_SRC_NAME=$(download_src ${XF86INPUT_SRC_URL}) +XF86VIDEOATI_SRC_NAME=$(download_src ${XF86VIDEOATI_SRC_URL}) XF86VIDEOVESA_SRC_NAME=$(download_src ${XF86VIDEOVESA_SRC_URL}) +XF86VIDEOINTEL_SRC_NAME=$(download_src ${XF86VIDEOINTEL_SRC_URL}) +XF86VIDEODUMMY_SRC_NAME=$(download_src ${XF86VIDEODUMMY_SRC_URL}) XF86VIDEOQXL_SRC_NAME=$(download_src ${XF86VIDEOQXL_SRC_URL}) XF86VIDEOAMD_SRC_NAME=$(download_src ${XF86VIDEOAMD_SRC_URL}) XF86VIDEOFBDEV_SRC_NAME=$(download_src ${XF86VIDEOFBDEV_SRC_URL}) @@ -394,7 +400,10 @@ LIBEVDEV_SRC_DIR=$(unzip_src ".tar.xz" ${LIBEVDEV_SRC_NAME}); echo "unzip ${LIBE LIBINPUT_SRC_DIR=$(unzip_src ".tar.xz" ${LIBINPUT_SRC_NAME}); echo "unzip ${LIBINPUT_SRC_NAME} source code" SPICEPROT_SRC_DIR=$(unzip_src ".tar.xz" ${SPICEPROT_SRC_NAME}); echo "unzip ${SPICEPROT_SRC_NAME} source code" XF86INPUT_SRC_DIR=$(unzip_src ".tar.xz" ${XF86INPUT_SRC_NAME}); echo "unzip ${XF86INPUT_SRC_NAME} source code" +XF86VIDEOATI_SRC_DIR=$(unzip_src ".tar.bz2" ${XF86VIDEOATI_SRC_NAME}); echo "unzip ${XF86VIDEOATI_SRC_NAME} source code" XF86VIDEOVESA_SRC_DIR=$(unzip_src ".tar.bz2" ${XF86VIDEOVESA_SRC_NAME}); echo "unzip ${XF86VIDEOVESA_SRC_NAME} source code" +XF86VIDEOINTEL_SRC_DIR=$(unzip_src ".tar.bz2" ${XF86VIDEOINTEL_SRC_NAME}); echo "unzip ${XF86VIDEOINTEL_SRC_NAME} source code" +XF86VIDEODUMMY_SRC_DIR=$(unzip_src ".tar.xz" ${XF86VIDEODUMMY_SRC_NAME}); echo "unzip ${XF86VIDEODUMMY_SRC_NAME} source code" XF86VIDEOQXL_SRC_DIR=$(unzip_src ".tar.bz2" ${XF86VIDEOQXL_SRC_NAME}); echo "unzip ${XF86VIDEOQXL_SRC_NAME} source code" XF86VIDEOAMD_SRC_DIR=$(unzip_src ".tar.bz2" ${XF86VIDEOAMD_SRC_NAME}); echo "unzip ${XF86VIDEOAMD_SRC_NAME} source code" XF86VIDEOFBDEV_SRC_DIR=$(unzip_src ".tar.bz2" ${XF86VIDEOFBDEV_SRC_NAME}); echo "unzip ${XF86VIDEOFBDEV_SRC_NAME} source code" @@ -864,11 +873,20 @@ llvm_build() { meson_build libinput ${LIBINPUT_SRC_DIR} # xf86input ( libinput 的封装,使 libinput 用于 X 上的输入设备代替其他用于 X 输入的软件包即以 xf86-input- 为前缀的软件包 ) common_build xf86input ${XF86INPUT_SRC_DIR} + # xf86videoati ( 为了虚拟机上能显示图形,我们把常用的显卡驱动全部编译了 ) + # common_build xf86videoati ${XF86VIDEOATI_SRC_DIR} # xf86videovesa ( vesa是一个支持大部分显卡的通用驱动,不提供任何 2D 和 3D 加速功能 也可以 apt install libgl1-mesa-dri ) common_build xf86videovesa ${XF86VIDEOVESA_SRC_DIR} + # xf86videointel + # common_build xf86videointel ${XF86VIDEOINTEL_SRC_DIR} + # xf86videodummy + common_build xf86videodummy ${XF86VIDEODUMMY_SRC_DIR} # xf86videoamd ( qemu 要模拟 vmware 的显卡,需要编译此工程 -vga vmware ) # common_build xf86videoamd ${XF86VIDEOAMD_SRC_DIR} # xf86videoqxl ( 需要: spice_protocol, qemu 要模拟 vmware 的显卡,需要编译此工程 -vga vmware ) + if [ ! -f ".xf86videoqxl" ]; then + sed -i "s/value.bool/value.boolean/" ${XF86VIDEOQXL_SRC_DIR}/src/qxl_option_helpers.c + fi common_build xf86videoqxl ${XF86VIDEOQXL_SRC_DIR} # xf86videofbdev ( qemu 要模拟 vmware 的显卡,需要编译此工程 -vga vmware ) common_build xf86videofbdev ${XF86VIDEOFBDEV_SRC_DIR}