Self revisor


Published on

step by step for respin fedora/CentSO/RHEL linux for you.

Published in: Self Improvement
  • Be the first to comment

  • Be the first to like this

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Self revisor

  1. 1. 纯手工打造虚拟器件Based on RedHat Linux distributions李建盛2010.10.191.5Copyright © 2010 CopyLeft
  2. 2. 议程Copyright © 2010 / 25注:本演示文稿大多数时候都是实际的例子粘贴!所以不会有太多的理论和教条。1. 制作虚拟编译环境2. 定制安装介质3. 制作虚拟镜像
  3. 3. 制作虚拟编译环境Copyright © 2010 / 25也许你听说过LFS发行版,从头开始定制环境是个什么样的流程,你已经成竹在胸。制作虚拟编译环境
  4. 4. 准备工作制作虚拟编译环境 Copyright © 2010 / 25root@code Centos5.5]# scp CentOS-5.5-i386-bin-DVD.iso root@ authenticity of host ( cant be established.RSA key fingerprint is 31:e1:e4:fa:ef:26:8a:8b:5f:0e:43:e4:d6:25:e0:63.Are you sure you want to continue connecting (yes/no)? yesWarning: Permanently added (RSA) to the list of known hosts.reverse mapping checking getaddrinfo for bogon failed - POSSIBLE BREAK-IN ATTEMPT!root@ password:CentOS-5.5-i386-bin-DVD.iso 100% 3991MB 11.2MB/s 05:58[root@kvmsupport revisor]# mv ~/CentOS-5.5-i386-bin-DVD.iso .[root@kvmsupport revisor]# pwd/project/revisor[root@kvmsupport revisor]# mkdir t[root@kvmsupport revisor]# mount -oloop CentOS-5.5-i386-bin-DVD.iso t[root@kvmsupport revisor]# mkdir -p pool/RPMS/[root@kvmsupport revisor]# cp -vfp t/CentOS/*.rpm pool/RPMS/[root@kvmsupport revisor]# mkdir virenv
  5. 5. 开始制作虚拟编译环境制作虚拟编译环境 Copyright © 2010 / 25建立rpm执行环境[root@kvmsupport revisor]export ROOT=`pwd`/virenv[root@kvmsupport revisor]mkdir -p $ROOT/var/lib/rpm $ROOT/tmp/RPMS/ $ROOT/bin/$ROOT/proc $ROOT/etc[root@kvmsupport revisor]rpm2cpio pool/RPMS/glibc-2.5*.rpm | (cd $ROOT; cpio -idm)[root@kvmsupport revisor]# rpm2cpio pool/RPMS/glibc-devel-2.5*.rpm | (cd $ROOT; cpio -idm)[root@kvmsupport revisor]# rpm2cpio pool/RPMS/bzip2-libs-*.*.rpm |(cd $ROOT;cpio -idm)[root@kvmsupport revisor]# rpm2cpio pool/RPMS/popt-*.*.rpm |(cd $ROOT;cpio -idm)[root@kvmsupport revisor]# rpm2cpio pool/RPMS/sqlite-3*.*.rpm|(cd $ROOT;cpio -idm)[root@kvmsupport revisor]# rpm2cpio pool/RPMS/neon-0.25.*.rpm|(cd $ROOT;cpio -idm)[root@kvmsupport revisor]# rpm2cpio pool/RPMS/openssl-0.9.*.rpm|(cd $ROOT;cpio -idm)[root@kvmsupport revisor]# rpm2cpio pool/RPMS/krb5-libs-1.6*.rpm|(cd $ROOT;cpio -idm)[root@kvmsupport revisor]# rpm2cpio pool/RPMS/e2fsprogs-libs-1.39*.rpm|(cd $ROOT;cpio -idm)[root@kvmsupport revisor]# rpm2cpio pool/RPMS/expat-1.95.*.rpm|(cd $ROOT;cpio -idm)[root@kvmsupport revisor]# rpm2cpio pool/RPMS/libsepol-1.15.*.rpm|(cd $ROOT;cpio -idm)[root@kvmsupport revisor]# rpm2cpio pool/RPMS/libgcc-4.1.2*.rpm|(cd $ROOT;cpio -idm)[root@kvmsupport revisor]# rpm2cpio pool/RPMS/libstdc++-4.1.2*.rpm|(cd $ROOT;cpio -idm)[root@kvmsupport revisor]# rpm2cpio pool/RPMS/beecrypt-[^d]*.*.rpm|(cd $ROOT;cpio -idm)[root@kvmsupport revisor]# rpm2cpio pool/RPMS/libselinux-*.*.rpm|(cd $ROOT;cpio -idm)[root@kvmsupport revisor]# rpm2cpio pool/RPMS/nss-3*.*.rpm|(cd $ROOT;cpio -idm)[root@kvmsupport revisor]# rpm2cpio pool/RPMS/nspr-4*.*.rpm|(cd $ROOT;cpio -idm)[root@kvmsupport revisor]# rpm2cpio pool/RPMS/rpm-*.*.rpm|(cd $ROOT;cpio -idm)[root@kvmsupport revisor]# rpm2cpio pool/RPMS/rpm-libs-4.4.*.el5.i386.rpm|(cd $ROOT;cpio -idm)[root@kvmsupport revisor]# rpm2cpio pool/RPMS/libtermcap-[^d]*.*.rpm|(cd $ROOT;cpio -idm)[root@kvmsupport revisor]# rpm2cpio pool/RPMS/bash-*.*.rpm|(cd $ROOT;cpio -idm)
  6. 6. 开始制作虚拟编译环境 (Continued)制作虚拟编译环境 Copyright © 2010 / 25[root@kvmsupport revisor]# rpm2cpio pool/RPMS/zlib-[^d]*.*.rpm|(cd $ROOT;cpio -idm)[root@kvmsupport revisor]# rpm2cpio pool/RPMS/info-*.*.rpm|(cd $ROOT;cpio -idm)
  7. 7. 建立虚拟编译环境制作虚拟编译环境 Copyright © 2010 / 25[root@kvmsupport revisor]# cp /etc/resolv.conf $ROOT/etc/resolv.conf[root@kvmsupport revisor]# rpm2cpio pool/RPMS/gzip-*.*.rpm|(cd $ROOT/tmp;cpio -idm)[root@kvmsupport revisor]# cp $ROOT/tmp/bin/gzip $ROOT/bin/[root@kvmsupport revisor]# rpm2cpio pool/RPMS/grep-*.*.rpm|(cd $ROOT/tmp/;cpio -idm)[root@kvmsupport revisor]# cp $ROOT/tmp/bin/grep $ROOT/bin/[root@kvmsupport revisor]# rpm2cpio pool/RPMS/coreutils-*.*.rpm|(cd $ROOT/tmp/;cpio -idm)[root@kvmsupport revisor]# cp $ROOT/tmp/bin/ln $ROOT/bin/[root@kvmsupport revisor]# cp $ROOT/tmp/bin/cat $ROOT/bin/[root@kvmsupport revisor]# cp $ROOT/tmp/bin/rm $ROOT/bin/[root@kvmsupport revisor]# touch $ROOT/etc/mtab[root@kvmsupport revisor]# echo $ROOT > $ROOT/etc/virtroot[root@kvmsupport revisor]# cp /etc/sysconfig/network $ROOT/etc/sysconfig/[root@kvmsupport revisor]# cp /etc/sysconfig/network-scripts/ifcfg-eth0$ROOT/etc/sysconfig/network-scripts/[root@kvmsupport revisor]# mount proc $ROOT/proc -t proc[root@kvmsupport revisor]# for i in pool/RPMS/*.rpm; do cp -vfp $i $ROOT/tmp/RPMS/; done[root@kvmsupport revisor]# chroot virenv/bash-3.2# export PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/X11R6/binbash-3.2# rpm -ivh RPMS/setup-2.5.58-7.el5.noarch.rpm --force --root /bash-3.2# rpm -ivh RPMS/filesystem-2.4.0-3.el5.i386.rpm --force --root /bash-3.2# rpm -ivh RPMS/basesystem-8.0-5.1.1.el5.centos.noarch.rpm --force --root /bash-3.2# rpm -Uvh RPMS/*.rpm --force --nodeps --root /此时,你需要等待很长时间,大约在一个小时左右,视你的机器配置而定。完成后执行下列必备的文件拷贝:[root@kvmsupport revisor]# tar -czvf dev.tgz /dev/
  8. 8. 建立虚拟编译环境 (Continued)制作虚拟编译环境 Copyright © 2010 / 25[root@kvmsupport revisor]# tar -zxvf dev.tgz -C virenv/[root@kvmsupport revisor]# cp -rvf /usr/share/zoneinfo/ virenv/usr/share/zoneinfo/[root@kvmsupport revisor]# cp virenv/usr/share/zoneinfo/Asia/Shanghai virenv/etc/localtime[root@kvmsupport revisor]# cp /etc/fstab virenv/etc/[root@kvmsupport revisor]# cp /etc/hosts virenv/etc/[root@kvmsupport revisor]# cp /etc/mtab virenv/etc/
  9. 9. 开始为程序打rpm package制作虚拟编译环境 Copyright © 2010 / 25[root@kvmsupport revisor]# chroot virenv/现在我们以phpMyadmin这个软件包为例,编译一番。bash-3.2# wget .bash-3.2# rpm -ivh phpMyAdmin- cd /usr/src/redhat/SPECS/bash-3.2# rpmbuild -ba phpMyAdmin.specbash-3.2# cd ../RPMS/noarch/bash-3.2# lsphpMyAdmin-
  10. 10. 定制安装介质Copyright © 2010 / 25也许你熟悉kickstart,fedora liveCD等工具,那么基于大而全的linux发行版定制出满足自身需求的安装介质,是你的必备技能之一。定制安装介质
  11. 11. 复制rpm包,及修改comps.xml定制安装介质 Copyright © 2010 / 25[root@kvmsupport revisor]# cd /project/revisor/[root@kvmsupport revisor]# mkdir DIY[root@kvmsupport revisor]# cd DIY[root@kvmsupport DIY]# cp ../t/repodata/comps.xml .[root@kvmsupport DIY]# sed /xml:lang=/d comps.xml >comps-new.xml[root@kvmsupport DIY]# lscomps-new.xml comps.xml[root@kvmsupport DIY]# rm -rf comps.xml[root@kvmsupport DIY]# mv comps-new.xml comps.xml[root@kvmsupport DIY]# cp -rvf ../t/CentOS CentOS5.5[root@kvmsupport DIY]# cd CentOS5.5/#cp ../virenv/usr/src/redhat/RPMS/noarch/phpMyAdmin- CentOS/在comps.xml中添加如下内容:<category><id>Third_Party_Extras</id><name>Third Party Extras</name><description>A selection of requested extras from third party software suppliers. </description><display_order>110</display_order><grouplist><groupid>phpMyAdmin</groupid></grouplist></category><group><id>phpMyAdmin</id><name>PhpMyAdmin</name>
  12. 12. 复制rpm包,及修改comps.xml (Continued)定制安装介质 Copyright © 2010 / 25<description>Mysql DB GUI management tools, based php web application.</description><default>false</default><uservisible>true</uservisible><packagelist><packagereq type="default">phpMyAdmin</packagereq></packagelist></group>
  13. 13. 制作本地repo定制安装介质 Copyright © 2010 / 25你知道仓库吗?repo :[root@kvmsupport DIY]# createrepo -g comps.xml .[root@kvmsupport DIY]# cat yum.conf.tmp[mycentos]name=mycentosbaseurl=file:///project/revisor/DIY/CentOS5/enabled=0gpgcheck=0[root@kvmsupport DIY]# repoclosure -c yum.conf.tmp -r mycentosReading in repository metadata - please wait....Checking DependenciesRepos looked at: 1mycentosNum Packages in Repos: 2600package: phpMyAdmin- from mycentosunresolved deps:php-mcrypt >= 0:4.1.0编辑comps.xml添加如下一行,并将php-mcrypt包放到相应的目录。<packagereq type="default">php-mcrypt</packagereq><packagereq type="default">libmcrypt</packagereq>[root@kvmsupport CentOS5]# rm -rf repodata/[root@kvmsupport CentOS5]# createrepo -g repodata/comps.xml .[root@kvmsupport DIY]# rm -rf /var/cache/yum/mycentos/[root@kvmsupport DIY]# repoclosure -c yum.conf.tmp -r mycentos
  14. 14. 制作本地repo (Continued)定制安装介质 Copyright © 2010 / 25Reading in repository metadata - please wait....Checking DependenciesRepos looked at: 1mycentosNum Packages in Repos: 2602
  15. 15. 制作安装光盘定制安装介质 Copyright © 2010 / 25[root@kvmsupport DIY]# mkdir anaconda[root@kvmsupport DIY]# cd anaconda/[root@kvmsupport anaconda]# cp ../CentOS5/CentOS/anaconda-anaconda- anaconda-runtime-[root@kvmsupport anaconda]# cp ../CentOS5/CentOS/anaconda-* .[root@kvmsupport anaconda]# rpm2cpio anaconda-11.*.i386.rpm |cpio -idm39021 blocks[root@kvmsupport anaconda]# rpm2cpio anaconda-runtime-*.i386.rpm |cpio -idm6620 blocks[root@kvmsupport anaconda]# cd ..[root@kvmsupport DIY]# export ANA_DIR=/project/revisor/DIY/anaconda/[root@kvmsupport DIY]# export PYTHONPATH=${ANA_DIR}/usr/lib/anaconda:${PYTHONPATH}[root@kvmsupport DIY]# export PATH=${ANA_DIR}/usr/lib/anaconda-runtime:${PATH}[root@kvmsupport DIY]# export PRODUCT=CentOS5你可能需要安装一些软件如:pykickstart,libdhcp,python-pyblock,pyparted等[root@kvmsupport DIY]# pkgorder --product=CentOS /project/revisor/DIY/mycentos/x86_64 CentOS |tee pkgfile-x86-64继续安装软件:squashfs-tools[root@kvmsupport DIY]# buildinstall --comp dist-1.0.20101018 --pkgorder /project/revisor/DIY/pkgfile-x86-64 --version 1.0 --product CentOS--release 1.0 --prodpath CentOS `pwd`/mycentos[root@kvmsupport DIY]# createrepo --baseurl="media://$dvd_discinfo" -g comps.xml/project/revisor/DIY/mycentos3436/3436 - CentOS/sblim-cmpi-base-test-1.6.0-40.el5.x86_64.rpmSaving Primary metadata
  16. 16. 制作安装光盘 (Continued)定制安装介质 Copyright © 2010 / 25Saving file lists metadataSaving other metadata[root@kvmsupport DIY]# rm -rf .olddata[root@kvmsupport DIY]# find mycentos/CentOS/ -name "TRANS.TBL" -exec rm -f {} ;[root@kvmsupport DIY]# publisher=""[root@kvmsupport DIY]# mkisofs -q -r -R -J -T -no-emul-boot -boot-load-size 4 -b isolinux/isolinux.bin -c isolinux/ -boot-info-table -V "mycentos" -A "mycentos 1.0 update$date $arch DVD" -publisher "$publisher" -p "$publisher"-x lost+found -o mycentos-1.0-$date-$arch-DVD.iso mycentos/
  17. 17. 制作虚拟镜像及其更改Copyright © 2010 / 25也许你熟悉amazon AMI,KVM qcow2等镜像文件,那么对于其工作的方式以及驾驭它的能力,想必能够为虚拟化解决方案撑起一片独立天空!制作虚拟镜像及其更改
  18. 18. 制作镜像文件并qemu-kvm启动之制作虚拟镜像及其更改 Copyright © 2010 / 25lee@python:/media/test$ sudo kvm-img create -f qcow2 mycentos.img 5Glee@python:/media/test$ sudo kvm --m 512 --cdrom ../mycentos-1.0-20101018-x86_64-DVD.iso --drive file=mycentos.img,if=scsi,index=0 --boot d --net nic --net user --vnc :1此时启动vncview, 访问IP:1,
  19. 19. 安装刚才定制的Linux制作虚拟镜像及其更改 Copyright © 2010 / 25利用vncview,看实例吧!
  20. 20. 修改配置文件,以及定制应用(一)制作虚拟镜像及其更改 Copyright © 2010 / 25方法之一:利用古老的工具raw格式相对简单些:losetup /dev/loop0 image.imgkpartx -a /dev/loop0mount /dev/mapper/loop0p1 /mnt/imageqcow2.lee@python:~$ sudo modprobe nbd max_part=63sudo qemu-nbd -c /dev/nbd0 mycentos.imgsudo mount /dev/nbdp1 whatyoucreatedirsudo vgscansudo vgchange -aysudo mount /dev/VolGroup00/LogVol00 actsudo umount actsudo vgchange -an VolGroup00
  21. 21. 修改配置文件,以及定制应用(二)制作虚拟镜像及其更改 Copyright © 2010 / 25方法之二:利用libguestfs程序接口或工具libguestfs is a set of tools for accessing and modifying virtual machine (VM) disk images.You can use this for viewing and editing files inside guests, scripting changes to VMs,monitoring disk used/free statistics, P2V, V2V, performing partial backups, cloning VMs,and much else besides.libguestfs can access nearly any type of filesystem including: all known types of Linux filesystem (ext2/3/4, XFS, btrfs etc), any Windows filesystem (VFAT and NTFS), any Mac OS X and BSD filesystems, LVM2 volume management, MBR and GPT disk partitions, raw disks, qcow2,VirtualBox VDI, VMWare VMDK, CD and DVD ISOs, SD cards, and dozens more. libguestfs doesntneed root permissions.All this functionality is available through a convenient shell called guestfish, or usevirt-rescue to get a rescue shell for fixing unbootable virtual machines.libguestfs is also a library that can be linked with C and C++ management programs and hasbindings for Perl, Python, Ruby, Java, OCaml, PHP, Haskell and C#. You can also use it fromshell scripts or the command line. Using our FUSE module you can also mount guest filesystemson the host. There is a subproject to allow you to merge changes into the Windows Registry inWindows guests. You can examine unknown disk images to find out what they contain.libguestfs is a mature program, in development since Feb 2009, with a 100 page manual,deployed in enterprise environments, and with many successful users.
  22. 22. 结束语Copyright © 2010 / 25结束语
  23. 23. 关于反馈结束语 Copyright © 2010 / 25我需要你的反馈!
  24. 24. 参考资料结束语 Copyright © 2010 / 25Internet is good.google
  25. 25. Q&A结束语 Copyright © 2010 / 25有问题吗?Thanks!