Thursday, May 03, 2007

 

Trimming down etch to ~100 MB

The basic recepie:
  1. sudo debootstrap etch etch/ ftp://ftp.ee.debian.org/debian
  2. sudo chroot etch
  3. apt-get install localepurge
  4. apt-get --purge remove dselect aptitude dhcp3-client dhcp3-common info man-db manpages dmidecode laptop-detect
  5. apt-get install grub initrd-tools linux-image-686 ssh python-minimal
  6. mkdir /boot/grub; update-grub
  7. apt-get clean
  8. APT cache:
    6.4M /var/cache/apt/pkgcache.bin
    6.4M /var/cache/apt/srcpkgcache.bin
    19M /var/lib/apt/lists/archive.ubuntu.com_ubuntu_dists_etch_main_binary-i386_Packages
    3.6M /var/lib/dpkg/info
    internationalization:
    6.9M /usr/share/i18n
    4.9M /usr/lib/gconv
    documentation:
    8.2M /usr/share/doc
    4.7M /usr/share/man
    zoneinfo:
    5.6M /usr/share/zoneinfo
    kernel modules:
    44M lib/modules/2.6.18-4-686/kernel
  9. time for cleanup:
    1. vi /etc/apt/sources.list, comment everything out. This will temporarily disable apt
    2. apt-get update
    3. rm /usr/share/i18n/{charmaps,locales}/*
    4. rm -rf /usr/lib/gconv # or at least
      for i in IBM INIS EBCDIC MAC ISO- ISO_ KOI JOHAB CP BIG5 EUC ECMA ARM ASM GEOR GOST GREEK LATIN NATS GB SJIS; do rm /usr/lib/gconv/${i}*; done
    5. rm -rf /usr/share/{doc,man}/*
    6. boot into the system and check what modules are actually in use with lsmod, remove the modules you don't need (e.g. who needs sound in a router? or even better, build your own kernel):
      rm -rf /lib/modules/2.6.18-4-686/kernel/sound
      rm -rf /lib/modules/2.6.18-4-686/kernel/drivers/isdn
      rm -rf /lib/modules/2.6.18-4-686/kernel/drivers/net/wireless
      rm -rf /lib/modules/2.6.18-4-686/kernel/drivers/media
      rm -rf /lib/modules/2.6.18-4-686/kernel/drivers/scsi/pcmcia
      version=2.6.18-4-686
      depmod -a -F /boot/System.map-$version $version
      update-initramfs -u # to check that nothing is broken
      # other redundant modules:
      /lib/modules/2.6.18-4-686/kernel/net/{ax25,ipx,x25,ipv6,appletalk,atm,bluetooth,decnet,econet,irda}
      /lib/modules/2.6.18-4-686/kernel/fs/{reiserfs,smbfs,qnx4,xfs,befs,bfs,affs,afs,coda,cifs,freevxfs,hfs,hfsplus,hpfs,ocfs2,nfs,nfs_common,nfsd,ncpfs,ufs,udf}
      # remove modules that you don't need from (spacehogs):
      # /lib/modules/2.6.18-4-686/kernel/drivers/net
      # /lib/modules/2.6.18-4-686/kernel/drivers/scsi
      rm /lib/modules/2.6.18-4-686/kernel/drivers/scsi/sata*.ko
      rm -rf /lib/modules/2.6.18-4-686/kernel/drivers/scsi/aic7xxx*

  10. we are down to 97M now:
    97M /
  11. configure timezone, hosts, hostname, network interfaces, fstab, name resolver:
    1. tzconfig
    2. echo '127.0.0.1 localhost' > /etc/hosts # see http://www.howtoforge.com/perfect_setup_debian_etch_p3 for IPv6
    3. echo 'my.hostname' > /etc/hostname
    4. vi /etc/network/interfaces
      iface lo inet loopback
      ...
    5. vi /etc/fstab
      #
      proc /proc proc defaults 0 0
      /dev/hda2 none swap sw 0 0
      /dev/hda1 / ext3 defaults,errors=remount-ro 0 1
    6. vi /etc/resolv.conf
      nameserver x.x.x.x
  12. set root password or add an ordinary user and install sudo
    passwd
  13. disable IPv6 if you don't need it
  14. boot target with Knoppix, tomsrtbt or whatever other rescue tools you have
  15. create a parition for the new system, mkfs, mount and cd to target root
  16. transfer the filesystem:
    nc -lp 5555 | tar xf - # in target system
    cd etch; sudo tar cf - . | nc target 5555
  17. In target: chroot .; grub-install /dev/hda OR if you are unable to run grub from the target, create a grub floppy:
    1. dd if=/boot/grub/stage1 of=/dev/fd0 bs=512
      dd if=/boot/grub/stage2 of=/dev/fd0 bs=512 seek=1
    2. in grub shell:
      root (hd0,0)
      kernel /vmlinuz root=/dev/hda1 ro
      initrd /initrd.img
      boot
    3. when booted into target, run grub install
      if proc is not mounted, grub will complain Could Not Find Device For /boot,
      mount proc /proc
      cp /proc/mounts /etc/mtab
      grub-install /dev/hda
  18. ready, reboot target
  19. update-locale LC_ALL=C LANG=C
  20. setup /etc/iftab
  21. update-alternatives --set editor /usr/bin/vim.tiny
  22. apt-get install sudo; visudo
    # or user ALL=(ALL) NOPASSWD: ALL
    %admin ALL=(ALL) ALL


Comments: Post a Comment

<< Home

This page is powered by Blogger. Isn't yours?