View previous topic :: View next topic |
Author |
Message |
gonaked n00b
Joined: 29 Aug 2009 Posts: 3
|
Posted: Mon Aug 31, 2009 7:34 pm Post subject: Gentoo minimal initramfs (5 Mb) + joe tip |
|
|
Code: | #!/bin/bash
# Gentoo minimal initramfs build script (kernels without module support assumed)
# D=locationdir P=portagedir (W=workdir1 B=binarypackages I=workdir2)
D=/root/gentooembedded && P=/usr/portage && W=$D/gem && B=$D/pkg && I=$D/initrd
# merge to your build environment first, THEN merge to initramfs
ARCH="x86" && CFLAGS="-Os -march=i486 -pipe" && CHOST="i486-pc-linux-gnu"
USE="glibc-omitfp ipv6 minimal unicode nonfsv4 -cracklib -nls -tcpd" && EXTRA=""
KEYMAP="us" && NAMESERVER="192.168.1.1" && NFS_OPTION="nfsmount" # or "nfs"
WANT_DHCP=false && WANT_NFS=false && WANT_JOE=true && WANT_LINKS=false
KEEP_W=false && STRIP_GLIBC=true && NO_DOCS=true && NO_COREUTILS=true
merge_more_stuff () { false;
# emerge -bDkN --root=$W --config-root=$W --root-deps=rdeps jfsutils || exit
}; extra_code () { false; } # for ex. copy kernel modules over to workdir1
# build system to W
if [ -d $W ]; then rm -r $W; fi && mkdir -p $W/{usr,etc}/portage $B
cp -a $P/profiles $W/usr/portage || exit; RD=--root-deps=rdeps
ln -s ../usr/portage/profiles/embedded $W/etc/make.profile ; echo -e 'ARCH="'\
$ARCH'"\nACCEPT_KEYWORDS="${ARCH}"\nCFLAGS="'$CFLAGS'"\nCXXFLAGS="${CFLAGS}"
CHOST="'$CHOST'"\nUSE="'$USE'"\nPKGDIR="'$B'"\n'$EXTRA > $W/etc/make.conf
echo 'sys-apps/busybox static -make-symlinks' > $W/etc/portage/package.use
emerge -bDkN --{,config-}root=$W $RD busybox baselayout util-linux \
procps udev kbd e2fsprogs gawk && cd $W/dev &&./MAKEDEV generic || exit
if [[ $ARCH == *64* ]]; then ln -s lib $W/lib64 && ln -s lib $W/usr/lib64; fi
emerge -bkNO --{,config-}root=$W $RD glibc || exit ; chmod 1777 $W/tmp
if $WANT_DHCP; then emerge -bDkN --{,config-}root=$W $RD dhcpcd || exit
echo 'config_eth0=( "dhcp" )' > $W/etc/conf.d/net
echo 'nameserver '$NAMESERVER > $W/etc/resolv.conf
ln -s /etc/init.d/net.eth0 $W/etc/runlevels/default/net.eth0
else echo 'config_eth0=( "null" )' > $W/etc/conf.d/net; fi
if $WANT_JOE; then emerge -bDkN --{,config-}root=$W $RD joe || exit
sed -i 's:/bin/nano:/usr/bin/joe:' $W/etc/rc.conf
echo 'alias joe='\''joe -nobackups'\' > $W/root/.profile; fi
if $WANT_LINKS; then emerge -bDkN --{,config-}root=$W $RD links || exit; fi
if $WANT_NFS; then emerge -bDkN --{,config-}root=$W $RD shadow || exit
emerge -bDkNo --{,config-}root=$W $RD nfs-utils || exit
ln -snf ../usr/portage/profiles/default/linux/$ARCH/10.0 $W/etc/make.profile
emerge -bDkN --{,config-}root=$W $RD nfs-utils || exit
ln -snf ../usr/portage/profiles/embedded $W/etc/make.profile
ln -s /etc/init.d/$NFS_OPTION $W/etc/runlevels/default/$NFS_OPTION; fi
echo 'tmpfs / tmpfs defaults 0 0' > $W/etc/fstab ; merge_more_stuff
if $NO_COREUTILS; then emerge -C --{,config-}root=$W coreutils || exit; fi
cd $W && find ./var/db/pkg -type d | cut -d '/' -f 5,6 | grep "\/" > $W/tmp/p
rm -r $W/{usr,etc}/portage $W/etc/make.profile $W/var/{db/*,cache}
mv $W/tmp/p $W/var/db/pkg.list && touch $W/etc/{mtab,etc-update.conf,ntp.conf}
tar -xpf $W/usr/share/busybox/busybox-links.tar -C $W/tmp
rm $W/tmp/bin/{find,xargs} && cp -an $W/tmp/bin/* $W/bin # findutils
cp -an $W/tmp/sbin/* $W/sbin && rm -r $W/tmp/* && if $STRIP_GLIBC; then
rm -r `find $W -name *.a` $W/usr/{lib/gconv,include,share/i18n}; fi
if $NO_DOCS; then rm -r $W/usr/share/{doc,info,man}; fi
if [[ $KEYMAP == "us" ]]; then # strip down to US qwerty
rm -r $W/usr/share/{consolefonts/{[!d]*,dr*},consoletrans/*}
rm -r $W/usr/share/keymaps/{[!i]*,i386/{[!iq]*,q*z,qwerty/{[!u]*,u[!s]*}}}
else sed -i 's/"us"/"'$KEYMAP'"/' $W/etc/conf.d/keymaps; fi
if $WANT_NFS; then echo -e '#!/bin/bash\ngroupadd -g 111 rpc
useradd -u 111 -g 111 -d /dev/null -s /sbin/nologin rpc\npasswd' > $W/t && \
chmod 700 $W/t && chroot $W /bin/bash -c './t && exit' && rm $W/t
else chroot $W /bin/bash -c 'passwd && exit'; fi ; extra_code
# build initramfs to I
if [ -d $I ]; then rm -r $I; fi && mkdir -p $I/{bin,etc,proc,sys,tmpfs}
cp -a $W/bin/busybox $I/bin && touch $I/etc/mtab && echo 'Compressing ...'
cd $W && tar -cpf $I/tmpfs.tar * && lzma -9 $I/tmpfs.tar && echo -e \
'#!/bin/busybox sh\nmount -t proc proc /proc && mount -t sysfs sysfs /sys
mount -t tmpfs -o rw tmpfs /tmpfs && unlzma -c /*.lzma | tar -xpC /tmpfs
mount -o remount,ro /tmpfs && umount /proc /sys && rm -r /*.lzma /proc /sys
exec switch_root /tmpfs /sbin/init' > $I/init && chmod +x $I/init
cd $I && find . -print0 | cpio -0o --format=newc > $W/initramfs.cpio
gzip -9 $W/initramfs.cpio && rm -r $I/* && mv $W/initramfs.cpio.gz $I
cut -d '/' -f 2 $W/var/db/pkg.list | sort | awk 'BEGIN {FS="-"; printf \
"\n* \033[01;32m"}; {printf $1; for (n=2 ; n<=NF ; n++) if ($n !~ /[0-9]/) \
printf "-" $n; printf "\033[00m * \033[01;32m"};END {printf "\033[00m\n\n"}'
if ! $KEEP_W; then rm -r $W; fi && echo 'Done. >>> '$I'/initramfs.cpio.gz <<<'
######################## LILO
#image=/path/kernel
# initrd=/path/initramfs.cpio.gz
# read-only
# root=/dev/initramfspartition
######################## LILO |
Joe's most used commands:
ctrl-c kill window without save......ctrl-e edit file in window......ctrl-a goto beginning of line......ctrl-k h enter and exit help
ctrl-k x save and kill window......ctrl-k d save window......ctrl-e goto end of line......esc-"." help next box
ctrl-k b begin text selection......ctrl-k o split window in two......ctrl-j cut to the end of line......esc-"," help previos box
ctrl-k k end text selection......ctrl-k n goto next window......ctrl-k u goto beginning of window......esc-s find forward
ctrl-k c copy selected text......ctrl-k p goto previos window......ctrl-k v goto end of window......esc-r find backward
ctrl-k m move selected text......ctrl-y delete line......ctrl-k f replace text (followed by operation: i=just find r=replace etc)
ctrl-k y delete selected text ......esc-y undelete line......ctrl-l repeat last find......ctrl-k "\" n repeat n times next command
ctrl-"_" or ctrl-shift-"_" undo......ctrl-"^" or ctrl-shift-"^" redo......ctrl-k z is "ctrl-z" stop to shell......ctrl-d delete
You may also want put - alias joe='joe -nobackups' - to your .profile if root .bashrc if user.
Need fast copying of some text in file1 to file2 and file3. Check this out: Code: | joe file1 file2 file3 |
Easy linux partition backup with initramfs:
Code: | mkdir /from /to && mount /dev/partitiontobackup /from && mount /dev/partitionusb /to && cd /from && \
tar -cjpf /to/backup.tar.bz2 * && cd / && umount /from /to |
Restore:
Code: | mkdir /from /to && mount /dev/partitionusb /from && mount /dev/partitiontorestore /to && rm -r /to/* && \
tar -xjpf /from/backup.tar.bz2 -C /to && umount /from /to |
Last edited by gonaked on Fri Oct 23, 2009 4:28 pm; edited 79 times in total |
|
Back to top |
|
|
judepereira Apprentice
Joined: 19 Jan 2008 Posts: 179 Location: Portage, yes, somewhere out there
|
Posted: Tue Sep 01, 2009 3:23 am Post subject: |
|
|
I'm sorry, but what exactly does this script do? I followed it through. Why have you made it rewrite the whole make.conf? If any inexperienced user runs this script, it will screw up all the apps he/she installs as it rewrites the make.conf which is critical to a Gentoo System. _________________ Jude Pereira
(http://judepereira.com) |
|
Back to top |
|
|
mikegpitt Advocate
Joined: 22 May 2004 Posts: 3224
|
Posted: Tue Sep 01, 2009 3:51 am Post subject: |
|
|
judepereira wrote: | I'm sorry, but what exactly does this script do? I followed it through. Why have you made it rewrite the whole make.conf? If any inexperienced user runs this script, it will screw up all the apps he/she installs as it rewrites the make.conf which is critical to a Gentoo System. | I think he's only copying over the make.conf into the initramfs, so it wouldn't affect what is on a users harddrive. I am a bit confused why there is a make.conf inside an initramfs though, as well as a make.profile. The initramfs only has the job of booting the system, which means stuff like that shouldn't be necessary.
BTW - Those who want to edit the initramfs that is generated though genkernel (or any other one for that matter) should take a look at a script called convinitrd on this thread:
https://forums.gentoo.org/viewtopic-t-452378.html
I've been using it for years to make small edits to the default initramfs. |
|
Back to top |
|
|
gonaked n00b
Joined: 29 Aug 2009 Posts: 3
|
Posted: Tue Sep 01, 2009 5:59 am Post subject: Why this script? Why embedded profile? Why new make.conf? |
|
|
Initramfs is good for transferring binarys from fast to old pc and it also serves as a rescue
system. Embedded (aka empty) profile is perfect for building compact systems since it doesn't
pull in anything. Suppose your CFLAGS on environment with toolchain(gcc): -march=k8.
With --config-root you tell to use new make.conf in work dir1 to build binarys for i486 not k8.
Last edited by gonaked on Mon Sep 07, 2009 12:42 pm; edited 8 times in total |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|