From a4d14c12f3e2a89b4a8bd20a2ea2c65ddd3e8332 Mon Sep 17 00:00:00 2001 From: superconvert Date: Wed, 3 Aug 2022 22:19:42 +0800 Subject: [PATCH] 1. fix can not ping issue 2. add xorg compile --- 01_build_src.sh | 5 +++++ 02_build_img.sh | 17 ++++++++++----- 03_run_qemu.sh | 12 +++++++---- cat_img.sh | 1 + common.sh | 4 ++++ mk_sdb.sh | 4 ++++ mk_xorg.sh | 57 ++++++++++++++++++++++++++++++++++++++++++++++--- 7 files changed, 88 insertions(+), 12 deletions(-) diff --git a/01_build_src.sh b/01_build_src.sh index 66f4d6c..4e3c678 100755 --- a/01_build_src.sh +++ b/01_build_src.sh @@ -197,4 +197,9 @@ fi cd .. +# 编译 xorg-server +if [ "${with_xorg}" = true ]; then + ./mk_xorg.sh +fi + echo "Run the next script: 02_build_img.sh" diff --git a/02_build_img.sh b/02_build_img.sh index 49857c5..cdffaed 100755 --- a/02_build_img.sh +++ b/02_build_img.sh @@ -123,10 +123,10 @@ make_init() { cat<<"EOF">init #!/bin/sh # 必须首先挂载,否则 mdev 不能正常工作 -mount -t sysfs none /sys -mount -t proc none /proc -mount -t devtmpfs none /dev -mount -t tmpfs none /tmp -o mode=1777 +mount -t sysfs sysfs /sys +mount -t proc proc /proc +mount -t devtmpfs udev /dev +mount -t tmpfs tmpfs /tmp -o mode=1777 # 必须挂载一下,否则下面的 mount 不上 mdev -s mount -t ext3 /dev/sda1 /mnt @@ -136,7 +136,7 @@ echo 0 > /proc/sys/kernel/printk 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 none /dev/pts +mount -t devpts devpts /dev/pts # 切换之前,修改 mount 路径 mount --move /dev /mnt/dev mount --move /sys /mnt/sys @@ -224,6 +224,13 @@ nameserver 8.8.8.8 nameserver 114.114.114.114 EOF +cat -> ${diskfs}/etc/fstab << EOF +# +proc /proc proc defaults 0 0 +tmpfs /tmp tmpfs defaults 0 0 +sysfs /sys sysfs defaults 0 0 +EOF + # 生成 /etc/init.d/rcS 文件 title=$(cat<dnsmasq.conf strict-order @@ -70,11 +69,10 @@ dhcp-hostsfile=/var/lib/libvirt/dnsmasq/default.hostsfile addn-hosts=/var/lib/libvirt/dnsmasq/default.addnhosts EOF /usr/sbin/dnsmasq --conf-file=./dnsmasq.conf - } stop_dns() { - # 杀掉 dhcp 服务 + # 停止 dhcp 服务 killall dnsmasq } @@ -95,10 +93,16 @@ else sdb_img="-hdb extra.img" fi -rm -rf ./qemu.log +# 主磁盘 disk="-drive format=raw,file=disk.img" + +# grub 启动参数必须加上 console=ttyS0 +rm -rf ./qemu.log logfile="-serial file:./qemu.log" + +# 网络参数 network="-netdev tap,id=nd0,ifname=tap0,script=no,downscript=no -device e1000,netdev=nd0" + # 启动镜像 网络对应 run_nat.sh 里面的配置 qemu-system-x86_64 ${disk} ${sdb_img} ${network} ${logfile} diff --git a/cat_img.sh b/cat_img.sh index 2a31c8d..c9df1d5 100755 --- a/cat_img.sh +++ b/cat_img.sh @@ -8,6 +8,7 @@ mkdir -p ./mnt1 mount -t ext3 ${loop_dev} ./mnt1 echo "/ ---------------------------------------" du ./mnt1 -h +ls ./mnt1/etc echo "lib -------------------------------------" find ./mnt1 -name "*.a" -exec du -h {} \; umount ./mnt1 diff --git a/common.sh b/common.sh index 330d880..a22ff2c 100755 --- a/common.sh +++ b/common.sh @@ -4,6 +4,9 @@ core_num=`nproc` # 是否开启 gcc with_gcc=false +# 是否开启 xorg +with_org=false + # 是否挂载第二块硬盘 with_sdb=false @@ -19,6 +22,7 @@ glibc_install=${build_dir}"/glibc_install" busybox_install=${build_dir}"/busybox_install" gcc_install=${build_dir}"/gcc_install" binutils_install=${build_dir}"/binutils_install" +xorg_install=${build_dir}"/xorg_install" # 从完整路径获取文件名 file_name() { diff --git a/mk_sdb.sh b/mk_sdb.sh index 85faa25..cdb0024 100755 --- a/mk_sdb.sh +++ b/mk_sdb.sh @@ -6,6 +6,10 @@ # #---------------------------------------------- +if [ -f "extra.img" ]; then + exit +fi + echo "${CYAN}开始制作磁盘...${NC}" # 创建磁盘 64M diff --git a/mk_xorg.sh b/mk_xorg.sh index 402b713..daf4c03 100755 --- a/mk_xorg.sh +++ b/mk_xorg.sh @@ -1,6 +1,57 @@ #!/bin/sh -wget https://www.x.org/archive/individual/xserver/xorg-server-1.20.11.tar.bz2 -tar xf xorg-server-1.20.11.tar.bz2 -C ./ +# 预装工具 apt install xutils-dev libtool m4 pkg-config xtrans-dev libpixman-1-dev libdrm-dev libx11-dev libgl-dev libgcrypt-dev libxkbfile-dev libxfont-dev libpciaccess-dev libepoxy-dev libgbm-dev libegl1-mesa-dev -y -cd xorg-server-1.20.11 && ./autogen.sh + +#----------------------------------------------- +# +# 导入公共变量 +# +#----------------------------------------------- +. ./common.sh + +XORG_SRC_URL=https://www.x.org/archive/individual/xserver/xorg-server-1.20.11.tar.bz2 + +#---------------------------- +# +# 下载源码 +# +#---------------------------- +mkdir -pv source +cd source + +XORG_SRC_NAME=$(file_name ${XORG_SRC_URL}) +if [ ! -f ${XORG_SRC_NAME} ]; then + wget $XORG_SRC_URL +fi + +cd .. + +#--------------------------- +# +# 解压源码 +# +#--------------------------- +mkdir -pv ${build_dir} + +XORG_SRC_DIR=${build_dir}"/"$(file_dirname ${XORG_SRC_NAME} .tar.bz2) +if [ ! -d ${XORG_SRC_DIR} ]; then + echo "unzip ${XORG_SRC_NAME} source code" + tar xf source/${XORG_SRC_NAME} -C ${build_dir} +fi + +#--------------------------------------------- +# +# 编译源码 +# +#--------------------------------------------- +cd ${build_dir} + +# 编译 +if [ ! -d "xorg_install" ]; then + mkdir -pv xorg_install && cd ${XORG_SRC_DIR} && make distclean && ./autogensh + ./configure --prefix=/usr + CFLAGS="-L${glibc_install}/lib64 $CFLAGS" make -j8 && make install -j8 DESTDIR=${xorg_install} && cd .. +fi + +cd ..