update some script

This commit is contained in:
superconvert 2022-10-24 22:14:20 +08:00
parent e9c9c533bf
commit b4153d2f65
5 changed files with 79 additions and 44 deletions

View File

@ -10,11 +10,10 @@ fi
#-----------------------------------------------
#
# 导入公共变量 ( xfce4 需要 5.4.0 的内核 )
# 导入公共变量 ( xfce4 需要 5.4.0 的内核, glibc 必须为 2.27 否则 xfce4 相关的编译有问题 )
#
#-----------------------------------------------
. ./common.sh
#LINUX_SRC_URL=https://kernel.org/pub/linux/kernel/v4.x/linux-4.14.9.tar.xz
LINUX_SRC_URL=https://mirror.bjtu.edu.cn/kernel/linux/kernel/v5.x/linux-5.8.6.tar.xz
#GLIBC_SRC_URL=https://ftp.gnu.org/gnu/glibc/glibc-2.32.tar.bz2
@ -31,8 +30,6 @@ 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
BINUTILS_SRC_URL=https://mirrors.ustc.edu.cn/gnu/binutils/binutils-2.36.tar.xz
export CFLAGS="-Os -s -fno-stack-protector -fomit-frame-pointer -U_FORTIFY_SOURCE"
#----------------------------------------------
#
# 下载源码
@ -59,7 +56,6 @@ cd ..
#
#---------------------------------------------
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"
@ -90,6 +86,8 @@ fi
# 编译源码
#
#---------------------------------------------
export CFLAGS="-Os -s -fno-stack-protector -fomit-frame-pointer -U_FORTIFY_SOURCE"
cd ${build_dir}
# 编译内核, 最终所有模块都装到目录 /lib/modules/5.8.6
@ -287,7 +285,8 @@ if [ ! -d "linux_install" ]; then
make modules -j8
#cd linux-5.8.6 && make x86_64_defconfig && make bzImage -j8 && make modules && make modules_install && cd ..
make INSTALL_HDR_PATH=${linux_install} headers_install -j8
make modules_install INSTALL_MOD_PATH=${linux_install} -j8 && cp arch/x86_64/boot/bzImage ${linux_install} && cd ..
make modules_install INSTALL_MOD_PATH=${linux_install} -j8 && cp arch/x86_64/boot/bzImage ${linux_install} || exit
cd ..
fi
# 编译glibc
@ -301,7 +300,7 @@ if [ ! -d "glibc_install" ]; then
--disable-werror \
--disable-werror \
CFLAGS="$CFLAGS"
make -j8 && make install -j8 DESTDIR=${glibc_install}
make -j8 && make install -j8 DESTDIR=${glibc_install} || exit
cd .. && cd ..
fi
@ -317,21 +316,21 @@ if [ ! -d "busybox_install" ]; then
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
make busybox -j8 && make CONFIG_PREFIX=${busybox_install} install || exit
cd ..
fi
# 编译 lshw ( 调试方便 )
if [ ! -d "lshw_install" ]; then
mkdir -pv lshw_install && cd ${LSHW_SRC_DIR}
CFLAGS="-L${glibc_install}/lib64 $CFLAGS" make -j8 && make install -j8 DESTDIR=${lshw_install} PREFIX=/usr
CFLAGS="-L${glibc_install}/lib64 $CFLAGS" make -j8 && make install -j8 DESTDIR=${lshw_install} PREFIX=/usr || exit
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
CFLAGS="-L${glibc_install}/lib64 $CFLAGS" make -j8 && make install -j8 DESTDIR=${pciutils_install} PREFIX=/usr || exit
cd ..
fi
@ -339,8 +338,7 @@ fi
if [ ! -d "lsof_install" ]; then
mkdir -pv lsof_install && cd ${LSOF_SRC_DIR}
./Configure linux -n
CFLAGS="-L${glibc_install}/lib64 $CFLAGS" make -j8
mkdir -pv ${lsof_install}/usr/bin && cp ./lsof ${lsof_install}/usr/bin
CFLAGS="-L${glibc_install}/lib64 $CFLAGS" make -j8 && mkdir -pv ${lsof_install}/usr/bin && cp ./lsof ${lsof_install}/usr/bin || exit
cd ..
fi
@ -348,7 +346,7 @@ fi
if [ ! -d "strace_install" ]; then
mkdir -pv strace_install && cd ${STRACE_SRC_DIR}
./configure --prefix=/usr --enable-mpers=no
CFLAGS="-L${glibc_install}/lib64 $CFLAGS" make -j8 && make install -j8 DESTDIR=${strace_install} PREFIX=/usr
CFLAGS="-L${glibc_install}/lib64 $CFLAGS" make -j8 && make install -j8 DESTDIR=${strace_install} PREFIX=/usr || exit
cd ..
fi
@ -356,11 +354,11 @@ fi
if [ ! -d "openssl_install" ]; then
mkdir -pv openssl_install && cd ${OPENSSL_SRC_DIR}
./config --prefix=/usr shared
CFLAGS="-L${glibc_install}/lib64 $CFLAGS" make -j8 && make install -j8 DESTDIR=${openssl_install} PREFIX=/usr
CFLAGS="-L${glibc_install}/lib64 $CFLAGS" make -j8 && make install -j8 DESTDIR=${openssl_install} PREFIX=/usr || exit
cd ..
fi
# 编译 openssh
# 编译 openssh ( 需要 openssl )
if [ ! -d "openssh_install" ]; then
mkdir -pv openssh_install && cd ${OPENSSH_SRC_DIR}
./configure --prefix=/usr --sysconfdir=/etc/ssh --with-ssl-dir=${openssl_install}/usr/ --without-openssl-header-check
@ -403,7 +401,7 @@ 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}
CFLAGS="-L${glibc_install}/lib64 $CFLAGS" make -j8 && make install -j8 DESTDIR=${binutils_install} || exit
cd ..
fi

View File

@ -1,6 +1,10 @@
#!/bin/sh
#----------------------------------------------
#
# 导入公共环境
#
#----------------------------------------------
. ./common.sh
#----------------------------------------------
@ -31,7 +35,7 @@ losetup -o 1048576 ${loop_dev} disk.img
# 对磁盘进行格式化
mkfs.ext3 ${loop_dev}
# 如果制作的 disk.img 转换为 qemu-img convert disk.img -f raw -O vmdk out.vmdk, vmware 的磁盘类型一定设置为 SATA ,否则,启动失败
# 如果制作的 disk.img
diskfs="diskfs"
# 挂载磁盘到本地目录
mkdir -pv ${diskfs}
@ -57,6 +61,7 @@ mkdir -pv rootfs/sbin
mkdir -pv rootfs/proc
mkdir -pv rootfs/root
mkdir -pv rootfs/lib64
mkdir -pv rootfs/var/run
mkdir -pv rootfs/lib/modules
# 拷贝内核镜像
@ -69,6 +74,7 @@ rm -rf rootfs/var/db
rm -rf rootfs/share
rm -rf rootfs/usr/share
find rootfs/ -name "*.a" -exec rm -rf {} \;
# 编译的镜像带有 gcc 编译器
if [ "${with_gcc}" = false ]; then
rm -rf rootfs/usr/include
@ -103,18 +109,23 @@ make_init() {
cat<<"EOF">init
#!/bin/sh
# 必须首先挂载,否则 mdev 不能正常工作
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
# 关闭内核烦人的输出信息
echo 0 > /proc/sys/kernel/printk
# 热插拔处理都交给 mdev
# 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
@ -123,10 +134,11 @@ mount --move /dev /mnt/dev
mount --move /sys /mnt/sys
mount --move /proc /mnt/proc
mount --move /tmp /mnt/tmp
# 切换到真正的磁盘系统上 rootfs ---> diskfs
# 因为 busybox 的 init 会重置环境变量,因此需要加动这里
# 因为 busybox 的 init 会重置环境变量 PATH 等,因此需要放到这里加载
export LD_LIBRARY_PATH="/lib:/lib64:/usr/lib:/usr/lib64:/usr/local/lib:/usr/local/lib64:/usr/lib/x86_64-linux-gnu"
# 切换到真正的文件系统
# 切换到真正的磁盘系统上 rootfs ---> diskfs 切换到真正的文件系统
exec switch_root /mnt /sbin/init
EOF
@ -144,23 +156,22 @@ make_init
# mknod -m 600 dev/console c 5 1
# mknod -m 644 dev/null c 1 3
# mknod -m 640 dev/sda1 b 8 1
# xfce 需要显卡设备
# mknod -m 664 dev/dri/card0 c 226 0
# 指定了利用 /etc/init.d/rcS 启动
cat<<"EOF">etc/inittab
# 启动 syslogd
# 启动 syslogd ( 日志系统 )
::sysinit:/bin/echo "starting syslogd ... ..."
::sysinit:/sbin/syslogd
::sysinit:/sbin/klogd
# 启动 udevd 服务,保证鼠标设备能正常监视,否则键盘不能使用
# 启动 udevd 服务,保证鼠标设备能正常监视,否则桌面系统下键盘不能使用
::sysinit:/bin/echo "starting udevd ... ..."
::sysinit:/usr/sbin/udevd --daemon
::sysinit:/usr/sbin/udevadm trigger
::sysinit:/usr/sbin/udevadm settle
# 基本启动信息都放到这个脚本里
::sysinit:echo "sysinit ++++++++++++++++++++++++++++++++++++++"
::sysinit:/etc/init.d/rcS
::sysinit:echo "sysinit ++++++++++++++++++++++++++++++++++++++"
@ -173,6 +184,7 @@ cat<<"EOF">etc/inittab
# this yourself...
#
# Start an "askfirst" shell on the console (whatever that may be) -f root 自动登录
# 一定要加 tty1 ,否则登录时,会提示 : root login on 'UNKNOWN'
tty1::respawn:-/bin/login -f root
# Start an "askfirst" shell on /dev/tty2-4
@ -200,6 +212,7 @@ tty5::respawn:/sbin/getty 38400 tty6
::shutdown:/sbin/swapoff -a
EOF
# 制作 initrd 文件系统
find . | cpio -R root:root -H newc -o | gzip -9 > ../${diskfs}/boot/initrd
echo "${GREEN}+++ build initrd ok +++${NC}"
cd ..
@ -270,21 +283,25 @@ if [ "${with_xfce}" = true ]; then
if [ -f "${xfce_install}/usr/local/lib/libffi.so.8" ]; then
cp ${xfce_install}/usr/local/lib/libffi.so.8 ${xfce_install}/usr/local/lib/libffi.so.6
fi
# dbus 用户添加
echo "video:x:44:" >> ${diskfs}/etc/group
echo "messagebus:x:107:" >> ${diskfs}/etc/group
echo "messagebus:x:103:107::/nonexistent:/usr/sbin/nologin" >> ${diskfs}/etc/passwd
# dbus 启动需要这个,否则 upowerd 就不能正常工作
cp ${xfce_install}/usr/share/dbus-1/* ${xfce_install}/usr/local/share/dbus-1/ -r
# dbus 启动脚本
# dbus-daemon --system --address=systemd: --nofork --nopidfile --systemd-activation --syslog-only
# dbus-daemon --session --address=systemd: --nofork --nopidfile --systemd-activation --syslog-only
# dbus-daemon --config-file=/usr/share/defaults/at-spi2/accessibility.conf --nofork --print-address 3
# dbus-daemon --system --address=systemd: --nofork --nopidfile --systemd-activation --syslog-only
# dbus-daemon --session --address=systemd: --nofork --nopidfile --systemd-activation --syslog-only
# dbus-daemon --config-file=/usr/share/defaults/at-spi2/accessibility.conf --nofork --print-address 3
# 常用的 dbus 命令
# 列出所有的dbus服务 :
# dbus-send --system --print-reply --dest=org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus.ListActivatableNames
# UPower 的dbus服务 :
# dbus-send --print-reply --system --dest=org.freedesktop.UPower /org/freedesktop/UPower org.freedesktop.UPower.EnumerateDevices
# 列出所有的dbus服务 :
# dbus-send --system --print-reply --dest=org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus.ListActivatableNames
# UPower 的dbus服务 :
# dbus-send --print-reply --system --dest=org.freedesktop.UPower /org/freedesktop/UPower org.freedesktop.UPower.EnumerateDevices
# 产生 xfce 启动脚本,进入系统后,手工执行这个就能拉起桌面
echo "if [ -f "/swapfile" ]; then" > ${diskfs}/xfce.sh
echo " dd if=/dev/zero of=/swapfile bs=1M count=2048" >> ${diskfs}/xfce.sh
echo " mkswap /swapfile" >> ${diskfs}/xfce.sh
@ -295,22 +312,18 @@ if [ "${with_xfce}" = true ]; then
echo "dbus-daemon --system --nopidfile --systemd-activation" >> ${diskfs}/xfce.sh
echo "xinit /xinitrc -- /usr/local/bin/Xorg :10" >> ${diskfs}/xfce.sh
chmod +x ${diskfs}/xfce.sh ${diskfs}/xinitrc
# 添加 machine-id
mkdir -p ${diskfs}/usr/local/var/lib/dbus
echo "2add25d2f5994832ba171755bc21f9fe" > ${diskfs}/etc/machine-id
echo "2add25d2f5994832ba171755bc21f9fe" > ${diskfs}/usr/local/var/lib/dbus/machine-id
# 这些本来需要编译完成,目前暂且拷贝
cp /usr/lib/x86_64-linux-gnu/libLLVM-10.so.1 build/xfce_install/usr/lib/x86_64-linux-gnu/
# cp /usr/lib/x86_64-linux-gnu/libffi.so.6 build/xfce_install/usr/lib/x86_64-linux-gnu/
# 拷贝 xfce4 到镜像目录
cp ${xfce_install}/* ${diskfs} -r -n
# xfce 需要系统内执行下面两句,保证键盘数据存在 Xorg :10 才能执行成功
# 1. 键盘数据
# rm /usr/local/share/X11/xkb -rf
# ln -s /usr/share/X11/xkb /usr/local/share/X11
# 2. 需要改动 libpcre.so.1 ---> libpcre.so.3
# 3. xfce4-session 需要 libuuid.so
# 删除冗余文件,防止后续编译很多警告
# 依赖版本 libpcre.so.3
if [ -f "${xfce_install}/usr/local/lib/libpcre.so.1" ]; then
rm ${xfce_install}/usr/local/lib/libpcre.so.3 -rf
@ -350,6 +363,7 @@ nameserver 8.8.8.8
nameserver 114.114.114.114
EOF
# 生成 /etc/fstab 挂载文件
cat -> ${diskfs}/etc/fstab << EOF
# <file system> <dir> <type> <options> <dump> <pass>
proc /proc proc defaults 0 0
@ -370,6 +384,8 @@ title=$(cat<<EOF
\e[0m
EOF
)
# 生成 /etc/init.d/rcS 脚本
mkdir -pv ${diskfs}/etc/init.d
cat - > ${diskfs}/etc/init.d/rcS << EOF
#!/bin/sh
@ -379,10 +395,11 @@ echo -e "\n“${title}”\n"
cd /lib/modules && insmod hello_world.ko
# dns 测试 busybox 必须动态编译 动态编译 glibc 已经集成 dns 功能
# qemu
# qemu 网卡设置(调试方便)
# ifconfig eth0 192.168.100.6 && ifconfig eth0 up
# route add default gw 192.168.100.1
# vmware
# vmware 网卡设置 ( 调试方便 )
ifconfig eth0 192.168.222.195 && ifconfig eth0 up
route add default gw 192.168.222.2
@ -441,7 +458,7 @@ losetup -d ${loop_dev}
#---------------------------------------------------------------
#
# 转换为 vmware 格式
# 转换为 vmware 格式, 虚拟机的磁盘类型一定设置为 SATA ,否则启动失败
#
#---------------------------------------------------------------
qemu-img convert disk.img -f raw -O vmdk disk.vmdk

View File

@ -31,4 +31,5 @@ export PS1 HOSTNAME
EOF
# 重新生成 inittab 文件
sed -i "/::sysinit:\/etc\/init.d\/rcS/a\::sysinit:\/bin\/hostname -F \/etc\/hostname" ${diskfs}/etc/inittab
sed -i "1i\::sysinit:\/bin\/hostname -F \/etc\/hostname" ${diskfs}/etc/inittab
sed -i "1i\# 加载主机名称" ${diskfs}/etc/inittab

View File

@ -3,6 +3,7 @@
# 导入公共环境
. ./common.sh
# 对指定的目录进行 strip
strip_dir() {
for file in `ls $1`
do
@ -32,7 +33,25 @@ strip_dir ${glibc_install}
# strip busybox
rm -rf ${busybox_install}/linuxrc
strip ${busybox_install}/bin/busybox
strip_dir ${busybox_install}/bin/busybox
# strip lshw
strip_dir ${lshw_install}
# strip pciutils_install
strip_dir ${pciutils_install}
# strip lsof
strip_dir ${lsof_install}
# strip strace
strip_dir ${strace_install}
# strip openssl
strip_dir ${openssl_install}
# strip openssh
strip_dir ${openssh_install}
# strip gcc
#rm -rf work/libgcc_install/usr/share

View File

@ -806,7 +806,7 @@ llvm_build() {
meson_build pango ${PANGO_SRC_DIR}
# 编译基础库 ( 这些都是系统库,新系统需要集成 )
if [ "${with_xfce}" = true ] && [ "$1" = "img" ]; then
# 编译 llvm ( swrast 依赖此库 )
# 编译 llvm ( swrast 依赖此库,可以加大 swap 分区,编译时对内存要求极高 )
# llvm_build llvm ${LLVM_SRC_DIR}
# 编译 expat
common_build expat ${EXPAT_SRC_DIR}