Execute a script before fsstab is read

For a netboot cluster, I’m creating a CentOS 6.5 root disk. The goal is to mount / read-only over NFS, and various other folders, such as /var/log, on the local disk.

Here’s my first idea:

  1. On boot, a script is executed as early as possible, which checks whether the local disk needs to be initialized or not;

  2. If the disk needs initialization, the LVM volumes are created;

  3. Normal boot continues, and the partitions are mounted whenever /etc/fstab is read.

However, other than modifying /etc/inittab or /etc/rc.d/rc.sysinit, which doesn’t sound quite reasonable, I can’t see how to execute a script before /etc/inittab is read.

As using local disks with a netboot setup seems to be a fairly common need, I wonder whether there is other solutions to achieve this behavior?

Answer

You’ll probably want to do what you’re looking for in a custom initrd. The initrd is used getting drivers loaded, getting software RAID up and going, etc. If you look around for diskless / stateless boot tutorials I suspect you’ll be able to cobble together the pieces.

Attribution
Source : Link , Question Author : Pierre , Answer Author : Evan Anderson

Leave a Comment