From 84a7f620bb67b800c5d0b3a2e73c35844f7a9a1d Mon Sep 17 00:00:00 2001
From: Achim Gottinger <achim@gentoo.org>
Date: Mon, 22 Jan 2001 04:00:34 +0000
Subject: *** empty log message ***

---
 sys-apps/bootdisk/files/bootgrub-1.0_rc5.img | Bin 0 -> 1474560 bytes
 sys-apps/bootdisk/files/etc/install.conf     |   4 +-
 sys-apps/bootdisk/files/etc/profile          |   5 +
 sys-apps/bootdisk/files/linuxrc              | Bin 16035 -> 18888 bytes
 sys-apps/bootdisk/files/linuxrc6.c           | 187 +++++++++++++++
 sys-apps/bootdisk/files/mkcd4.sh             | 338 +++++++++++++++++++++++++++
 sys-apps/bootdisk/files/sbin/rc              |   4 +-
 7 files changed, 534 insertions(+), 4 deletions(-)
 create mode 100644 sys-apps/bootdisk/files/bootgrub-1.0_rc5.img
 create mode 100644 sys-apps/bootdisk/files/etc/profile
 create mode 100644 sys-apps/bootdisk/files/linuxrc6.c
 create mode 100755 sys-apps/bootdisk/files/mkcd4.sh

(limited to 'sys-apps')

diff --git a/sys-apps/bootdisk/files/bootgrub-1.0_rc5.img b/sys-apps/bootdisk/files/bootgrub-1.0_rc5.img
new file mode 100644
index 000000000000..59e448047196
Binary files /dev/null and b/sys-apps/bootdisk/files/bootgrub-1.0_rc5.img differ
diff --git a/sys-apps/bootdisk/files/etc/install.conf b/sys-apps/bootdisk/files/etc/install.conf
index 226a20293f62..3ea0e684e8eb 100644
--- a/sys-apps/bootdisk/files/etc/install.conf
+++ b/sys-apps/bootdisk/files/etc/install.conf
@@ -1,10 +1,10 @@
 # Uncomment the following if you dont't want to generate the devices
 
-#NODEV="yes"
+NODEV="yes"
 
 # OSNAME
 OSNAME="gentoolinux"
-ARCH="i686-pc-linux-gnu"
+ARCH="i486-pc-linux-gnu"
 
 # Enter your partition information here 
 # ROOT has to be reiserfs !
diff --git a/sys-apps/bootdisk/files/etc/profile b/sys-apps/bootdisk/files/etc/profile
new file mode 100644
index 000000000000..a0adefabf58e
--- /dev/null
+++ b/sys-apps/bootdisk/files/etc/profile
@@ -0,0 +1,5 @@
+alias d="ls --color"
+alias ll="ls --color -l"
+
+export PS1='\[\033[01;34;40m\]\W > \[\033[00m\]'
+export PATH=/sbin:/bin:/usr/sbin:/usr/bin
diff --git a/sys-apps/bootdisk/files/linuxrc b/sys-apps/bootdisk/files/linuxrc
index 9d320972dc2b..5b7be462085b 100755
Binary files a/sys-apps/bootdisk/files/linuxrc and b/sys-apps/bootdisk/files/linuxrc differ
diff --git a/sys-apps/bootdisk/files/linuxrc6.c b/sys-apps/bootdisk/files/linuxrc6.c
new file mode 100644
index 000000000000..324263e37438
--- /dev/null
+++ b/sys-apps/bootdisk/files/linuxrc6.c
@@ -0,0 +1,187 @@
+#include <stdio.h>
+
+#include <stdio.h>
+#include <string.h>
+#include <ctype.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <getopt.h>
+#include <errno.h>
+#include <sys/ioctl.h>
+#include <linux/fs.h>
+#include <linux/loop.h>
+
+#define NUMDRIVES (5)
+
+char *blurb="    Gentoo Linux CD mounter - Copyright 1999-2001 Gentoo Technologies, Inc.     ";
+char *color="\033[36;01m";
+char *off="\033[0m";
+char readbuf[80];
+
+/*drobbins notes (11 Dec 2000)
+	device=(major*256)+minor
+	mount /proc
+	turn off module ickyness
+		echo "0 0 0 0" > /proc/sys/kernel/printk
+	use this info to set the new root fs
+		echo 0x902>/proc/sys/kernel/real-root-dev
+	umount /proc
+*/
+/* achim notes (14 Dec 2000)
+	replaced getchar with fgetc
+	modifyed mount to work with diet-libc
+*/	
+int set_loop(const char *device, const char *file, int offset, int loopro)
+{
+	struct loop_info loopinfo;
+	int	fd, ffd, mode, i;
+	char	*pass;
+
+	mode = loopro ? O_RDONLY : O_RDWR;
+	if ((ffd = open (file, mode)) < 0 && !loopro
+	    && (errno != EROFS || (ffd = open (file, mode = O_RDONLY)) < 0)) {
+	  perror (file);
+	  return 0;
+	}
+	if ((fd = open (device, mode)) < 0) {
+	  perror (device);
+	  return 0;
+	}
+	loopro = (mode == O_RDONLY);
+
+	memset(&loopinfo, 0, sizeof(loopinfo));
+	strncpy(loopinfo.lo_name, file, LO_NAME_SIZE);
+	loopinfo.lo_name[LO_NAME_SIZE-1] = 0;
+	loopinfo.lo_offset = offset;
+	loopinfo.lo_encrypt_key_size = 0;
+	if (ioctl(fd, LOOP_SET_FD, ffd) < 0) {
+		perror("ioctl: LOOP_SET_FD");
+		exit(1);
+	}
+	if (ioctl(fd, LOOP_SET_STATUS, &loopinfo) < 0) {
+		(void) ioctl(fd, LOOP_CLR_FD, 0);
+		perror("ioctl: LOOP_SET_STATUS");
+		exit(1);
+	}
+	close(fd);
+	close(ffd);
+	return 1;
+}
+
+//does a mount and performs some error checking/debugging too
+//2=success; 1=no media; 0=failure
+int domount(const char *dev, 
+			const char *loc, 
+			const char *fstype, 
+			unsigned long flags, 
+			const void *data) 
+{
+	int result;
+	result=mount(dev,loc,fstype,0,flags,data);
+	if (result==-1) {
+		if (errno==ENOMEDIUM) {
+			printf("Media not found in %s\n",dev);
+			return 1;
+		}
+		printf("Error mounting %s at %s of type %s:\n",dev,loc,fstype);
+		perror("mount");
+		return 0;
+	}
+	return 2;
+}
+
+//writes data to a file and performs some error checking
+//1=success; 0=failure
+int writefile(const char *myfile, char *mystring) {
+	FILE *myf;
+	int result;
+	myf=fopen(myfile,"w");
+	if (myf==NULL) {
+		printf("Error opening file %s: errno %d\n",myfile,errno);
+		perror("fopen");
+		return 0;
+	}
+	fwrite(mystring,1,strlen(mystring),myf);
+	fclose(myf);
+	return 1;
+}
+
+
+int getspace(char *dev) {
+	char mychar,dummy;
+	printf("\n1) Try %s again\n2) Continue looking\n\n%s> %s",dev,color,off);
+	mychar=fgetc(stdin);
+	dummy=fgetc(stdin); // return
+	if (mychar=='1')
+		return 1;
+	return 0;
+}
+int main(void) {
+	char *drives[]={ "/dev/hdc","/dev/hdd","/dev/hdb","/dev/hda","/dev/scd0","/dev/scd1"};
+	int i,mresult;
+	char mychar;
+	FILE *distfile;	
+	printf("\033c\n\0337\033[01;23r\033[24;01f\033[01;44;32m%s\033[0m\0338\033[A",blurb); 
+	printf("\nRemounting root fs read-write...\n");
+	//should be rw anyway but it's not?
+	domount("/dev/ram0","/","ext2",MS_MGC_VAL|MS_REMOUNT,NULL);
+	printf("%sLet's begin...%s\n\n",color,off);
+	printf("%sMounting /proc...%s\n",color,off);
+	//mount /proc filesystem
+	domount("proc","/proc","proc",MS_MGC_VAL|MS_NOEXEC,NULL);
+	//turn off kernel logging to console
+	writefile("/proc/sys/kernel/printk","0 0 0 0");
+	
+	i=0;
+	while ( 1 ) {
+		printf("Trying %s...",drives[i]);
+		sleep(1);
+		mresult=domount(drives[i],"/distcd","iso9660",MS_MGC_VAL|MS_RDONLY,NULL);
+		if (mresult==2) {
+			//a CD of some kind was found
+			printf("\n%sCD found...%s\n",color,off);
+			if ((distfile=fopen("/distcd/version","r"))==NULL) {
+				printf("%sThis does not appear to be the Gentoo Linux distribution disc.%s\n",color,off);
+				umount(drives[i]);
+				if (!getspace(drives[i]))
+					i++;
+					if (i>NUMDRIVES)
+						i=0;
+				continue;
+			} else {
+				fclose(distfile);
+				break;
+				//success!
+			}
+		} else if (mresult==1) {
+			if (!getspace(drives[i]))
+				i++;
+				if (i>NUMDRIVES)
+					i=0;
+			continue;
+		} else {
+			i++;
+			if (i>NUMDRIVES)
+				i=0;
+		}
+	}
+	printf("%sAssociating loopback CD-ROM filesystem...%s\n",color,off);
+	if(!(set_loop("/dev/loop0","/distcd/images/boot.img",0,0))) {
+		printf("%sError associating loopback CD-ROM filesystem.  This program is stuck!%s\n",color,off);
+		exit(1);
+	}
+
+	printf("%sSuccess!%s\n",color,off);		
+	mresult=domount("/dev/loop0","/","ext2",MS_MGC_VAL|MS_RDONLY,0);
+	printf("%sSuccess /dev/loop0!%s\n",color,off);		
+	//set real root device to /dev/loop0 (major 7, minor 0)
+	writefile("/proc/sys/kernel/real-root-dev","0x700");
+	printf("%sRoot changed ...%s\n",color,off);
+	//umount /proc
+	umount("proc");
+	printf("%sProc unmounted ...%s\n",color,off);
+	printf("\0337\033[r\033[24;01f\033[K\0338");
+}
+
+
+
diff --git a/sys-apps/bootdisk/files/mkcd4.sh b/sys-apps/bootdisk/files/mkcd4.sh
new file mode 100755
index 000000000000..a7eda64e4bee
--- /dev/null
+++ b/sys-apps/bootdisk/files/mkcd4.sh
@@ -0,0 +1,338 @@
+#!/bin/sh
+
+export PATH=/usr/lib/portage/bin:${PATH}
+
+
+eval `import-settings PORTDIR PKGDIR PACKAGE PORTAGE_TMPDIR`
+export BROOT=${PORTAGE_TMPDIR}/boot
+export BOOTIMG=${BROOT}/bootcd
+export INITDISK=${BROOT}/initrd
+export PORTDIR=$PORTDIR/gentoo-x86
+export BOOTDIR=$PORTDIR/sys-apps/bootdisk
+export KERNEL=${PKGDIR}/All/linux-bootdisk-2.4.1_pre8-r1.${PACKAGE}
+export KV=2.4.1-pre8
+
+if [ ! -d "${BOOTDIR}" ]
+then
+  echo "Sorry no bootdisk in the cvs tree $PORTDIR !"
+  exit 1
+fi
+
+if [ ! -f "${KERNEL}" ]
+then
+  echo "Sorry no kernel-package found in ${KERNEL}!"
+  exit 1
+fi
+
+
+dodirs() {
+  for i in $@
+  do
+    mkdir $i
+  done
+}
+
+doexes() {
+  for i in $@
+  do
+    cp `which $i` $i
+    strip $i &>/dev/null
+  done
+}
+
+
+mkbootimg() {
+
+        echo ">>> Creating boot.img"
+        echo
+
+        cd ${BOOTIMG}
+
+        # *********** 1 ************
+
+        echo "1. Creating basic dirs"
+        dodirs bin dev initrd lib sbin usr proc
+
+        # *********** 2 ************
+
+        echo "2. Creating initdisk stuff in initrd first"
+        cd ${BOOTIMG}/initrd
+        dodirs dev distcd etc root tmp var mnt
+        cd mnt
+        dodirs floppy gentoo ram boot
+        ln -sf /initrd/distcd .
+        cd ../..
+        ln -sf mnt/boot boot
+
+
+
+        # *********** 4 ************
+
+        echo "4. Populating /initrd/etc"
+        cd ${BOOTIMG}/initrd/etc
+        cp -af ${BOOTDIR}/files/etc.boot/* .
+        rm -r CVS
+        touch ld.so.conf
+	mkdir modules
+	cp ${BROOT}/kernel/lib/modules/${KV}/modules.* modules
+
+        # *********** 5 ************
+
+        echo "5. Creating other dirs for initrd"
+        cd ${BOOTIMG}/initrd/var
+        dodirs log run lib shm
+	mkdir lib/nfs
+        touch log/wtmp
+        touch run/utmp
+
+        # *********** 6 ************
+
+        echo "6. Creating links to initrd"
+        cd ${BOOTIMG}
+        for i in etc root tmp var mnt 
+        do
+            ln -s initrd/$i $i
+        done
+
+
+
+        # *********** 7 ************
+
+        echo "7. Creating devices"
+        cd ${BOOTIMG}/dev
+        tar xzf ${BOOTDIR}/files/devices.tgz -C .
+        ln -s ram0 ram
+
+
+        # *********** 3 ************
+
+        echo "8. Creating /initrd devices"
+
+        cd ${BOOTIMG}/dev
+	for i in tty tty1 tty2 initrd
+	do
+	  mv $i ../initrd/dev/$i
+	  ln -sf ../initrd/dev/$i $i
+	done
+	ln -sf ../initrd/dev/initctl .
+
+
+        # *********** 9 ************
+
+        echo "9. Populating /bin"
+        cd ${BOOTIMG}/bin
+        doexes bash cat  cp df du hostname kill ldd ln login loadkeys \
+	         ls mkdir mount mv ps rm umount uname
+        ln -s bash sh
+
+        # *********** 10 ************
+
+        echo "10. Populating /sbin"
+        cd ${BOOTIMG}/sbin
+        doexes agetty cfdisk ctrlaltdel depmod e2fsck fdisk grub halt ifconfig init \
+	        insmod ldconfig lilo ln lsmod mke2fs mkraid mkreiserfs mkswap \
+	        raidstart reboot resize2fs reiserfsck \
+	        sfdisk shutdown touch
+
+        # portmap? removed; Ups added again
+        # reiserfsck and resize_reiserfs does not exist in 2.4 so 
+	# you need the 2.2.18 kernel installed too!
+
+	# Copy kernel binaries
+
+	cp /sbin/rpc.statd .
+        ln -s insmod modprobe
+        ln -s mkraid raid0run
+        ln -s raidstart raidhotadd
+        ln -s raidstart raidhotremove
+        ln -s raidstart raidstop
+        cp ${PORTDIR}/autoinstaller.sh .
+        cp ${BOOTDIR}/files/sbin/rc . 
+
+        # *********** 11 ************
+
+        echo "11. Creating /usr dirs"
+        cd ${BOOTIMG}/usr
+        dodirs bin lib sbin share
+
+        # *********** 12 ************
+
+        echo "12. Populating /usr/bin"
+        cd ${BOOTIMG}/usr/bin
+        doexes awk bzip2 cut chgrp chmod chown chroot expr fdformat ftp grep gzip joe killall \
+	         most mknod ping rm rmdir scp sed sleep ssh strace tar top vi wget
+	ln gzip gunzip
+	ln gzip zcat
+        # *********** 13 ************
+
+        echo "13. Populating /usr/sbin"
+        cd ${BOOTIMG}/usr/sbin
+        doexes ifconfig portmap route tcpd
+	cp -a ${BROOT}/kernel/sbin/* .
+        cp /usr/sbin/rc-update .
+	cp ${BOOTDIR}/files/sbin/network .
+        # *********** 14 ************
+
+        echo "14. Populating /usr/share"
+        cd ${BOOTIMG}/usr/share
+        echo "   - keymaps"
+        cp -af /usr/share/keymaps .
+        echo "   - tabset"
+        cp -af /usr/share/tabset .
+        echo "   - terminfo"
+        cp -af /usr/share/terminfo .
+
+        # *********** 15 ************
+
+        echo "15. Populating /usr/lib"
+        cd ${BOOTIMG}/usr/lib
+        cp /usr/lib/joerc .
+        cp /lib/libnss_files.so.2 .
+	cp /lib/libnss_dns.so.2 .
+	cp /lib/libresolv.so.2 .
+        cp /lib/security/pam_permit.so ${BOOTIMG}/lib/pam_permit.so
+
+        # *********** 16 ************
+
+        echo "16. Finding required libs"
+        for j in "/bin" "/sbin" "/usr/bin" "/usr/sbin"
+        do
+            echo "   - $j"
+            myfiles=`find ${BOOTIMG}$j -print | /usr/lib/portage/bin/find-requires | grep -v "/bin/bash" | grep -v "/bin/sh"`
+
+            for i in $myfiles
+            do
+                if [ -f /lib/$i ]
+                then
+                    cp /lib/$i ${BOOTIMG}/lib/$i
+                    strip ${BOOTIMG}/lib/$i
+                else
+                    if [ -f /usr/lib/$i ]
+                    then
+                        cp /usr/lib/$i ${BOOTIMG}/usr/lib/$i
+                        strip ${BOOTIMG}/usr/lib/$i &>/dev/null
+                    else
+                        echo "!!! $i not found !"
+                    fi
+                fi
+            done
+        done
+        ldconfig -r ${BOOTIMG} -f /initrd/etc/ld.so.conf
+
+        # *********** 17 ************
+
+	echo "17. Copying kernel modules"
+	cd ${BOOTIMG}/lib
+	cp -a ${BROOT}/kernel/lib/modules .
+	cd modules/${KV}
+	rm modules.*
+	ln -s ../../../initrd/etc/modules/modules.* .
+
+	# *********** 18 ************
+        echo
+        echo "18. boot.img successfully created in ${BOOTIMG}"
+	echo
+}
+
+mkinitrd() {
+
+        echo ">>> Creating initdisk"
+        echo
+
+        cd ${INITDISK}
+
+        # *********** 1 ************
+
+        echo "1. Copying linuxrc"
+        cp ${PORTDIR}/sys-apps/bootdisk/files/linuxrc .
+        strip linuxrc
+
+        # *********** 2 ************
+
+        echo "2. Creating basic dirs"
+        dodirs dev distcd etc mnt proc root tmp var
+
+        # *********** 3 ************
+
+        echo "3. Populating /dev"
+        cd dev
+        for i in console fd0 fd0u1440 hda hdb hdc hdd hde hdf hdg hdh loop0 ram0 \
+                scd0 scd1 scd2 scd3 scd4 scd5 scd6 scd7 initrd
+        do
+            cp -a ${BOOTIMG}/dev/$i .
+        done
+	mknod -m 666 tty c 5 0
+        mknod -m 600 tty1 c 4 1
+        mknod -m 600 tty2 c 4 2
+        mkfifo -m 600 initctl
+        mkdir pts
+	# Just for testing
+	cp -a ${BOOTIMG}/dev/hda2 .
+
+        # *********** 4 ************
+
+        echo "4. Populating /etc"
+        cd ../etc
+        cp -af ${BOOTDIR}/files/etc/* .
+	mv ${BOOTIMG}/etc/modules .
+        find . -type d -name "CVS" -exec rm -r {} \; &>/dev/null
+        cp ${BOOTIMG}/initrd/etc/ld.so.conf .
+        cp ${BOOTIMG}/initrd/etc/ld.so.cache .
+
+        # *********** 5 ************
+
+        echo "5. Creating /mnt dirs"
+        cd ../mnt
+        dodirs floppy gentoo ram boot
+	ln -sf /initrd/distcd distcd
+        # *********** 6 ************
+
+        echo "6. Populating /var"
+        cd ../var
+        cp -a ${BOOTIMG}/var/* .
+
+	# *********** 7 ************
+
+	echo
+	echo "7. initrd successfully created in ${INITDISK}"
+	echo
+
+}
+
+if [ -d ${BROOT} ]
+then
+  rm -r ${BROOT}
+  mkdir ${BROOT}
+fi
+
+cd ${BROOT}
+
+dodirs ${BOOTIMG} ${INITDISK} kernel mnt
+echo ">>> Unpacking kernel package"
+echo
+
+tar xjf ${KERNEL} -C ${BROOT}/kernel || exit 1
+
+mkbootimg
+mkinitrd
+
+
+cd ${BROOT}
+
+echo ">>> Generating boot.img"
+dd if=/dev/zero of=boot.img bs=1024 count=20480
+mke2fs -N8000 boot.img
+mount -o loop ${BROOT}/boot.img ${BROOT}/mnt
+#cp -af ${BOOTIMG}/* ${BROOT}/mnt
+umount ${BROOT}/mnt
+echo
+
+echo ">>> Generating initdisk"
+dd if=/dev/zero of=initdisk bs=1024 count=4096
+mke2fs initdisk
+mount -o loop ${BROOT}/initdisk ${BROOT}/mnt
+#cp -af ${INITDISK}/* ${BROOT}/mnt
+umount ${BROOT}/mnt
+gzip -9 initdisk
+echo
+
diff --git a/sys-apps/bootdisk/files/sbin/rc b/sys-apps/bootdisk/files/sbin/rc
index 1e91c2e61b73..bfa6e374bdc0 100755
--- a/sys-apps/bootdisk/files/sbin/rc
+++ b/sys-apps/bootdisk/files/sbin/rc
@@ -5,9 +5,9 @@ cd /
 echo "Setting Hostname (gentoo-box)"
 /bin/hostname gentoo-box
 /bin/umount -n /initrd
-/bin/mount /initrd/proc
-/bin/mount /initrd/dev/pts
+/bin/mount /proc
 /bin/mount -o remount /
 /bin/mount -o remount /initrd
+/bin/mount /dev/pts
 
 
-- 
cgit v1.2.3-65-gdbad