diff --git a/02_build_img.sh b/02_build_img.sh index bcef7a3..49857c5 100755 --- a/02_build_img.sh +++ b/02_build_img.sh @@ -163,12 +163,13 @@ make_init # 指定了利用 /etc/init.d/rcS 启动 cat<<"EOF">etc/inittab -::sysinit:echo "sysinit 1++++++++++++++++++++++++++++++++++++++" -::sysinit:/etc/init.d/rcS -::sysinit:echo "sysinit 2++++++++++++++++++++++++++++++++++++++" ::restart:/sbin/init ::ctrlaltdel:/sbin/reboot ::shutdown:/bin/umount -a -r +::shutdown:/sbin/swapoff -a +::sysinit:echo "sysinit 1++++++++++++++++++++++++++++++++++++++" +::sysinit:/etc/init.d/rcS +::sysinit:echo "sysinit 2++++++++++++++++++++++++++++++++++++++" tty1::once:echo "hello smart-os tty1" tty1::respawn:/bin/sh tty2::once:echo "hello smart-os tty2" @@ -196,6 +197,12 @@ if [ "${with_gcc}" = true ]; then fi rm -rf ${diskfs}/init ${diskfs}/lost+found +# 测试用户登陆模式: root/123456 +if [ "${with_login}" = true ]; then + echo "${RED} with-login --- it's an exciting time ${NC}" + ./mk_login.sh ${diskfs} +fi + # 我们测试驱动, 制作的镜像启动后,我们进入此目录 insmod hello_world.ko 即可 ./mk_drv.sh $(pwd)/${diskfs}/lib/modules # 编译网卡驱动 ( 目前版本内核已集成 e1000 ) @@ -211,6 +218,12 @@ menuentry "smart-os" { } EOF +# 生成 /etc/resolv.conf 文件 +cat -> ${diskfs}/etc/resolv.conf << EOF +nameserver 8.8.8.8 +nameserver 114.114.114.114 +EOF + # 生成 /etc/init.d/rcS 文件 title=$(cat<> /etc/resolv.conf # exec 执行 /etc/init.d/rc.local 脚本 EOF diff --git a/03_run_qemu.sh b/03_run_qemu.sh index d6e1850..469a404 100755 --- a/03_run_qemu.sh +++ b/03_run_qemu.sh @@ -1,5 +1,10 @@ #!/bin/sh +#--------------------- +# 初始化公共环境 +#--------------------- +. ./common.sh + #--------------------- # 停掉 NAT #--------------------- @@ -74,18 +79,22 @@ stop_dns() { #---------------------------------------------- start_nat -rm -rf ./qemu.log -# 启动镜像 网络对应 run_nat.sh 里面的配置 -qemu-system-x86_64 -serial file:./qemu.log -drive format=raw,file=disk.img -netdev tap,id=nd0,ifname=tap0 -device e1000,netdev=nd0 - -# stop nat -stop_nat - #---------------------------------------------------- # # 多硬盘测试 -hdb extra.img # #---------------------------------------------------- -# ./mk_sdb.sh -# qemu-system-x86_64 -drive format=raw,file=disk.img -hdb extra.img +if [ "${with_sdb}" = false ]; then + sdb_img="" +else + ./mk_sdb.sh + sdb_img="-hdb extra.img" +fi +rm -rf ./qemu.log +# 启动镜像 网络对应 run_nat.sh 里面的配置 +qemu-system-x86_64 -drive format=raw,file=disk.img ${sdb_img} -netdev tap,id=nd0,ifname=tap0 -device e1000,netdev=nd0 +#qemu-system-x86_64 -serial file:./qemu.log -drive format=raw,file=disk.img -netdev tap,id=nd0,ifname=tap0 -device e1000,netdev=nd0 + +# stop nat +stop_nat diff --git a/common.sh b/common.sh index e16ec7d..330d880 100755 --- a/common.sh +++ b/common.sh @@ -4,6 +4,12 @@ core_num=`nproc` # 是否开启 gcc with_gcc=false +# 是否挂载第二块硬盘 +with_sdb=false + +# 是否登陆模式 +with_login=false + # 编译工程目录 build_dir=`pwd`"/build" diff --git a/mk_login.sh b/mk_login.sh new file mode 100755 index 0000000..058f745 --- /dev/null +++ b/mk_login.sh @@ -0,0 +1,40 @@ +#!/bin/sh + +diskfs=$1 + +# 用户组文件 +cat<${diskfs}/etc/group +root:x:0:root +EOF + +# 用户密码文件 +cat<${diskfs}/etc/passwd +root:x:0:0:root:/:/bin/sh +EOF + +# 用户 shadow 文件 +cat<${diskfs}/etc/shadow +root:\$1\$abcdefgh\$KJHEbEnUJaxWv269o9nH60:1:0:99999:7::: +EOF + +# 用户 hostname 文件 +cat<${diskfs}/etc/hostname +localhost +EOF + +# 用户 profile 文件 +cat<${diskfs}/etc/profile +HOSTNAME=$(/bin/hostname -F /etc/hostname) +PS1="[\u@\h \w]\# " +export PS1 HOSTNAME +EOF + +cat<${diskfs}/etc/inittab +::sysinit:/bin/hostname -F /etc/hostname +::sysinit:/etc/init.d/rcS +tty0::respawn:-/bin/login +::restart:/sbin/init +::ctrlaltdel:/sbin/reboot +::shutdown:/bin/umount -a -r +::shutdown:/sbin/swapoff -a +EOF diff --git a/mk_xorg.sh b/mk_xorg.sh new file mode 100755 index 0000000..402b713 --- /dev/null +++ b/mk_xorg.sh @@ -0,0 +1,6 @@ +#!/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