工作中经常遇到新的硬件老版本的iso不识别,经常是需要安装的时候放进去驱动加载。但是使用批量装机的时候总不能一台台做吧,这里就说说怎么把驱动打进iso中,其实很简单。
实现目的:1.安装过程中加入elinks包,dell raid卡驱动程序
1.准备工作
2.创建key
3.编译库
4.更改initrd
1.准备工作
#准备工作目录
mkdir -p /var/www/ubuntu
mkdir -p /var/www/build
#copy安装光盘中dists和pool
cp ~/ubuntu*/dists .
cp ~/ubuntu*/pool .
2.创建key
#创建key
gpg --gen-key
#如果提示Not enough random bytes available.安装rng-toolslinux
apt-get install rng-tools
rngd -r /dev/urandom -o /dev/random -f -t 1 执行几秒钟 应该随机数就有四位数了
还不够的话狂敲键盘
#显示key
gpg --list-key
pub 2048R/3104C4E1 2012-08-10
uid cheyongsheng (yunrang)
sub 2048R/D36C1F68 2012-08-10
apt-get install fakeroot
apt-get source ubuntu-keyring
#导入ubuntu 官方key
cd /var/www/build/pool/u/ubuntu-keyring-*/keyrings
gpg --import < ubuntu-archive-keying.gpg
#导入进来了
root@yongshengche-desktop:/tmp# gpg --list-key
/home/yongshengche/.gnupg/pubring.gpg
-------------------------------------
pub 1024R/DD71C28D 2012-08-10
uid cheyongsheng (yunrang)
sub 1024R/1BC33117 2012-08-10
pub 2048R/3104C4E1 2012-08-10
uid cheyongsheng (yunrang)
sub 2048R/D36C1F68 2012-08-10
pub 1024D/437D05B5 2004-09-12
uid Ubuntu Archive Automatic Signing Key
sub 2048g/79164387 2004-09-12
pub 1024D/FBB75451 2004-12-30
uid Ubuntu CD Image Automatic Signing Key
#将两个key导入ubuntu-archive-keying.gpg文件中
gpg --export 437D05B5 FBB75451 3104C4E1 > ubuntu-archive-keyring.gpg
#build目录
cd ..
dpkg-buildpackage -rfakeroot -mcheyongsheng -k3104C4E1
#将生成两个文件*.deb *.udeb
cd ..
cp ubuntu-keyring*deb /var/www/ubuntu/pool/main/u/ubuntu-keyring/
3.编译库
#建立所需目录
mkdir -p /var/www/ubuntu/indices
mkdir -p /var/www/ubuntu/apt-ftparchive
mkdir -p /var/www/ubuntu1/pool/restricted
#创建build库所需文件
cd /var/www/ubuntu/apt-ftparchive
vim apt-ftparchive-deb.conf
Dir {
ArchiveDir "/var/www/ubuntu/";
};
TreeDefault {
Directory "pool/";
};
BinDirectory "pool/main" {
Packages "dists/lucid/main/binary-amd64/Packages";
BinOverride "/var/www/ubuntu/indices/override.lucid.main";
ExtraOverride "/var/www/ubuntu/indices/override.lucid.extra.main";
};
BinDirectory "pool/restricted" {
Packages "dists/lucid/restricted/binary-amd64/Packages";
BinOverride "/var/www/ubuntu/indices/override.lucid.restricted";
};
Default {
Packages {
Extensions ".deb";
Compress ". gzip";
};
};
Contents {
Compress "gzip";
};
~
~
vim apt-ftparchive-udeb.conf
Dir {
ArchiveDir "/var/www/ubuntu/";
};
TreeDefault {
Directory "pool/";
};
BinDirectory "pool/main" {
Packages "dists/lucid/main/debian-installer/binary-amd64/Packages";
BinOverride "/var/www/ubuntu/indices/override.lucid.main.debian-installer";
};
BinDirectory "pool/restricted" {
Packages "dists/lucid/restricted/debian-installer/binary-amd64/Packages";
BinOverride "/var/www/ubuntu/indices/override.lucid.restricted.debian-installer";
};
Default {
Packages {
Extensions ".udeb";
Compress ". gzip";
};
};
Contents {
Compress "gzip";
};
~
vim release.conf
APT::FTPArchive::Release::Origin "Ubuntu";
APT::FTPArchive::Release::Label "Ubuntu";
APT::FTPArchive::Release::Suite "lucid";
APT::FTPArchive::Release::Version "10.04.4";
APT::FTPArchive::Release::Codename "lucid";
APT::FTPArchive::Release::Architectures "amd64";
APT::FTPArchive::Release::Components "main restricted";
APT::FTPArchive::Release::Description "Ubuntu 10.04.4 LTS";
#所需文件可以在http://archive.ubuntu.com/ubuntu/indices下载.
#把需要安装的包放进/var/www/ubuntu/pool/restricted,包括所有依赖的包。
root@yongshengche-desktop:/var/www/ubuntu/pool/restricted# ls
elinks_0.12~pre5-2ubuntu1_amd64.deb libfreetype6_2.3.11-1ubuntu2.6_amd64.deb liblualib50_5.0.3-4_amd64.deb libruby1.8_1.8.7.249-2ubuntu0.1_amd64.deb
elinks-data_0.12~pre5-2ubuntu1_all.deb liblua50_5.0.3-4_amd64.deb libperl5.10_5.10.1-8ubuntu2.1_amd64.deb
#如果要更改deb包,如push文件进已有deb包则(以更新DELL Raid卡硬盘乱序驱动为例):
在iso中提取linux-p_w_picpath-2.6.32-38-server_2.6.32-38.83_amd64.deb和Packages.gz
root@yongshengche-desktop:/tmp# mkdir p_w_picpath
root@yongshengche-desktop:/tmp# dpkg-deb -e linux-p_w_picpath-2.6.32-38-server_2.6.32-38.83_amd64.deb ./p_w_picpath/DEBIAN
root@yongshengche-desktop:/tmp# dpkg-deb -x linux-p_w_picpath-2.6.32-38-server_2.6.32-38.83_amd64.deb ./p_w_picpath/
root@yongshengche-desktop:/tmp# cp mpt2sas.ko p_w_picpath/lib/modules/2.6.32-38-server/kernel/drivers/scsi/mpt2sas/
root@yongshengche-desktop:/tmp# md5sum mpt2sas.ko #算出新的md5值 ,更新./p_w_picpath/DEBIAN/md5sums
3a1ed58bdad6be17e1e79336c79354f8 mpt2sas.ko
root@yongshengche-desktop:/tmp# dpkg-deb -b -Z bzip2 p_w_picpath ./new-linux-p_w_picpath-2.6.32-38-server_2.6.32-38.83_amd64.deb #重新打包
dpkg-deb:正在新建软件包“linux-p_w_picpath-2.6.32-38-server”,包文件为“./new-linux-p_w_picpath-2.6.32-38-server_2.6.32-38.83_amd64.deb”。
重新生成Packages.gz
apt-get install dpkg-dev (dpkg-scanpackages)
dpkg-scanpackages pool/main /dev/null | gzip > dists/lucid/main/binary-amd64/Packages.gz
######第二种打包方法,以上内容与以下内容互斥#########
#更新Packages.gz文件中linux-p_w_picpath-2.6.32-38-server_2.6.32-38.83_amd64.deb一段,需更新字段:Install size;size;md5;sha1;sha256
#Install size:124744
root@yongshengche-desktop:/tmp# du -s ./p_w_picpath/
124744./p_w_picpath/
#Size:32353228
root@yongshengche-desktop:/tmp# ll |grep new-linux-p_w_picpath
-rw-r--r-- 1 root root 32353228 2012-08-13 19:18 new-linux-p_w_picpath-2.6.32-38-server_2.6.32-38.83_amd64.deb
#md5:5dc69479da1bfef79e651bac6431d41c
root@yongshengche-desktop:/tmp# md5sum new-linux-p_w_picpath-2.6.32-38-server_2.6.32-38.83_amd64.deb
5dc69479da1bfef79e651bac6431d41c new-linux-p_w_picpath-2.6.32-38-server_2.6.32-38.83_amd64.deb
#sha1:6c21dd674c2e1f1ec36d5379a2db9da67af62654
root@yongshengche-desktop:/tmp# sha1sum new-linux-p_w_picpath-2.6.32-38-server_2.6.32-38.83_amd64.deb
6c21dd674c2e1f1ec36d5379a2db9da67af62654 new-linux-p_w_picpath-2.6.32-38-server_2.6.32-38.83_amd64.deb
#sha256:ba2c0df6247492e6f3ea9eb71be6d660f6c824a09037b7b6ec3947ab71117111
root@yongshengche-desktop:/tmp# sha256sum new-linux-p_w_picpath-2.6.32-38-server_2.6.32-38.83_amd64.deb
ba2c0df6247492e6f3ea9eb71be6d660f6c824a09037b7b6ec3947ab71117111 new-linux-p_w_picpath-2.6.32-38-server_2.6.32-38.83_amd64.deb
######################
#开始build库
vim /tmp/build.sh
#!/bin/sh
BUILD=/var/www/ubuntu
APTCONF=/var/www/ubuntu/apt-ftparchive/release.conf
DISTNAME=lucid
apt-ftparchive -c $APTCONF generate /var/www/ubuntu/apt-ftparchive/apt-ftparchive-deb.conf
apt-ftparchive -c $APTCONF generate /var/www/ubuntu/apt-ftparchive/apt-ftparchive-udeb.conf
apt-ftparchive -c $APTCONF release $BUILD/dists/$DISTNAME > $BUILD/dists/$DISTNAME/Release
gpg --default-key 3104C4E1 --output $BUILD/dists/$DISTNAME/Release.gpg -ba $BUILD/dists/$DISTNAME/Release
4.更改initrd
PXE Server端 /var/lib/tftpboot/initrd.gz中有原版iso签名,得替换否则报错。然后打包好
cp /var/lib/tftpboot/initrd.gz /tmp/
cd !$
mkdir initrddi
gunzip initrd.gz
mv initrd initrd.img
cd initrd
cpio -i < ../initrd.img
cp /var/www/ubuntu/build/ubuntu-keyring-2010.11.09/keyrings/ubuntu-archive-keyring.gpg .
find . | cpio -o -H newc |gzip -9 >../initrd.gz
cp ../initrd.gz /var/lib/tftpboot/initrd.gz
将新的initrd.gz放进pxe server 成功!