Find the answer to your Linux question:
Results 1 to 6 of 6
Hi, I'm hacking some code in the kernel, and want to pass in a custom parameter to the kernel (either at boot time, or after startup), which my new code ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Jul 2006
    Posts
    12

    Passing a custom parameter to the kernel


    Hi,

    I'm hacking some code in the kernel, and want to pass in a custom parameter
    to the kernel (either at boot time, or after startup), which my new code will
    use. This parameter is a number, ranging from 40 to 800, for example.

    The existing boot command line parameters do not allow the use of a user
    defined custom parameter to be passed in to the kernel. Is there a way to
    do this, either during or after boot?

    Thanks,
    John

  2. #2
    Linux Enthusiast
    Join Date
    Apr 2004
    Location
    UK
    Posts
    682
    I am certain is is possible to pass anything you like as a parameter to the kernel, but I think it depends on which boot loader you use.

    Do you use grub, lilo or something else entirely? If you are not certain then tell us which distribution you use and we should be able to look it up.

    Chris...
    To be good, you must first be bad. "Newbie" is a rank, not a slight.

  3. #3
    Just Joined!
    Join Date
    Jul 2006
    Posts
    12
    Quote Originally Posted by kakariko81280 View Post
    I am certain is is possible to pass anything you like as a parameter to the kernel, but I think it depends on which boot loader you use.

    Do you use grub, lilo or something else entirely? If you are not certain then tell us which distribution you use and we should be able to look it up.

    Chris...

    I'm using grub with Fedora core 7.

  4. $spacer_open
    $spacer_close
  5. #4
    Linux Enthusiast
    Join Date
    Apr 2004
    Location
    UK
    Posts
    682
    You need to edit the menu.lst file. From examples on this site:

    Code:
    title Linux
        root (hd0,1)
        kernel /boot/summer-usb ro root=/dev/hda2 hdc=ide-scsi
    You should be able to add your parameters to the end of the kernel line as it exists in your version of this file and have them passed to the kernel on boot.

    Let us know how you get on,

    Chris...
    To be good, you must first be bad. "Newbie" is a rank, not a slight.

  6. #5
    Just Joined!
    Join Date
    Jul 2006
    Posts
    12
    Thanks, kakariko81280

    In this case, I'd have to hack init.c, parse/collect my parameter from
    /proc/cmdline, and set a global variable that my new code (located in
    mm/memory.c) could use. I was going to try this, but am also interested
    in passing in the parameter after kernel nitilaization is completed, if that
    is possible.

    John

  7. #6
    Linux Enthusiast
    Join Date
    Apr 2004
    Location
    UK
    Posts
    682
    There are ways to pass data to and from the kernel, but I'm not a kernel hacker so my advice is going to be limited.

    I have been told that netlink is a decent method of passing data in and out of the kernel, or since it is a single value you plan on working with, you could look at creating an entry in the procfs filesystem, but I'm afraid I don't know the first thing about doing either of these things.

    The bonus with these methods would be that you can change them as much as you want without needing to reboot your computer.

    Let us know how you get on,

    Chris...
    To be good, you must first be bad. "Newbie" is a rank, not a slight.

Posting Permissions

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