[EMAIL PROTECTED] wrote:
> This is very good. Quick question :)
> How did you compile insmod, isoinfo,
> losetup, mount, run-init, sh, and sleep
> to be SSOO small in your initramfs?
Short answer: klibc. Long answer: See the attached (not well-tested) patch
against the SVN livecd buildscripts. After patching -Np0, please chmod
initramfs/init to 755.
--
Alexander E. Patrakov
Index: initramfs/init
===================================================================
--- initramfs/init (revision 0)
+++ initramfs/init (revision 0)
@@ -0,0 +1,23 @@
+#!/bin/sh
+LABEL="LFS_CD"
+DEVS=`echo /dev/hd* /dev/scd*`
+
+sleep 5
+
+for DEV in $DEVS ; do
+ if [ "`isoinfo -V $DEV 2>/dev/null`" = "$LABEL" ] ; then
+ CDROM=$DEV
+ fi
+done
+
+[ -z "$CDROM" ] && exit 1
+
+echo "CD-ROM is $CDROM"
+
+mount -w -t tmpfs -o size=90%,mode=755 tmpfs /.tmpfs
+mount -r -t iso9660 $CDROM /.cdrom
+losetup /dev/loop0 /.cdrom/root.sqfs
+mount -r -t squashfs /dev/loop0 /.sqfs
+insmod /lib/unionfs.ko
+mount -w -t unionfs -o dirs=/.tmpfs=rw:/.cdrom=ro:/.sqfs=ro unionfs /.union
+exec run-init /.union /sbin/init
Index: initramfs/Makefile
===================================================================
--- initramfs/Makefile (revision 103)
+++ initramfs/Makefile (working copy)
@@ -2,14 +2,20 @@
# Written by Jeremy Huntwork, 2004-12-16
#
-CFLAGS = -Os -s -Wall -static
-CC = gcc
-all: init
+all: initramfs_data.cpio.gz
MK= mknod
+CP= cp
WD= temp
+KLIBC= /usr/lib/klibc
-init: init.c
- mkdir -p $(WD)/dev
+initramfs_data.cpio.gz: init
+ @make -C .. ch-klibc
+ @make -C .. ch-unionfs
+ mkdir -p $(WD)/{dev,bin,lib,.cdrom,.sqfs,.tmpfs,.union}
+ $(CP) $(KLIBC)/bin/{insmod,isoinfo,losetup,mount,run-init,sh,sleep} $(WD)/bin
+ $(CP) $(KLIBC)/lib/klibc-*.so $(WD)/lib
+ $(CP) /lib/modules/$(KVERS)/kernel/fs/unionfs.ko $(WD)/lib
+ $(CP) init $(WD)
$(MK) -m 640 $(WD)/dev/console c 5 1
$(MK) -m 660 $(WD)/dev/hda b 3 0
$(MK) -m 660 $(WD)/dev/hdb b 3 64
@@ -28,11 +34,10 @@
$(MK) -m 660 $(WD)/dev/sr5 b 11 5
$(MK) -m 660 $(WD)/dev/sr6 b 11 6
$(MK) -m 660 $(WD)/dev/sr7 b 11 7
- $(CC) $(CFLAGS) $? -o $(WD)/$@
+ $(MK) -m 660 $(WD)/dev/loop0 b 7 0
cd $(WD); find . | cpio -o -H newc | gzip -9 > ../initramfs_data.cpio.gz
rm -rf temp
clean:
- -rm -f init
-rm -rf temp
-rm -f initramfs_data*
Index: Makefile
===================================================================
--- Makefile (revision 103)
+++ Makefile (working copy)
@@ -55,6 +55,7 @@
export chbash2 := SHELL=/bin/bash
export WHICH= $(WD)/bin/which
export WGET= wget --passive-ftp
+export KVERS= 2.6.11.6
FTPGET= $(WD)/bin/ftpget
WGET_V= 1.9.1
@@ -161,7 +160,7 @@
@if [ ! -f $(MP)/etc/X11/xorg.conf ] ; then if [ -f /etc/X11/xorg.conf ] ; then cp /etc/X11/xorg.conf $(PKG)/Xorg ; fi ; fi
pre-bash: createdirs createfiles popdev ch-linux-libc-headers ch-man-pages ch-glibc ch-re-adjust-toolchain \
- ch-binutils ch-gcc ch-coreutils ch-zlib ch-mktemp ch-iana-etc ch-findutils ch-gawk ch-sharutils ch-ncurses \
+ ch-binutils ch-gcc ch-coreutils ch-zlib ch-mktemp ch-iana-etc ch-findutils ch-gawk ch-sharutils ch-gpm ch-ncurses \
ch-readline ch-vim ch-m4 ch-bison ch-less ch-groff ch-sed ch-flex ch-gettext ch-inetutils \
ch-iproute2 ch-perl ch-texinfo ch-autoconf ch-automake ch-bash
@@ -169,7 +168,7 @@
ch-hotplug ch-man ch-make ch-module-init-tools ch-patch ch-procps ch-psmisc ch-shadow \
ch-sysklogd ch-sysvinit ch-tar ch-udev ch-util-linux ch-environment
-blfs: ch-openssl ch-wget ch-reiserfsprogs ch-xfsprogs ch-slang ch-nano ch-joe ch-screen ch-curl ch-gpm ch-zip \
+blfs: ch-openssl ch-wget ch-reiserfsprogs ch-xfsprogs ch-slang ch-nano ch-joe ch-screen ch-curl ch-zip \
ch-unzip ch-lynx ch-libxml2 ch-expat ch-subversion ch-lfs-bootscripts ch-docbook-xml ch-libxslt \
ch-docbook-xsl ch-html_tidy ch-LFS-BOOK ch-libpng ch-freetype ch-fontconfig ch-Xorg ch-freefont ch-libjpeg \
ch-libtiff ch-links ch-openssh ch-pkgconfig ch-glib2 ch-libungif ch-imlib2 ch-pango ch-atk ch-gtk2 \
@@ -851,6 +850,10 @@
make -C $(PKG)/$@ chroot
make unmount
+klibc: prep-chroot
+ make -C $(PKG)/$@ chroot
+ make unmount
+
strip: prep-chroot
@chroot $(MP) $(chenvstrip) 'cd $(ROOT) && make ch-strip'
make unmount
@@ -1339,6 +1342,12 @@
ch-syslinux: popdev
make -C $(PKG)/syslinux stage2
+ch-klibc: popdev
+ make -C $(PKG)/klibc stage2
+
+ch-unionfs: popdev
+ make -C $(PKG)/unionfs stage2
+
ch-strip: popdev
@$(WD)/bin/find /{,usr/}{bin,lib,sbin} -type f -exec $(WD)/bin/strip --strip-debug '{}' ';'
@@ -1346,7 +1355,7 @@
# Rules to create the iso
#----------------------------------
-prepiso:
+prepiso: unmount
@-rm $(MP)/etc/rc.d/rc{2,3,5}.d/{K,S}21xprint
@install -m644 etc/issue $(MP)/etc/issue
@sed -i "s/Version:/Version: $(VERSION)/" $(MP)/etc/issue
@@ -1354,12 +1363,12 @@
@-mv $(MP)/bin/uname.real $(MP)/bin/uname
@-mkdir $(MP)/iso
@-rm $(MP)/etc/X11/xorg.conf
- @for i in bin boot etc lib sbin sources ; do cp -ra $(MP)/$$i $(MP)/iso ; done && \
- cd $(MP) && tar cjvf etc.tar.bz2 etc && cp etc.tar.bz2 iso/ && \
- if [ -f root/.bash_history ] ; then rm root/.bash_history ; fi && \
- tar cjvf root.tar.bz2 root && cp root.tar.bz2 iso/ && \
- $(WD)/bin/mksquashfs usr usr.sqfs && mv usr.sqfs iso/ && \
- echo "LFS-LIVECD" > iso/LFS
+ @cp -rav $(MP)/sources $(MP)/iso && \
+ cp -rav $(MP)/boot $(MP)/iso && \
+ rm -f iso/root.sqfs && \
+ $(WD)/bin/mksquashfs $(MP) $(MP)/iso/root.sqfs -info -e \
+ boot sources tools iso lfs-livecd lost+found && \
+ echo "LFS-LIVECD" > $(MP)/iso/LFS
@touch prepiso
iso: prepiso
Index: packages/ncurses/Makefile
===================================================================
--- packages/ncurses/Makefile (revision 103)
+++ packages/ncurses/Makefile (working copy)
@@ -36,7 +36,7 @@
@if [ ! -f $(PATCH) ] ; then $(WGET) $(URL1) && bunzip2 $(PATCH).bz2 ; fi
@if [ ! -f /usr/bin/clear ] ; then tar -xjvf $(SRC)/$(FILE) && cd $(DIR) && \
sh ../$(PATCH) && \
- ./configure --prefix=/usr --with-shared --without-debug && \
+ ./configure --prefix=/usr --with-shared --without-debug --with-gpm && \
make sources && make -j3 && make install && chmod 755 /usr/lib/*.5.4 && \
chmod 644 /usr/lib/libncurses++.a && mv /usr/lib/libncurses.so.5* /lib && \
ln -sf ../../lib/libncurses.so.5 /usr/lib/libncurses.so && \
Index: packages/gpm/Makefile
===================================================================
--- packages/gpm/Makefile (revision 103)
+++ packages/gpm/Makefile (working copy)
@@ -27,7 +27,7 @@
@if [ ! -f $(PATCH2) ] ; then $(WGET) $(URL2) ; fi
@if [ ! -f /usr/sbin/gpm ] ; then tar xjvf $(FILE) && cd $(DIR) && \
patch -Np1 -i ../$(PATCH1) && patch -Np1 -i ../$(PATCH2) && \
- CFLAGS="" LDFLAGS="-lm" ./configure --prefix=/usr --sysconfdir=/etc && \
+ CFLAGS="" LDFLAGS="-lm" ./configure --prefix=/usr --sysconfdir=/etc --without-curses && \
make LDFLAGS="-lm" && make install && \
cp conf/gpm-root.conf /etc && /sbin/ldconfig ; fi
@make clean
Index: packages/lfs-bootscripts/Makefile
===================================================================
--- packages/lfs-bootscripts/Makefile (revision 103)
+++ packages/lfs-bootscripts/Makefile (working copy)
@@ -21,8 +21,12 @@
@echo ""
@if [ ! -f $(SRC)/$(FILE) ] ; then $(WGET) $(URL) && \
mv $(FILE) $(SRC) ; fi
- @if [ ! -f /etc/rc.d/init.d/mountsqfs ] ; then tar xjvf ${SRC}/${FILE} && \
- cd ${DIR} && make install-livecd ; fi
+ @if [ ! -f /etc/rc.d/init.d/functions ] ; then tar xjvf ${SRC}/${FILE} && \
+ cd ${DIR} && make install-livecd && \
+ install -m 755 lfs/init.d/{mountkernfs,udev} /etc/rc.d/init.d && \
+ ln -sf ../init.d/mountkernfs /etc/rc.d/rcsysinit.d/S00mountkernks && \
+ ln -sf ../init.d/udev /etc/rc.d/rcsysinit.d/S10udev && \
+ rm -f /etc/rc.d/*/*mountsqfs /etc/rc.d/*/*startup ; fi
clean:
@-rm -rf bootscripts
Index: packages/util-linux/Makefile
===================================================================
--- packages/util-linux/Makefile (revision 103)
+++ packages/util-linux/Makefile (working copy)
@@ -6,12 +6,12 @@
DIR= $(NM)-$(VRS)
FILE= $(DIR).tar.bz2
PATCH= $(DIR)-cramfs-1.patch
-URL= http://www.kernel.org/pub/linux/utils/$(NM)/$(FILE)
-URL1= http://www.linuxfromscratch.org/patches/lfs/cvs/testing/$(PATCH)
+URL= http://www.kernel.org/pub/linux/utils/$(NM)/$(FILE)
+URL1= http://www.linuxfromscratch.org/patches/lfs/cvs/testing/$(PATCH)
# RULES
-.PHONY: stage1 clean chroot stage2
+.PHONY: stage1 clean chroot stage2 klibc-losetup
stage1:
@echo ""
@@ -43,6 +43,15 @@
make HAVE_KILL=yes HAVE_SLN=yes install ; fi
@make clean
-
+klibc-losetup:
+ @echo ""
+ @echo "=====> Building losetup with klibc"
+ @echo ""
+ @if [ ! -f /usr/lib/klibc/bin/losetup ] ; then tar xjvf $(SRC)/$(FILE) && cd $(DIR) && \
+ patch -Np1 -i ../../klibc/util-linux-2.12q-klibc-1.patch && \
+ CC="klcc" LDFLAGS="-shared" ./configure && \
+ make lib/xstrncpy.o lib/getpass.o && make -C mount losetup && \
+ strip -s mount/losetup && install mount/losetup /usr/lib/klibc/bin ; fi
+ @make clean
clean:
@-rm -rf $(DIR)
Index: packages/klibc/util-linux-2.12q-klibc-1.patch
===================================================================
--- packages/klibc/util-linux-2.12q-klibc-1.patch (revision 0)
+++ packages/klibc/util-linux-2.12q-klibc-1.patch (revision 0)
@@ -0,0 +1,54 @@
+diff -urN util-linux-2.12q.orig/lib/getpass.c util-linux-2.12q/lib/getpass.c
+--- util-linux-2.12q.orig/lib/getpass.c 1970-01-01 05:00:00.000000000 +0500
++++ util-linux-2.12q/lib/getpass.c 2005-04-22 13:57:34.000000000 +0600
+@@ -0,0 +1,7 @@
++#include <stdio.h>
++
++const char *getpass(const char *prompt)
++{
++ fprintf(stderr, "This version of losetup doesn't support passwords.\n");
++ return "";
++}
+diff -urN util-linux-2.12q.orig/mount/lomount.c util-linux-2.12q/mount/lomount.c
+--- util-linux-2.12q.orig/mount/lomount.c 2004-12-21 03:11:04.000000000 +0500
++++ util-linux-2.12q/mount/lomount.c 2005-04-22 13:39:50.000000000 +0600
+@@ -395,7 +395,6 @@
+
+ #ifdef LOOP_SET_FD
+
+-#include <getopt.h>
+ #include <stdarg.h>
+
+ int verbose = 0;
+@@ -448,10 +447,6 @@
+ int pfd = -1;
+ unsigned long long off;
+
+- setlocale(LC_ALL, "");
+- bindtextdomain(PACKAGE, LOCALEDIR);
+- textdomain(PACKAGE);
+-
+ delete = find = 0;
+ off = 0;
+ offset = encryption = passfd = NULL;
+diff -urN util-linux-2.12q.orig/mount/Makefile util-linux-2.12q/mount/Makefile
+--- util-linux-2.12q.orig/mount/Makefile 2004-12-22 14:32:08.000000000 +0500
++++ util-linux-2.12q/mount/Makefile 2005-04-22 13:51:59.000000000 +0600
+@@ -29,7 +29,7 @@
+
+ MAYBE = pivot_root swapoff
+
+-LO_OBJS = lomount.o $(LIB)/xstrncpy.o
++LO_OBJS = lomount.o $(LIB)/xstrncpy.o $(LIB)/getpass.o
+ NFS_OBJS = nfsmount.o nfsmount_xdr.o nfsmount_clnt.o
+ GEN_FILES = nfsmount.h nfsmount_xdr.c nfsmount_clnt.c
+
+@@ -64,7 +64,7 @@
+ main_losetup.o: lomount.c
+ $(COMPILE) -DMAIN lomount.c -o $@
+
+-losetup: main_losetup.o $(LIB)/xstrncpy.o
++losetup: main_losetup.o $(LIB)/xstrncpy.o $(LIB)/getpass.o
+ $(LINK) $^ -o $@
+
+ mount.o umount.o nfsmount.o losetup.o fstab.o realpath.o sundries.o: sundries.h
Index: packages/klibc/isoinfo-0.03.02-fixes-1.patch
===================================================================
--- packages/klibc/isoinfo-0.03.02-fixes-1.patch (revision 0)
+++ packages/klibc/isoinfo-0.03.02-fixes-1.patch (revision 0)
@@ -0,0 +1,57 @@
+diff -urN isoinfo-0.03.02/isoinfo.c isoinfo-0.03.02.fixed/isoinfo.c
+--- isoinfo-0.03.02/isoinfo.c 2002-10-13 03:28:17.000000000 +0600
++++ isoinfo-0.03.02.fixed/isoinfo.c 2005-04-22 13:31:33.000000000 +0600
+@@ -103,7 +103,7 @@
+ iso_str( char* p, int n ) {
+ static char string[256];
+ int i= 0;
+- while( i < n ) string[i]= p[i++];
++ while( i < n ) { string[i]= p[i]; i++;}
+ string[i--]= '\0';
+ while( string[i] == ' ' ) string[i--]= '\0';
+ return( string );
+@@ -340,7 +340,7 @@
+ if( in_fd != STDIN_FILENO ) {
+ if( (in_fd=open(in_fn,O_RDONLY)) == -1 ) {
+ fprintf( ERROR_CHANNEL, "%s: Cannot open `%s'. %s.\n",
+- pn, in_fn, sys_errlist[errno] );
++ pn, in_fn, strerror(errno) );
+ retval= RETVAL_ERROR; goto DIE_NOW;
+ }
+ }
+@@ -354,12 +354,12 @@
+ if( in_fd != STDIN_FILENO ) { /* we can lseek() */
+ if( lseek(in_fd,blk_to_read*ISO_BLOCK_SIZE,SEEK_SET) == -1 ) {
+ fprintf( ERROR_CHANNEL, "%s: Cannot lseek `%s'. %s.\n",
+- pn, in_fn, sys_errlist[errno] );
++ pn, in_fn, strerror(errno) );
+ retval= RETVAL_ERROR; goto DIE_NOW;
+ }
+ if( (nbr=my_read(in_fd,buf,ISO_BLOCK_SIZE)) == -1 ) {
+ fprintf( ERROR_CHANNEL, "%s: Cannot read block %ld of `%s'. %s.\n",
+- pn, blk, in_fn, sys_errlist[errno] );
++ pn, blk, in_fn, strerror(errno) );
+ retval= RETVAL_ERROR; goto DIE_NOW;
+ }
+ blk= blk_to_read;
+@@ -411,7 +411,7 @@
+
+ if( close(in_fd) == -1 ) {
+ fprintf( ERROR_CHANNEL, "%s: Cannot close `%s'. %s.\n",
+- pn, in_fn, sys_errlist[errno] );
++ pn, in_fn, strerror(errno) );
+ retval= RETVAL_ERROR; goto DIE_NOW;
+ }
+
+diff -urN isoinfo-0.03.02/isoinfo.h isoinfo-0.03.02.fixed/isoinfo.h
+--- isoinfo-0.03.02/isoinfo.h 2002-10-13 03:28:17.000000000 +0600
++++ isoinfo-0.03.02.fixed/isoinfo.h 2005-04-22 11:00:53.000000000 +0600
+@@ -5,7 +5,7 @@
+ #undef DEBUG
+
+ #include <stdio.h> /* printf() */
+-#include <getopt.h> /* getopt() */
++/*#include <getopt.h> */ /* getopt() */
+ #include <errno.h> /* error numbers */
+ #include <unistd.h> /* read(), write(), close(), STDIN_FILENO */
+ #include <sys/types.h> /* open() */
Index: packages/klibc/Makefile
===================================================================
--- packages/klibc/Makefile (revision 0)
+++ packages/klibc/Makefile (revision 0)
@@ -0,0 +1,31 @@
+# Klibc Makefile
+
+# Package versions
+NM= klibc
+VRS= 1.0
+DIR= $(NM)-$(VRS)
+FILE= $(DIR).tar.bz2
+URL= http://www.kernel.org/pub/linux/libs/$(NM)/$(FILE)
+
+# RULES
+
+.PHONY: clean chroot stage2
+
+chroot:
+ @chroot "$(MP)" $(chenv3) 'cd $(ROOT) && make ch-$(NM) $(chbash2)'
+
+stage2:
+ @echo ""
+ @echo "=====> Building $(NM) in chroot"
+ @echo ""
+ @if [ ! -f $(SRC)/$(FILE) ] ; then $(WGET) $(URL) && \
+ mv $(FILE) $(SRC) ; fi
+ @if [ ! -d /usr/lib/klibc ] ; then tar xjvf $(SRC)/$(FILE) && cd $(DIR) && \
+ ln -nsf ../../linux/linux-$(KVERS) linux && make && make install && \
+ make -C ../../util-linux klibc-losetup && \
+ make -C ../../isoinfo klibc-isoinfo ; fi
+ @make clean
+
+
+clean:
+ @-rm -rf $(DIR)
Index: packages/flex/Makefile
===================================================================
--- packages/flex/Makefile (revision 103)
+++ packages/flex/Makefile (working copy)
@@ -40,11 +40,11 @@
@if [ ! -f /usr/bin/flex ] ; then tar xjvf $(SRC)/$(FILE) && cd $(DIR) && \
patch -Z -Np1 -i $(SRC)/$(PATCH) && touch doc/flex.1 && \
./configure --prefix=/usr && make -j3 && make install && \
- ln -s libfl.a /usr/lib/libl.a && \
+ ln -sf libfl.a /usr/lib/libl.a && \
echo "#!/bin/sh" > /usr/bin/lex && \
echo "# Begin /usr/bin/lex" >> /usr/bin/lex && \
echo "" >> /usr/bin/lex && \
- echo "exec /usr/bin/flex -l \"[EMAIL PROTECTED]"" >> /usr/bin/lex && \
+ echo "exec /usr/bin/flex -l \"[EMAIL PROTECTED]"" >> /usr/bin/lex && \
echo "" >> /usr/bin/lex && \
echo "# End /usr/bin/lex" >> /usr/bin/lex && \
chmod 755 /usr/bin/lex ; fi
Index: packages/linux/Makefile
===================================================================
--- packages/linux/Makefile (revision 103)
+++ packages/linux/Makefile (working copy)
@@ -2,12 +2,12 @@
# Package versions
NM= linux
-VRS= 2.6.11.6
+VRS= $(KVERS)
DIR= $(NM)-$(VRS)
FILE= $(DIR).tar.bz2
PATCH1= squashfs2.1-patch
PATCH2= $(DIR)-reiser4_missing_export-1.patch
-URL= http://www.kernel.org/pub/linux/kernel/v2.6/$(FILE)
+URL= http://www.kernel.org/pub/linux/kernel/v2.6/$(FILE)
URL1= http://ftp.namesys.com/pub/reiser4-for-2.6/2.6.11/broken-out
#RULES
Index: packages/isoinfo/Makefile
===================================================================
--- packages/isoinfo/Makefile (revision 0)
+++ packages/isoinfo/Makefile (revision 0)
@@ -0,0 +1,29 @@
+# isoinfo Makefile
+
+# Package versions
+NM= isoinfo
+VRS= 0.03.02
+DIR= $(NM)-$(VRS)
+FILE= $(DIR).tar.gz
+URL= ftp://metalab.unc.edu/pub/Linux/utils/disk-management/$(FILE)
+
+#RULES
+
+.PHONY: clean chroot klibc-isoinfo
+
+chroot:
+ @chroot "$(MP)" $(chenv3) 'cd $(ROOT) && make ch-$(NM) $(chbash2)'
+
+klibc-isoinfo:
+ @echo ""
+ @echo "=====> Building $(NM) in chroot"
+ @echo ""
+ @if [ ! -f $(FILE) ] ; then $(WGET) $(URL) ; fi
+ @if [ ! -f /usr/lib/klibc/bin/isoinfo ] ; then tar -xzvf $(FILE) && cd $(DIR) && \
+ patch -Np1 -i ../../klibc/$(NM)-$(VRS)-fixes-1.patch && \
+ make CC="klcc -shared" -f Makefile.Linux isoinfo && \
+ install isoinfo /usr/lib/klibc/bin ; fi
+ @make clean
+
+clean:
+ @-rm -rf $(DIR)
--
http://linuxfromscratch.org/mailman/listinfo/livecd
FAQ: http://www.linuxfromscratch.org/faq/
Unsubscribe: See the above information page