]> www.hackdaworld.org Git - hdw-linux/hdw-linux.git/blob - scripts/Create-FAI
finished minimal fai procedure + docu
[hdw-linux/hdw-linux.git] / scripts / Create-FAI
1 #!/bin/bash
2 #
3 # author: hackbard@hackdaworld.dyndns.org
4 #
5 # script creating a minimal system nfsroot for automated installation of hdw
6 #
7
8 fairoot="$1"
9 myip="`ifconfig eth0 | grep inet\ addr | awk '{ print $2 }' | awk -F: '{ print $2 }'`"
10 home_dir=$PWD
11
12 usage() {
13         echo
14         echo "usage:"
15         echo "$0 <fai-root>"
16         echo
17         exit
18         }
19
20 [ "$#" != "1" ] && usage
21 [ ! -d $fairoot ] && usage
22
23 echo "reading config ..."
24 if [ ! -f ./Config ] ; then
25         echo "config file not found, aborting"
26         exit
27 fi
28 . ./Config
29
30 if [ ! -f ./fai/nfsroot-packages ] ; then
31         echo "storing $hdw_target as original target"
32         hdw_orig_target=$hdw_target
33
34         echo "pretending default target for nfsroot install now"
35         export hdw_target=default
36         echo "hdw_target=default # FAI_WAS_HERE" >> Config # dirty!
37
38         ./scripts/Helper -create_dist_files
39
40         export hdw_target=$hdw_orig_target
41         grep -v '# FAI_WAS_HERE' Config > tmp~
42         mv tmp~ Config
43         echo "orig target restored to $hdw_target"
44
45         cp ./distro/default ./fai/nfsroot-packages
46
47         echo "deleting some packages from list now"
48         del="linux-libc-headers man-pages binutils gcc m4 autoconf automake"
49         del="$del man make patch bin86 nasm lilo cvs"
50         del="$del bootdisk" # just by now - may contain kernel image later
51         for package in $del; do
52                 grep -v ^$package ./fai/nfsroot-packages > ./fai/tmp~
53                 mv ./fai/tmp~ ./fai/nfsroot-packages
54         done
55         echo "adding needed packages to list now"
56         echo "portmap" >> ./fai/nfsroot-packages
57         [ "$hdw_arch" = "ia32" ] && echo "lilo" >> ./fai/nfsroot-packages
58 fi
59
60 if [ ! -f $fairoot/packages_installed ] ; then
61         echo "creating nfsroot..."
62         chmod 755 ./misc/hdw-tools/hdw-get
63         ./misc/hdw-tools/hdw-get dist-install $fairoot ./fai/nfsroot-packages
64         touch $fairoot/packages_installed
65         echo "done"
66 else
67         echo "nfsroot seems to be available already"
68         echo "(del $fairoot/packages_installed to recreate it)"
69 fi
70
71 if [ ! -f $fairoot/prepared_nfsroot ] ; then
72         echo "preparing nfsroot for automated install routine ..."
73         cd $fairoot
74         # special files (null & console)
75         [ ! -c dev/null ] && mknod -m 0666 dev/null c 1 3
76         [ ! -c dev/console ] && mknod -m 0600 dev/console c 5 1
77         # fstab
78         cp $home_dir/misc/sysfiles/etc/fstab ./etc
79         # the target directory
80         mkdir -p ./trg
81         # dir for mounting fai config
82         mkdir -p fai
83         # removing some services
84         for i in sysklogd network inetd nscd; do
85                 rm -f etc/init.d/rc2.d/*${i}
86         done
87         # modified inittab, rc and bootscript
88         sed "s%| /sbin/btee .*%%g" $home_dir/misc/sysfiles/etc/inittab > \
89                 etc/inittab
90         cp $home_dir/misc/fai/fai_boot ./etc/init.d/boot
91         sed "s%^FAI_MOUNT_LINE%mount -tnfs $myip:/$home_dir/fai /fai%" \
92                 $home_dir/misc/fai/fai_rc > etc/init.d/rc
93         chmod 755 etc/init.d/rc
94         # modify hdw-get.conf
95         sed "s%hdw_arch_opt=.*%hdw_arch_opt=$hdw_arch_opt%" etc/hdw-get.conf > \
96                 tmp~
97         mv tmp~ etc/hdw-get.conf
98         # get to home_dir again
99         cd $home_dir
100         echo "done"
101         touch $fairoot/prepared_nfsroot
102 else
103         echo "nfsroot seems to be prepared already"
104         echo "(del $fairoot/prepared_nfsroot to recreate it)"
105 fi
106
107 echo "checking pxe/nfs environment ..."
108 mkdir -p /tftpboot
109 cp $fairoot/boot/vmlinuz_hdw /tftpboot
110 if [ ! -f /tftpboot/pxelinux.0 ] ; then
111         if [ ! -f /usr/lib/syslinux/pxelinux.0 ] ; then
112                 echo "pxelinux (syslinux) not found, fix this manually now :p"
113         fi
114         cp /usr/lib/syslinux/pxelinux.0 /tftpboot
115 fi
116 mkdir -p /tftpboot/pxelinux.cfg
117 cat > /tftpboot/pxelinux.cfg/fai << EOF
118 PROMPT 1
119 DEFAULT disk
120 TIMEOUT 200
121
122 LABEL fai
123         KERNEL vmlinuz_hdw
124         APPEND root=/dev/nfs nfsroot=$myip:$fairoot ip=dhcp
125
126 LABEL disk
127         LOCALBOOT 0
128 EOF
129 echo -e "$fairoot\tfoobar(async,ro,no_root_squash)" >> /etc/exports
130 echo -e "$home_dir/fai\tfoobar(async,ro,no_root_squash)" >> /etc/exports
131
132 echo "everything should work now. now do the following:"
133 echo "1) edit /etc/exports to allow your clients to mount the nfsroot"
134 echo "2) link the ipaddr in hex of the client to fai in pxe config dir"
135 echo "3) tell your dhcpd (see syslinux docs for more help)"
136 echo "4) make sure inetd/nfs/dhcpd are up running"
137 echo "5) do the configuration stuff (see doc/FAI)"
138 echo
139 echo "note: tftp must support tsize option (use e.g. tftp-hpa package)"
140 echo
141
142 echo "done"