1 TITLE: Perl script for creating a LFS bootdisk
3 AUTHOR: Randy Janinda <randy.janinda@ndcorp.com>
6 This script creates a bootdisk that you can use to install LFS on a given computer.
10 #Randy Janinda <randy.janinda@ndcorp.com>
70 $distro = "/home/distro";
71 $image = "/home/distro.img";
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}
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");
87 unless (-e $_) {mkdir $_, 0755;}
90 foreach (@dev_files) {
91 unless (-e $_) {system("/bin/cp -dpR /dev/$_ $_");}
96 open BINLIB, ">$distro/bin.lib";
97 foreach (@bin_files) {
98 unless (-e $_) {system("$file_copy /bin/$_ $_")}
99 print BINLIB `/usr/bin/ldd $_`;
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}
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}
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 $_`;
125 open LIB, ">$distro/lib.list";
126 open BINLIB, "$distro/bin.lib";
127 open SBINLIB, "$distro/sbin.lib";
130 s/^\t\/?lib.*\s=\>\s\/lib\/(.*)\s\(0x.{8}\)$/$1/;
136 s/^\t\/?lib.*\s=\>\s\/lib\/(.*)\s\(0x.{8}\)$/$1/;
143 unlink "$distro/bin.lib";
144 unlink "$distro/sbin.lib";
147 open LIB, "$distro/lib.list";
149 while (chomp($new = <LIB>)) {
150 @{$lib_files{$new}} = stat "/lib/$new";
154 foreach $key (keys %lib_files) {
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}
161 unless (-e $key) {system("$lib_copy /lib/$key $key")}
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")}
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"}
176 foreach (@etc_files) {
177 unless (-e $_) {system("/bin/cp /etc/$_ $_")}
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")}
186 open INIT, ">$distro/etc/inittab";
190 1:2345:respawn:/sbin/mingetty tty1
191 2:2345:respawn:/sbin/mingetty tty2
195 open FSTAB, ">$distro/etc/fstab";
197 /dev/ram0 / ext2 defaults
198 /dev/fd0 / ext2 defaults
199 /proc /proc proc defaults
203 open RC, ">$distro/etc/rc";
207 /bin/hostname Kangaroo
211 open PAM, ">$distro/etc/pam.conf";
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
220 open NS, ">$distro/etc/nsswitch.conf";
241 system("/usr/sbin/chroot $distro /sbin/ldconfig");
244 system("/bin/umount $distro");
246 system("/bin/dd if=$device bs=1k | /bin/gzip -v9 > rootfs.gz");
248 system("/sbin/losetup -d $device");
249 system("/bin/dd if=/home/rootfs.gz of=/dev/fd0 bs=1k");