How To Build Linux Driver Into Booting img for PXE booting

How To Build Linux Driver Into Booting img for PXE booting

Written by: Libo.Ma
Created on July 28,2011

1. mkdir /tmp/testkernel/ # create testkernel package dir
2. gzip -cd /pxeist/tftpboot_centos54/initrd.img |cpio -ivd
3. cd modules; gzip -dc modules.cgz | cpio -ivd
4. cp /var/www/html/drivers/tg3.ko ./2.6.18-164.el5/x86_64 # Copy driver to kernel dir
5. modinfo -F alias 2.6.18-164.el5/x86_64/tg3.ko | sed -e ‘s/^/alias /’ -e ‘s/$/ tg3/’ >>modules.alias
6. find 2.6.18-164.el5 | cpio -o -H crc | gzip -9 > modules.cgz; rm -rf 2.6.18-164.el5
7. cd ..;find . | cpio -o -H newc | gzip -9 > /tmp/initrd.img
8. cd /pxeist/tftpboot_centos54/;
mv initrd.img bak_initrd.img
9. cp /tmp/initrd.img /pxeist/tftpboot_centos54/
10. OK

reference scripts:

#This scripts is used to making kernel images for PXE BOOTING of linux
#Created by @ July 26,2011

if [ ! -f $1 ]
echo “Usage: `basename $0` driver.ko”
exit 1


FILE_NAME=$(basename $FILE)
if [ -f $FILE ]
cp $FILE /var/www/html/drivers/2.6.18-164.el5/x86_64/ -rf
sed -i “/$FILE_ALIAS\$/d” $MODULES/modules.alias
modinfo -F alias 2.6.18-164.el5/x86_64/$FILE_NAME | sed -e “s/^/alias /” -e “s/$/ $FILE_ALIAS/” >> $MODULES/modules.alias
echo “Packag driver into modules.cgz”…
find 2.6.18-164.el5 | cpio -o -H crc | gzip -9 > $MODULES/modules.cgz
echo “Making kernel initrd.img…”
if find . | cpio -o -H newc | gzip -9 > /tmp/initrd.img;
echo “/tmp/initrd.img making successfully.”
echo “Failure.”

Refernece links:

Kickstart options notes

refer to :Fedora Kickstart Configration
Here is my Kickstart config file for general Centos Installation.

# Kickstart file automatically generated by anaconda.

url --url
lang en_US.UTF-8
keyboard us
network --device eth0 --bootproto static --ip --netmask --gateway --nameserver, --hostname VIA-02
rootpw --iscrypted $1$Jd5lGnyJ$jcziaYiiCTqf4uWi8h4lc.
firewall --enabled --port=22:tcp
authconfig --enableshadow --enablemd5
selinux --disabled
timezone --utc Asia/Chongqing
bootloader --location=mbr --driveorder=sda
# The following is the partition information you requested
# Note that any partitions you deleted are not expressed
# here so unless you clear all partitions first, this is
# not guaranteed to work
#clearpart --linux --drives=sda
part /boot --fstype ext3 --size=100 --ondisk=sda
part pv.7 --size=0 --grow --ondisk=sda
volgroup VolGroup00 --pesize=32768 pv.7
logvol / --fstype ext3 --name=LogVol00 --vgname=VolGroup00 --size=40000
logvol /images --fstype ext3 --name=images.disk --vgname=VolGroup00 --size=60000
logvol swap --fstype swap --name=LogVol01 --vgname=VolGroup00 --size=1000 --grow --maxsize=5856



significant Options explaination:

  • clearpart –all –drives=sda

    Erases all partitions from the system.

    Initializes the disk label to the default for your architecture (for example msdos for x86 and gpt for Itanium). It is useful so that the installation program does not ask if it should initialize the disk label if installing to a brand new hard drive.

    Erases all Linux partitions.
    –none (default)
    Do not remove any partitions.

  • firewall

    This option corresponds to the Firewall Configuration screen in the installation program:
    firewall –enabled|–disabled [options]

    Listing a device here, such as eth0, allows all traffic coming from that device to go through the firewall. To list more than one device, use –trust eth0 –trust eth1. Do NOT use a comma-separated format such as –trust eth0, eth1.

    Replace with none or more of the following to allow the specified services through the firewall.
    –ssh – The ssh option is enabled by default, regardless of the presence of this flag.
    You can specify that ports be allowed through the firewall using the port:protocol format. You can also specify ports numerically. Multiple ports can be combined into one option as long as they are separeted by commas. For example:
    firewall –port=imap:tcp,1234:ucp,47
    This option provides a higher-level way to allow services through the firewall. Some services (like cups, avahi, etc.) require multiple ports to be open in order for the service to work. You could specify each individual service with the –port option, or specify –service= and open them all at once. Valid options are anything recognized by the lokkit program in the system-config-firewall-base package

  • graphical

    Perform the kickstart installation in graphical mode. This is the default.

  • install

    Tells the system to install a fresh system rather than upgrade an existing system. This is the default mode. For installation, you must specify the type of installation from one of cdrom, harddrive, nfs, or url (for ftp or http installations). The install command and the installation method command must be on separate lines.
    Install from the first CD-ROM/DVD drive on the system.
    Install from a directory of ISO images on a local drive, which must be either vfat or ext2. In addition to this directory, you must also provide the install.img in some way. You can either do this by booting off the boot.iso or by creating an images/ directory in the same directory as the ISO images and placing install.img in there.
    BIOS partition to install from (such as 82p2).
    Partition to install from (such as, sdb2).
    Directory containing both the ISO images and the images/install.img. For example:
    harddrive –partition=hdb2 –dir=/tmp/install-tree
    Install from the NFS server specified. This can either be an exploded installation tree or a directory of ISO images. In the latter case, the install.img must also be provided subject to the same rules as with the harddrive installation method described above.
    Server from which to install (hostname or IP).
    Directory containing the Packages/ directory of the installation tree. If doing an ISO install, this directory must also contain images/install.img.
    Mount options to use for mounting the NFS export. Any options that can be specified in /etc/fstab for an NFS mount are allowed. The options are listed in the nfs(5) man page. Multiple options are separated with a comma.
    For example:
    nfs – –dir=/tmp/install-tree
    Install from an installation tree on a remote server via FTP or HTTP.
    The URL to install from.
    Specify an HTTP/HTTPS/FTP proxy to use while performing the install. The various parts of the argument act like you would expect.
    For a tree on a HTTPS server do not check the server’s certificate with what well-known CA validate and do not check the server’s hostname matches the certificate’s domain name.

  • logvol

    Create a logical volume for Logical Volume Management (LVM).
    logvol –vgname= –size= –name=

    Use an existing logical volume and do not format it.
    Use an existing logical volume and reformat it.
    Sets the file system type for the logical volume. Valid values include ext4, ext3, ext2, btrfs, swap, and vfat. Other filesystems may be valid depending on command line arguments passed to anaconda to enable other filesystems. Btrfs is a experimental filesystem. Do take regular backups if you are using it.
    Specifies a free form string of options to be used when mounting the filesystem. This string will be copied into the /etc/fstab file of the installed system and should be enclosed in quotes.
    Tells the logical volume to grow to fill available space (if any), or up to the maximum size setting. Note that –grow is not supported for logical volumes containing a RAID volume on top of them.
    The maximum size in megabytes when the logical volume is set to grow. Specify an integer value here, and do not append the number with MB.
    Determine the size of the logical volume automatically.
    Specify the size of the logical volume as a percentage of available space in the volume group. Without the above –grow option, this may not work.
    Specify that this logical volume should be encrypted.
    Specify the passphrase to use when encrypting this logical volume. Without the above –encrypted option, this option does nothing. If no passphrase is specified, the default system-wide one is used, or the installer will stop and prompt if there is no default.
    Load an X.509 certificate from . Store the data encryption key of this logical volume, encrypted using the certificate, as a file in /root. Only relevant if –encrypted is specified as well.
    Only relevant if –escrowcert is specified as well. In addition to storing the data encryption key, generate a random passphrase and add it to this logical volume. Then store the passphrase, encrypted using the certificate specified by –escrowcert, as a file in /root. If more than one LUKS volume uses –backuppassphrase, the same passphrase will be used for all such volumes.
    Create the partition first, create the logical volume group, and then create the logical volume. For example:
    part pv.01 –size 3000
    volgroup myvg pv.01
    logvol / –vgname=myvg –size=2000 –name=rootvol

  • network

    Configures network information for target system and activates network devices in installer environment. Device of the first network command is activated if network is required, e.g. in case of network installation or using vnc. Activation of the device can be also explicitly required by –activate option. If the device has already been activated to get kickstart file (e.g. using configuration provided with boot options or entered in loader UI) it is re-activated with configuration from kickstart file.
    In F15, the device of first network command is activated also in case of non-network installs, and device is not re-activated using kickstart configuration.
    Additional devices configured in kickstart with network command can be activated in installer using –activate option (since F16).
    The default setting is dhcp. bootp and dhcp are treated the same.
    The DHCP method uses a DHCP server system to obtain its networking configuration. As you might guess, the BOOTP method is similar, requiring a BOOTP server to supply the networking configuration.
    The static method requires that you enter all the required networking information in the kickstart file. As the name implies, this information is static and will be used during and after the installation. The line for static networking is more complex, as you must include all network configuration information on one line. You must specify the IP address, netmask, gateway, and nameserver. For example: (the \ indicates that it is all one line):
    network –bootproto=static –ip= \
    –netmask= –gateway= \
    If you use the static method, be aware of the following restriction:
    All static networking configuration information must be specified on one line; you cannot wrap lines using a backslash, for example.
    ibft setting is for reading the configuration from iBFT table. It was added in F16.
    Specifies device to be configured and/or activated with the network command. The device can be specified in the same ways as ksdevice boot option. For example:
    network –bootproto=dhcp –device=eth0
    For the first network command, if the option is not specified it defaults to 1) ksdevice boot option, 2) device activated to fetch kickstart, or 3) selection dialog in UI. For following network commands, the –device option is required.
    IP address for the interface.
    IPv6 address for the interface. This can be the static address, “auto” for address assignment based on automatic neighbor discovery, or “dhcp” to use the DHCPv6 protocol.
    Default gateway, as an IPv4 or IPv6 address.
    Prevents grabbing of the default route by the device. It can be useful when activating additional devices in installer using –activate option. Since F16.
    Primary nameserver, as an IP address. Multiple nameservers must be comma separated.
    Do not configure any DNS server.
    Netmask for the installed system.
    Hostname for the installed system.
    Specifies additional low-level settings for the network device which will be passed to the ethtool program.
    The network ID for wireless networks.
    The encryption key for wireless networks.
    Whether or not to enable the device a boot time.
    The DHCP class.
    The MTU of the device.
    Disable IPv4 on this device.
    Disable IPv6 on this device

  • selinux

    Sets the state of SELinux on the installed system. SELinux defaults to enforcing in anaconda.
    selinux [–disabled|–enforcing|–permissive]
    If this is present, SELinux is disabled.
    If this is present, SELinux is set to enforcing mode.
    If this is present, SELinux is enabled, but only logs things that would be denied in enforcing mode

  • skipx
    If present, X is not configured on the installed system.
  • volgroup

    Use to create a Logical Volume Management (LVM) group.

    Name given to the volume group. The (which denotes that multiple partitions can be listed) lists the identifiers to add to the volume group.
    Use an existing volume group and do not format it.
    Use an existing volume group and reformat it.
    Set the size of the physical extents.
    Create the partition first, create the logical volume group, and then create the logical volume. For example:
    part pv.01 –size 3000
    volgroup myvg pv.01
    logvol / –vgname=myvg –size=2000 –name=rootvol

  • %packages

    refer to the repodata/*comps.xml file on the first CD-ROM for a list of groups.

    PS: This may be handy if the kickstart file is used as a template and pulls in various other files with the %include mechanism.

  • Pre-installation Script

    This section must be at the end of the kickstart file (after the commands) and must start with the %pre command. You can access the network in the %pre section; however, name service has not been configured at this point, so only IP addresses will work.
    Preinstallation scripts are required to be closed with %end.

  • <2h2>post-install


    Run a script named runme from an NFS share:
    mkdir /mnt/temp
    mount /mnt/temp
    open -s -w — /mnt/temp/runme
    umount /mnt/temp
    Copy the file /etc/resolv.conf to the file system that was just installed:
    %post –nochroot
    cp /etc/resolv.conf /mnt/sysimage/etc/resolv.conf

  • Creating a Kickstart Boot CD-ROM
    Installation Boot CD-ROM section in the Red Hat Enterprise Linux Installation Guide for instruction on creating a boot CD-ROM; however, before making the file.iso image file, copy the ks.cfg kickstart file to the isolinux/ directory.

LVM Using snapot to backup data–from google searching..

This is a Daily script


VG=/dev/vg1 #whichever folder your xen files located at)
LV[0]=xen-1 # (name of diff, xen machines/guests)
LV[2]=xen2-data #xen2 is a web server with large amount of data

cd $DIR
while [ $COUNT -lt ${#LV[@]} ]
./$BACKUP_CMD $VG/${LV[$COUNT]} &> last-backup-${LV[$COUNT]}
CAT_STR="${CAT_STR} last-backup-${LV[$COUNT]}"

ls -lh /mnt/system_backups/ &> last-backup-ls
cat $CAT_STR last-backup-ls > last-backup.txt
echo "daily backup report attached" | mutt -s "$HOSTNAME daily backup report" -a last-backup.txt

Continue reading “LVM Using snapot to backup data–from google searching..”




模块原则 (使用简洁的接口拼合简单的部件)



清晰原则 (清晰胜于技巧)



组合原则 (设计时考虑拼接组合)





分离原则 (策略同机制分离,接口同引擎分离)



简洁原则 (设计要简洁,复杂度能低就低)


吝啬原则 (除非确无它法,不要编写庞大的程序)


透明原则 (设计要可见,以便审查和调试)





健壮原则 (健壮源于透明与简洁)




表示原则 (把知识代入数据以求逻辑质朴而健壮)


通俗原则 (接口避免标新立异)


缄默原则 (无话可说?那就沉默)


补救原则 (出现异常时,马上退出并给出足够错误信息)



经济原则 (宁花机器一分,不花程序员一秒)


生成原则 (避免手工hack,尽量编写程序去生成程序)

优化原则 (过早优化是万恶之源)


先制作原型,再精雕细琢。优化之前先确保能用。”极限编程”宗师Kent Beck从另一种不同的文化将这点有效地扩展为:先求运行,再求正确,最后求快。

多样原则 (绝不相信所谓”不二法门”的断言)

扩展原则 (设计着眼未来,未来总比预想来得快)



CentOS yum repository management tools

CentOS yum repository management tool

    —- Search

  • 1. yum list package_name (simple search)
    yum list package_name* wildcard supported.
  • 2. yum search package_name (deep search)
  • 3. To do a search for any packages that provide php, you can use the following command
    yum provider php*
    —- Group

  • 1. yum grouplist
  • 2. yum groupinstall groupname

Python-OptParser Global args operations.

def setup_cmdline_parser():
    parser = _o.OptionParser()
    parser.add_option("-l", "--live", dest="live", action="store_true",
                      default=True, help = "show the ncurses live monitoring frontend (default)")
    parser.add_option("-n", "--notlive", dest="live", action="store_false",
                      default="True", help = "write to file instead of live monitoring")
    parser.add_option("-p", "--prefix", dest="prefix",
                      default = "log", help="prefix to use for output files")
    parser.add_option("-t", "--time", dest="duration", action="store", type="int", default=10,
            help="stop logging to file after this much time has elapsed (in seconds). set to 0 to keep logging indefinitely")
    return parser

def main():
    global options
    global args
    global domains

    parser = setup_cmdline_parser()
    (options, args) = parser.parse_args()

    if len(args):
        parser.error("No parameter required")
    if options.mspersample < 0:
        parser.error("option --ms_per_sample: invalid negative value: '%d'" %
    # If --ms_per_sample= is too large, no data may be logged.
    if not and options.duration != 0 and \
       options.mspersample > options.duration * 1000:
        parser.error("option --ms_per_sample: too large (> %d ms)" %
                     (options.duration * 1000))

            print 'Quitting.'

Using options, args out of functions with “global”

Python learning schadule

1. Python Basic skills & fundamental — Programming Python 3rd Edition [book recommend]

2. Python cook book — learning the contents are associated with system administration :

  • text


  • re


  • os


  • file operation.

3. Ipython interactive shell —Python.for.Unix.and.Linux.System.Administration[book recommend]

Python-Django clean_data 和 cleaned_data

clean_data 和 cleaned_data

>>>python shell
>>>from pageage1 import MyForm


>>>form.clean_data # Django 0.96
>>>form.cleaned_data # Django 1.0