Image patchen ============= ###### tags: 'development' ## Einleitung Das Image kann von "scratch" erstellt werden, oder es kann von einem bestehenden Image gepatcht werden. Hier wird die zweite Methode beschrieben. Das Image kann mit drei einfachen Schritten gepatcht werden: 1. Image auspacken 2. Image im chroot patchen 3. Image einpacken. ``` puavo-img-clone -t ext4 <quellimage.img> <unpacked.img> puavo-img-chroot <unpacked.img> #mach was du willst puavo-img-clone -t squashfs <unpacked.img> <zielimage.img> ``` :::warning Die Datei ```unpacked.img``` ist etwa 60GByte gross ::: Das war's dann schon. ## Ein minimales Image-Patch-Script :::warning Diese Script muss noch an die lokalen Gegebenheiten angepasst werden, bevor es genutzt werden kann! ::: ```bash #!/bin/sh ################################ # Anpassungen # ################################ # adaptiere diese Vars QUELLE="opinsys-os-opinsys-stretch-2019-01-15-094627-amd64.img" # set image class name CLASS="sachsenanhalt" #Die debs in diesem Verzeichnis werden installiert DEBS="pfad/zu/den/debs/" # zusätzlich zu installierendePakete EXTRA="autossh sox ..." ################################ # Prolog # ################################ #image auspacken und auf /mnt mounten if [ -e unpacked.img ];then rm unpacked.img;fi puavo-img-clone --type ext4 ${QUELLE} unpacked.img mount -o loop unpacked.img /mnt ################################ # Hier passiert's # ################################ # # und dateien auf's Image kopieren mkdir /mnt/install cp ${DEBS}/*.deb /mnt/install/. #in chroot patchen cat <<'EOF' | puavo-img-chroot unpacked.img #this is done in the chroot! #install local debs apt-get --yes update for D in /install/*.deb; do dpkg -i ${D} done # install missing dependencies apt-get --yes -f install #list of debs to be installed from repo apt-get --yes install ${EXTRA} #maybe do other funny things and exit EOF #remove install files from Image rm -r /mnt/install #gen imagename and pack image IMAGE="puavo-os-${CLASS}-stretch-$(date +%Y-%m-%d-%H%M%S)-amd64.img" puavo-img-clone --type squashfs unpacked.img ${IMAGE} ################################# # Epilog # ################################ #umount unpacked.img umount /mnt exit ``` ##### Es geht auch schneller... Das Auspacken des originalen Image mit `puavo-img-clone` dauert (bei mir) 30 Minuten und benötigt 56GByte Diskplatz. Mit dieser Methode wird dies in Null Sekunden (und null Diskplatz) erledigt: ```bash #!/bin/sh ############################## # Adaptiere diese Vars # ############################## QUELLE="opinsys-os-opinsys-stretch-2019-01-15-094627-amd64.img" # set image class name CLASS="sachsenanhalt" #Die debs in diesem Verzeichnis werden installiert DEBS="pfad/zu/den/debs/" EXTRA="autossh sox ..." ############################### # Prolog # ############################### #this mimics puav-img-clone -t ext4 #remove old mountpoints if [ -d image.work ]; then rm -r image.work;fi if [ -d image.rwfs ]; then rm -r image.rwfs;fi #make mountpounts if ![ -d image.rofs ]; then mkdir image.rofs;fi if ![ -d image.rwfs ]; then mkdir image.rwfs;fi if ![ -d image.work ]; then mkdir image.work;fi #mount source image readonly mount -r -o loop ${QUELLE} image.rofs #make it writeble: mount overlay mount -t overlay overlay -o lowerdir=image.rofs,upperdir=image.rwfs,workdir=image.work /mnt #this minics puavo-img-chroot mount -o bind /dev /mnt/dev mount -o bind /dev/pts /mnt/dev/pts mount -o bind /proc /mnt/proc ##################################### # hier passiert's # ##################################### # # Dateien auf's Image kopieren mkdir /mnt/install cp ${DEBS}/*.deb /mnt/install/. # chroot starten cat <<'EOF' | chroot /mnt # #this is done in the chroot! #install local debs apt-get --yes update for D in /install/*.deb; do dpkg -i ${D} done # install missing dependencies apt-get --yes -f install #list of debs to be installed from repo apt-get --yes install ${EXTRA} #maybe do other funny things and exit EOF #remove install files from Image rm -r /mnt/install ##this mimics puavo-img-clone -t squashfs IMAGE="puavo-os-${CLASS}-stretch-$(date +%Y-%m-%d-%H%M%S)-amd64.img" echo "${IMAGE}" > /mnt/etc/puavo-image/name echo "${CLASS}" > /mnt/etc/puavo-image/class mksquashfs /mnt ${IMAGE} -noappend -no-recovery -no-sparse -wildcards -comp lzo ################################ # Epilog # ################################ ##umount umount image.rofs umount /mnt/dev umount /mnt/dev/pts umount /mnt/proc umount /mnt exit ```