{
    "mode": "man",
    "parameter": "initramfs-tools",
    "section": "7",
    "url": "https://www.chedong.com/phpMan.php/man/initramfs-tools/7/json",
    "generated": "2026-11-21T20:26:55Z",
    "sections": {
        "NAME": {
            "content": "initramfs-tools - an introduction to writing scripts for mkinitramfs\n\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "initramfs-tools  has  one main script and two different sets of subscripts which will be used\nduring different phases of execution. Each of these will be discussed separately  below  with\nthe  help  of  an  imaginary  tool  which performs a frobnication of a lvm partition prior to\nmounting the root partition.\n\n",
            "subsections": []
        },
        "Kernel Command Line": {
            "content": "The root filesystem used by the kernel is specified by the boot loader as always. The  tradi‐\ntional  root=/dev/sda1  style  device  specification  is  allowed.  If a label is used, as in\nroot=LABEL=rootPart the initrd will search all available devices for a  filesystem  with  the\nappropriate  label,  and mount that device as the root filesystem.  root=UUID=uuidnumber will\nmount the partition with that UUID as the root filesystem.\n\n",
            "subsections": [
                {
                    "name": "Standard",
                    "content": "init= \"<path to real init>\"\nthe binary to hand over execution to on the root fs after the  initramfs  scripts  are\ndone.\n\n\ninitramfs.clear\nclear screen at the beginning\n\n\ninitramfs.runsize\nThe  size  of  the /run tmpfs mount point in bytes (suffixes are supported) or as per‐\ncentage of your physical RAM. This parameter is used as the value of  the  size  mount\noption  to  tmpfs.  See https://www.kernel.org/doc/Documentation/filesystems/tmpfs.txt\nfor details. The default is 10%.\n\n\nroot= \"<path to blockdevice>\"\nthe device node to mount as the root file system.  The recommended usage is to specify\nthe UUID as followed \"root=UUID=xxx\".\n\n\nrootfstype\nset the root file system type.\n\n\nroottimeout\nset timeout in seconds. Determines how long mountroot waits for root to  appear.   The\ndefault is 30 seconds.\n\n\nrootdelay\nalias for roottimeout.\n\n\nrootflags\nset the file system mount option string.\n\n\nloop= \"<path to image>\"\npath  within the original root file system to loop-mount and use as the real root file\nsystem.\n\n\nloopfstype\nset the loop file system type, if applicable.\n\n\nloopflags\nset the loop file system mount option string, if applicable.\n\n\nnfsroot\ncan be either \"auto\" to try to get the relevant information from DHCP or a  string  of\nthe form NFSSERVER:NFSPATH or NFSSERVER:NFSPATH:NFSOPTS.  Use root=/dev/nfs for NFS to\nkick to in. NFSOPTS can be looked up in nfs(5).\n\n\nip    tells  how  to configure the ip address. Allows one to specify an different NFS server\nthan the DHCP server. See Documentation/filesystems/nfsroot.txt in  any  recent  Linux\nsource for details. Optional parameter for NFS root.\n\n\nvlan  tells  to  create  a  VLAN tagged device. Allows one to configure one or multiple VLAN\ntagged devices using the \"vlan=$name.$id:$parent\" syntax. E.g. \"vlan=eth0.1:eth0\"  Op‐\ntional parameter for NFS root.\n\n\nBOOTIF\nis  a  mac  address in pxelinux format with leading \"01-\" and \"-\" as separations.  px‐\nelinux passes mac address of network card used to PXE boot on with this bootarg.\n\n\nboot  either local or NFS (affects which initramfs scripts are run, see the \"Subdirectories\"\nsection under boot scripts).\n\n\nresume\nThe resume hook tries to autodetect the resume partition and uses the first swap  par‐\ntition  as  valid  guess. It is possible to set the RESUME variable in /etc/initramfs-\ntools/conf.d/resume.  The boot variable noresume overrides it.\n\n\nresumeoffset\nSpecify the offset from the partition given by \"resume=\" at which the swap  header  of\nthe swap file is located.\n\n\nquiet reduces the amount of text output to the console during boot.\n\n\nro    mounts the rootfs read-only.\n\n\nrw    mounts the rootfs read-write.\n\n\nblacklist\ndisables  load of specific modules.  Use blacklist=module1,module2,module3 bootparame‐\nter.\n\n"
                },
                {
                    "name": "Debug",
                    "content": "panic sets an timeout on panic.  panic=<sec> is a documented security feature:  it  disables\nthe debug shell.\n\n\ndebug generates  lots of output. It writes a log to /run/initramfs/initramfs.debug.  Instead\nwhen invoked with an arbitrary argument output is written to console.  Use for example\n\"debug=vc\".\n\n\nbreak spawns a shell in the initramfs image at the chosen  phase  (top,  modules,  premount,\nmount,  mountroot,  bottom,  init) before actually executing the corresponding scripts\n(see the \"Boot scripts\" section) or action.  Multiple phases may be specified,  delim‐\nited by commas.  The default, if no phase is specified, is \"premount\".  Beware that if\nboth  \"panic\"  and \"break\" are present, initramfs will not spawn any shells but reboot\ninstead.\n\n\nnetconsole\nloads netconsole linux modules with the chosen args.\n\n\nallgenericide\nloads generic IDE/ATA chipset support on boot.\n\n\n"
                }
            ]
        },
        "SCRIPTS": {
            "content": "Valid boot and hook scripts names consist solely of alphabetics, numerics, dashes and  under‐\nscores. Other scripts are discarded.\n\n",
            "subsections": [
                {
                    "name": "Configuration hook scripts",
                    "content": "These  are  used to override the user configuration where necessary, for example to force use\nof busybox instead of klibc utilities.\n\n"
                },
                {
                    "name": "Hook scripts",
                    "content": "These are used when an initramfs image is created and not included in the image itself.  They\ncan  however  cause  files  to be included in the image.  Hook scripts are executed under er‐\nrexit. Thus a hook script can abort the mkinitramfs build on possible errors (exitcode != 0).\n\n"
                },
                {
                    "name": "Boot scripts",
                    "content": "These are included in the initramfs image and normally executed during  kernel  boot  in  the\nearly user-space before the root partition has been mounted.\n\n\n"
                }
            ]
        },
        "CONFIGURATION HOOK SCRIPTS": {
            "content": "Configuration hook scripts can be found in /usr/share/initramfs-tools/conf-hooks.d.  They are\nsourced  by  mkinitramfs  after  the  configuration files in /etc and before running any hook\nscripts.  They can override any of the variables documented in  initramfs.conf(5),  but  this\nshould  be  done  only  if absolutely necessary.  For example, if a package's boot script re‐\nquires commands not provided by klibc-utils, it should also install a configuration hook that\nsets BUSYBOX=y.\n\n\n",
            "subsections": []
        },
        "HOOK SCRIPTS": {
            "content": "Hooks can be  found  in  two  places:  /usr/share/initramfs-tools/hooks  and  /etc/initramfs-\ntools/hooks.  They  are executed during generation of the initramfs-image and are responsible\nfor including all the necessary components in the image itself. No guarantees are made as  to\nthe  order  in  which  the different scripts are executed unless the prereqs are setup in the\nscript.  Please notice that PREREQ is only honored inside a single directory.  So  first  the\nscripts  in  /usr/share/initramfs-tools are ordered according to their PREREQ values and exe‐\ncuted. Then all scripts in /etc/initramfs-tools are ordered according to their PREREQ  values\nand  executed.  This  mean  that  currently  there  is  no possibility to have a local script\n(/etc/initramfs-tools) get executed before one from the package (/usr/share/initramfs-tools).\n\nIf a hook script requires configuration beyond the exported variables listed below, it should\nread a private configuration file that is separate from the  /etc/initramfs-tools  directory.\nIt must not read initramfs-tools configuration files directly.\n\n",
            "subsections": [
                {
                    "name": "Header",
                    "content": "In order to support prereqs, each script should begin with the following lines:\n\n#!/bin/sh\nPREREQ=\"\"\nprereqs()\n{\necho \"$PREREQ\"\n}\n\ncase $1 in\nprereqs)\nprereqs\nexit 0\n;;\nesac\n\n. /usr/share/initramfs-tools/hook-functions\n# Begin real processing below this line\n\nFor example, if you are writing a new hook script which relies on lvm, the line starting with\nPREREQ  should  be  changed to PREREQ=\"lvm\" which will ensure that the lvm hook script is run\nbefore your custom script.\n\n"
                },
                {
                    "name": "Help functions",
                    "content": "/usr/share/initramfs-tools/hook-functions contains a number of functions which deal with some\ncommon tasks in a hook script:\n\nmanualaddmodules adds a module  (and  any  modules  which  it  depends  on)  to  the\ninitramfs image.\n\nExample: manualaddmodules isofs\n\n\naddmodulesfromfile  reads  a file containing a list of modules (one per line) to be\nadded to the initramfs image. The file can contain comments (lines  starting  with  #)\nand  arguments to the modules by writing the arguments on the same line as the name of\nthe module.\n\nExample: addmodulesfromfile /tmp/modlist\n\n\nforceload adds a module (and its dependencies) to the initramfs image and also uncon‐\nditionally loads the module during boot. Also supports passing arguments to the module\nby listing them after the module name.\n\nExample: forceload cdrom debug=1\n\n\ncopymodulesdir copies an entire module  directory  from  /lib/modules/KERNELVERSION/\ninto the initramfs image.\n\nExample: copymodulesdir kernel/drivers/ata\n\n"
                },
                {
                    "name": "Including binaries",
                    "content": "If  you  need  to copy an executable or shared library to the initramfs module, use a command\nlike this:\n\ncopyexec /sbin/mdadm /sbin\n\nmkinitramfs will automatically detect which libraries it depends on  and  copy  them  to  the\ninitramfs.  This  means that most executables, unless compiled with klibc, will automatically\ninclude glibc in the image which will increase its size by several hundred kilobytes.\n\n"
                },
                {
                    "name": "Including a system firmware preimage (early initramfs)",
                    "content": "If you need to prepend data to the initramfs image, you need to prepare it  in  a  file,  and\ncall  the  prependearlyinitramfs function.  The file can be disposed of as soon as the func‐\ntion returns.\n"
                },
                {
                    "name": "Example:",
                    "content": "TEMPFILE=$(mktemp ...)\n...\nprependearlyinitramfs ${TEMPFILE}\nrm -f ${TEMPFILE}\n\n\n"
                },
                {
                    "name": "Exported variables",
                    "content": "mkinitramfs sets several variables for the hook scripts environment.\n\n\nMODULESDIR\ncorresponds to the linux modules dir.\n\nversion\nis the $(uname -r) linux version against mkinitramfs is run.\n\nCONFDIR\nis the path of the used initramfs-tools configurations.\n\nDESTDIR\nis the root path of the newly build initramfs.\n\nDPKGARCH\nallows arch specific hook additions.\n\nverbose\ncorresponds to the verbosity of the update-initramfs run.\n\nBUSYBOX, MODULES\nare as described in initramfs.conf(5).\n\nBUSYBOXDIR\nis the directory where busybox utilities should be installed from, or empty if busybox\nis not being used.\n\n\n"
                }
            ]
        },
        "BOOT SCRIPTS": {
            "content": "Similarly to hook scripts, boot scripts can be  found  in  two  places  /usr/share/initramfs-\ntools/scripts/  and  /etc/initramfs-tools/scripts/.  There  are a number of subdirectories to\nthese two directories which control the boot stage at which the scripts are executed.\n\n",
            "subsections": [
                {
                    "name": "Header",
                    "content": "Like for hook scripts, there are no guarantees as to the order in which the different scripts\nin one subdirectory (see \"Subdirectories\" below) are executed. In order to define  a  certain\norder, a similar header as for hook scripts should be used:\n\n#!/bin/sh\nPREREQ=\"\"\nprereqs()\n{\necho \"$PREREQ\"\n}\n\ncase $1 in\nprereqs)\nprereqs\nexit 0\n;;\nesac\n\nWhere PREREQ is modified to list other scripts in the same subdirectory if necessary.\n\n"
                },
                {
                    "name": "Help functions",
                    "content": "A  number  of  functions  (mostly  dealing  with  output)  are  provided  to  boot scripts in\n/scripts/functions :\n\n\nlogsuccessmsg Logs a success message\n\nExample: logsuccessmsg \"Frobnication successful\"\n\n\nlogfailuremsg Logs a failure message\n\nExample: logfailuremsg \"Frobnication component froobz missing\"\n\n\nlogwarningmsg Logs a warning message\n\nExample: logwarningmsg \"Only partial frobnication possible\"\n\n\nlogbeginmsg Logs a message that some processing step has begun\n\n\nlogendmsg Logs a message that some processing step is finished\n\nExample:\n\nlogbeginmsg \"Frobnication begun\"\n# Do something\nlogendmsg\n\n\npanic Logs an error message and executes a shell in the initramfs image to  allow  the\nuser to investigate the situation.\n\nExample: panic \"Frobnication failed\"\n\n\naddmountrootfailhook  NN-name  Deprecated: This function is now a stub which is ef‐\nfectively a no-op. It will be removed in a future  version;  please  remove  mountroot\nfailure hooks from existing packages accordingly.\n\n"
                },
                {
                    "name": "Subdirectories",
                    "content": "Both /usr/share/initramfs-tools/scripts and /etc/initramfs-tools/scripts contains the follow‐\ning subdirectories.\n\n\ninit-top  the  scripts  in  this  directory are the first scripts to be executed after\nsysfs and procfs have been mounted.  It also runs the udev  hook  for  populating  the\n/dev tree (udev will keep running until init-bottom).\n\n\ninit-premount  happens  after modules specified by hooks and /etc/initramfs-tools/mod‐\nules have been loaded.\n\n\nlocal-top OR nfs-top After these scripts have been executed, the root device  node  is\nexpected  to  be  present  (local)  or  the network interface is expected to be usable\n(NFS).\n\n\nlocal-block These scripts are called with the name of a  local  block  device.   After\nthese  scripts  have been executed, that device node should be present.  If the local-\ntop or local-block scripts fail to create the  wanted  device  node,  the  local-block\nscripts will be called periodically to try again.\n\n\nlocal-premount  OR  nfs-premount  are run after the sanity of the root device has been\nverified (local) or the network interface has been brought up (NFS),  but  before  the\nactual root fs has been mounted.\n\n\nlocal-bottom  OR  nfs-bottom  are run after the rootfs has been mounted (local) or the\nNFS root share has been mounted.\n\n\ninit-bottom are the last scripts to be executed before procfs and sysfs are  moved  to\nthe  real  rootfs  and execution is turned over to the init binary which should now be\nfound in the mounted rootfs. udev is stopped.\n\n"
                },
                {
                    "name": "Boot parameters",
                    "content": "/conf/param.conf allows boot scripts to change exported variables that are  listed  on\ntop  of  init. Write the new values to it. It will be sourced after an boot script run\nif it exists.\n\n\n"
                }
            ]
        },
        "EXAMPLES": {
            "content": "",
            "subsections": [
                {
                    "name": "Hook script",
                    "content": "An example hook script would look something  like  this  (and  would  usually  be  placed  in\n/etc/initramfs-tools/hooks/frobnicate):\n\n#!/bin/sh\n# Example frobnication hook script\n\nPREREQ=\"lvm\"\nprereqs()\n{\necho \"$PREREQ\"\n}\n\ncase $1 in\nprereqs)\nprereqs\nexit 0\n;;\nesac\n\n. /usr/share/initramfs-tools/hook-functions\n# Begin real processing below this line\n\nif [ ! -x \"/sbin/frobnicate\" ]; then\nexit 0\nfi\n\nforceload frobnicator interval=10\ncopyexec /sbin/frobnicate /sbin\nexit 0\n\n"
                },
                {
                    "name": "Boot script",
                    "content": "An  example  boot  script  would  look  something  like  this (and would usually be placed in\n/etc/initramfs-tools/scripts/local-top/frobnicate):\n\n#!/bin/sh\n# Example frobnication boot script\n\nPREREQ=\"lvm\"\nprereqs()\n{\necho \"$PREREQ\"\n}\n\ncase $1 in\nprereqs)\nprereqs\nexit 0\n;;\nesac\n\n. /scripts/functions\n# Begin real processing below this line\nif [ ! -x \"/sbin/frobnicate\" ]; then\npanic \"Frobnication executable not found\"\nfi\n\nif [ ! -e \"/dev/mapper/frobb\" ]; then\npanic \"Frobnication device not found\"\nfi\n\nlogbeginmsg \"Starting frobnication\"\n/sbin/frobnicate \"/dev/mapper/frobb\" || panic \"Frobnication failed\"\nlogendmsg\n\nexit 0\n\n"
                },
                {
                    "name": "Exported variables",
                    "content": "init sets several variables for the boot scripts environment.\n\n\nROOT  corresponds to the root boot option.  Advanced boot scripts like cryptsetup  or  live-\ninitramfs need to play tricks.  Otherwise keep it alone.\n\nROOTDELAY, ROOTFLAGS, ROOTFSTYPE, IP\ncorresponds to the rootdelay, rootflags, rootfstype or ip boot option.  Use of ROOTDE‐\nLAY is deprecated; you should implement a local-block boot script rather than delaying\nor polling.\n\nDPKGARCH\nallows arch specific boot actions.\n\nblacklist, panic, quiet, resume, noresume, resumeoffset\nset according relevant boot option.\n\nbreak Useful for manual intervention during setup and coding an boot script.\n\nREASON\nArgument  passed  to the panic helper function.  Use to find out why you landed in the\ninitramfs shell.\n\ninit  passes the path to init(8) usually /sbin/init.\n\nreadonly\nis the default for mounting the root corresponds to the ro bootarg.  Overridden by  rw\nbootarg.\n\nrootmnt\nis the path where root gets mounted usually /root.\n\ndebug indicates that a debug log is captured for further investigation.\n\n\n"
                }
            ]
        },
        "UPDATING THE INITRAMFS FROM ANOTHER PACKAGE": {
            "content": "Package maintainer scripts should not run update-initramfs directly.  A package that installs\nhooks for initramfs-tools should include a triggers file containing:\nactivate-noawait update-initramfs\n\nKernel packages must call the kernel hooks as documented in the Debian Kernel Handbook.\n\nA package that requires an initramfs to function, but is not a kernel package, should include\na triggers file containing:\nactivate-await update-initramfs\n\n\n",
            "subsections": []
        },
        "KERNEL HOOKS": {
            "content": "initramfs-tools  includes hook scripts that are called by kernel packages on installation and\nremoval, so that an initramfs is automatically created, updated or deleted as necessary.  The\nhook scripts do nothing if the environment variable INITRD is set to No.  This  will  be  the\ncase  for  kernel  packages built with make deb-pkg and with CONFIGBLKDEVINITRD not set in\nthe kernel config, or built with make-kpkg and not using the --initrd option.\n\n\n",
            "subsections": []
        },
        "DEBUG": {
            "content": "It is easy to check the generated initramfs for its content. One may need to double-check  if\nit contains the relevant binaries, libs or modules:\nlsinitramfs /boot/initrd.img-3.16-3-amd64\n\n\n",
            "subsections": []
        },
        "FILES": {
            "content": "/run/initramfs/fsck.log\nLog of fsck commands run within the initramfs, with their output.\n\n/run/initramfs/fsck-root\nExists only if fsck ran successfully for the root filesystem.\n\n/run/initramfs/fsck-usr\nExists only if fsck ran successfully for the /usr filesystem.\n\n\n",
            "subsections": []
        },
        "AUTHOR": {
            "content": "The  initramfs-tools  are  written by Maximilian Attems <maks@debian.org>, Jeff Bailey <jbai‐\nley@raspberryginger.com> and numerous others.\n\nThis manual was written by David  Härdeman <david@hardeman.nu>, updated by Maximilian  Attems\n<maks@debian.org>.\n\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "initramfs.conf(5), mkinitramfs(8), update-initramfs(8), lsinitramfs(8).\n\ninitramfs-tools                              2018/07/18                           INITRAMFS-TOOLS(7)",
            "subsections": []
        }
    },
    "summary": "initramfs-tools - an introduction to writing scripts for mkinitramfs",
    "flags": [],
    "examples": [
        "An example hook script would look something  like  this  (and  would  usually  be  placed  in",
        "/etc/initramfs-tools/hooks/frobnicate):",
        "#!/bin/sh",
        "# Example frobnication hook script",
        "PREREQ=\"lvm\"",
        "prereqs()",
        "echo \"$PREREQ\"",
        "case $1 in",
        "prereqs)",
        "prereqs",
        "exit 0",
        ";;",
        "esac",
        ". /usr/share/initramfs-tools/hook-functions",
        "# Begin real processing below this line",
        "if [ ! -x \"/sbin/frobnicate\" ]; then",
        "exit 0",
        "fi",
        "forceload frobnicator interval=10",
        "copyexec /sbin/frobnicate /sbin",
        "exit 0",
        "An  example  boot  script  would  look  something  like  this (and would usually be placed in",
        "/etc/initramfs-tools/scripts/local-top/frobnicate):",
        "#!/bin/sh",
        "# Example frobnication boot script",
        "PREREQ=\"lvm\"",
        "prereqs()",
        "echo \"$PREREQ\"",
        "case $1 in",
        "prereqs)",
        "prereqs",
        "exit 0",
        ";;",
        "esac",
        ". /scripts/functions",
        "# Begin real processing below this line",
        "if [ ! -x \"/sbin/frobnicate\" ]; then",
        "panic \"Frobnication executable not found\"",
        "fi",
        "if [ ! -e \"/dev/mapper/frobb\" ]; then",
        "panic \"Frobnication device not found\"",
        "fi",
        "logbeginmsg \"Starting frobnication\"",
        "/sbin/frobnicate \"/dev/mapper/frobb\" || panic \"Frobnication failed\"",
        "logendmsg",
        "exit 0",
        "init sets several variables for the boot scripts environment.",
        "ROOT  corresponds to the root boot option.  Advanced boot scripts like cryptsetup  or  live-",
        "initramfs need to play tricks.  Otherwise keep it alone.",
        "ROOTDELAY, ROOTFLAGS, ROOTFSTYPE, IP",
        "corresponds to the rootdelay, rootflags, rootfstype or ip boot option.  Use of ROOTDE‐",
        "LAY is deprecated; you should implement a local-block boot script rather than delaying",
        "or polling.",
        "DPKGARCH",
        "allows arch specific boot actions.",
        "blacklist, panic, quiet, resume, noresume, resumeoffset",
        "set according relevant boot option.",
        "break Useful for manual intervention during setup and coding an boot script.",
        "REASON",
        "Argument  passed  to the panic helper function.  Use to find out why you landed in the",
        "initramfs shell.",
        "init  passes the path to init(8) usually /sbin/init.",
        "readonly",
        "is the default for mounting the root corresponds to the ro bootarg.  Overridden by  rw",
        "bootarg.",
        "rootmnt",
        "is the path where root gets mounted usually /root.",
        "debug indicates that a debug log is captured for further investigation."
    ],
    "see_also": [
        {
            "name": "initramfs.conf",
            "section": "5",
            "url": "https://www.chedong.com/phpMan.php/man/initramfs.conf/5/json"
        },
        {
            "name": "mkinitramfs",
            "section": "8",
            "url": "https://www.chedong.com/phpMan.php/man/mkinitramfs/8/json"
        },
        {
            "name": "update-initramfs",
            "section": "8",
            "url": "https://www.chedong.com/phpMan.php/man/update-initramfs/8/json"
        },
        {
            "name": "lsinitramfs",
            "section": "8",
            "url": "https://www.chedong.com/phpMan.php/man/lsinitramfs/8/json"
        },
        {
            "name": "INITRAMFS-TOOLS",
            "section": "7",
            "url": "https://www.chedong.com/phpMan.php/man/INITRAMFS-TOOLS/7/json"
        }
    ]
}