Find the answer to your Linux question:
Results 1 to 2 of 2
Its nice to see a linux community thats not a list server OK - about 40 hours later - I cannot fix this last piece of my custom linuxrc for ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    May 2006
    Posts
    3

    Custom initrd & linuxrc console issue


    Its nice to see a linux community thats not a list server

    OK - about 40 hours later - I cannot fix this last piece of my custom linuxrc for my custom initrd. BTW - this for an embedded x86 project thats going to boot from a flash drive but during the prototyping I am want to gen a boot CD. So the the current target is bootable LiveCD.

    My custom kernel executes, my initrd mounts, my squashfs mounts, and my linuxrc script executes - until I get to the very end...

    Here is the script:

    Code:
    # mount proc to be able to use /proc/filesystems
     
    mount /proc 
    
    # Stage 1 filesystem 
    # ==================
    #
    # Minimal initrd filesystem with /dev initialized for std , console and hd{a-d}
    # Mount -t devfs devfs /dev shows the cdroms in /dev/cdroms
    echo "**** remounting root"
    mount -o remount,rw /
     
     
    # Stage 2 filesystem
    # ==================
    #
    # A new ramdisk with some stuff copied in, other stuff symlinked from a 
    # loop mounted image on the cdrom.
     
    echo "**** creating stage2"
    mkdir -p /mnt/stage2
    mount -t tmpfs tmpfs /mnt/stage2
     
    mkdir /mnt/stage2/dev \
          /mnt/stage2/mnt \
          /mnt/stage2/mnt/cdrom \
          /mnt/stage2/mnt/livecd \
          /mnt/stage2/tmp \
          /mnt/stage2/tmp/.initrd \
          /mnt/stage2/proc \
          /mnt/stage2/sys
     
     
    # mount the cdrom inside stage2
    
    echo "**** copying initrd devices"
    cp -Rap /dev/* /mnt/stage2/dev
     
    echo "**** mounting cd"
    cp -Rap /dev/hdc /mnt/stage2/dev
    mount -t iso9660 -o ro /mnt/stage2/dev/hdc /mnt/stage2/mnt/cdrom
     
    # mount the image on the cdrom - TODO: use stage2 /dev
    
    echo "**** mounting /dev" 
    mount -o bind /mnt/stage2/dev /dev
    echo "**** mounting squashfs" 
    mount -t squashfs -o loop,ro /mnt/stage2/mnt/cdrom/livecd.squashfs /mnt/stage2/mnt/livecd
    umount /dev
     
    # fill stage2 with symlinks to the loop mounted image
     
    cd /mnt/stage2
    
    echo "**** mounting creating links" 
     
    for x in ${ROOT_LINKS}
    do
        ln -s "mnt/livecd/${x}" "${x}"
    done
     
    # fill stage2 with data copied from the loop mounted image
    
    echo "**** mounting creating links" 
     
    cd /mnt/stage2/mnt/livecd
    cp -a ${ROOT_TREES} /mnt/stage2
     
    mkdir -p /mnt/stage2/home
     
    # make sure permissions are ok
    
    echo "**** chmod-ing /tmp" 
    
    cd /mnt/stage2
    chmod 1777 tmp
     
    echo "**** unmounting /proc" 
    umount /proc 2>/dev/null
     
    # switch / from stage1 to stage2
     
    echo "**** pivot_root" 
    pivot_root . tmp/.initrd
    
    mount -t sysfs /sys /sys
    
    echo "**** console redirect" 
    exec dev/console 2>&1
    exec chroot . /bin/ash <<- EOF
        exec /sbin/init
    EOF
     
    echo "**** exec /bin/ash" 
    exec /bin/ash

    The error I get is

    /linuxrc: dev/console: Permission denied
    kernel panic - not syncing:Attempted to kill init!


    This is the line its yacking on:
    exec dev/console 2>&1


    Thanks in advance for any help...

  2. #2
    Just Joined!
    Join Date
    May 2006
    Posts
    3
    Well after reading the pivot_root man page closer, I came across:

    Note that exec chroot changes the running executable, which is necessary if the old root directory should be unmounted afterwards. Also note that standard input, output, and error may still point to a device on the old root file system, keeping it busy. They can easily be changed when invoking chroot (see below; note the absence of leading slashes to make it work whether pivot_root has changed the shell's root or not).
    This lead me to think that the /dev/console might be locked with the current shell?

    So I a changed

    Code:
    exec dev/console 2>&1 
    exec chroot . /bin/ash <<- EOF 
        exec /sbin/init 
    EOF
    to

    Code:
    exec chroot . sh <<- EOF 
       <dev/console >dev/console 2>&1 
       exec /sbin/init 
    EOF
    This changes the the stdin, stdout & stderr during the exec of chroot instead of before hand...

    I hope this helps anyone with similar issues - or my assumptions here are wrong please let me know!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •