LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 3490|回复: 16

轻轻松松定制debian发行版

[复制链接]
发表于 2006-10-13 12:44:28 | 显示全部楼层 |阅读模式
轻轻松松定制自动安装的debian发行版
作者:ailantian
请大家先别跟贴,我先发完,
相关的工作记录比较多,正在整理中.
 楼主| 发表于 2006-10-13 12:55:47 | 显示全部楼层
准备preseed,自动安装所需要的文件,要写到initrd.gz中去
先下载一个netinstall cd
[red]注意!!!我这里所有的文章都是针对etch的,现在的etch是testing,所以这里链接到testing.以后etch不是testing的时候
请大家自己下载etch对应的版本[/red]
http://www.debian.org/devel/debian-installer/
http://cdimage.debian.org/cdimag ... ng-i386-netinst.iso
[php]
mount debian-testing-i386-netinst.iso -o loop /mnt/
mkdir cd
rsync -a -H --exclude=TRANS.TBL /mnt/ cd
umount debian-testing-i386-netinst.iso
mkdir initrd
cp cd/install/initrd.gz initrd
cd initrd
gzip -d < initrd.gz |cpio --extract --verbose --make-directories --no-absolute-filenames
cp ../preseed.cfg ./
find . | cpio -H newc --create --verbose |         gzip -9 > ../cd/install/initrd.gz
[/php]
其中preseed的内容如下
[php]
d-i        languagechooser/language-name-fb        select        English
d-i        countrychooser/shortlist-en        select        US
d-i        console-keymaps-at/keymap        select        us


d-i        debian-installer/locale        select        en_US.UTF-8
d-i console-tools/archs select at

d-i netcfg/choose_interface select auto
#d-i netcfg/choose_interface select eth0
d-i netcfg/disable_dhcp boolean true
d-i netcfg/get_nameservers string 202.106.196.115
d-i netcfg/get_ipaddress string 192.168.2.144
d-i netcfg/get_netmask string 255.255.255.0
d-i netcfg/get_gateway string 192.168.2.1
d-i netcfg/confirm_static boolean true
d-i netcfg/get_hostname string grandi
d-i netcfg/get_domain string
d-i netcfg/wireless_wep string

d-i        mirror/bad        error       
d-i        mirror/codename        string       
d-i        mirror/country        string       
d-i        mirror/http/countries        select        US
d-i        mirror/http/directory        string        /debian/
d-i        mirror/http/hostname        string       
d-i        mirror/http/mirror        select        ftp.debian.org
d-i        mirror/http/proxy        string       
d-i        mirror/noarch        error       
d-i        mirror/protocol        select        http
d-i        mirror/suite        select
# Suite to install.
#d-i mirror/suite string testing
# Suite to use for loading installer components (optional).
#d-i mirror/udeb/suite string testing

#d-i partman-auto/disk string /dev/hda


#d-i partman-auto/expert_recipe string boot-root :: 20 50 100 ext3 $primary{ } $bootable{ } method{ format } format{ } use_filesystem{ } filesystem{ ext3 } mountpoint{ /boot } .  500 10000 1000000000 ext3 method{ format } format{ } use_filesystem{ } filesystem{ ext3 } mountpoint{ / } .  64 512 300% linux-swap method{ swap } format{ } .

d-i partman-auto/expert_recipe string boot-root :: 500 10000 700 reiserfs $primary{ } method{ format } format{ } use_filesystem{ } filesystem{ reiserfs } mountpoint{ /tmp } .  200 512 300% linux-swap method{ swap } format{ } . 700 100000 100000000 reiserfs $primary{ } $bootable{ } method{ format } format{ } use_filesystem{ } filesystem{ reiserfs } mountpoint{ / } .  

#d-i partman-auto/expert_recipe string boot-root :: 700 100000 1000000000 ext3 $primary{ } $bootable{ }  method{ format } format{ }  use_filesystem{ } filesystem{ ext3 }  mountpoint{ / } . 200 512 300% linux-swap   method{ swap } format{ } . 500 500 700 ext3 method{ format }format{ } use_filesystem{ } filesystem{ ext3 }  mountpoint{ /tmp } .

#d-i partman-auto/text/home_scheme :: 700 100000 1000000000 ext3 $primary{ } $bootable{ }  method{ format } format{ }  use_filesystem{ } filesystem{ ext3 }  mountpoint{ / } . 200 512 300% linux-swap   method{ swap } format{ } . 500 500 700 ext3 method{ format }format{ } use_filesystem{ } filesystem{ ext3 }  mountpoint{ /tmp } .

d-i partman/confirm_write_new_label boolean true
d-i partman/choose_partition  select Finish partitioning and write changes to disk
d-i partman/confirm boolean true

d-i clock-setup/utc boolean true

d-i time/zone string US/Eastern

### Apt setup
# You can choose to install non-free and contrib software.
#d-i apt-setup/non-free boolean true
#d-i apt-setup/contrib boolean true
d-i        apt-setup/contrib        boolean        false
d-i        apt-setup/mirror/error        select        Retry
d-i        apt-setup/non-free        boolean        false
d-i        apt-setup/security_host        string       
d-i        apt-setup/security-updates-failed        error       
d-i        apt-setup/use_mirror        boolean        false

d-i passwd/root-password password password
d-i passwd/root-password-again password password
d-i passwd/user-fullname string grandi
d-i passwd/username string grandi
d-i passwd/user-password password grandi
d-i passwd/user-password-again password grandi

d-i grub-installer/only_debian boolean true
d-i grub-installer/with_other_os boolean true

d-i finish-install/reboot_in_progress note

#d-i preseed/early_command string anna-install some-udeb

#d-i preseed/run string
#d-i preseed/late_command string apt-install zsh; in-target chsh -s /bin/zsh
#d-i preseed/run string /cdrom/scripts/config.sh

d-i preseed/late_command string apt-install ssh apache2 php5-mysql;apt-install libapache2-mod-php5 mysql-server-5.0 vim python-paste python-pastescript python-formencode python-turbogears python-sqlobject python-turbokid python-configobj python-cheetah python-cherrypy python-celementtree python-elementtree cracklib2 expat rcconf  php-pear libapache2-mod-scgi  sysfsutils python-xml sysfsutils slocate psmisc   procps procmail libpcre3 libjpeg62 libpng12-0 libpopt0 sqlite3 libslang1 slocate  python-sqlite hesiod attr hwdata python-libxslt1 libxslt1.1;sh /cdrom/scripts/config.sh;


[/php]


其中有几点需要注意的是,一个是分区的问题,
1:能够确定大小的分区在前面,不能确定大小的在后面,比如/要使用剩余的分区就放在最后面
2:第一个分区要设置成主分区,不然分区会失败.
3:分区的这个命令一长串是一行,不能分行.其实这里的配置都不能分行

配置文件的格式说明以下面这个为例
500 10000 700 reiserfs $primary{ } method{ format } format{ } use_filesystem{ } filesystem{ reiserfs } mountpoint{ /tmp } .  

表示该分区最小为500M,最大为700M,中间的是一个优先级数,可以这么理解吧
如果较大则尽量接近后面这个值,后面说明这个分区为主分区,需要格式化,创建文件系统,使用这个文件系统,挂载到/tmp去

后期配置使用的是
late_commond这个是系统安装完成后,在重启之前需要执行的命令,你需要的预配置命令都可以放在这里,多个命令用分号隔开
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-10-13 13:11:42 | 显示全部楼层
自动安装的相关脚本,因为有些设置必须到系统第一次重新启动之后等相关软件启动起来之后才能够设置,比如要导入mysql的数据库,
这个我没有想到好的方法,只能自己来编写一个一次性执行的脚本了.
内容如下,
preseed中调用的是conf.sh
[PHP]
#ls
apt.conf     config_binary     dists    install     pics     tools
autorun.bat  config_installer  doc      isolinux    pool
autorun.inf  debian            indices  md5sum.txt  scripts
[/PHP]
我的脚本都放在了scripts目录下面了
[php]
ls
cleanup.sh           config.sh  firstreboot.sh  php.ini
config_misc_once.sh  default    htdocs.tar.gz   wn.sql

[/php]

conf.sh
这个脚本是在系统安装的时候,grub安装之后,在重启前,会执行的脚本.
这里我进行了一些预配置,比如把www文件解开放到了特定的目录下面了.
还设置了init脚本,创造一个执行一次的环境,rc脚本里面的一些动作
实际上下面的echo并没有起作用,或者说至少我们在屏幕上看不到这些echo,
当时写了没有改过来
[PHP]
#this file called by preseed,just before reboot,this is last install stage
#it copy files to overide ,or set the first reboot setting
#after first reboot ,will sh firstreboot.sh,this is rc.d scripts
#firstreboot.sh->config_misc_once.sh->cleanup.sh
#cleanup.sh will clean up firstreboot.sh and it links,then rm config_misc_once,then rm cleanup.sh itself
cd /cdrom/scripts/
tar zxf htdocs.tar.gz -C /target/var/www/
cp wn.sql /target/
cp /cdrom/scripts/php.ini /target/etc/php5/apache2/
cp /cdrom/scripts/default /target/etc/apache2/sites-available/default
echo "set apache php ok@@"
cp /cdrom/scripts/firstreboot.sh /target/etc/init.d/
cd /target/etc/rc0.d/
ln -s ../init.d/firstreboot.sh K99firstreboot.sh
cd /target/etc/rc1.d/
ln -s ../init.d/firstreboot.sh K99firstreboot.sh
cd /target/etc/rc2.d/
ln -s ../init.d/firstreboot.sh S99firstreboot.sh
cd /target/etc/rc3.d/
ln -s ../init.d/firstreboot.sh S99firstreboot.sh
cd /target/etc/rc4.d/
ln -s ../init.d/firstreboot.sh S99firstreboot.sh
cd /target/etc/rc5.d/
ln -s ../init.d/firstreboot.sh S99firstreboot.sh
cd /target/etc/rc6.d/
ln -s ../init.d/firstreboot.sh K99firstreboot.sh
echo -e "set first reboot.sh ok\n"
echo -e "cp config_misc_once.sh cleanup.sh\n"
cp /cdrom/scripts/config_misc_once.sh /target/
cp /cdrom/scripts/cleanup.sh /target/
echo -e "rebooting now\n"

[/PHP]

config_misc_once.sh
所有需要在系统第一次重新启动时设置的内容都放到这里吧
[PHP]
#all your preconfigs are needed to put in this file
#after first reboot ,will sh firstreboot.sh,this is rc.d scripts
#firstreboot.sh->config_misc_once.sh->cleanup.sh
#cleanup.sh will clean up firstreboot.sh and it links,then rm config_misc_once,then rm cleanup.sh itself
echo -e "dump to mysql\n"
mysqladmin create sugarcrm
mysqladmin -u root password '1'
mysql --user=root --password=1 <wn.sql
echo -e "dump to mysql ok\n"

[/PHP]

firstreboot.sh
看得出来从cron的启动脚本改过来的,呵呵
[PHP]
#!/bin/sh
#
#after first reboot ,will sh firstreboot.sh,this is rc.d scripts
#firstreboot.sh->config_misc_once.sh->cleanup.sh
#cleanup.sh will clean up firstreboot.sh and it links,then rm config_misc_once,then rm cleanup.sh itself
#test -f /usr/sbin/cron || exit 0

#LSBNAMES='-l'  # Uncomment for LSB name support in /etc/cron.d/

case "$1" in
start)        echo -n "Starting first time setting system"
        /config_misc_once.sh
        /cleanup.sh
        echo "."
        ;;
stop)        echo -n "Stopping first time setting system"
        echo "."
        ;;
*)        echo "setting failed"
        exit 1
        ;;
esac
exit 0

[/PHP]

cleanup.sh
如其名,
做清理,所谓一次性的设置,设置完了以后要清理掉这些设置脚本.
主要是删除这些文件和脚本,也包括cleanup.sh
奇怪吧,
在cleanup.sh里面删除cleanup.sh,但是这个的确是能够正常工作的.
可能脚本都是一行一行的读的.到最后一行删除自己的时候脚本文件已经读完了.
[PHP]
#do cleanup configs
#after first reboot ,will sh firstreboot.sh,this is rc.d scripts
#firstreboot.sh->config_misc_once.sh->cleanup.sh
#cleanup.sh will clean up firstreboot.sh and it links,then rm config_misc_once,then rm /etc/init.d/firstreboot.sh
#then rm cleanup.sh itself
unlink /etc/rc0.d/K99firstreboot.sh
unlink /etc/rc1.d/K99firstreboot.sh
unlink /etc/rc2.d/S99firstreboot.sh
unlink /etc/rc3.d/S99firstreboot.sh
unlink /etc/rc4.d/S99firstreboot.sh
unlink /etc/rc5.d/S99firstreboot.sh
unlink /etc/rc6.d/K99firstreboot.sh
rm /config_misc_once.sh /etc/init.d/firstreboot.sh /wn.sql /cleanup.sh

[/PHP]

需要注意的是,在安装过程中执行脚本的时候
/target才是安装完系统的根目录,所以要拷贝到新系统的根目录的话
只能拷贝到/target,当系统安装完成的时候,重新启动,就会在根目录下面发现这个脚本
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-10-13 13:43:58 | 显示全部楼层
这贴是由于sir反映太慢,发帖失败造成的,只出来一半
只好空出来了

添加一些链接吧
http://wiki.debian.org/
搜installer 或者custom preseed

preseed是自动安装所需要的,其实就是在安装过程中的那些问题的答案

顺便还说些其他的,
比如怎么获取到软件包呢,我怎么知道那些软件依赖关系?
我是这么做的,做ISO不会只做一份,所以事先的准备是必要的,
在一台空出来的电脑上装一个etch系统,光盘用的就是这个netinstall,(当然你用虚拟机装也是可以的)
然后就是安装定制系统,apt-get install ....
然后就是调试你的应用系统,比如各个配置什么的,
等到一切调整好了以后,把配置文件弄出来.
把deb包也弄出来,
如果你没有apt-get clean的习惯的话,
那么你安装的软件包都会在
/var/cache/apt/archives找到
所有的依赖关系就不用自己找了.

同志,定制系统一定要少装软件
如果你喜欢可以把installer里面的udeb包也删去一些,
都是自己定制的.
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-10-13 13:45:31 | 显示全部楼层
制作光盘,包含加入自己需要的软件包.
到光盘的根目录下面创建indices目录,这个目录和dists是同级的
cd cd
mkdir indices
然后到这里下载
http://ftp.de.debian.org/debian/indices/override.etch.main.gz
http://ftp.de.debian.org/debian/ ... .etch.extra.main.gz
解开到indices目录下面
ailantian@vax:~/ISO_debian/cd/indices$ ls
override  override.extra
ailantian@vax:~ISO_debian/cd/indices$
cd ..
回到cd根目录
创建三个个文件

config_installer
内容如下

[PHP]
Dir {
    ArchiveDir "./";
    OverrideDir "indices";
    CacheDir "indices";
};
            
TreeDefault {
    Directory "pool/";
};
                    
BinDirectory "pool/main" {
    Packages "dists/etch/main/debian-installer/binary-i386/Packages";
    BinOverride "override";
    ExtraOverride "override.extra";
};
                                   
Default {
    Packages {
        Extensions ".udeb";
    };
};

[/PHP]

config_binary
内容如下
[PHP]
Dir {
    ArchiveDir "./";
    OverrideDir "indices";
    CacheDir "indices";
};
            
TreeDefault {
    Directory "pool/";
};
                    
BinDirectory "pool/main" {
    Packages "dists/etch/main/binary-i386/Packages";
    BinOverride "override";
    ExtraOverride "override.extra";
};
                                   
Default {
    Packages {
        Extensions ".deb";
        Compress ". gzip";
    };
};

Contents {
         Compress "gzip";
     };
    };

[/PHP]

apt.conf内容如下
[php]
ailantian@vax:~/working_asterisk/ISO_debian/cd$ cat apt.conf
    APT {
       FTPArchive {
         Release {
             Origin "debian-cd";
             Label "etch";
             Suite "testing";
             Version "0.1";
             Codename "etch";
             Architectures "i386";
             Components "main contrib";
             Description "grandi ata";
         };
       };
    };
ailantian@vax:~/working_asterisk/ISO_debian/cd$

[/php]
然后创建一个目录来存放自己定制的软件包,我的是misc,
这个不用按字符序,随便建一个目录就可以.
[php]
ailantian@vax:~/ISO_debian/cd/pool/main$ ls
a  c  e  g  i  k  liba  libd  libg  libp  libt  m     n  p  s  u  x
b  d  f  h  j  l  libc  libe  libl  libs  libu  misc  o  r  t  w  z
ailantian@vax:~/ISO_debian/cd/pool/main$

[/php]

下面就是同步信息了.
[php]
# rm dists/etch/main/debian-installer/binary-i386/Packages*

# apt-ftparchive generate config_installer
W: Malformed override indices/override.extra line 12462 #2
pool/main: New 135kB 187 files 18.3MB 0s
Done Packages, Starting contents.
Done. 18.3MB in 187 archives. Took 1s

#rm dists/etch/main/binary-i386/*
#apt-ftparchive generate config_binary
W: Malformed override indices/override.extra line 12462 #2
pool/main: New 541kB 457 files 222MB 13s
Done Packages, Starting contents.
Done. 222MB in 457 archives. Took 13s

#apt-ftparchive -c apt.conf release dists/etch/main/binary-i386/  >dists/etch/main/binary-i386/Release

#apt-ftparchive -c apt.conf release dists/etch/contrib/binary-i386/  >dists/etch/contrib/binary-i386/Release

#apt-ftparchive -c apt.conf release dists/etch >dists/etch/Release

[/php]
如果不更新release的话,光盘生成后安装会有问题

[php]
cat dists/etch/main/binary-i386/Release
Architectures: i386
Codename: etch
Components: main contrib
Date: Wed, 11 Oct 2006 15:56:35 UTC
Description: grandi ata
Label: etch
Origin: debian-cd
Suite: testing
Version: 0.1
MD5Sum:
a52387f93e3d21fda79799536afbf615           419981 Packages
451286a231c36f635a954d5efb24c3d1           121094 Packages.gz
d41d8cd98f00b204e9800998ecf8427e                0 Release
SHA1:
e8f2c914aa13a2b8895ab49246b23122ac06b456           419981 Packages
108698552e365b8c602ae4e5c586c6afd69fecef           121094 Packages.gz
da39a3ee5e6b4b0d3255bfef95601890afd80709                0 Release
[/php]
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-10-13 13:54:28 | 显示全部楼层
生成光盘
[php]
cd ..
mkisofs -o /source/test.iso -r -J -no-emul-boot -boot-load-size 4 -boot-info-table -b isolinux/isolinux.bin -c isolinux/boot.cat ./cd/
[/php]

测试安装

[php]
ailantian@vax:~/ISO/debian/working$ qemu-img create debian.img 4G
Formating 'debian.img', fmt=raw, size=4194304 kB
ailantian@vax:~/ISO/debian/working$ qemu -hda debian.img -net nic -cdrom  /source/test.iso -boot d -no-kqemu
[/php]

kqemu是一个专有的软件,经常性的导致系统重启,所以这里没用kqemu
如果要上网的话
-net nic -net tap
然后/etc/qemu-ifup
[php]
#!/bin/sh
ifconfig $1 192.168.2.1
[/php]
root用户才行
[php]
modprobe tun
iptables -t nat -A POSTROUTING -s 192.168.2.0/24 -o eth0 -j MASQUERADE
echo 1 >/proc/sys/net/ipv4/ip_forward
[/php]
回复 支持 反对

使用道具 举报

发表于 2006-10-13 15:37:23 | 显示全部楼层
谢谢!

正是我需要的。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-10-13 16:41:40 | 显示全部楼层
再来点激动人心的
修改光盘启动时候的图片
[PHP]
apt-get install imagemagick netpbm
[/PHP]


需要准备一张图片
比如a.png的图片(其他格式的图片可以用imagemagick里面的convert来转或者使用netpbm里面的包来转)
netpbm的工具非常的多,比如pngtobmp,pngtopnm....几十个工具
[PHP]
convert a.png a.gif
convert a.gif b.png
pngtopnm b.png >b.pnm
./ppmtolss16 <b.pnm >b.rle
cp b.rle ../cd/isolinux/splash.rle

[/PHP]

相关的脚本比如ppmtolss16老程序里面有,新的没有了,
到这里下
http://sweb.cz/Frantisek.Rysanek ... x-splash-HOWTO.html
http://sweb.cz/Frantisek.Rysanek/splash/ppmtolss16.tgz
别装那个ppmplus,是netpbm的前身

看看图片吧,自己找个好看的图片,下面是原图和显示结果
记住图片的大小小于640x320

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
回复 支持 反对

使用道具 举报

发表于 2006-10-13 16:50:27 | 显示全部楼层


/up
回复 支持 反对

使用道具 举报

发表于 2006-10-13 17:07:36 | 显示全部楼层
so good! thank you!

I will try
回复 支持 反对

使用道具 举报

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

本版积分规则

快速回复 返回顶部 返回列表