Add .gitignore file
[s390-tools.git] / zfcpdump / ramdisk / create_rd.sh
blob03f79187fdcd7af8569468bca667f71a7c7f0ef7
1 #!/bin/sh
3 # Shell script to build and install the zfcpdump ramdisk
5 # > create_rd.sh (ARCH) : build ramdisk
6 # > create_rd.sh -r : cleanup
7 # > create_rd.sh -i : install files
9 # Copyright IBM Corp. 2003, 2006.
10 # Author(s): Michael Holzheu <holzheu@de.ibm.com>
13 . ../config
15 E2FS_PROGS="../extern/$E2FS_PROGS_TARBALL"
16 EXT2_RD_FREE_SIZE=200
18 RD_TMP=rd
19 RD_IMAGE=ramdisk.dump
20 DIR_LIST="sbin \
21 dev \
22 proc \
23 etc \
24 mnt \
25 sys "
28 # check() function to check error codes
30 function check ()
32 if [ $? != 0 ]
33 then
34 echo "failed"
35 exit 1
36 else
37 echo "ok"
42 # build(): build the ramdisk
45 function build ()
47 echo "build: `date`"
49 echo "==============================================================="
50 echo "Removing old installation"
51 echo "==============================================================="
52 rm -rf $RD_TMP
53 echo "ok"
55 echo "==============================================================="
56 echo "Creating RD dir structure"
57 echo "==============================================================="
58 mkdir $RD_TMP
59 for i in $DIR_LIST
61 mkdir "$RD_TMP/$i"
62 done
63 check
66 # Build e2fsprogs
69 if [ ! -f e2fsprogs-$E2FS_PROGS_VERSION/e2fsck/e2fsck ]
70 then
71 echo "==============================================================="
72 echo "Extracting E2FSPROGS"
73 echo "==============================================================="
74 tar xfzv $E2FS_PROGS
75 check
76 echo "==============================================================="
77 echo "Compiling E2FSPROGS"
78 echo "==============================================================="
79 cd e2fsprogs-$E2FS_PROGS_VERSION
80 ./configure
81 make
82 check
83 cd ..
85 echo "==============================================================="
86 echo "Installing e2fsck"
87 echo "==============================================================="
88 strip e2fsprogs-$E2FS_PROGS_VERSION/e2fsck/e2fsck
89 cp e2fsprogs-$E2FS_PROGS_VERSION/e2fsck/e2fsck $RD_TMP/sbin
90 check
93 # copy additional files
96 strip zfcp_dumper
97 cp zfcp_dumper $RD_TMP/sbin/init
98 ln -s /proc/mounts "$RD_TMP/etc/mtab"
101 # create ramdisk
104 echo "==============================================================="
105 echo "Creating ramdisk ($RD_FS)"
106 echo "==============================================================="
108 if [ "$RD_FS" == "romfs" ]
109 then
110 printf "%-30s: " "Creating romfs"
111 genromfs -f $ZFCPDUMP_RD -d $RD_TMP
112 check
113 printf "%-30s: " "zip romfs"
114 gzip $ZFCPDUMP_RD
115 check
116 mv "$ZFCPDUMP_RD.gz" $ZFCPDUMP_RD
117 elif [ "$RD_FS" == "ext2" ]
118 then
119 RD_MIN_SIZE=`du -k -s $RD_TMP | awk '{print $1}'`
120 RD_SIZE=`expr $RD_MIN_SIZE + $EXT2_RD_FREE_SIZE`
122 printf "creating rd with size $RD_SIZE KB (used $RD_MIN_SIZE):"
123 dd if=/dev/zero of=$RD_IMAGE bs=1k count=$RD_SIZE
124 check
126 printf "%-30s: " "Creating ext2"
127 yes | mke2fs $RD_IMAGE
128 check
129 printf "%-30s: " "Mounting RD"
130 if [ ! -d mnt ]
131 then
132 mkdir mnt
134 mount $RD_IMAGE "`pwd`/mnt" -o loop
135 check
137 printf "%-30s: " "Copy RD"
138 cp -R $RD_TMP/* mnt
139 if [ $? != 0 ]
140 then
141 umount mnt
142 exit
144 echo "ok"
146 printf "%-30s: " "Umount RD"
147 umount mnt
148 check
150 printf "%-30s: " "packing RD"
151 gzip $RD_IMAGE
152 check
153 mv "$RD_IMAGE.gz" $ZFCPDUMP_RD
154 check
155 else
156 echo "ERROR: Invalid ramdisk filesystem '$RD_FS'"
157 exit
159 echo "=============================================================="
160 echo "SUCCESS: built ramdisk '$ZFCPDUMP_RD'"
161 echo "=============================================================="
165 # cleanup(): function to remove build files
167 function cleanup()
169 rm -rf $RD_TMP
170 rm -rf e2fs*
171 rm -f zfcp_dumper
172 rm -f $RD_IMAGE
173 rm -f "$RD_IMAGE.gz"
174 rm -f $ZFCPDUMP_RD
178 # install(): function to install zfcpdump kernel
180 function install()
182 cp $ZFCPDUMP_RD "$INSTROOT/$ZFCPDUMP_DIR"; chmod 644 "$INSTROOT/$ZFCPDUMP_DIR/$ZFCPDUMP_RD"
186 # main
189 if [ "$1" == "-r" ]
190 then
191 cleanup
192 elif [ "$1" == "-i" ]
193 then
194 install
195 else
196 ARCH="$1"
197 build