From 0e57149de99f0276d8b47ca532766de62c59af00 Mon Sep 17 00:00:00 2001 From: Michael Shigorin Date: Thu, 18 Aug 2011 22:56:12 +0300 Subject: [PATCH] initial rescue image NB: this implementation is awfully cut-n-paste one, there are lots of common code with install2 which are subject to careful surgery --- distro.mk | 4 + features.in/installer/config.mk | 3 +- features.in/stage1kernel/README | 3 + features.in/stage1kernel/config.mk | 2 + .../stage1/scripts.d/01-initfs | 0 .../stage1/scripts.d/02-kdefault | 0 .../stage1/scripts.d/03-test-kernel | 0 features.in/syslinux/cfg.in/80rescue.cfg | 3 +- libdistro.mk | 5 +- sub.in/README | 11 +- sub.in/rescue/Makefile | 40 +++++ sub.in/rescue/README | 5 + sub.in/rescue/image-scripts.d/50udev | 9 ++ sub.in/rescue/image-scripts.d/85cleanup-cjk | 22 +++ .../rescue/image-scripts.d/85cleanup-legacy | 15 ++ sub.in/rescue/image-scripts.d/90cleanup | 123 +++++++++++++++ sub.in/rescue/image-scripts.d/98systemM | 21 +++ sub.in/rescue/image-scripts.d/99cleanupdb | 6 + sub.in/rescue/packages | 141 ++++++++++++++++++ 19 files changed, 406 insertions(+), 7 deletions(-) create mode 100644 features.in/stage1kernel/README create mode 100644 features.in/stage1kernel/config.mk rename features.in/{installer => stage1kernel}/stage1/scripts.d/01-initfs (100%) rename features.in/{installer => stage1kernel}/stage1/scripts.d/02-kdefault (100%) rename features.in/{installer => stage1kernel}/stage1/scripts.d/03-test-kernel (100%) create mode 100644 sub.in/rescue/Makefile create mode 100644 sub.in/rescue/README create mode 100755 sub.in/rescue/image-scripts.d/50udev create mode 100755 sub.in/rescue/image-scripts.d/85cleanup-cjk create mode 100755 sub.in/rescue/image-scripts.d/85cleanup-legacy create mode 100755 sub.in/rescue/image-scripts.d/90cleanup create mode 100755 sub.in/rescue/image-scripts.d/98systemM create mode 100755 sub.in/rescue/image-scripts.d/99cleanupdb create mode 100644 sub.in/rescue/packages diff --git a/distro.mk b/distro.mk index 3ce50728..3a17fd36 100644 --- a/distro.mk +++ b/distro.mk @@ -59,6 +59,10 @@ distro/minicd: distro/server-base @$(call set,KFLAVOURS,pure-emerald) # usually recent drivers @$(call add,MAIN_PACKAGES,etcnet-full) +distro/rescue: distro/.branding sub/rescue use/stage1kernel use/syslinux/ui-menu + @$(call set,KFLAVOURS,un-def) # usually recent drivers too + @$(call add,RESCUE_PACKAGES,etcnet-full) + # desktop distributions distro/desktop-base: distro/installer sub/main \ diff --git a/features.in/installer/config.mk b/features.in/installer/config.mk index 82fe9664..49bdf267 100644 --- a/features.in/installer/config.mk +++ b/features.in/installer/config.mk @@ -1,7 +1,6 @@ -use/installer: sub/install2 use/syslinux/install2.cfg +use/installer: use/stage1kernel sub/install2 use/syslinux/install2.cfg @$(call add,FEATURES,installer) @$(call set,INSTALL2_PACKAGES,installer-distro-$$(INSTALLER)-stage2) @$(call add,INSTALL2_PACKAGES,branding-$$(BRANDING)-alterator) @$(call add,MAIN_PACKAGES,branding-$$(BRANDING)-release) -# @$(call set,BASE_LISTS,base) @$(call add,BASE_LISTS,$(call tags,basesystem)) diff --git a/features.in/stage1kernel/README b/features.in/stage1kernel/README new file mode 100644 index 00000000..ef75065c --- /dev/null +++ b/features.in/stage1kernel/README @@ -0,0 +1,3 @@ +Эта фича предназначена для обобщения скриптовых хуков, +нужных для различных live-образов, загружаемых с ядром +из stage1 (инсталятор, спасательная и живая система). diff --git a/features.in/stage1kernel/config.mk b/features.in/stage1kernel/config.mk new file mode 100644 index 00000000..11671a6a --- /dev/null +++ b/features.in/stage1kernel/config.mk @@ -0,0 +1,2 @@ +use/stage1kernel: sub/stage1 + @$(call add,FEATURES,stage1kernel) diff --git a/features.in/installer/stage1/scripts.d/01-initfs b/features.in/stage1kernel/stage1/scripts.d/01-initfs similarity index 100% rename from features.in/installer/stage1/scripts.d/01-initfs rename to features.in/stage1kernel/stage1/scripts.d/01-initfs diff --git a/features.in/installer/stage1/scripts.d/02-kdefault b/features.in/stage1kernel/stage1/scripts.d/02-kdefault similarity index 100% rename from features.in/installer/stage1/scripts.d/02-kdefault rename to features.in/stage1kernel/stage1/scripts.d/02-kdefault diff --git a/features.in/installer/stage1/scripts.d/03-test-kernel b/features.in/stage1kernel/stage1/scripts.d/03-test-kernel similarity index 100% rename from features.in/installer/stage1/scripts.d/03-test-kernel rename to features.in/stage1kernel/stage1/scripts.d/03-test-kernel diff --git a/features.in/syslinux/cfg.in/80rescue.cfg b/features.in/syslinux/cfg.in/80rescue.cfg index 115c754c..2ea91268 100644 --- a/features.in/syslinux/cfg.in/80rescue.cfg +++ b/features.in/syslinux/cfg.in/80rescue.cfg @@ -1,4 +1,5 @@ label rescue menu label ^Rescue LiveCD kernel alt0/vmlinuz - append initrd=alt0/full.cz live fastboot stagename=rescue + append initrd=alt0/full.cz live ramdisk_size=72000 fastboot stagename=rescue showopts automatic=method:cdrom + ### FIXME: see m-p-d::profiles/scripts.d/03-syslinux diff --git a/libdistro.mk b/libdistro.mk index 42eebbcf..8873748f 100644 --- a/libdistro.mk +++ b/libdistro.mk @@ -4,9 +4,10 @@ sub/%: @$(call add,SUBPROFILES,$(@:sub/%=%)) -sub/install2: sub/stage1 +sub/install2 sub/rescue: sub/stage1 -boot/%: distro/.init +# FIXME: maybe syslinux feature belongs to distro/.init? +boot/%: distro/.init use/syslinux @$(call set,BOOTLOADER,$*) # initalize config from scratch, put some sane defaults in diff --git a/sub.in/README b/sub.in/README index 5e7e3a8f..3cf10988 100644 --- a/sub.in/README +++ b/sub.in/README @@ -1,13 +1,18 @@ Этот каталог содержит субпрофили; содержимое заказанных в формируемый профиль (названия которых содержатся в значении переменной SUBPROFILES, которую обычно заполняют цели sub/* -- -см. ditro.mk в корневом каталоге) будет скопировано в каталог -$(BUILDDIR)/image/. +см. ../distro.mk) будет скопировано в каталог $(BUILDDIR)/image/. Просьба ответственно относиться к модификации существующих и вдумчиво -- к созданию новых; возможно, достаточно всего лишь оформить нужное новой фичей (см. ../features.in/). +Новый субпрофиль технологически обоснован тогда, когда он может +потребоваться одновременно с уже существующим схожим (поскольку +сборка частей образа и происходит в каталогах субпрофилей, т.е. +повторное использование одного субпрофиля в рамках одного уже +сгенерированного профиля штатным образом невозможно). + Краткое описание существующих: - stage1: propagator и загрузчик (при подключении фичи syslinux); @@ -19,3 +24,5 @@ $(BUILDDIR)/image/. - main: пакетная база, укладываемая на образ (NB: поскольку рабочий чрут в этом случае не содержит ничего, кроме пакетов, добавлять image-scripts.d/* смысла нет, только scripts.d/*) + +- rescue: спасательная система diff --git a/sub.in/rescue/Makefile b/sub.in/rescue/Makefile new file mode 100644 index 00000000..4305e79b --- /dev/null +++ b/sub.in/rescue/Makefile @@ -0,0 +1,40 @@ +# step 4: build rescue subprofile (custom livecd) + +ifndef GLOBAL_BUILDDIR +$(error GLOBAL_BUILDDIR not defined) +endif + +default: all + +include $(GLOBAL_BUILDDIR)/distcfg.mk +include $(GLOBAL_BUILDDIR)/functions.mk +include $(MKIMAGE_PREFIX)/config.mk + +# this might have been prepared by ../stage1/scripts.d/03-test-kernel +-include $(GLOBAL_BUILDDIR)/squashcfg.mk + +# here we also try and come up with the stage1 kernel/modules, if any; +# no kernel flavour specified will result in no modules for stage1 vmlinuz +STAGE1_KFLAVOUR ?= $(lastword $(KFLAVOURS)) + +ifeq "$(STAGE1_KFLAVOUR)" "" +$(error STAGE1_KFLAVOUR is utterly empty; cannot guess either) +endif + +# need kernel modules only (which require corresponding kernel-image); +# these go into work chroot; NB: no vmlinuz there +IMAGE_PACKAGES_REGEXP = $(call kpackages,$(STAGE1_KMODULES),$(STAGE1_KFLAVOUR)) +IMAGE_PACKAGES = $(COMMON_PACKAGES) \ + $(RESCUE_PACKAGES) \ + ./packages + +MKI_PACK_RESULTS = squash:rescue + +include $(MKIMAGE_PREFIX)/targets.mk + +all: | $(GLOBAL_DEBUG) build-image run-image-scripts pack-image \ + $(GLOBAL_CLEAN_WORKDIR) + +debug: + @echo "** rescue: IMAGE_PACKAGES: $(IMAGE_PACKAGES)" + @echo "** rescue: IMAGE_PACKAGES_REGEXP: $(IMAGE_PACKAGES_REGEXP)" diff --git a/sub.in/rescue/README b/sub.in/rescue/README new file mode 100644 index 00000000..53aa2b40 --- /dev/null +++ b/sub.in/rescue/README @@ -0,0 +1,5 @@ +Этот каталог содержит субпрофиль "живой" второй стадии, +подходящей для сборки спасательных образов. + +Результат -- squashfs в файле rescue, подлежащем копированию +в итоговый образ. diff --git a/sub.in/rescue/image-scripts.d/50udev b/sub.in/rescue/image-scripts.d/50udev new file mode 100755 index 00000000..8ff3e054 --- /dev/null +++ b/sub.in/rescue/image-scripts.d/50udev @@ -0,0 +1,9 @@ +#!/bin/sh + +# for udev, "FATAL ERROR IN INIT: overmounting /image" otherwise +ln -sf /proc/mounts /etc/mtab + +# pam_console_apply is harmful during install +find /etc/udev/rules.d/ -type f -print0 | + xargs -r0 fgrep -Zl pam_console_apply -- | + xargs -r0 rm -fv -- diff --git a/sub.in/rescue/image-scripts.d/85cleanup-cjk b/sub.in/rescue/image-scripts.d/85cleanup-cjk new file mode 100755 index 00000000..db7c44a0 --- /dev/null +++ b/sub.in/rescue/image-scripts.d/85cleanup-cjk @@ -0,0 +1,22 @@ +#!/bin/sh + +# remove unused fonts +cd /usr/share/fonts/bitmap/misc/ && + rm -f *ja.* *ko.* han* gb* jis* k14* rk* *rk.* *kana* cl* *JIS* + +# drop unneeded translations +cd /usr/share/qt4/translations/ && rm -f *_zh* *_ja* + +# l10n +cd /usr/share/X11/locale && rm -rf ja* ko* th* vi* zh* + +# xkb +cd /usr/share/X11/xkb/symbols && rm -rf jp kr th vn cn + +# locales +cd /usr/lib*/locale && rm -rf ja_* ko_* th_* zh_* + +# gconv +cd /usr/lib*/gconv && rm -f JIS* T* + +: diff --git a/sub.in/rescue/image-scripts.d/85cleanup-legacy b/sub.in/rescue/image-scripts.d/85cleanup-legacy new file mode 100755 index 00000000..67958b1b --- /dev/null +++ b/sub.in/rescue/image-scripts.d/85cleanup-legacy @@ -0,0 +1,15 @@ +#!/bin/sh + +# remove unused legacy/tiny fonts +cd /usr/share/fonts/bitmap/misc/ && rm -f *ISO* *KOI* [1456]* + +# l10n +cd /usr/share/X11/locale/ && rm -rf *[^C8]/ iso* + +# xkb +cd /usr/share/X11/xkb/symbols && rm -rf *_vndr + +# gconv +cd /usr/lib*/gconv && rm -f CP* ISO* *JIS* KOI* HP* MAC* + +: diff --git a/sub.in/rescue/image-scripts.d/90cleanup b/sub.in/rescue/image-scripts.d/90cleanup new file mode 100755 index 00000000..4d8d6fc7 --- /dev/null +++ b/sub.in/rescue/image-scripts.d/90cleanup @@ -0,0 +1,123 @@ +#!/bin/sh + +# remove all docs +rpmquery -adl |grep ^/ |xargs -r rm -f -- +rm -rf /usr/share/{doc,man,info,license,gfxboot} + +# remove unused icons +rm -rf /usr/share/icons/{hicolor,large,mini} + +# remove PAM plugins +rm -rf /lib*/security + +# remove some unused files +rm -rf /usr/share/ca-certificates +rm -rf /usr/lib/qt4/plugins/codecs +rm -f /usr/lib*/gconv/IBM* +rm -f /usr/lib*/gconv/BIG5* +rm -f /usr/lib*/gconv/EBCDIC* + +# remove unneeded timezones +rm -rf /usr/share/zoneinfo/{posix,right}/ + +# remove unneeded l10n +find /usr/share/locale/ -type f \! -name 'alterator*' -delete + +# remove non-utf8 locales +find /usr/lib*/locale -mindepth 1 -maxdepth 1 -type d \! -name '*.utf8' -print0 | + xargs -r0 rm -rf -- + +# xorg modules +rm -r /usr/lib*/X11/modules/dri + +# remove ogfs +rm -f /lib*/evms/*/ogfs* + +# remove cpp, gcc and perl +rpmquery -a cpp\* gcc\* perl-base | + xargs -r rpmi -e --nodeps -- + +# remove unneeded kernel modules +rm -rf /lib/modules/*/kernel/arch +rm -rf /lib/modules/*/kernel/drivers/atm +rm -rf /lib/modules/*/kernel/drivers/char/ipmi +rm -rf /lib/modules/*/kernel/drivers/char/watchdog +rm -rf /lib/modules/*/kernel/drivers/cpufreq +rm -rf /lib/modules/*/kernel/drivers/edac +rm -rf /lib/modules/*/kernel/drivers/firmware ### +rm -rf /lib/modules/*/kernel/drivers/hwmon +rm -rf /lib/modules/*/kernel/drivers/infiniband ### +rm -rf /lib/modules/*/kernel/drivers/input/{gameport,joy*} +rm -rf /lib/modules/*/kernel/drivers/isdn +rm -rf /lib/modules/*/kernel/drivers/media +rm -rf /lib/modules/*/kernel/drivers/mmc +rm -rf /lib/modules/*/kernel/drivers/mtd* +rm -rf /lib/modules/*/kernel/drivers/net/irda +rm -rf /lib/modules/*/kernel/drivers/net/wireless +rm -rf /lib/modules/*/kernel/drivers/staging +rm -rf /lib/modules/*/kernel/drivers/spi +rm -rf /lib/modules/*/kernel/drivers/telephony +rm -rf /lib/modules/*/kernel/drivers/usb/{misc,mon} +rm -rf /lib/modules/*/kernel/drivers/w1 +rm -rf /lib/modules/*/kernel/fs/9p +rm -rf /lib/modules/*/kernel/fs/adfs +rm -rf /lib/modules/*/kernel/fs/affs +rm -rf /lib/modules/*/kernel/fs/afs +rm -rf /lib/modules/*/kernel/fs/autofs +rm -rf /lib/modules/*/kernel/fs/autofs4 +rm -rf /lib/modules/*/kernel/fs/befs +rm -rf /lib/modules/*/kernel/fs/bfs +rm -rf /lib/modules/*/kernel/fs/btrfs +rm -rf /lib/modules/*/kernel/fs/cifs +rm -rf /lib/modules/*/kernel/fs/coda +rm -rf /lib/modules/*/kernel/fs/configfs +rm -rf /lib/modules/*/kernel/fs/cramfs +rm -rf /lib/modules/*/kernel/fs/efs +rm -rf /lib/modules/*/kernel/fs/freevxfs +rm -rf /lib/modules/*/kernel/fs/fuse +rm -rf /lib/modules/*/kernel/fs/hfs +rm -rf /lib/modules/*/kernel/fs/hfsplus +rm -rf /lib/modules/*/kernel/fs/hpfs +rm -rf /lib/modules/*/kernel/fs/jffs +rm -rf /lib/modules/*/kernel/fs/jffs2 +rm -rf /lib/modules/*/kernel/fs/lockd +rm -rf /lib/modules/*/kernel/fs/minix +rm -rf /lib/modules/*/kernel/fs/ncpfs +rm -rf /lib/modules/*/kernel/fs/nilfs2 +rm -rf /lib/modules/*/kernel/fs/ocfs2 +rm -rf /lib/modules/*/kernel/fs/qnx4 +rm -rf /lib/modules/*/kernel/fs/smbfs +rm -rf /lib/modules/*/kernel/fs/sysv +rm -rf /lib/modules/*/kernel/fs/udf +rm -rf /lib/modules/*/kernel/fs/ufs +rm -rf /lib/modules/*/kernel/net/*/netfilter +rm -rf /lib/modules/*/kernel/net/appletalk +rm -rf /lib/modules/*/kernel/net/ax25 +rm -rf /lib/modules/*/kernel/net/bluetooth +rm -rf /lib/modules/*/kernel/net/dccp +rm -rf /lib/modules/*/kernel/net/decnet +rm -rf /lib/modules/*/kernel/net/econet +rm -rf /lib/modules/*/kernel/net/ipv6 +rm -rf /lib/modules/*/kernel/net/ipx +rm -rf /lib/modules/*/kernel/net/irda +rm -rf /lib/modules/*/kernel/net/netfilter +rm -rf /lib/modules/*/kernel/net/netrom +rm -rf /lib/modules/*/kernel/net/rose +rm -rf /lib/modules/*/kernel/net/sctp +rm -rf /lib/modules/*/kernel/net/tipc +rm -rf /lib/modules/*/kernel/net/x25 +rm -rf /lib/modules/*/kernel/sound + +# remove blacklisted kernel modules +sed -n 's/^blacklist[[:space:]]\+\([^[:space:]]\+\).*/\1/p' /etc/modprobe.d/* | + while read i; do + find /lib/modules/ -type f -name "$i.ko" -delete + done + +# run depmod after kernel modules removal +for i in /lib*/modules/*; do + /sbin/depmod -a -F /boot/System.map-${i##*/} ${i##*/} +done + +# remove kernel images +rm -rf /boot/* diff --git a/sub.in/rescue/image-scripts.d/98systemM b/sub.in/rescue/image-scripts.d/98systemM new file mode 100755 index 00000000..5916cfb8 --- /dev/null +++ b/sub.in/rescue/image-scripts.d/98systemM @@ -0,0 +1,21 @@ +#!/bin/sh + +# stage1 needs this +mkdir -p /image + +# m-p-d::profiles/rescue/image-scripts.d/999system +mv -f -- /etc/inittab.rescue /etc/inittab + +# enable NFS mounts +chkconfig rpcbind on +sed -i 's,#\(RPCBIND_ARGS="-l".*\),\1,' /etc/sysconfig/rpcbind + +# remove unwanted startup scripts +find /etc/rc.d/rc{2,3,4,5}.d/ -type l -name 'S*' \ + -not -name '*logd' \ + -not -name '*network' \ + -not -name '*rpcbind' \ + -not -name '*random' \ + -not -name '*sysreport' \ + -not -name '*udev*' \ + -delete -print diff --git a/sub.in/rescue/image-scripts.d/99cleanupdb b/sub.in/rescue/image-scripts.d/99cleanupdb new file mode 100755 index 00000000..c05d84f0 --- /dev/null +++ b/sub.in/rescue/image-scripts.d/99cleanupdb @@ -0,0 +1,6 @@ +# remove rpm database +rm -rf /var/lib/rpm/* + +# remove apt data files +rm -rf /var/cache/apt /var/lib*/apt + diff --git a/sub.in/rescue/packages b/sub.in/rescue/packages new file mode 100644 index 00000000..86ff35bf --- /dev/null +++ b/sub.in/rescue/packages @@ -0,0 +1,141 @@ +udev +e2fsprogs +glibc-nss + +firmware-linux +firmware-aic94xx-seq + +#altlinux-release +interactivesystem + +### Startup +#kernel-image-@KERNEL@ +rootfiles +sysvinit +startup +startup-rescue + +udev + +### Common +coreutils +glibc-locales +glibc-nss +glibc-utils +lilo +man +man-pages +sysfsutils +sysklogd +util-linux + +### CPU utils +cpuburn +x86info + +### Disk utils +bonnie++ +cfdisk +ddrescue +disktype +evms +evms-ncurses +gpart +hdparm +lvm2 +mdadm +ms-sys +parted +sdparm +sfdisk +smartmontools +testdisk +mtools +partimage + +### Applications +binutils +dmidecode +hexedit +pciutils +procps +quota +shadow-suite +sharutils +time +openssl + +### Applications/Archiving +arj +bzip2 +gzip +unrar +unzip +zip + +### Applications/Editors +vim-console + +### Applications/File +findutils +file +less +mtools + +### Filesystem utils +dosfstools +e2fsprogs +jfsprogs +ntfs-3g +recover +recoverdm +reiserfsprogs +xfsprogs +btrfs-progs + +### Applications/Networking +arpwatch +bridge-utils +dhcpcd +elinks +etcnet +hostinfo +ifrename +iftop +iproute2 +iptables +iputils +lftp +mailx +netcat +netlist +nfs-utils +ngrep +nmap +openssh-clients +openssh-server +p0f +postfix +rsync +scanssh +#stunnel +tcpdump +tcptraceroute +telnet +traceroute +wget +whois +wireless-tools +wpa_supplicant + + +### Applications/Shells +ash +bash +bc +gpm +mc + +### Development/Debuggers +strace +sysstat