Typo
[linux_from_scratch_hints.git] / OLD / create-bootdisk.txt
blobcd53f584f1b637476e35b82681f8349aa1ef0ef9
1 TITLE:          Perl script for creating a LFS bootdisk
2 LFS VERSION:    obsolete
3 AUTHOR:         Randy Janinda <randy.janinda@ndcorp.com>
5 SYNOPSIS:
6         This script creates a bootdisk that you can use to install LFS on a given computer.
8 HINT:
9 #!/usr/bin/perl
10 #Randy Janinda <randy.janinda@ndcorp.com>
12 @root_dir = qw(
13         bin
14         dev
15         etc
16         home
17         lib
18         root
19         sbin
20         usr
21         usr/lib
22         usr/bin
23         usr/sbin
24         var
25         proc
28 @etc_files = qw(
29         group 
30         passwd
31         shadow
32         termcap
35 @bin_files = qw(
36         bash
37         ls
38         cat
39         df
40         login 
41         mount
42         ps
43         chmod
44         chown
45         cp
46         mkdir
47         rm
48         hostname
51 @sbin_files = qw(
52         ldconfig
53         shutdown
54         getty 
55         mingetty 
56         init
59 @dev_files = qw(
60         console
61         mem
62         kmem
63         null
64         zero
65         tty1
66         tty2
67         ram
70 $distro = "/home/distro";
71 $image = "/home/distro.img";
72 $size = 4000;
73 $device = "/dev/loop0";
74 $file_copy = "/usr/bin/objcopy --strip-all";
75 $lib_copy = "/usr/bin/objcopy --strip-debug";
77 unless(-e $distro) {mkdir $distro, 0755}
78 unless(-e $image) {
79         system("/bin/dd if=/dev/zero of=$image bs=1k count=$size");
80         system("/sbin/losetup $device $image");
81         system("/sbin/mkfs -t ext2 $device $size");
82         system("/bin/mount -t ext2 $device $distro");
85 chdir $distro;
86 foreach (@root_dir) {
87         unless (-e $_) {mkdir $_, 0755;}
89 chdir "$distro/dev";
90 foreach (@dev_files) {
91         unless (-e $_) {system("/bin/cp -dpR /dev/$_ $_");}
94 # bin file setup
95 chdir "$distro/bin";
96 open BINLIB, ">$distro/bin.lib";
97 foreach (@bin_files) {
98         unless (-e $_) {system("$file_copy /bin/$_ $_")}
99         print BINLIB `/usr/bin/ldd $_`;
101 close BINLIB;
102 #unless (-e "true") {system("/bin/cp /bin/true $distro/bin/true")}
103 #unless (-e "false") {system("/bin/cp /bin/false $distro/bin/false")}
104 #unless (-e "sh") {symlink bash, sh}
105 #unless (-e "gunzip") {symlink gzip, gunzip}
106 #unless (-e "zcat") {symlink gzip, zcat}
108 #/usr/bin
109 #chdir "$distro/usr/bin";
110 #unless (-e top) {system("$file_copy /usr/bin/top top")}
111 #chdir "$distro/usr/lib";
112 #unless (-e libncurses.so.4.2) {system("$lib_copy /usr/lib/libncurses.so.4.2 libncurses.so.4.2")}
113 #unless (-e libncurses.so.4) {symlink libncurses.so.4.2, libncurses.so.4}
115 # sbin file setup
116 chdir "$distro/sbin";
117 open SBINLIB, ">$distro/sbin.lib";
118 foreach (@sbin_files) {
119         unless (-e $_) {system("$file_copy /sbin/$_ $_")}
120         print SBINLIB `/usr/bin/ldd $_`;
122 close SBINLIB;
123         
124 # Setup library list
125 open LIB, ">$distro/lib.list";
126 open BINLIB, "$distro/bin.lib";
127 open SBINLIB, "$distro/sbin.lib";
128 while (<BINLIB>) {
129         if (/^\t\/?lib/) {
130                 s/^\t\/?lib.*\s=\>\s\/lib\/(.*)\s\(0x.{8}\)$/$1/;
131                 print LIB $_;
132         }
134 while (<SBINLIB>) {
135         if (/^\t\/?lib/) {
136                 s/^\t\/?lib.*\s=\>\s\/lib\/(.*)\s\(0x.{8}\)$/$1/;
137                 print LIB $_;
138         }
140 close LIB;
141 close BINLIB;
142 close SBINLIB;
143 unlink "$distro/bin.lib";
144 unlink "$distro/sbin.lib";
146 # Get libraries
147 open LIB, "$distro/lib.list";
149 while (chomp($new = <LIB>)) {
150         @{$lib_files{$new}} = stat "/lib/$new";
153 chdir "$distro/lib";
154 foreach $key (keys %lib_files) {
155         #print "$key\n";
156         if (-l "/lib/$key") {
157                 $file = readlink "/lib/$key"; 
158                 unless (-e $file) {system("$lib_copy /lib/$file $file")}
159                 unless (-e $key) {symlink $file, $key}
160         }else{
161                 unless (-e $key) {system("$lib_copy /lib/$key $key")}
162         }
164 close LIB;
165 unlink "$distro/lib.list";
167 unless (-e "security") {mkdir "$distro/lib/security", 0755}
168 chdir "$distro/lib/security";
169 unless (-e "$distro/lib/security/pam_permit.so") {system("$lib_copy /lib/security/pam_permit.so pam_permit.so")}
170 chdir "$distro/lib";
171 unless(-e "$distro/lib/libnss_files-2.1.1.so") {system("$lib_copy /lib/libnss_files-2.1.1.so libnss_files-2.1.1.so")}
172 unless(-e "$distro/lib/libnss_files.so.1") {symlink "libnss_files-2.1.1.so", "libnss_files.so.1"}
174 # ETC files
175 chdir "$distro/etc";
176 foreach (@etc_files) {
177         unless (-e $_) {system("/bin/cp /etc/$_ $_")}
180 # start cleanup
181 unless (-e "$distro/var/log") {mkdir "$distro/var/log", 0755}
182 unless (-e "$distro/var/run") {mkdir "$distro/var/run", 0755}
183 unless (-e "$distro/var/run/utmp") {system("/bin/touch $distro/var/run")} 
184 # Link libraries
186 open INIT, ">$distro/etc/inittab";
187 print INIT <<EOF;
188 id:2:initdefault:
189 si::sysinit:/etc/rc
190 1:2345:respawn:/sbin/mingetty tty1
191 2:2345:respawn:/sbin/mingetty tty2
193 close INIT;
195 open FSTAB, ">$distro/etc/fstab";
196 print FSTAB <<EOF;
197 /dev/ram0       /               ext2    defaults
198 /dev/fd0        /               ext2    defaults
199 /proc           /proc           proc            defaults
201 close FSTAB;
203 open RC, ">$distro/etc/rc";
204 print RC <<EOF;
205 #!/bin/sh       
206 /bin/mount -av
207 /bin/hostname Kangaroo
209 close RC;
211 open PAM, ">$distro/etc/pam.conf";
212 print PAM <<EOF;
213 OTHER   auth       optional     /lib/security/pam_permit.so
214 OTHER   account    optional     /lib/security/pam_permit.so
215 OTHER   password   optional     /lib/security/pam_permit.so
216 OTHER   session    optional     /lib/security/pam_permit.so
218 close PAM;
220 open NS, ">$distro/etc/nsswitch.conf";
221 print NS <<EOF;
222 passwd:     files 
223 shadow:     files 
224 group:      files 
225 hosts:      files
226 services:   files
227 networks:   files
228 protocols:  files
229 rpc:        files
230 ethers:     files
231 netmasks:   files     
232 bootparams: files
233 automount:  files 
234 aliases:    files
235 netgroup:   files
236 publickey:  files
238 close NS;
240 chdir $distro; 
241 system("/usr/sbin/chroot $distro /sbin/ldconfig");
242 chdir "/home";
243 sleep 2;
244 system("/bin/umount $distro"); 
245 sleep 2;
246 system("/bin/dd if=$device bs=1k | /bin/gzip -v9 > rootfs.gz");
247 sleep 2;
248 system("/sbin/losetup -d $device");
249 system("/bin/dd if=/home/rootfs.gz of=/dev/fd0 bs=1k");