免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1918 | 回复: 1

LiveCD是这么产生的(转) [复制链接]

论坛徽章:
0
发表于 2011-12-21 08:41 |显示全部楼层
属于原创作品,如果转载,请注明出处和作者(springwind@bhu.edu.cn)


内核配置文件和busybox的配置文件,以及squashfs的补丁在附件中
LFS部分是参考LFS-6.3rc1来进行的,需要特别修改的地方已经标明在下面
全程制作过程见附件livecd.sh.gz


glibc-2.5
安装locale部分,使用自定义方式,只安装下面我需要的locale
代码:
mkdir -pv /usr/lib/locale localedef -i en_US -f ISO-8859-1 en_US localedef -i en_US -f UTF-8 en_US.UTF-8 localedef -i zh_CN -f GB2312 zh_CN localedef -i zh_CN -f GBK zh_CN.GBK localedef -i zh_CN -f GB18030 zh_CN.GB18030 localedef -i zh_CN -f UTF-8 zh_CN.UTF-8
按照晨想版主的建议,使用PRC
代码:
cp -v --remove-destination /usr/share/zoneinfo/PRC /etc/localtime

第八章
代码:
mv -v /etc/udev/rules.d/{75-cd-aliases-generator.rules,../} mv -v /etc/udev/rules.d/{75-persistent-net-generator.rules,../} rm -v /etc/udev/rules.d/70-persistent-cd.rules cat >/etc/udev/rules.d/81-cdrom.rules <<"EOF" # /etc/udev/rules.d/81-cdrom.rules: Set CD-ROM permissions. ACTION=="add", SUBSYSTEM=="block", ENV{ID_TYPE}=="cd", PROGRAM="getcdrom %k", SYMLINK+="cdrom%c", GROUP="cdrom" EOF cat >/lib/udev/getcdrom <<"EOF" #!/bin/sh i=0 while [ -e /dev/cdrom${i} ] do [ X$(realpath /dev/cdrom${i}) == X/dev/$1 ] && break let i=i+1 done echo $i exit 0 EOF chmod 755 /lib/udev/getcdrom
解释:

1、75-cd-aliases-generator.rules
75-persistent-net-generator.rules
的作用是创建一些静态的规则(写文件),在livecd上没有意义,在liveUSB上,会引起问题(因为每台机器的网卡的MAC都不同,直接导致的后果 是每在一台新的机器上运行后,网卡的编号是递增的,比如在A机上启动后,网卡的名字是eth0,可是,到另外一台机器上启动后,网卡是 eth1,....,另外,CDROM的名字也有这样的情况发生)
2、修改81-cdrom.rules,作用是在/dev目录下创建cdrom?这样的符号连接,链接到实际的光驱上面,第一个光驱是cdrom0,第二 个是cdrom1,依次类推(/lib/udev/getcdrom是一个shell脚本,目的就是获取某个光驱的编号,返回值从0开始)


代码:
cat > /etc/sysconfig/clock << "EOF" # Begin /etc/sysconfig/clock UTC=0 # End /etc/sysconfig/clock EOF
解释:

设置UTC=0,就是使用本地时间,否则看起来别扭,总是差8个小时


代码:
echo "HOSTNAME=livecd" > /etc/sysconfig/network cd /etc/sysconfig/network-devices mkdir -v ifconfig.eth0 cat > ifconfig.eth0/ipv4 << "EOF" ONBOOT=yes SERVICE=ipv4-static IP=192.168.1.1 GATEWAY=192.168.1.2 PREFIX=24 BROADCAST=192.168.1.255 EOF cat > /etc/resolv.conf << "EOF" # Begin /etc/resolv.conf #domain <Your Domain Name> nameserver 202.96.64.68 nameserver 202.96.69.38 # End /etc/resolv.conf EOF cat > /etc/fstab << "EOF" # Begin /etc/fstab # file system mount-point type options dump fsck # order #/dev/<xxx> / <fff> defaults 1 1 #/dev/<yyy> swap swap pri=1 0 0 proc /proc proc defaults 0 0 sysfs /sys sysfs defaults 0 0 devpts /dev/pts devpts gid=4,mode=620 0 0 shm /dev/shm tmpfs defaults 0 0 # End /etc/fstab EOF
解释:

1、设置机器名字为livecd
2、使用静态IP
3、DNS服务器是我使用的,这个需要按照实际情况改动
4、因为是用于liveCD或者liveUSB,因此,在/etc/fstab中是没有/和swap的,因此不需要写


内核编译部分
代码:
wget http://nchc.dl.sourceforge.net/sourceforge/squashfs/squashfs3.2-r2.tar.gz tar xf squashfs3.2-r2.tar.gz cd linux-2.6.22.1 patch -Np1 -i ../squashfs3.2-r2/kernel-patches/linux-2.6.20/squashfs3.2-patch cd /sources/squashfs3.2-r2/squashfs-tools make cd /sources/linux-2.6.22.1 patch -Np1 -i ../linux-2.6.22.1-squashfs.patch make make modules_install cp -v arch/i386/boot/bzImage /boot/vmlinuz-2.6.22.1 cp -v System.map /boot/System.map-2.6.22.1 cp -v .config /boot/config-2.6.22.1 cd /sources/aufs make KDIR=/lib/modules/2.6.22.1/build/ -f local.mk install -m 500 -p mount.aufs umount.aufs auplink aulchown /sbin echo FLUSH=ALL > /etc/default/auplink mkdir /lib/modules/2.6.22.1/kernel/fs/aufs cp aufs.ko /lib/modules/2.6.22.1/kernel/fs/aufs/ depmod -a 2.6.22.1 echo 6.3-rc1 > /etc/lfs-release #mkinitrd cd /sources tar xf busybox-1.5.1.tar.bz2 cd busybox-1.5.1 make defconfig make mkdir /initrd cd /initrd mkdir bin dev etc lib mnt/{,cdrom,root,roroot,rwroot} proc root sbin sys tmp chmod 1777 tmp cp /sbin/{modinfo,udevd,udevtrigger,depmod,modprobe,udevcontrol,udevsettle} sbin/ cp -a /sources/busybox-1.5.1/_install/{bin,sbin} . cp -a /etc/udev etc/ cp -a /lib/udev lib/ cp -a /lib/{ld-linux.so.2,libc.so.6,libvolume_id.so.0,libvolum_id.so.0.78.0} lib/ mkdir -p lib/modules/2.6.22.1/kernel/{drivers,fs} cp -a /lib/modules/2.6.22.1/kernel/drivers/{ata,block,cdrom,hid,ide,input,pcmia,scsi,usb} lib/modules/2.6.22.1/kernel/drivers/ cp -a /lib/modules/2.6.22.1/kernel/fs lib/modules/2.6.22.1/kernel/ cat >init <<"EOF" #!/bin/sh PATH=/bin:/sbin mount -t proc proc /proc mount -t sysfs sysfs /sys ro=-r INIT=/sbin/init ROOTDELAY= DEBUG= NOAUFS= for i in $(cat /proc/cmdline) do case "$i" in rootdelay=*) ROOTDELAY=${i#rootdelay=} ;; esac done /sbin/depmod -a echo > /proc/sys/kernel/hotplug cp -a /lib/udev/devices/* /dev /sbin/udevd --daemon /sbin/udevtrigger /sbin/udevsettle if [ X$ROOTDELAY != X ] then echo "wait $ROOTDELAY seconds ......" sleep $ROOTDELAY fi for i in $(cat /proc/cmdline) do case "$i" in root=*) ROOT=${i#root=} case "$ROOT" in UUID=*) ROOT=${ROOT#UUID=} ROOT=$(realpath /dev/disk/by-uuid/$ROOT) ;; /dev/*) ROOT=$ROOT ;; *) ROOT= esac ;; init=*) INIT=${i#init=} ;; ro) ro=-r ;; rw) ro= ;; debug) DEBUG=1 ;; noaufs) NOAUFS=1 ;; esac done if [ X$DEBUG != X ] then echo "enter debug mode..." PS1='\[\033[0;34m(debug)\033[0m\]$ ' /bin/sh -i else PS1='\[033[0;31m(initramfs)\033[0m\]$ ' [ -d /mnt/cdrom ] || mkdir /mnt/cdrom [ -d /mnt/root ] || mkdir /mnt/root [ -d /mnt/roroot ] || mkdir /mnt/roroot [ -d /mnt/rwroot ] || mkdir /mnt/rwroot if [ X$ROOT == X ] then echo "mount cdrom ......" modprobe iso9660 for i in 1 2 4 8 do for CDROM in /dev/cdrom* do mount -nt iso9660 -o ro $CDROM /mnt/cdrom mountpoint -q /mnt/cdrom && break [ -f /mnt/cdrom/root.sqfs ] && break umount /mnt/cdrom done [ -f /mnt/cdrom/root.sqfs ] && break sleep $i done else echo "mount rootdev(${ROOT}) ......" FSTYPE=$(/lib/udev/vol_id -t "${ROOT}" 2> /dev/null) if [ X$FSTYPE != X ] then modprobe nls_iso8859-1 modprobe nls_cp437 modprobe $FSTYPE for i in 1 2 4 8 do mount -nt $FSTYPE -o ro $ROOT /mnt/cdrom mountpoint -q /mnt/cdrom && break sleep $i done fi fi mountpoint -q /mnt/cdrom || (echo "no rootdev";/bin/sh -i) if [ X$AUFS == X ] then echo "mount roroot ......" mount -o remount,rw /mnt/cdrom modprobe loop modprobe squashfs for i in 1 2 4 8 do mount -nt squashfs -o loop,ro /mnt/cdrom/root.sqfs /mnt/roroot mountpoint -q /mnt/roroot && break sleep $i done mountpoint -q /mnt/roroot || (echo "no roroot";/bin/sh -i) mount -nt tmpfs -o mode=755 tmpfs /mnt/rwroot mountpoint -q /mnt/rwroot || (echo "no tmpfs";/bin/sh -i) echo "mount realroot ......" modprobe aufs for i in 1 2 4 8 do mount -nt aufs -o br:/mnt/rwroot=rw:/mnt/roroot=ro aufsroot /mnt/root mountpoint -q /mnt/root && break sleep $i done mountpoint -q /mnt/root || (echo "no root";/bin/sh -i) mkdir /mnt/root/mnt/.rootdev mount --bind /mnt/cdrom /mnt/root/mnt/.rootdev touch /mnt/root/fastboot touch /mnt/root/.livecd else mount -n -o move /mnt/cdrom /mnt/root fi #start up hook [ -f /mnt/cdrom/onboot.sh ] && sh /mnt/cdrom/onboot.sh killall udevd umount /proc umount /sys fi exec switch_root /mnt/root $INIT "$@" EOF
解释:

1、因为CD和USB的空间有限,因此需要对root文件系统进行压缩,我使用的是squashfs来进行压缩,因为squashfs是只读的,可是实际 运行中需要对/文件系统进行写操作,因此使用aufs来挂载/文件系统,将所有的写操作在内存中进行(squashfs和aufs的获取可能通过官方网站 的提示进行,我的aufs是通过cvs获取的)
2、initrd使用initramfs,这种initrd比较简单,而且可控性很强,因为启动后,这个initrd就被释放,因此,使用busybox 来提供大部分工具,省得复制一些运行库,目的是尽可能减少initrd的空间,不过,因为把一部分内核模块复制到initrd中了,initrd的容量已 经比较大了,有20M左右,因此,这部分的减小没有太大意义,不过,如果只是编译内核,使得内核只支持IDE的cdrom的话,和部分USB的光驱,以及 部分SATA的光驱的话,内核模块的容量还是比较小的。
3、在复制内核模块的fs部分,实际上只需要复制部分用得着的,比如livecd只需要isofs,aufs,squashfs,liveUSB只需要aufs,squashfs和USB分区的分区类型的相应模块
4、initrd中使用的是udev,只是为了方便,如果有能力的话,可以自己去创建设备节点(那样做有一些麻烦,因为还需要手动去加载相应的内核模块,工作量确实不少),就可以不用udev了


额外工具
其中一部分是参考BLFS的开发版的手册,其它的都可以从internet上获取
代码:
tar xf zhcon-0.2.5.tar.gz cd zhcon-0.2.5 zcat ../zhcon-0.2.5-to-0.2.6.diff.gz | patch -Np1 ./configure --prefix=/usr --sysconfdir=/etc make && make install
解释:
因为暂时不想安装X,因此,在控制台下面对中文的支持是必要的

代码:
tar xf openssl-0.9.8d.tar.gz cd openssl-0.9.8d patch -Np1 -i ../openssl-0.9.8d-fix_manpages-1.patch make MANDIR=/usr/share/man make MANDIR=/usr/share/man install cp -v -r certs /etc/ssl && install -v -d -m755 /usr/share/doc/openssl-0.9.8d && cp -v -r doc/{HOWTO,README,*.{txt,html,gif}} \ /usr/share/doc/openssl-0.9.8d cd /sources/blfs/ && rm -rf openssl-0.9.8d tar xf wget-1.10.2.tar.gz cd wget-1.10.2 ./configure --prefix=/usr --sysconfdir=/etc && make && make install cd /sources/blfs/ && rm -rf wget-1.10.2 tar xf pcre-7.2.tar.bz2 cd pcre-7.2 ./configure --prefix=/usr \ --docdir=/usr/share/doc/pcre-7.2 \ --enable-utf8 && make && make install mv -v /usr/lib/libpcre.so.* /lib/ && ln -v -sf ../../lib/libpcre.so.0 /usr/lib/libpcre.so cd /sources/blfs/ && rm -rf pcre-7.2 cat > /usr/bin/which << "EOF" #!/bin/bash type -pa "$@" | head -n 1 ; exit ${PIPESTATUS[0]} EOF chmod -v 755 /usr/bin/which chown -v root:root /usr/bin/which tar xf pkg-config-0.22.tar.gz cd pkg-config-0.22 ./configure --prefix=/usr && make && make install cd /sources/blfs/ && rm -rf pkg-config-0.22 tar xf cpio-2.9.tar.bz2 cd cpio-2.9 ./configure CPIO_MT_PROG=mt \ --prefix=/usr \ --bindir=/bin \ --libexecdir=/tmp \ --with-rmt=/usr/sbin/rmt && make && make install cd /sources/blfs/ && rm -rf cpio-2.9 tar xf pciutils-2.2.3.tar.bz2 cd pciutils-2.2.3 sed -i 's/null ;/null 2>\&1 ;/' update-pciids.sh && make PREFIX=/usr && make PREFIX=/usr install && install -v -m 755 -d /usr/include/pci && install -v -m 644 lib/libpci.a /usr/lib && install -v -m 644 lib/*.h /usr/include/pci update-pciids cd /sources/blfs/ && rm -rf pciutils-2.2.3 tar xf gc6.8.tar.gz cd gc6.8 sed -i "s|\$(datadir)/@PACKAGE@|&-6.8|" doc/Makefile.in && ./configure --prefix=/usr \ --datadir=/usr/share/doc --enable-cplusplus && make && make install && install -v -m644 doc/gc.man /usr/share/man/man3/gc_malloc.3 && ln -v -s gc_malloc.3 /usr/share/man/man3/gc.3 && cd /sources/blfs/ && rm -rf gc6.8 tar xf w3m-0.5.2.tar.gz cd w3m-0.5.2 ./configure --prefix=/usr \ --libexecdir=/usr/lib \ --sysconfdir=/etc && make && make install && install -v -m644 -D doc/keymap.default /etc/w3m/keymap && install -v -m644 doc/menu.default /etc/w3m/menu && install -v -m755 -d /usr/share/doc/w3m-0.5.2 && install -v -m644 doc/{HISTORY,READ*,keymap.*,menu.*,*.html} \ /usr/share/doc/w3m-0.5.2 cd /sources/blfs/ && rm -rf w3m-0.5.2 tar xf screen-4.0.3.tar.gz cd screen-4.0.3 ./configure --prefix=/usr --with-socket-dir=/var/run/screen \ --with-sys-screenrc=/etc/screenrc && sed -i -e "s%/usr/local/etc/screenrc%/etc/screenrc%" {etc,doc}/* && make && make install && install -m 644 etc/etcscreenrc /etc/screenrc cd /sources/blfs/ && rm -rf screen-4.0.3 tar xf openssh-4.6p1.tar.gz cd openssh-4.6p1 install -v -m700 -d /var/lib/sshd && chown -v root:sys /var/lib/sshd && groupadd -g 50 sshd && useradd -c 'sshd PrivSep' -d /var/lib/sshd -g sshd \ -s /bin/false -u 50 sshd sed -i "s:-lcrypto:/usr/lib/libcrypto.a -ldl:g" configure sed -i "s/lkrb5 -ldes/lkrb5/" configure && ./configure --prefix=/usr --sysconfdir=/etc/ssh \ --libexecdir=/usr/lib/openssh --with-md5-passwords \ --with-privsep-path=/var/lib/sshd && make && make install && install -v -m755 -d /usr/share/doc/openssh-4.6p1 && install -v -m644 INSTALL LICENCE OVERVIEW README* WARNING.RNG \ /usr/share/doc/openssh-4.6p1 cd /sources/blfs/ && rm -rf openssh-4.6p1 tar xf dhcp-3.0.5.tar.gz cd dhcp-3.0.5 patch -Np1 -i ../dhcp-3.0.5-client_dns-1.patch patch -Np1 -i ../dhcp-3.0.5-iproute2-1.patch ./configure && make && make LIBDIR=/usr/lib INCDIR=/usr/include install cat > /etc/dhclient.conf << "EOF" # dhclient.conf interface "eth0"{ prepend domain-name-servers 127.0.0.1; request subnet-mask, broadcast-address, time-offset, routers, domain-name, domain-name-servers, host-name; require subnet-mask, domain-name-servers; } # end dhclient.conf EOF cd /sources/blfs/ && rm -rf dhcp-3.0.5 cat > /etc/sysconfig/network-devices/dhclient.example << "EOF" ONBOOT="yes" SERVICE="dhclient" DHCP_START="-q <add additional start parameters here>" DHCP_STOP="-q -r <add additional stop parameters here>" # Set PRINTIP="yes" to have the script print # the DHCP assigned IP address PRINTIP="no" # Set PRINTALL="yes" to print the DHCP assigned values for # IP, SM, DG, and 1st NS. This requires PRINTIP="yes". PRINTALL="no" EOF tar xf ppp-2.4.4.tar.gz && cd ppp-2.4.4 && ./configure --prefix=/usr && make && make install && make install-etcppp && cd /sources/blfs/ && rm -rf ppp-2.4.4 tar xf rp-pppoe-3.8.tar.gz && cd rp-pppoe-3.8 && patch -Np1 -i ../rp-pppoe-3.8-iproute2-1.patch && sed -i s%/usr/bin/logger%/bin/logger% scripts/pppoe-{connect,setup,stop}.in && cd src && ./configure && make && make install && cat > /etc/sysconfig/network-devices/pppoe-example << "EOF" ONBOOT="yes" SERVICE="pppoe" EOF cd /sources/blfs/ && rm -rf rp-pppoe-3.8 cd blfs-bootscripts-20070726 && make install-service-pppoe && cd /sources/blfs tar xf libpcap-0.9.6.tar.gz && cd libpcap-0.9.6 && ./configure --prefix=/usr && make && make install && install -v -m755 -d /usr/share/doc/libpcap-0.9.6 && install -v -m644 doc/* /usr/share/doc/libpcap-0.9.6 && cd /sources/blfs/ && rm -rf libpcap-0.9.6 tar xf wireless_tools.28.tar.gz && cd wireless_tools.28 && make && make install && cd /sources/blfs/ && rm -rf wireless_tools.28 tar xf glib-2.12.12.tar.bz2 && cd glib-2.12.12 && ./configure --prefix=/usr && make && make install && cat > /etc/profile.d/glib2-locale.sh << "EOF" # Use the current locale charset for filenames # in applications using GLib export G_FILENAME_ENCODING=@locale EOF cd /sources/blfs/ && rm -rf glib-2.12.12 tar xf wireshark-0.99.6.tar.bz2 && cd wireshark-0.99.6 && ./configure --prefix=/usr \ --sysconfdir=/etc \ --enable-threads \ --disable-wireshark && make && make install && install -v -m755 -d /usr/share/doc/wireshark-0.99.6 && install -v -m644 FAQ README{,.linux} doc/README.* doc/*.{pod,txt} \ /usr/share/doc/wireshark-0.99.6 && pushd /usr/share/doc/wireshark-0.99.6 && for FILENAME in ../../wireshark/*.html; do \ ln -s -v $FILENAME . done && popd && cd /sources/blfs/ && rm -rf wireshark-0.99.6 tar xf nmap-4.20.tar.bz2 && cd nmap-4.20 && ./configure --prefix=/usr --without-nmapfe && make && make install && cd /sources/blfs/ && rm -rf nmap-4.20 tar xf traceroute-1.4a12.tar.gz && cd traceroute-1.4a12 && sed -i -e 's/-o bin/-o root/' Makefile.in && ./configure --prefix=/usr && make && make install && make install-man && cd /sources/blfs/ && rm -rf traceroute-1.4a12 tar xf whois_4.7.21.tar.gz && cd whois-4.7.21 && make && make prefix=/usr install && cd /sources/blfs/ && rm -rf whois-4.7.21 tar xf bind-9.4.1-P1.tar.gz && cd bind-9.4.1-P1 && ./configure --prefix=/usr && make -C lib/dns && make -C lib/isc && make -C lib/bind9 && make -C lib/isccfg && make -C lib/lwres && make -C bin/dig && make -C bin/dig install && cd /sources/blfs/ && rm -rf bind-9.4.1-P1 tar xf lftp-3.5.12.tar.bz2 && cd lftp-3.5.12 && ./configure --prefix=/usr && make && make install && cd /sources/blfs/ && rm -rf lftp-3.5.12 groupadd -g 46 proftpd && useradd -c proftpd -d /srv/ftp -g proftpd \ -s /usr/bin/proftpdshell -u 46 proftpd && install -v -d -m775 -o proftpd -g proftpd /srv/ftp && ln -v -s /bin/false /usr/bin/proftpdshell && echo /usr/bin/proftpdshell >> /etc/shells && tar xf proftpd-1.3.0.tar.bz2 && cd proftpd-1.3.0 && ./configure --prefix=/usr --sysconfdir=/etc \ --localstatedir=/var/run && make && make install && cat > /etc/proftpd.conf << "EOF" # This is a basic ProFTPD configuration file # It establishes a single server and a single anonymous login. ServerName "ProFTPD Default Installation" ServerType standalone DefaultServer on # Port 21 is the standard FTP port. Port 21 # Umask 022 is a good standard umask to prevent new dirs and files # from being group and world writable. Umask 022 # To prevent DoS attacks, set the maximum number of child processes # to 30. If you need to allow more than 30 concurrent connections # at once, simply increase this value. Note that this ONLY works # in standalone mode, in inetd mode you should use an inetd server # that allows you to limit maximum number of processes per service # (such as xinetd) MaxInstances 30 # Set the user and group that the server normally runs at. User proftpd Group proftpd # Normally, files should be overwritable. <Directory /*> AllowOverwrite on </Directory> # A basic anonymous configuration, no upload directories. <Anonymous ~proftpd> User proftpd Group proftpd # Clients should be able to login with "anonymous" as well as "proftpd" UserAlias anonymous proftpd # Limit the maximum number of anonymous logins MaxClients 10 # 'welcome.msg' should be displayed at login, and '.message' displayed # in each newly chdired directory. DisplayLogin welcome.msg DisplayFirstChdir .message # Limit WRITE everywhere in the anonymous chroot <Limit WRITE> DenyAll </Limit> </Anonymous> EOF cd /sources/blfs/ && rm -rf proftpd-1.3.0 cd /sources/blfs/blfs-bootscripts-20070726 make install-proftpd cd /sources/blfs tar xf gpm-1.20.1.tar.bz2 && cd gpm-1.20.1 && patch -Np1 -i ../gpm-1.20.1-segfault-1.patch && patch -Np1 -i ../gpm-1.20.1-silent-1.patch && ./configure --prefix=/usr --sysconfdir=/etc && LDFLAGS="-lm" make && make install && cp -v conf/gpm-root.conf /etc && ldconfig && cat > /etc/sysconfig/mouse << "EOF" # Begin /etc/sysconfig/mouse MDEVICE="/dev/input/mouse0" PROTOCOL="imps2" GPMOPTS="" # End /etc/sysconfig/mouse EOF cd /sources/blfs/ && rm -rf gpm-1.20.1 cd /sources/blfs/blfs-bootscripts-20070726 make install-gpm cd /sources/blfs tar xf slang-2.1.1.tar.bz2 && cd slang-2.1.1 && ./configure --prefix=/usr --sysconfdir=/etc && make && make install_doc_dir=/usr/share/doc/slang-2.1.1 install-all && chmod -v 755 /usr/lib/libslang.so.2.1.1 \ /usr/lib/slang/v2/modules/*.so && cd /sources/blfs/ && rm -rf slang-2.1.1 tar xf mc-4.6.1.tar.gz && cd mc-4.6.1 && patch -Np1 -i ../mc-4.6.1-bash32-1.patch && patch -Np1 -i ../mc-4.6.1-debian_fixes-1.patch && CPPFLAGS="-DUTF8" ./configure --prefix=/usr \ --enable-charset && make && convert-mans ISO-8859-1 UTF-8 lib/mc.hint{,.es,.it,.nl} && convert-mans ISO-8859-2 UTF-8 lib/mc.hint{.cs,.hu,.pl} && convert-mans ISO-8859-5 UTF-8 lib/mc.hint.sr && convert-mans KOI8-R UTF-8 lib/mc.hint.ru && convert-mans KOI8-U UTF-8 lib/mc.hint.uk && convert-mans BIG5 UTF-8 lib/mc.hint.zh && convert-mans ISO-8859-1 UTF-8 doc/{es,it}/mc.hlp.* && convert-mans ISO-8859-2 UTF-8 doc/{hu,pl}/mc.hlp.* && convert-mans ISO-8859-5 UTF-8 doc/sr/mc.hlp.sr && convert-mans KOI8-R UTF-8 doc/ru/mc.hlp.ru && make install && chmod 1755 /usr/lib/mc/cons.saver && cd /sources/blfs/ && rm -rf mc-4.6.1 #comiple p7zip need nasm #wget "http://downloads.sourceforge.net/nasm/nasm-0.99.01.tar.bz2?modtime=1180529807&big_mirror=0" tar xf nasm-0.99.01.tar.bz2 && cd nasm-0.99.01 && ./configure && make && cp nasm /usr/local/bin/ && cd /sources/blfs/ && rm -rf nasm-0.99.01 tar xf p7zip_4.51_src_all.tar.bz2 && cd p7zip_4.51 && cp makefile.linux_x86_asm_gcc_4.X makefile.machine && make clean && make all3 && sed -i "s@DEST_HOME=/usr/local@DEST_HOME=/usr@" install.sh && ./install.sh && cd /sources/blfs/ && rm -rf p7zip_4.51 tar xf fuse-2.7.0.tar.gz && cd fuse-2.7.0 && ./configure --disable-kernel-module --prefix=/usr && make && make install && cd /sources/blfs/ && rm -rf fuse-2.7.0 tar xf sshfs-fuse-1.8.tar.gz && cd sshfs-fuse-1.8 && ./configure --prefix=/usr && make && make install && cd /sources/blfs/ && rm -rf sshfs-fuse-1.8 tar xf curl-7.16.3.tar.bz2 && cd curl-7.16.3 && ./configure --prefix=/usr && make && make install && find docs -name "Makefile*" -o -name "*.1" -o -name "*.3" | xargs rm && install -v -d -m755 /usr/share/doc/curl-7.16.3 && cp -v -R docs/* /usr/share/doc/curl-7.16.3 && cd /sources/blfs/ && rm -rf curl-7.16.3 #wget "http://downloads.sourceforge.net/curlftpfs/curlftpfs-0.9.1.tar.gz?modtime=1175788159&big_mirror=0" tar xf curlftpfs-0.9.1.tar.gz && cd curlftpfs-0.9.1 && ./configure --prefix=/usr && make && make install && cd /sources/blfs/ && rm -rf curlftpfs-0.9.1 tar xf ntfs-3g-1.710.tgz && cd ntfs-3g-1.710 && ./configure --prefix=/usr && make && make install && cd /sources/blfs/ && rm -rf ntfs-3g-1.710
解释:

我只是安装一些我觉得有用的工具,具体应该安装哪些,视各人喜好而定
1、wget,lftp可以用来下载文件和访问ftp服务器
2、w3m可以浏览网页
3、screen是一个可爱的工具
4、openssh,proftpd分别提供ssh服务和ftp服务
5、dhcp可以动态获取IP,在很多场合下是必要的
6、rp-pppoe可以提供ADSL拨号功能
7、wireless-tool可以提供对无线网卡的控制(内核中已经把大部分无线网卡的驱动编译成模块了)
8、nmap,wireshark是网络工具
9、sshfs,curlftpfs,ntfs-3g是一些可爱的工具,sshfs可以通过ssh将远程主机上的文件系统挂载到本地;curlftpfs可以将远程FTP上的目录挂载到本地;ntfs-3g可以提供对ntfs的读写操作
10、cpio,p7zip是压缩解压工具,p7zip可以支持大部分的压缩格式
11、gpm支持控制台下面使用鼠标(启动后,我发现在/dev/input下面有鼠标的设备节点,分别是mouse0,mouse1....,所以就在配置文件中使用了/dev/input/mouse0作为鼠标的设备节点了)
12、mc是一个大部分人都说好的工具

期待您的参与,给提供一些好的工具,以便添加到livecd中



修正启动脚本中的一点问题
代码:
ln -sf /proc/mounts /etc/mtab cat > /etc/rc.d/init.d/mountfs <<"EOF" #!/bin/sh ######################################################################## # Begin $rc_base/init.d/mountfs # # Description : File System Mount Script # # Authors : Gerard Beekmans - gerard@linuxfromscratch.org # # Version : 00.00 # # Notes : # ######################################################################## . /etc/sysconfig/rc . ${rc_functions} case "${1}" in start) boot_mesg "Remounting root file system in read-write mode..." [ -f /.livecd ] || mount -n -o remount,rw / >/dev/null 2>&1 evaluate_retval # Remove fsck-related file system watermarks. rm -f /fastboot /forcefsck /.livecd # This will mount all filesystems that do not have _netdev in # their option list. _netdev denotes a network filesystem. boot_mesg "Mounting remaining file systems..." mount -an -O no_netdev >/dev/null 2>&1 evaluate_retval ;; stop) boot_mesg "Unmounting all other currently mounted file systems..." umount -a -d -r >/dev/null 2>&1 evaluate_retval ;; *) echo "Usage: ${0} {start|stop}" exit 1 ;; esac # End $rc_base/init.d/mountfs EOF
解释:

因为livecd使用的方式有些特别,因此,在mountfs中运行的一些脚本可能出现错误(不影响实际的使用)
在livecd的initrd中已经挂载了/文件系统,并且是可写的,因此,在mountfs中就不需要重新以rw方式挂载/了


设置一些必要的配置文件(来自BLFS手册)
代码:
cat > /etc/profile << "EOF" # Begin /etc/profile # Written for Beyond Linux From Scratch # by James Robertson <jameswrobertson@earthlink.net> # modifications by Dagmar d'Surreal <rivyqntzne@pbzpnfg.arg> # System wide environment variables and startup programs. # System wide aliases and functions should go in /etc/bashrc. Personal # environment variables and startup programs should go into # ~/.bash_profile. Personal aliases and functions should go into # ~/.bashrc. # Functions to help us manage paths. Second argument is the name of the # path variable to be modified (default: PATH) pathremove () { local IFS=':' local NEWPATH local DIR local PATHVARIABLE=${2:-PATH} for DIR in ${!PATHVARIABLE} ; do if [ "$DIR" != "$1" ] ; then NEWPATH=${NEWPATH:+$NEWPATH:}$DIR fi done export $PATHVARIABLE="$NEWPATH" } pathprepend () { pathremove $1 $2 local PATHVARIABLE=${2:-PATH} export $PATHVARIABLE="$1${!PATHVARIABLE:+:${!PATHVARIABLE}}" } pathappend () { pathremove $1 $2 local PATHVARIABLE=${2:-PATH} export $PATHVARIABLE="${!PATHVARIABLE:+${!PATHVARIABLE}:}$1" } # Set the initial path export PATH=/bin:/usr/bin if [ $EUID -eq 0 ] ; then pathappend /sbin:/usr/sbin unset HISTFILE fi # Setup some environment variables. export HISTSIZE=1000 export HISTIGNORE="&:[bf]g:exit" # Setup a red prompt for root and a green one for users. NORMAL="\[\e[0m\]" RED="\[\e[1;31m\]" GREEN="\[\e[1;32m\]" if [[ $EUID == 0 ]] ; then PS1="$RED\u [ $NORMAL\w$RED ]# $NORMAL" else PS1="$GREEN\u [ $NORMAL\w$GREEN ]\$ $NORMAL" fi for script in /etc/profile.d/*.sh ; do if [ -r $script ] ; then . $script fi done # Now to clean up unset pathremove pathprepend pathappend # End /etc/profile EOF install --directory --mode=0755 --owner=root --group=root /etc/profile.d cat > /etc/profile.d/dircolors.sh << "EOF" # Setup for /bin/ls to support color, the alias is in /etc/bashrc. if [ -f "/etc/dircolors" ] ; then eval $(dircolors -b /etc/dircolors) if [ -f "$HOME/.dircolors" ] ; then eval $(dircolors -b $HOME/.dircolors) fi fi alias ls='ls --color=auto' EOF cat > /etc/profile.d/readline.sh << "EOF" # Setup the INPUTRC environment variable. if [ -z "$INPUTRC" -a ! -f "$HOME/.inputrc" ] ; then INPUTRC=/etc/inputrc fi export INPUTRC EOF cat > /etc/profile.d/umask.sh << "EOF" # By default we want the umask to get set. if [ "$(id -gn)" = "$(id -un)" -a $EUID -gt 99 ] ; then umask 002 else umask 022 fi EOF cat > /etc/profile.d/i18n.sh << "EOF" # Set up i18n variables export LANG=zh_CN.UTF-8 EOF cat > /etc/bashrc << "EOF" # Begin /etc/bashrc # Written for Beyond Linux From Scratch # by James Robertson <jameswrobertson@earthlink.net> # updated by Bruce Dubbs <bdubbs@linuxfromscratch.org> # System wide aliases and functions. # System wide environment variables and startup programs should go into # /etc/profile. Personal environment variables and startup programs # should go into ~/.bash_profile. Personal aliases and functions should # go into ~/.bashrc # Provides a colored /bin/ls command. Used in conjunction with code in # /etc/profile. alias ls='ls --color=auto' # Provides prompt for non-login shells, specifically shells started # in the X environment. [Review the LFS archive thread titled # PS1 Environment Variable for a great case study behind this script # addendum.] NORMAL="\[\e[0m\]" RED="\[\e[1;31m\]" GREEN="\[\e[1;32m\]" if [[ $EUID == 0 ]] ; then PS1="$RED\u [ $NORMAL\w$RED ]# $NORMAL" else PS1="$GREEN\u [ $NORMAL\w$GREEN ]\$ $NORMAL" fi # End /etc/bashrc EOF cat > ~/.bash_profile << "EOF" # Begin ~/.bash_profile # Written for Beyond Linux From Scratch # by James Robertson <jameswrobertson@earthlink.net> # updated by Bruce Dubbs <bdubbs@linuxfromscratch.org> # Personal environment variables and startup programs. # Personal aliases and functions should go in ~/.bashrc. System wide # environment variables and startup programs are in /etc/profile. # System wide aliases and functions are in /etc/bashrc. append () { # First remove the directory local IFS=':' local NEWPATH for DIR in $PATH; do if [ "$DIR" != "$1" ]; then NEWPATH=${NEWPATH:+$NEWPATH:}$DIR fi done # Then append the directory export PATH=$NEWPATH:$1 } if [ -f "$HOME/.bashrc" ] ; then source $HOME/.bashrc fi if [ -d "$HOME/bin" ] ; then append $HOME/bin fi unset append # End ~/.bash_profile EOF cat > ~/.bashrc << "EOF" # Begin ~/.bashrc # Written for Beyond Linux From Scratch # by James Robertson <jameswrobertson@earthlink.net> # Personal aliases and functions. # Personal environment variables and startup programs should go in # ~/.bash_profile. System wide environment variables and startup # programs are in /etc/profile. System wide aliases and functions are # in /etc/bashrc. if [ -f "/etc/bashrc" ] ; then source /etc/bashrc fi # End ~/.bashrc EOF dircolors -p > /etc/dircolors cat > /etc/shells << "EOF" # Begin /etc/shells /bin/sh /bin/bash /sbin/nologin /usr/bin/proftpdshell # End /etc/shells EOF
创建initrd和ISO
代码:
cd /initrd find . | cpio -o -H newc | gzip -9 > /boot/initrd.img-2.6.22.1 umount $LFS/{proc,sys,dev/shm,dev/pts,dev} #在宿主系统中执行 /sources/squashfs3.2-r2/squashfs-tools/mksquashfs bin boot dev etc home lib media mnt opt proc root sbin srv sys tmp usr var /sources/root.sqfs
下面代码需要在宿主系统中操作
代码:
cd $LFS mkdir -p isolinux/boot/grub cp ${LFS}/boot/{initrd.img-2.6.22.1,vmlinuz-2.6.22.1} isolinux/boot/ cp ${LFS}/usr/lib/grub/i386-pc/{stage2_eltorito,stage1,stage2} isolinux/boot/grub/ cp ${LFS}/sources/root.sqfs isolinux/ cat > isolinux/boot/grub/menu.lst <<"EOF" default 0 timeout 5 title lfs(kernel 2.6.22.1) kernel /boot/vmlinuz-2.6.22.1 vga=788 initrd /boot/initrd.img-2.6.22.1 EOF mkisofs -R -b boot/grub/stage2_eltorito -no-emul-boot -boot-load-size 4 -boot-info-table -o lfs.iso isolinux
至此,liveCD已经完成,$LFS目录下的lfs.iso就是最终的光盘映象文件,可以用虚拟机挂载上,看看效果了


因为写得仓促,如有错误之处,敬请指正

论坛徽章:
0
发表于 2013-01-05 13:36 |显示全部楼层
回复 1# lantianyu520


    路过
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP