标签:ott ima cut aliyun apt xorg export fun 好的
本文关键字:debootstrap从jessie升级到buster,将git当成debian源
在本系列《7》中,我们尝试在dibuilder.sh中整合了linuxlivekit的实践代码,本文对《7》作补充,整优,继续处理dibuilder.sh
我们按《将pebuilder变成dibuilder.sh,将di tools集入boot层(4)》,把dibuilder.sh和jessie mirror全部升级到buster,还有cdi-initrd.gz,tdl-initrd.gz,为了追求纯净和方便,我们使用debian10.8.0 netinst安装的一个系统密码用户名都是tdl,方便给linuxkit准备素材,在下一步,我们将用得到的tdl-initd.gz用于chroot执行linux-live-kit脚本而不是进入一个系统内部运行脚本,注意到chroot和主机OS都是一个版本。
与jessie比较,这里要显式添加systemd-sysv(它会添加systemd)和udev,才能达到与前面《1》类似的基本系统可用性效果,看来在debootstrap和包组成方面,随着版本提高也提高了抽象,不过它虽然是好事不过会导致问题,我们在整理xorg包时也提过包这方面的事。
sudo debootstrap --verbose --no-check-gpg --no-check-certificate --variant=minbase --include=sudo,kmod,systemd-sysv,udev,ifupdown,isc-dhcp-client buster tinydebianlive http://mirrors.aliyun.com/debian/
以下省略与《4》相同或相差不大的部分:(net启动出错modinfo查看virtionet依赖,需要failover, virtioblk这个hdmedia自带,aufs是接下来用的,apt-get install aufs-dkms在主机上编译过程中得到,我们只提取aufs.ko,,而squashfs在主机linux-image-4.19.0-14-amd64包中,已安装直接复制即可,注意路径上加不加/的变化)
以下全部initrd包从http://mirrors.aliyun.com/debian/dists/buster/main/installer-amd64/current/images/cdrom,hd-media,netboott等而来
上面的cdi-initrd.gz,是从上面网址直接下来的无修改。对于tdl-initrd.gz,则:
sudo mkdir hdmedia-extracted netboot-extracted
......
sudo cp -af hdmedia-extracted/lib/modules tinydebianlive/lib
.....
sudo mkdir -p tinydebianlive/lib/modules/4.19.0-14-amd64/kernel/net/core/
sudo cp -f netboot-extracted/lib/modules/4.19.0-14-amd64/kernel/net/core/failover.ko tinydebianlive/lib/modules/4.19.0-14-amd64/kernel/net/core/
sudo cp -f netboot-extracted/lib/modules/4.19.0-14-amd64/kernel/drivers/net/net_failover.ko tinydebianlive/lib/modules/4.19.0-14-amd64/kernel/drivers/net/
sudo cp -f netboot-extracted/lib/modules/4.19.0-14-amd64/kernel/drivers/net/virtio_net.ko tinydebianlive/lib/modules/4.19.0-14-amd64/kernel/drivers/net/
......
sudo cp -f /lib/modules/4.19.0-14-amd64/kernel/drivers/input/evdev.ko tinydebianlive/lib/modules/4.19.0-14-amd64/kernel/drivers/input/
sudo cp -f /lib/modules/4.19.0-14-amd64/kernel/lib/xxhash.ko tinydebianlive/lib/modules/4.19.0-14-amd64/kernel/lib/
sudo cp -fr /lib/modules/4.19.0-14-amd64/kernel/lib/zstd/ tinydebianlive/lib/modules/4.19.0-14-amd64/kernel/lib/
sudo cp -fr /lib/modules/4.19.0-14-amd64/kernel/fs/squashfs/ tinydebianlive/lib/modules/4.19.0-14-amd64/kernel/fs/
sudo cp -fr /lib/modules/4.19.0-14-amd64/kernel/fs/aufs/ tinydebianlive/lib/modules/4.19.0-14-amd64/kernel/fs/
.....
sudo chroot tinydebianlive depmod
sudo sh -c "echo ‘failover‘ >> tinydebianlive/etc/modules-load.d/modules.conf"
sudo sh -c "echo ‘net_failover‘ >> tinydebianlive/etc/modules-load.d/modules.conf"
sudo sh -c "echo ‘virtio_blk‘ >> tinydebianlive/etc/modules-load.d/modules.conf"
sudo sh -c "echo ‘virtio_net‘ >> tinydebianlive/etc/modules-load.d/modules.conf"
sudo sh -c "echo ‘evdev‘ >> tinydebianlive/etc/modules-load.d/modules.conf"
sudo sh -c "echo ‘xxhash‘ >> tinydebianlive/etc/modules-load.d/modules.conf"
sudo sh -c "echo ‘zstd_decompress‘ >> tinydebianlive/etc/modules-load.d/modules.conf"
sudo sh -c "echo ‘squashfs‘ >> tinydebianlive/etc/modules-load.d/modules.conf"
sudo sh -c "echo ‘aufs‘ >> tinydebianlive/etc/modules-load.d/modules.conf"
......
cd tinydebianlive;sudo sh -c ‘find . | cpio -o -H newc | gzip -9 > ../tdl-initrd.gz‘
(如果换成xz打包比gz打包压缩更高)
当然,在buster的udev rules中,默认网卡名不再是eth0,而是 其它的。但在initramfs中修正/etc/network/interface后/etc/init.d/networking restart是可以正确工作的。这个以后修正吧。毕竟tdl-initrd.gz本来就供dibuilder.sh再次remaster的。
整个打包40多m快突破50m我认为一个initramfs包能给出最大的体积了。
这里有一个重点问题:
buster debian-installer那个initrd在云主机上引导正常但在PD虚拟机上引导时出现screen black hang at Trying to enable the frame buffer,实践在官方netinst.iso的syslinux引导下给cmdline喂fb=false(实际上是debian-installer/framebuffer=false缩写)可以解决问题进入,但grub2下不行,故在preseed.cfg处开头d-i debian-installer/locale string en_US下添加:
d-i debian-installer/framebuffer boolean true
(代码中http://10.211.55.2:8000/mirrors/debian/这个mirrors集成了所有要安装的包,是我用PD测试时内网地址,外网地址为d.shalol.com/mirrors/debian。)
## GPL,Written By MoeClub.org,moded by minlearn (www.shalol.com) for both remastering and installing (local install and cloud dd) purposes and for onedrive mirror/image hosting.
.....
function CheckDependence(){
.....
[[ $lostdeplist =~ "squashfs" ]] && echo "mksquashfs: debian:squashfs-tools"
.....
elif [[ "$tmpTARGET" == ‘minstackos‘ ]] && [[ "$tmpMODE" == ‘1‘ ]] && [[ "$tmpPLAT" == ‘0‘ ]] ; then
CheckDependence wget,ar,awk,grep,sed,cut,cat,cpio,curl,gzip,find,dirname,basename,xzcat,zcat,losetup,parted,mksquashfs,chroot;
.....
sleep 2s && echo -en "\runpacking grub files ..."
targetdir=‘/tmp/tmptarget‘
mkdir -p $targetdir
export tmpMNT=/tmp/tmptarget/mnt
......
dd if=/dev/zero of=/tmp/tmptarget/minstackos bs=1024 count=1048576 >/dev/null 2>&1
[[ "$tmpPLAT" == "0" ]] && tmpDEV=`losetup -fP --show /tmp/tmptarget/minstackos | awk ‘{print $1}‘` || tmpDEV=`hdiutil attach -imagekey diskimage-class=CRawDiskImage -nomount /tmp/tmptarget/minstackos | awk ‘{print $1}‘`
.....
[ ! -d "$tmpMNT" ] && [[ "$tmpPLAT" == "0" ]] && mkdir -p "$tmpMNT" && mount "$tmpDEV"p1 "$tmpMNT" || tmpMNT=/Volumes/TMPVOL;[[ ! -d /tmp/tmptarget/mnt ]] && ln -s /Volumes/TMPVOL /tmp/tmptarget/mnt
......
# Automatically remove DISK on exit
[[ "$tmpPLAT" == "0" ]] && trap ‘echo; echo "- Ejecting tmpdev disk(linux)"; umount "$tmpMNT" && losetup -d "$tmpDEV" && rm -rf /tmp/tmptarget/mnt‘ EXIT || trap ‘echo; echo "- Ejecting tmpdev disk(osx)"; diskutil eject "$tmpDEV"; rm -rf /tmp/tmptarget/mnt‘ EXIT
(你甚至在这里可以创建第二个分区以便稍后把livekitdata/boot分开放)
.....
core.img是我用bootinfoscript得到的静态文件,参见《5》。linux-live有一个bootfiles/booinst.sh也是好的参考不过我没用它:
(grub.gz也移到了这里,所以前面下载到downdir的grub二条语句去掉)
......
#echo "- before installing/remastering grub,unzip it"
mkdir -p /tmp/tmpremastering/grub
wget -qO- http://10.211.55.2:8000/mirrors/debian/static/grub.gz | tar -xzf - -C /tmp/tmpremastering/grub
wget -qO- http://10.211.55.2:8000/mirrors/debian/static/core_img > /tmp/tmpremastering/grub/core_img
grub202=‘.......‘
grub202+=‘\x80‘
printf $grub202 | dd of="$tmpDEV" bs=447 count=1
dd if=/tmp/tmpremastering/grub/core_img of="$tmpDEV" seek=1
......
sleep 2s && echo -en "\nprocessing grub ......"
[[ -d $tmpMNT ]] && [[ "$tmpTARGET" == "minstackos" ]] && mkdir -p "$tmpMNT"/boot/grub;cp -a --no-perserve=all /tmp/tmpremastering/grub/* "$tmpMNT"/boot/grub
.....
if [[ "$tmpTARGET" == ‘minstackos‘ ]] && [[ "$tmpMODE" == ‘1‘ ]] && [[ "$tmpPLAT" == ‘0‘ ]]; then
sleep 2s && echo -en "\nmake a separated initramfs with init for vda2"
......
mkdir -p /tmp/tmpremastering/initrd/mnt/sysroot
sed -i ‘/exec \/sbin\/init/i\\/etc/rcS.d/S02udev start‘ /tmp/tmpremastering/initrd/init
sed -i ‘/exec \/sbin\/init/i\\mount -t ext4 /dev/vda2 /mnt/sysroot‘ /tmp/tmpremastering/initrd/init
sed -i ‘s/exec \/sbin\/init/exec \/sbin\/switch_root \/mnt\/sysroot \/sbin\/init/‘ /tmp/tmpremastering/initrd/init
.....
统一判断,非2,和2
echo -en "\ncopying vmlinuz to the target/mnt ......"
[[ -d /boot ]] && [[ "$tmpPLAT" != "1" ]] && [[ "$tmpMODE" == "2" ]] && cp -f "$downdir/dists/buster/main/debian-installer/binary-amd64/vmlinuz" /boot/vmlinuz
[[ -d /tmp/tmptarget/mnt/boot ]] && [[ "$tmpMODE" != "2" ]] && [[ "$tmpTARGET" == "minstackos" ]] && cp -f "$downdir/dists/buster/main/binary-amd64/vmlinuz" /tmp/tmptarget/mnt/boot/vmlinuz
echo "current pwd is:"$CWD
[[ "$tmpMODE" == ‘2‘ ]] && sleep 2s && echo -en "\npackaging initrd to the target/mnt....." && [[ "$tmpPLAT" == ‘0‘ ]] && find . | cpio -H newc --create --quiet | gzip -9 > /boot/initrd.img #|| find . | cpio -H rpax --create --quiet | gzip -9 > /Volumes/TMPVOL/initrd.img
[[ "$tmpMODE" != ‘2‘ ]] && sleep 2s && echo -en "\npackaging finished,and all done! auto reboot after 9999s...(if needed, you can press ctrl c to interrupt to bak the downdir under tmp/, then manually reboot to continue)" && sleep 9999s
将pebuilder变成dibuilder.sh,将di tools集入boot层(8):继续整优dibuilder.sh
标签:ott ima cut aliyun apt xorg export fun 好的
原文地址:https://www.cnblogs.com/minlearn/p/14481452.html