linux kernel 随记

来源:互联网 发布:多益网络下载 编辑:程序博客网 时间:2024/05/21 22:35


vmlinuz
--------
od -t x1 -A d vmlinuz| grep "1f 8b 08 00"
0013920 f3 a5 fc 5e 8d 83 80 b8 38 00 ff e0 1f 8b 08 00


#13920+12=13932


dd if=vmlinuz bs=1 skip=13932 |zcat > vmlinux
strings vmlinux|grep /sbin/
strings vmlinux|grep 'init='                 -----查看第一个执行的程序,默认是/sbin/init
strings vmlinux|grep 'Linux version'         -----查看内核版本号




readelf -a vmlinux
objdump 


initrd.img
----------
cp initrd.img /tmp/initrd.img.gz
cd /tmp/ && gzip -d initrd.img.gz
mount -o loop initrd.img /mnt            ----2.4内核
mkdir initrd && cd initrd && cpio -ivmd <../initrd.img         ---2.6内核




---------
file vmlinuz-2.6.32-372.el6_jay.x86_64
vmlinuz-2.6.32-372.el6_jay.x86_64: Linux kernel x86 boot executable bzImage,
# 查找gzip压缩内容的开始头部,通过“1f 8b 08”这个签名来查找
od -t x1 -A d vmlinuz-2.6.32-372.el6_jay.x86_64 | grep "1f 8b 08"
0014432 48 8d 83 70 81 3d 00 ff e0 1f 8b 08 00 c4 01 9c
# 计算bizip压缩内容开始处的offset,为:14432 + 9 = 14441  (9是从0014431起到"if 8b 08"之间的字节数)
# 解压出被压缩的kernel中的内容


dd if=vmlinuz-2.6.32-372.el6_jay.x86_64 bs=1 skip=14441 | zcat > vmlinux-jay
gzip: stdin: decompression OK, trailing garbage ignored
file vmlinux-jay
vmlinux-jay: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, stripped
 
strings vmlinux-jay | grep 'Linux version'
Linux version 2.6.32-372.el6.bz635846_jay.x86_64 (n0ano@sobek
strings vmlinux-jay | grep '/sbin/'
/sbin/init
/sbin/request-key
/sbin/poweroff
/sbin/modprobe




-------------


mount -o loop initrd.img /mnt/initrd




dd if=/dev/zero of=../initrd.img bs=512k count=64
mkfs.ext2 -F -m0 ../initrd.img
mount -t ext2 -o loop ../initrd.img  /mnt/daniel
cp -r  * /mnt/daniel
umount /mnt/daniel
gzip -c ../initrd.img > ../initrd.gz






endian
=======
 
more /bin/mountsource.sh
------------------------
#!/bin/sh


#
# to be banished by kudzu!
#


echo "Scanning source media"


echo "--------"
echo "xNet Extensible Network Solutions"
echo "--------"
#kudzu -qps  -t 30 -c HD
cat /proc/partitions
sleep 10


# scan CDROM devices
for DEVICE in $(kudzu -qps  -t 30 -c CDROM | grep device: | cut -d ' ' -f 2 | sort | uniq); do
    mount /dev/${DEVICE} /cdrom 2> /dev/null
    if [ -e /cdrom/data/endian.gpg ] && [ -e /cdrom/data/bootstrap.tar.gz ]; then
        echo -n ${DEVICE} > /source_device
        exit 0
    fi
    umount /cdrom 2> /dev/null
done


# scan USB devices with fat32
for DEVICE in $(cat /proc/partitions |  awk '{print$4}'); do
    mount -t vfat /dev/${DEVICE} /cdrom 2> /dev/null
    if [ -e /cdrom/data/endian.gpg ] && [ -e /cdrom/data/bootstrap.tar.gz ]; then
        echo -n ${DEVICE} > /source_device
        exit 0
    fi
    umount /cdrom 2> /dev/null
done


# scan HD device (usb sticks, etc.)
for DEVICE in $(kudzu -qps  -t 30 -c HD | grep device: | cut -d ' ' -f 2 | sort | uniq); do
    mount -t ext3 /dev/${DEVICE}1 /cdrom 2> /dev/null
    if [ -e /cdrom/data/endian.gpg ] && [ -e /cdrom/data/bootstrap.tar.gz ]; then
        echo -n ${DEVICE}1 > /source_device
        exit 1
    fi
    umount /cdrom 2> /dev/null
done


# scan the disaster recovery key ( second partition contains the data)
for DEVICE in $(kudzu -qps  -t 30 -c HD | grep device: | cut -d ' ' -f 2 | sort | uniq); do
    mount -t ext3 /dev/${DEVICE}2 /cdrom 2> /dev/null
    if [ -e /cdrom/data/endian.gpg ] && [ -e /cdrom/data/bootstrap.tar.gz ]; then
        echo -n ${DEVICE}2 > /source_device
        exit 1
    fi
    umount /cdrom 2> /dev/null
done


UNATTENDED_CONF="/cdrom/data/unattended.conf"
CONFIG=/tmp/deployment.conf
STATUS=$1


if [ ! -f "$CONFIG" ]; then
    exit 10
fi


# load config file
. $CONFIG


if [ -e $URL ]; then
    # not a deploy system
    exit 10
fi




# net install ?
mkdir -p /mnt/cdrom
mkdir -p /mnt/production


if [ ! -e /tmp/dhcp_done ]; then
    for i in `ip l | grep eth[0-9]: | awk {' print $2 '} | cut -d: -f1 | xargs`; do
       ifconfig $i up
       udhcpc -i $i -b -s /bin/ip-up.sh -p /tmp/dhclient.$i.pid &&
       touch /tmp/dhcp_done
    done
fi


# usb stick
for DEVICE in $(kudzu -qps  -t 30 -c HD | grep device: | cut -d ' ' -f 2 | sort | uniq); do
    mount -t ext3 /dev/${DEVICE}1 /mnt/cdrom 2> /dev/null
    if [ -e /mnt/cdrom/data/endian.gpg ] && [ -e /mnt/cdrom/data/unattended.conf ]; then
        cp /mnt/cdrom/data/unattended.conf /tmp/deployment.conf
        . /tmp/deployment.conf
        if [ -e $URL ]; then
            # not a deploy system
            exit 10
        fi
        echo -n ${DEVICE}1 > /source_device
        umount /mnt/cdrom
        sendstatus.sh mount
        exit 1
    fi
    umount /mnt/cdrom 2&>/dev/null
done


#usb with fat32
for DEVICE in $(cat /proc/partitions |  awk '{print$4}'); do
    mount -t vfat /dev/${DEVICE} /mnt/cdrom 2> /dev/null
    if [ -e /mnt/cdrom/data/endian.gpg ] &&  [ -e /mnt/cdrom/data/unattended.conf ]; then
            echo -n ${DEVICE} > /source_device
            cp /mnt/cdrom/data/unattended.conf /tmp/deployment.conf
            . /tmp/deployment.conf
            if [ -e $URL ]; then
                # not a deploy system
                exit 10
            fi
            sendstatus.sh mount
            exit 0
    fi
    umount /mnt/cdrom 2&>/dev/null
done


#cdrom
for DEVICE in $(kudzu -qps  -t 30 -c CDROM | grep device: | cut -d ' ' -f 2 | sort | uniq); do
    mount /dev/${DEVICE} /mnt/cdrom 2> /dev/null
    if [ -e /mnt/cdrom/data/endian.gpg ] &&  [ -e /mnt/cdrom/data/unattended.conf ]; then
            echo -n ${DEVICE} > /source_device
            cp /mnt/cdrom/data/unattended.conf /tmp/deployment.conf
            . /tmp/deployment.conf
            if [ -e $URL ]; then
                # not a deploy system
                exit 10
            fi
            sendstatus.sh mount
            exit 0
    fi
    umount /mnt/cdrom 2&>/dev/null
done


exit 10
                                                              
0 0
原创粉丝点击