Find the answer to your Linux question:
Results 1 to 1 of 1
Yes, it is possible. It's no real deep secret, and it doesn't require long nights of coding, and only a couple of line edits in a single file to pull ...
  1. #1
    Linux Newbie
    Join Date
    Apr 2005
    Location
    CT --> PA
    Posts
    170

    Colorizing the Debian boot process

    Yes, it is possible.

    It's no real deep secret, and it doesn't require long nights of coding, and only a couple of line edits in a single file to pull off what several Debian-derivatives have been doing for several coding generations. It's not a finished project, and it's only a recently-started play-thing of mine, but with about 20 minutes of work, a basic user of Debian can accomplish this task.

    A quick breakdown of the systems I have successfully performed this on

    • Debian > 6.0 (testing is my preferred flavor)
      grub2
      linux kernel 2.6.39-2-amd64
      lsb-base => 3.2-27
      a successfully configured framebuffer (running @ 1280x800x32) - will run at 640x480 with screen fonts, just looks chunky
      color monitor (yes. it's obligatory I mentioned it)



    I started this on an install that was running a default video configuration (VGA console), and that the specifics I listed are NOT scripture, and that older versions will likely be able to perform the modification - just with a little bit of work.

    Synopsis
    Thanks to Chris Lawrence, for a well documented init-functions file, which only requires some basic modification to enable colorized screen output, for those who require it. Functionally, init-functions is what controls how Debian outputs initiation functions to the user, via the video subsystem, and utilizes /bin/echo (predominantly) to relay information to the user. With several simple changes to the init-functions file, the user (with appropriately secured su credentials) can control how output is relayed.

    Some light homework
    I would recommend some studying prior to undertaking any modification of a system file, for knowledge purposes. If you BORK YOUR SYSTEM by jumping in haphazardly, and rendering your system unusable due to sloppy work, and not saving backups of files, it's YOUR FAULT. If you break your system, I accept no responsibility, and cannot be held liable for damages sustained, data loss, or significant other leaving you. You have been warned.


    • google "ANSI escape codes"
      read documentation on grub2 (or grub) if you want a prettier, higher resolution screen for boot (i am not even going into LILO)



    Code:
    man echo
    This would be the most important one, as /bin/echo is what relays everything that init-functions parses, and will have what data is passed to it, changed.

    The modifications of init-functions

    Place your self in the directory
    Code:
    cd /lib/lsb
    Back up your work. You have been warned. This is also required due to the two subsequent commands.
    Code:
    sudo cp -a init-functions init-functions.original
    Warning, i'm a sym-linker. Creature of habit. We are eliminating the original file, and sym-linking the edited file to it, so if your lsb-base package is updated, you will not lose your work.
    Code:
    sudo rm -rf init-functions
    Create a symbolic link from the original file, so as to maintain system operation - we will be changing this after the mod is done. If you re-boot (for any reason), this step keeps you up and running.
    Code:
    sudo ln -s init-functions.original init-functions
    Create the file to be modified, so you are not diddling with the only copy on your system.
    Code:
    cp -a init-functions init-functions.modified
    All of this should be self-explanatory. If you are not comfortable with these steps, do not continue.

    I'm also a pico user. No judgment please. Open the file with your editor of choice.
    Code:
    sudo pico init.functions.modified
    Find the section of init-functions that reads (on 3.2-27 it's the first part after the commented section by Chris)
    Code:
    start_daemon () {
    and you are going to add these ANSI escape declarations of colors you will be using before them. Change the names if you see fit, just remember to change the usages globally, or you will get undesired results.
    Code:
        RED='\033[1;31m'
        GREEN='\033[1;32m'
        YELLOW='\033[1;33m'
        BLUE='\033[1;34m'
        DMAGENTA='\033[0;35m'
        MAGENTA='\033[1;35m'
        CYAN='\033[1;36m'
        WHITE='\033[1;37m'
        NORMAL='\033[0;37m'
        DARKGREY='\033[1;30m'
    around line 260, find the section with the following
    Code:
    # int log_begin_message (char *message)
    log_begin_msg () {
        if [ -z "${1:-}" ]; then
            return 1
        fi
       /bin/echo -n "$@"
    }
    Modify the code to reflect these changes
    Code:
     
    #    /bin/echo -n "$@"
         /bin/echo -ne "${DARKGREY}$@${NORMAL}"
    Comment out the initial /bin/echo line, and add the newer line below it. Pay particular attention to the new flags we are passing to /bin/echo. This will subdue a majority of the standard white boot messages, to a darker grey.

    Around line 280, find the section with the following
    Code:
    og_daemon_msg () {
        if [ -z "${1:-}" ]; then
            return 1
        fi
        log_daemon_msg_pre "$@"
    
        if [ -z "${2:-}" ]; then
            /bin/echo -n "$1:"
            return
        fi
    
           /bin/echo -e "$1: $2"
        log_daemon_msg_post "$@"
    }
    And you will comment out both of the /bin/echo lines again, and replace them with the lines I added below. The differences should be obvious.
    Code:
    #       /bin/echo -n "$1:"
            /bin/echo -ne "${DARKGREY}$1:${NORMAL}"
            return
        fi
    
    #       /bin/echo -e "$1: $2"
           /bin/echo -ne "${DARKGREY}$1: ${CYAN}$2${NORMAL}"
    Find the section with the following
    Code:
    log_progress_msg () {
        if [ -z "${1:-}" ]; then
            return 1
        fi
       /bin/echo -n " $@"
    }
    ...and modify it, just like before, with the following modified lines.
    Code:
    #   /bin/echo -n " $@"
        /bin/echo -ne "${YELLOW} $@${NORMAL}"
    find the section with the following
    Code:
    log_end_msg () {
        # If no arguments were passed, return
        if [ -z "${1:-}" ]; then
            return 1
        fi
    
        local retval
        retval=$1
    
        log_end_msg_pre "$@"
    
        # Only do the fancy stuff if we have an appropriate terminal
        # and if /usr is already mounted
        if log_use_fancy_output; then
            RED=$( $TPUT setaf 1)
            YELLOW=$( $TPUT setaf 3)
            NORMAL=$( $TPUT op)
        else
            else
            RED=''
            YELLOW=''
            NORMAL=''
        fi
    
        if [ $1 -eq 0 ]; then
    
         echo "."
        elif [ $1 -eq 255 ]; then
            /bin/echo -e " ${YELLOW}(warning).${NORMAL}"
        else
            /bin/echo -e " ${RED}failed!${NORMAL}"
        fi
        log_end_msg_post "$@"
        return $retval
    }
    and modify it like so...
    Code:
    #        echo "."
            /bin/echo -e " ${GREEN}ok.${NORMAL}"
    find the section with the following
    Code:
    log_action_msg () {
        echo "$@."
    }
    and modify it to reflect
    Code:
    log_action_msg () {
    #    echo "$@."
            /bin/echo -e "${BLUE}$@.${NORMAL}"
    }
    find the section with the following
    Code:
    log_action_begin_msg () {
        /bin/echo -n "$@..."
    }
    and modify it to reflect
    Code:
    log_action_begin_msg () {
    #    /bin/echo -n "$@..."
            /bin/echo -ne "${DMAGENTA}$@...${NORMAL}"
    }
    the final section to find is
    Code:
    log_action_end_msg () {
        local end
        log_action_end_msg_pre "$@"
        if [ -z "${2:-}" ]; then
            end="."
        else
            end=" ($2)."
        fi
    
        if [ $1 -eq 0 ]; then
    
            echo "done${end}"
        else
            if log_use_fancy_output; then
                RED=$( $TPUT setaf 1)
                NORMAL=$( $TPUT op)
                /bin/echo -e "${RED}failed${end}${NORMAL}"
            else
                echo "failed${end}"
            fi
        fi
        log_action_end_msg_post "$@"
    }
    to be modified to reflect
    Code:
    log_action_end_msg () {
        local end
        log_action_end_msg_pre "$@"
        if [ -z "${2:-}" ]; then
            end="."
        else
            end=" ($2)."
        fi
    
        if [ $1 -eq 0 ]; then
    
    #        echo "done${end}"
            /bin/echo -e "${GREEN}done${end}${NORMAL}"
        else
            if log_use_fancy_output; then
                RED=$( $TPUT setaf 1)
                NORMAL=$( $TPUT op)
                /bin/echo -e "${RED}failed${end}${NORMAL}"
            else
                echo "failed${end}"
            fi
        fi
        log_action_end_msg_post "$@"
    }
    These were the modifications I made to my init-functions that gave me a colorized boot process, similar to Knoppix (but without the flashiness) that made it a little easier to find errors, as they mounted.

    In order to make these changes effective, save the file, and eliminate the sym-link, and recreate the symlink to the new file, and then reboot.

    Code:
    sudo rm -f init-functions
    sudo ln -s init-functions.modified init-functions
    sudo shutdown -r now
    Conclusion
    As you will see, all we had to do was to modify what /bin/echo was passed, in about 5 different areas, and we had a vastly different result. If you make some simple character modifications, a user can make errors blink, change intensities, or change how things are formatted on the screen. With some work, a novice user with good reading skills can accomplish far more than was done here, with a minimal amount of stress.

    Disclaimer, again
    If your system does not work, it's your fault. You decided to make these changes. Don't blame me. Single-user mode, and some quick commands regarding the sym-link can recover you to base, should you need to. . I might have made some mistakes in moving my notes from my system, to this post. I will correct the post as I find mistakes, or as I figure out more functionality.

    Comments, questions, concerns?

    (this is a cross post from the Debian User Forums - i'll try to keep them both up to date)

    Please remember, this is not authoritative, feel free to hack away.
    Last edited by TheBigPhish; 11-02-2011 at 12:29 AM.
    Chicks dig giant mechanized war machines

Posting Permissions

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