diff --git a/target/livecd/build.sh b/target/livecd/build.sh index 5edb74b6f..024aa7cfe 100644 --- a/target/livecd/build.sh +++ b/target/livecd/build.sh @@ -1,8 +1,8 @@ disksdir="$build_rock/livecd" -if [ -z "`which create_compressed_fs`" ] ; then - echo "Please make sure create_compressed_fs is installed! Rock Package: fake/cloop" +if [ -z "`which mksquashfs`" ] ; then + echo "Please make sure mksquashfs is installed! Rock Package: fake/squashfs-tools" exit 1; fi ; diff --git a/target/livecd/build_stage1.sh b/target/livecd/build_stage1.sh index 9a42b26e4..5c6ed2b1a 100644 --- a/target/livecd/build_stage1.sh +++ b/target/livecd/build_stage1.sh @@ -4,8 +4,12 @@ rm -rf $disksdir/initrd mkdir -p $disksdir/initrd/{dev,proc,tmp,bin-static,mnt/cdrom,ramdisk,etc,ROCK} cd $disksdir/initrd; ln -s bin-static sbin-static; ln -s . usr # +if [ ! -x ../../../usr/bin/diet ] ; then + echo_error "can not find the target's diet binary - did dietlibc build?"; + exit 1; +fi echo_status "Create linuxrc binary." -diet $CC $base/target/$target/linuxrc.c -Wall \ +../../../usr/bin/diet $CC $base/target/$target/linuxrc.c -Wall \ -DSTAGE_2_IMAGE="\"${ROCKCFG_SHORTID}/2nd_stage.img.z\"" \ -o linuxrc # @@ -27,8 +31,9 @@ do fi done # -echo_status "Copy scsi and network kernel modules." -for x in ../2nd_stage/lib/modules/*/kernel/drivers/net/*.{ko,o} ../2nd_stage/lib/modules/*/misc/cloop.{ko,o} ; do +echo_status "Copy kernel modules." +for x in ../2nd_stage/lib/modules/*/kernel/drivers/{scsi,cdrom,ide,ide/pci,ide/legacy}/*.{ko,o} \ + ../2nd_stage/lib/modules/*/misc/cloop.{ko,o} ; do # this test is needed in case there are only .o or only .ko files if [ -f $x ]; then xx=${x#../2nd_stage/} @@ -41,7 +46,7 @@ for x in ../2nd_stage/lib/modules/*/modules.{dep,pcimap,isapnpmap} ; do cp $x ${x#../2nd_stage/} || echo "not found: $x" ; done # -for x in lib/modules/*/kernel/drivers/net lib/modules/*/misc; do +for x in lib/modules/*/kernel/drivers/* lib/modules/*/misc; do ln -s ${x#lib/modules/} lib/modules/ done rm -f lib/modules/[0-9]*/kernel/drivers/net/{dummy,ppp*}.{o,ko} @@ -52,7 +57,7 @@ cd .. echo_header "Creating initrd filesystem image: " -ramdisk_size=4096 +ramdisk_size=8139 echo_status "Creating temporary files." tmpdir=initrd_$$.dir; mkdir -p $disksdir/$tmpdir; cd $disksdir diff --git a/target/livecd/build_stage2.sh b/target/livecd/build_stage2.sh index 97b339126..39e80e552 100644 --- a/target/livecd/build_stage2.sh +++ b/target/livecd/build_stage2.sh @@ -62,10 +62,11 @@ tar $taropt ../../pkgs/pciutils.tar.bz2 \ echo_status "replacing some vital files for live useage ..." cp -f $base/target/$target/fixedfiles/inittab etc/inittab cp -f $base/target/$target/fixedfiles/login-shell sbin/login-shell +# this got drop once, so we ensure it's +xed. +chmod 0755 sbin/login-shell cp -f $base/target/$target/fixedfiles/system etc/rc.d/init.d/system cp -f $base/target/$target/fixedfiles/XF86Config etc/X11/XF86Config # -### DOC ### create_compressed_fs and mkisofs need to be in path !!! ### DOC ### echo_status "Creating 2nd_stage.img.z image... (this takes some time)... " -cd .. ; ( mkisofs -R -l 2nd_stage | create_compressed_fs - 65536 > 2nd_stage.img.z ) > /dev/null 2>&1 +cd .. ; mksquashfs 2nd_stage 2nd_stage.img.z -noappend > /dev/null 2>&1 diff --git a/target/livecd/default.pkgmap b/target/livecd/default.pkgmap index 03845dbcd..696f496c1 100644 --- a/target/livecd/default.pkgmap +++ b/target/livecd/default.pkgmap @@ -18,7 +18,7 @@ package_map=' +bzip2 +cracklib -cron -+cloop ++squashfs-tools +cpio +cpuburn +cpuid @@ -36,10 +36,13 @@ package_map=' -flex +fbset +gawk -+gcc ++gcc32 ++gcc33 ++gcc34 -gettext +genromfs -+glibc ++glibc22 ++glibc23 +grep -groff +grub @@ -162,6 +165,7 @@ package_map=' -nasm +readline +bdb33 ++bdb40 +bdb41 +bdb42 +gdbm diff --git a/target/livecd/default.pkgsel b/target/livecd/default.pkgsel index 57411d64e..13eb0d970 100644 --- a/target/livecd/default.pkgsel +++ b/target/livecd/default.pkgsel @@ -48,7 +48,7 @@ pkgfilter sed ' / bzip2 / { p; d; }; / cracklib/ { p; d; }; / cron / { p; d; }; -/ cloop / { p; d; }; +/ squashfs-tools / { p; d; }; / cpio / { p; d; }; / curl / { p; d; }; / diffutils / { p; d; }; diff --git a/target/livecd/fixedfiles/login-shell b/target/livecd/fixedfiles/login-shell index 16b782881..6219e5962 100644 --- a/target/livecd/fixedfiles/login-shell +++ b/target/livecd/fixedfiles/login-shell @@ -1,3 +1,4 @@ -#!/bin/sh +#!/bin/bash echo "root and rocker's password is 'rock'" -exec su - rocker -c "/bin/bash --login" +cd /home/rocker +exec /bin/su - rocker -c "/bin/bash --login" diff --git a/target/livecd/fixedfiles/system b/target/livecd/fixedfiles/system index 4c44db268..9acb345a4 100644 --- a/target/livecd/fixedfiles/system +++ b/target/livecd/fixedfiles/system @@ -46,7 +46,7 @@ status() { case "$1" in start) title "Runnind depmod ..." - /sbin/depmod -a || error=$? + /sbin/depmod -a -n > /etc/modules.dep || error=$? status title "Mounting /sys, /dev/shm and /dev/pts." diff --git a/target/livecd/kernel.conf b/target/livecd/kernel.conf index 8d743e9b6..a9c21b915 100644 --- a/target/livecd/kernel.conf +++ b/target/livecd/kernel.conf @@ -21,78 +21,39 @@ # # --- ROCK-COPYRIGHT-NOTE-END --- +# boot, damn it! +CONFIG_X86_GENERIC=y + +# FireWire support +CONFIG_IEEE1394=y +CONFIG_IEEE1394_EXTRA_CONFIG_ROMS=y +CONFIG_IEEE1394_CONFIG_ROM_IP1394=y +CONFIG_IEEE1394_OHCI1394=y +CONFIG_IEEE1394_SBP2=y + +#enough space for a few modules +CONFIG_BLK_DEV_RAM_SIZE=8192 +# enable squashfs +CONFIG_SQUASHFS=y + # the useful magic rq CONFIG_DEBUG_KERNEL=y CONFIG_MAGIC_SYSRQ=y -# will use alsa -CONFIG_SOUND=m +# this is mandatory +CONFIG_BLK_DEV_IDECD=y # Console drivers CONFIG_VGA_CONSOLE=y CONFIG_VIDEO_SELECT=y - -# all fbs in-kernel CONFIG_FB=y -CONFIG_DUMMY_CONSOLE=y -CONFIG_FB_RIVA=y -CONFIG_FB_CLGEN=y -CONFIG_FB_PM2=y -# CONFIG_FB_PM2_FIFO_DISCONNECT is not set -# CONFIG_FB_PM2_PCI is not set -CONFIG_FB_PM3=y -CONFIG_FB_CYBER2000=y CONFIG_FB_VESA=y +CONFIG_FRAMEBUFFER_CONSOLE=y +CONFIG_LOGO=y +CONFIG_LOGO_LINUX_CLUT224=y + #eek! this ovverides all others! evil! CONFIG_FB_VGA16=n -CONFIG_FB_HGA=y -CONFIG_VIDEO_SELECT=y -CONFIG_FB_MATROX=y -CONFIG_FB_MATROX_MILLENIUM=y -CONFIG_FB_MATROX_MYSTIQUE=y -CONFIG_FB_MATROX_G450=y -CONFIG_FB_MATROX_G100=y -# CONFIG_FB_MATROX_I2C is not set -# CONFIG_FB_MATROX_MAVEN is not set -# CONFIG_FB_MATROX_PROC is not set -# CONFIG_FB_MATROX_MULTIHEAD is not set -CONFIG_FB_ATY=y -CONFIG_FB_ATY_GX=y -CONFIG_FB_ATY_CT=y -# CONFIG_FB_ATY_GENERIC_LCD is not set -CONFIG_FB_RADEON=y -CONFIG_FB_ATY128=y -CONFIG_FB_INTEL=y -CONFIG_FB_SIS=y -CONFIG_FB_SIS_300=y -CONFIG_FB_SIS_315=y -CONFIG_FB_NEOMAGIC=y -CONFIG_FB_3DFX=y -CONFIG_FB_VOODOO1=y -CONFIG_FB_TRIDENT=y -CONFIG_FB_IT8181=y -# CONFIG_FB_VIRTUAL is not set -CONFIG_FBCON_ADVANCED=y -CONFIG_FBCON_MFB=y -# CONFIG_FBCON_CFB2 is not set -CONFIG_FBCON_CFB4=y -CONFIG_FBCON_CFB8=y -CONFIG_FBCON_CFB16=y -CONFIG_FBCON_CFB24=y -CONFIG_FBCON_CFB32=y -# CONFIG_FBCON_AFB is not set -# CONFIG_FBCON_ILBM is not set -# CONFIG_FBCON_IPLAN2P2 is not set -# CONFIG_FBCON_IPLAN2P4 is not set -# CONFIG_FBCON_IPLAN2P8 is not set -CONFIG_FBCON_MAC=m -CONFIG_FBCON_VGA_PLANES=y -# CONFIG_FBCON_VGA is not set -CONFIG_FBCON_HGA=y -# CONFIG_FBCON_FONTWIDTH8_ONLY is not set -# CONFIG_FBCON_FONTS is not set -CONFIG_FONT_8x8=y -CONFIG_FONT_8x16=y # agp already needed for some vga cards CONFIG_AGP=y @@ -120,9 +81,9 @@ CONFIG_DRM_I830=m CONFIG_DRM_MGA=m CONFIG_DRM_SIS=m -# FireWire support -CONFIG_IEEE1394=y -CONFIG_IEEE1394_OHCI1394=y -# needed for fw cdrom boot -CONFIG_IEEE1394_SBP2=y -CONFIG_IEEE1394_ETH1394=m +# SCSI support +CONFIG_BLK_DEV_SD=y +CONFIG_BLK_DEV_SR=y +CONFIG_CHR_DEV_SG=y +CONFIG_SCSI_PROC_FS=y + diff --git a/target/livecd/kernel.conf.sh b/target/livecd/kernel.conf.sh index e6fabcb19..ff8aa865c 100644 --- a/target/livecd/kernel.conf.sh +++ b/target/livecd/kernel.conf.sh @@ -1,23 +1,20 @@ -# here we disable settings we'll most probably not need on the bootdisk -echo "bootdisk target -> disabling some settings ..." +echo "livecd target -> disabling some settings ..." -sed -e "s/CONFIG_SOUND_\(.*\)=./# CONFIG_SOUND_\1 is not set/" \ - -e "s/CONFIG_VIDEO\(.*\)=./# CONFIG_VIDEO\1 is not set/" \ +sed -e "s/CONFIG_VIDEO\(.*\)=./# CONFIG_VIDEO\1 is not set/" \ -e "s/CONFIG_PHONE\(.*\)=./# CONFIG_PHONE\1 is not set/" \ -e "s/CONFIG_RADIO\(.*\)=./# CONFIG_RADIO\1 is not set/" \ -e "s/CONFIG_HAMRADIO\(.*\)=./# CONFIG_HAMRADIO\1 is not set/" \ -e "s/CONFIG_ATM\(.*\)=./# CONFIG_ATM\1 is not set/" \ -e "s/CONFIG_SMP\(.*\)=./# CONFIG_SMP\1 is not set/" \ + -e "s/CONFIG_SOUND_\(.*\)=./# CONFIG_SOUND_\1 is not set/" \ -e "s/CONFIG_PCI_NAMES\(.*\)=./# CONFIG_PCI_NAMES\1 is not set/" \ -e "s/CONFIG_INPUT_JOYDEV\(.*\)=./# CONFIG_INPUT_JOYDEV\1 is not set/" \ - -e "s/CONFIG_ACPI\(.*\)=./# CONFIG_ACPI\1 is not set/" \ -e "s/CONFIG_GAMEPORT\(.*\)=./# CONFIG_GAMEPORT\1 is not set/" \ -e "s/CONFIG_IP_NF\(.*\)=./CONFIG_IP_NF\1=m/" \ - -e "s/# CONFIG_EMBEDDED is not set/CONFIG_EMBEDDED=y/" \ -e "s/CONFIG_KALLSYMS=./# CONFIG_KALLSYMS is not set/" \ -e "s/CONFIG_IOSCHED_AS=./# CONFIG_IOSCHED_AS is not set/" \ - $1 > .config.boot + $1 > .config.livecd -mv .config.boot $1 +mv .config.livecd $1 diff --git a/target/livecd/linuxrc.c b/target/livecd/linuxrc.c index f5014624b..a48c16c94 100644 --- a/target/livecd/linuxrc.c +++ b/target/livecd/linuxrc.c @@ -41,21 +41,39 @@ #include #include #include - -#ifndef MS_MOVE -# define MS_MOVE 8192 -#endif +#include +/* this is actually a file included in dietlibc! */ +#include #ifndef STAGE_2_IMAGE # define STAGE_2_IMAGE "2nd_stage.img.z" #endif +#define DEBUG(F...) debug(__LINE__,F) + char mod_loader[50]; char mod_dir[255]; char mod_suffix[3]; int mod_suffix_len=0; +int do_debug=0; + +void debug(int line, const char* format, ...) +{ + if(do_debug == 0) return; + + va_list ap; + char string[128]; + + va_start(ap, format); + vsnprintf(string, sizeof(string), format, ap); + fprintf(stderr,"%i: %s\n", line, string); + va_end(ap); -void mod_load_info(char *mod_loader, char *mod_dir, char *mod_suffix) { + return; +} + +void mod_load_info(char *mod_loader, char *mod_dir, char *mod_suffix) +{ struct utsname uts_name; if(uname(&uts_name) < 0) { @@ -80,21 +98,68 @@ void mod_load_info(char *mod_loader, char *mod_dir, char *mod_suffix) { return; } +int loop_mount(const char *device, const char* file) +{ + DEBUG("loop mounting %s on %s", device, file); + struct loop_info loopinfo; + int fd, ffd; + + if ((ffd = open(file, O_RDONLY)) < 0) { + perror(file); + return 1; + } + if ((fd = open(device, O_RDONLY)) < 0) { + perror(device); + return 1; + } + + memset(&loopinfo, 0, sizeof(loopinfo)); + snprintf(loopinfo.lo_name, LO_NAME_SIZE, "%s", file); + + loopinfo.lo_offset = 0; + loopinfo.lo_encrypt_key_size = 0; + loopinfo.lo_encrypt_type = LO_CRYPT_NONE; + + if (ioctl(fd, LOOP_SET_FD, ffd) < 0) { + perror("ioctl: LOOP_SET_FD"); + return 1; + } + close(ffd); + + if(ioctl(fd, LOOP_SET_STATUS, &loopinfo) < 0) { + perror("ioctl: LOOP_SET_STATUS"); + (void) ioctl(fd, LOOP_CLR_FD, 0); + close(fd); + return 1; + } + close(fd); + + DEBUG("loop mount worked like a charm."); + return 0; +} + void doboot() { + DEBUG("doboot starting..."); if ( access("/sbin/init", R_OK) ) { perror("Can't find /sbin/init"); } else { - execlp("/sbin/init","/sbin/init"); + /* not sure why, but i get 'bad address' if i don't wait a bit here... */ + sleep(1); + execlp("/sbin/init","init"); + perror("execlp /sbin/init failed"); } + DEBUG("doboot returning - bad!"); } int trymount (const char* source, const char* target) { - return mount(source, target, "iso9660", MS_RDONLY, NULL) && - mount(source, target, "ext3", MS_RDONLY, NULL) && - mount(source, target, "ext2", MS_RDONLY, NULL) && - mount(source, target, "minix", MS_RDONLY, NULL) && - mount(source, target, "vfat", MS_RDONLY, NULL); + DEBUG("trying to mount %s on %s...", source, target); + if(mount(source, target, "iso9660", MS_RDONLY, NULL) != 0) { + DEBUG("try failed"); + return 1; + } + DEBUG("mount succeeded."); + return 0; } void trywait(pid) @@ -103,27 +168,17 @@ void trywait(pid) else waitpid(pid, NULL, 0); } -#define tryexeclp(file, arg, ...) ( { \ - int pid; \ -\ - if ( (pid = fork()) == 0 ) { \ - execlp(file, arg, __VA_ARGS__); \ - perror(file); \ - exit(1); \ - } \ -\ - trywait(pid); \ -} ) - /* check wether a file is a directory */ -int is_dir(const struct dirent *entry) { +int is_dir(const struct dirent *entry) +{ struct stat tmpstat; lstat(entry->d_name, &tmpstat); return S_ISDIR(tmpstat.st_mode); } /* this is used in the module loading system for sorting dirs before files */ -int dirs_first_sort(const struct dirent **a, const struct dirent **b) { +int dirs_first_sort(const struct dirent **a, const struct dirent **b) +{ if(is_dir(*a)) { if(is_dir(*b)) return 0; else return 1; @@ -133,14 +188,16 @@ int dirs_first_sort(const struct dirent **a, const struct dirent **b) { } /* this is used in the rm -r implementation */ -int no_dot_dirs_filter(const struct dirent *entry) { +int no_dot_dirs_filter(const struct dirent *entry) +{ if( is_dir(entry) && (!strcmp(entry->d_name,".") || !strcmp(entry->d_name,"..")) ) return 0; else return 1; } /* my own rm -r implementation - :P */ -int rm_recursive(char* directory) { +int rm_recursive(char* directory) +{ struct dirent **namelist; char oldcwd[256]; int n, ret=0; @@ -181,7 +238,8 @@ int rm_recursive(char* directory) { } /* symlink most files in /etc */ -int make_etc_symlinks() { +int make_etc_symlinks() +{ struct dirent **namelist; char source[256], target[256], oldcwd[100]; int n, ret=0; @@ -198,7 +256,9 @@ int make_etc_symlinks() { snprintf(source, 256, "/ROCK/etc/%s",namelist[n]->d_name); snprintf(target, 256, "/etc/%s",namelist[n]->d_name); - if (symlink(source, target) != 0) { + if (access(target, R_OK) == 0) { + printf("shyly skipping symlink for %s - already exists!\n", target); + } else if (symlink(source, target) != 0) { printf("error in symlinking %s -> %s\n",source,target); ret = -1; } @@ -222,25 +282,37 @@ int getdevice(char* devstr, int devlen) for (tmp_nr = 0; tmp_nr < 10; ++tmp_nr) { snprintf(devicefile, 100, devicebase, tmp_nr); + DEBUG("checking if %s is still a valid device", devicefile); - if ( access (devicefile, R_OK) ) break; + if ( access (devicefile, R_OK) ) { + DEBUG("%s first unvalid device, break search", devicefile); + break; + } else { + DEBUG("%s still valid",devicefile); + } devn[nr++] = strdup (devicefile); } if (!nr) { printf("could not find a suitable cdrom device!\n"); - return -1; + return -2; } devn[nr] = NULL; snprintf(filename,100,"/mnt/cdrom/%s",STAGE_2_IMAGE); + DEBUG("looking for %s on valid devices",STAGE_2_IMAGE); for (nr=0; devn[nr]; nr++) { - if(trymount(devn[nr],"/mnt/cdrom") == 0) { - if( access(filename, R_OK) ) continue; + if(trymount(devn[nr], "/mnt/cdrom") == 0) { + if( access(filename, R_OK) ) { + DEBUG("mounted %s, but could not access %s! continuing\n", devn[nr], filename); + if(umount("/mnt/cdrom") != 0) { perror("umount wrong cdrom failed"); break; } + continue; + } strncpy(devstr, devn[nr], devlen); + DEBUG("found 2nd stage image on %s", devstr); return 0; } } @@ -255,34 +327,42 @@ int prepare_root() { /* we need to set umask to 00 so we can set 777 perms */ umask(00); + DEBUG("symlinking /bin, /sbin, /boot, /opt"); /* simple symlinking */ if(symlink("/ROCK/bin","/bin") != 0) { perror("/bin symlink FAILED"); ret=-1; } if(symlink("/ROCK/sbin","/sbin") != 0) { perror("/sbin symlink FAILED"); ret=-1; } if(symlink("/ROCK/boot","/boot") != 0) { perror("/boot symlink FAILED"); ret=-1; } if(symlink("/ROCK/opt","/opt") != 0) { perror("/opt symlink FAILED"); ret=-1; } + DEBUG("creating /tmp"); /* if /tmp isn't empty, this is gonna blow... */ if(rmdir("/tmp") != 0) { perror("unable to remove old /tmp"); ret=-1; } if(mkdir("/ramdisk/tmp", 0777) != 0) { perror("unable to create /ramdisk/tmp"); ret=-1; } if(symlink("/ramdisk/tmp", "/tmp") != 0) { perror("/tmp symlink FAILED"); ret=-1; } + DEBUG("creating /home"); if(mkdir("/ramdisk/home", 0755) != 0) { perror("unable to create /ramdisk/home"); ret=-1; } if(symlink("/ramdisk/home", "/home") != 0) { perror("/home symlink FAILED"); ret=-1; } + DEBUG("symlinking /usr"); /* usr is just a symlink to / , that's why it works */ if(unlink("/usr") != 0) { perror("unable to remove old /usr"); ret=-1; } if(symlink("/ROCK/usr","/usr") != 0) { perror("/usr symlink FAILED"); ret=-1; } - + + DEBUG("symlinking /var"); if(mkdir("/ramdisk/var", 0755) != 0) { perror("unable to create /ramdisk/var"); ret=-1; } if(symlink("/ramdisk/var", "/var") != 0) { perror("/var symlink FAILED"); ret=-1; } + DEBUG("removing and symlinking /lib"); if(rm_recursive("/lib") != 0) { printf("removal of /lib FAILED\n"); ret=-1; } if(symlink("/ROCK/lib", "/lib") != 0) { perror("/lib symlink FAILED"); ret=-1; } + DEBUG("removing /sbin-static and /bin-static"); if(unlink("/sbin-static") != 0) { perror("error removing /sbin-static"); ret=-1; } if(rm_recursive("/bin-static") != 0) { printf("removal of /bin-static FAILED\n"); ret=-1; } fflush(stdout); + DEBUG("preparing /etc"); /* the /etc directory is a bit special */ if(make_etc_symlinks() != 0) { printf("error while symlinking individual files in /etc!\n"); ret=-1; } /* remove some files that either need to be writable or need to be replaced */ @@ -300,6 +380,7 @@ int prepare_root() { FILE* mod = fopen("/etc/mtab","w"); char buf[256]; + DEBUG("modifying /etc/mtab"); while(fgets(buf, 256, orig) != NULL) { if(memcmp(buf,"rootfs",6) == 0) continue; else fputs(buf, mod); @@ -307,6 +388,7 @@ int prepare_root() { fclose(orig); fclose(mod); buf[1]=0; /* add rocker to /etc/passwd and change root's home to /home/root */ + DEBUG("modifying /etc/passwd"); orig = fopen("/ROCK/etc/passwd","r"); mod = fopen("/etc/passwd","w"); while(fgets(buf, 256, orig) != NULL) { @@ -318,6 +400,7 @@ int prepare_root() { /* add rocker to /etc/shadow */ umask(066); + DEBUG("modifying /etc/shadow"); orig = fopen("/ROCK/etc/shadow","r"); mod = fopen("/etc/shadow","w"); while(fgets(buf, 256, orig) != NULL) { @@ -330,6 +413,7 @@ int prepare_root() { /* add rocker to group 'sound' */ int fnd = 0; umask(022); + DEBUG("modifying /etc/group"); orig = fopen("/ROCK/etc/group","r"); mod = fopen("/etc/group","w"); while(fgets(buf, 256, orig) != NULL) { @@ -343,12 +427,14 @@ int prepare_root() { fclose(orig); fclose(mod); buf[1]=0; /* copy over XF86Config */ + DEBUG("modifying /etc/X11/XF86Config"); orig = fopen("/ROCK/etc/X11/XF86Config","r"); mod = fopen("/etc/X11/XF86Config","w"); while(fgets(buf, 256, orig) != NULL) fputs(buf, mod); fclose(orig); fclose(mod); buf[1]=0; /* copy over resolv.conf */ + DEBUG("modifying /etc/resolv.conf"); unlink("/etc/resolv.conf"); orig = fopen("/ROCK/etc/resolv.conf","r"); mod = fopen("/etc/resolv.conf","w"); @@ -356,6 +442,7 @@ int prepare_root() { fclose(orig); fclose(mod); buf[1]=0; /* change modules.conf to place it's modules.dep in /etc */ + DEBUG("modifying /etc/modules.conf"); unlink("/etc/modules.conf"); orig = fopen("/ROCK/etc/modules.conf","r"); mod = fopen("/etc/modules.conf","w"); @@ -372,6 +459,7 @@ int prepare_root() { umask(00); /* we need to fix some things in /dev */ + DEBUG("preparing /dev"); if(chdir("/dev") != 0) { perror("could not chdir to /dev!"); ret=-1; } unlink("fd"); /*no problem if this fails*/ if(symlink("/proc/kcore","core") != 0) { perror("could not symlink /proc/kcore to /dev/core"); ret=-1; } @@ -382,13 +470,17 @@ int prepare_root() { if(chdir("/") != 0) { perror("could not chdir to /!"); ret=-1; } /* create needed directories in /var */ + DEBUG("preparing /var"); if(mkdir("/var/run",0755) != 0 ) { perror("could not create /var/run"); ret=-1; } if(mkdir("/var/lock",0755) != 0 ) { perror("could not create /var/lock"); ret=-1; } if(mkdir("/var/tmp",0777) != 0 ) { perror("could not create /var/tmp"); ret=-1; } if(mkdir("/var/log",0755) != 0 ) { perror("could not create /var/log"); ret=-1; } if(mkdir("/var/lib",0755) != 0 ) { perror("could not create /var/lib"); ret=-1; } if(mkdir("/var/lib/xkb",0755) != 0 ) { perror("could not create /var/lib/xkb"); ret=-1; } - if(symlink("/var/lib/xkb","/etc/X11/xkb/compiled")!=0) { perror("could not symlink /var/lib/xkb to /etc/X11/xkb/compiled"); ret=-1; } + if(symlink("/var/lib/xkb","/etc/X11/xkb/compiled")!=0) + { perror("could not symlink /var/lib/xkb to /etc/X11/xkb/compiled"); ret=-1; } + if(mkdir("/var/state",0755) != 0 ) { perror("could not create /var/state"); ret=-1; } + if(mkdir("/var/state/dhcp",0755) != 0 ) { perror("could not create /var/state/dhcp"); ret=-1; } if(mkdir("/var/rockplug",0755) != 0 ) { perror("could not create /var/rockplug"); ret=-1; } if(mkdir("/var/rockplug/ieee1394",0755) != 0 ) { perror("could not create /var/rockplug/ieee1394"); ret=-1; } if(mkdir("/var/rockplug/isapnp",0755) != 0 ) { perror("could not create /var/rockplug/isapnp"); ret=-1; } @@ -396,7 +488,9 @@ int prepare_root() { if(mkdir("/var/rockplug/pci",0755) != 0 ) { perror("could not create /var/rockplug/pci"); ret=-1; } if(mkdir("/var/rockplug/scsi",0755) != 0 ) { perror("could not create /var/rockplug/scsi"); ret=-1; } if(mkdir("/var/rockplug/usb",0755) != 0 ) { perror("could not create /var/rockplug/usb"); ret=-1; } + /* add rocker's home, change owner */ + DEBUG("creating homes"); if(mkdir("/home/rocker",0755) != 0 ) { perror("could not create /home/rocker"); ret=-1; } if(chown("/home/rocker",1000,100) != 0) { perror("could not chown /home/rocker to rocker:users"); ret=-1; } /* root's home */ @@ -409,28 +503,38 @@ int prepare_root() { void load_ramdisk_file() { char text[120], devicefile[100]; char filename[100]; - int pid; + int ret = 0; strcpy(filename, STAGE_2_IMAGE); - - if (getdevice(devicefile, 100) < 0) - return; + DEBUG("set stage 2 filename to %s",filename); - snprintf(text, 120, "file=/mnt/cdrom/%s", filename); - if ( (pid = fork()) == 0 ) { - printf("loading cloop..."); - execlp(mod_loader, mod_loader, "/lib/modules/misc/cloop.o", text); - perror("can't insmod cloop from"); - exit(1); + ret = getdevice(devicefile, 100); + if (ret == -1) { + DEBUG("getdevice failed: no cd with image found..."); + return; + /* this is needed for my firewire (sbp2) cd drive ... */ + } else if (ret == -2) { + DEBUG("getdevice failed - no cdrom drive?! - sleeping and retrying..."); + sleep(2); + if(getdevice(devicefile, 100) != 0) { + DEBUG("second try still did no good. giving up..."); + return; + } } - trywait(pid); + + snprintf(text, 120, "/mnt/cdrom/%s", filename); - if( access("/dev/cloop/0", R_OK) ) - { perror("can't access /dev/cloop/0, check if cloop insmod was succesfull!"); return; } + DEBUG("setting up loop device..."); + if(loop_mount("/dev/loop/0",text) != 0) { + DEBUG("loop device setup failed ... :("); + return; + } - if( mount("/dev/cloop/0", "/ROCK", "iso9660", MS_RDONLY, NULL) ) - { perror("Can't mount /dev/cloop/0 on /ROCK!"); return; } + DEBUG("mounting loop device on /ROCK ... "); + if( mount("/dev/loop/0", "/ROCK", "squashfs", MS_RDONLY, NULL) ) + { perror("Can't mount squashfs on /ROCK!"); return; } + DEBUG("mounting tmpfs on /ramdisk"); if ( mount("none", "/ramdisk", "tmpfs", 0, NULL) ) { perror("Can't mount /ramdisk"); return; } @@ -444,6 +548,7 @@ void load_ramdisk_file() { void autoload_modules() { + DEBUG("autoload modules starting"); char line[200], cmd[200], module[200]; int fd[2], rc; FILE *f; @@ -490,8 +595,18 @@ void exec_sh() trywait(rc); } -int main() +int main(int argc, char** argv) { + int args; + + if (argc > 1) { + do_debug = 1; + DEBUG("got an argument, switching debug mode on!"); + for(args=1; args $archdir/squashfs2.0.patch +} + +hook_add prepatch 1 extract_squashfspatch +var_append patchfiles " " "$archdir/squashfs2.0.patch"