GNU/Linux, rootfs <128 Mb

Проблема: имеется множество разных конфигураций машин, на которых хочется запускать свой софт. Общее в них – это PC, x86, не хуже Pentium-200. Хочется иметь базовую конфигурацию, которая будет работать без настройки на всех этих машинах.

Цель: с минимальными усилиями получить GNU/Linux rootfs <128Mb, включающий в себя X и работающий на всем.

Решение: собирать livecd, заливать его на винт/usb/cd/…

Детали (kickstart для Fedora8):

lang ru_RU.UTF-8
keyboard ru_win
timezone Europe/Moscow --utc
auth --useshadow --enablemd5
selinux --disabled
firewall --disabled
part / --size 1024

#X11
xconfig --startxonboot

repo --name=e8 --baseurl=ftp://192.168.4.23/pub/fedora/linux/releases/8/Everything/i386/os/
repo --name=u8 --baseurl=ftp://192.168.4.23/pub/fedora/linux/updates/8/i386/

%packages --excludedocs --nobase
glibc
initscripts
chkconfig

bash
kernel
passwd
authconfig

# cyrillic console
kbd

#X11
xorg-x11-drivers
xorg-x11-xinit

#window manager
#xorg-x11-xdm
#xorg-x11-twm
metacity

xterm
system-config-display

#fonts
liberation-fonts

#qt4
#qt4-devel
unixODBC-kde

#debugging
rpm
strace
vim-minimal
fedora-logos

%end


%post
cat > /etc/rc.d/init.d/fedora-live << EOF
#!/bin/bash
#
# live: Init script for live image
#
# chkconfig: 345 00 99
# description: Init script for live image.

. /etc/init.d/functions

if ! strstr "\`cat /proc/cmdline\`" liveimg || [ "\$1" != "start" ] || [ -e /.liveimg-configured ] ; then
    exit 0
fi

exists() {
    which \$1 >/dev/null 2>&1 || return
    \$*
}

touch /.liveimg-configured

# mount live image
if [ -b /dev/live ]; then
   mkdir -p /mnt/live
   mount -o ro /dev/live /mnt/live
fi

# read some variables out of /proc/cmdline
for o in \`cat /proc/cmdline\` ; do
    case \$o in
    ks=*)
        ks="\${o#ks=}"
        ;;
    xdriver=*)
        xdriver="--set-driver=\${o#xdriver=}"
        ;;
    esac
done


# if liveinst or textinst is given, start anaconda
if strstr "\`cat /proc/cmdline\`" liveinst ; then
   /usr/sbin/liveinst \$ks
fi
if strstr "\`cat /proc/cmdline\`" textinst ; then
   /usr/sbin/liveinst --text \$ks
fi

# enable swaps unless requested otherwise
swaps=\`blkid -t TYPE=swap -o device\`
if ! strstr "\`cat /proc/cmdline\`" noswap -a [ -n "\$swaps" ] ; then
  for s in \$swaps ; do
    action "Enabling swap partition \$s" swapon \$s
  done
fi

# configure X, allowing user to override xdriver
exists system-config-display --noui --reconfig --set-depth=24 \$xdriver

# add fedora user with no passwd
useradd -c "Fedora Live" fedora
passwd -d fedora > /dev/null

# turn off firstboot for livecd boots
echo "RUN_FIRSTBOOT=NO" > /etc/sysconfig/firstboot

# don't start yum-updatesd for livecd boots
chkconfig --level 345 yum-updatesd off 2>/dev/null

# don't start cron/at as they tend to spawn things which are
# disk intensive that are painful on a live image
chkconfig --level 345 crond off 2>/dev/null
chkconfig --level 345 atd off 2>/dev/null
chkconfig --level 345 anacron off 2>/dev/null
chkconfig --level 345 readahead_early off 2>/dev/null
chkconfig --level 345 readahead_later off 2>/dev/null

# Stopgap fix for RH #217966; should be fixed in HAL instead
touch /media/.hal-mtab

# workaround clock syncing on shutdown that we don't want (#297421)
sed -i -e 's/hwclock/no-such-hwclock/g' /etc/rc.d/init.d/halt
EOF


# workaround avahi segfault (#279301)
touch /etc/resolv.conf
/sbin/restorecon /etc/resolv.conf

chmod 755 /etc/rc.d/init.d/fedora-live
/sbin/restorecon /etc/rc.d/init.d/fedora-live
/sbin/chkconfig --add fedora-live

# save a little bit of space at least...
rm -f /boot/initrd*
# make sure there aren't core files lying around
rm -f /core*

rpm -e --nodeps fedora-release-notes
rpm -e --nodeps avahi
#rpm -e --nodeps cracklib-dicts

#glibc-common
rm -rf /usr/share/doc
rm -rf /usr/lib/locale/*
localedef -i /usr/share/i18n/locales/ru_RU -f UTF-8 ru_RU
localedef -i /usr/share/i18n/locales/ru_RU -f UTF-8 ru_RU.UTF-8
localedef -i /usr/share/i18n/locales/ru_RU -f KOI8-R ru_RU.KOI8-R
find /usr/share/i18n/locales -mindepth 1 -maxdepth 1 | grep -v ru | xargs rm -rf
find /usr/share/locale -mindepth 1 -maxdepth 1 | grep -v ru | xargs rm -rf

#kernel
rm -rf /lib/modules/*/kernel/{sound,drivers/{atm,bluetooth,firewire,mtd,net,pcmcia,watchdog}}

#perl is needed only during setup
rpm -e --nodeps perl perl-libs

#funny X setup
cat >/etc/X11/xinit/xinitrc << EOF
metacity &
xterm
EOF

chmod +x /etc/X11/xinit/xinitrc

cat >/etc/X11/prefdm << EOF
#! /bin/sh

PATH=/sbin:/usr/sbin:/bin:/usr/bin
# We need to source this so that the login screens get translated
[ -f /etc/sysconfig/i18n ] && . /etc/sysconfig/i18n
startx
EOF

chmod +x /etc/X11/prefdm

%end

Оно работает! ((: