Linux – EC2 – Want to mount before service starts

amazon ec2amazon-web-serviceschkconfiglinuxmount

I am using AWS EC2, and I have added an extra EBS volume. It is currently mounted as a new device.

MySQL & Redis DB stores their data on the new EBS volume, and they are registered in the chkconfig. Therefore, I need the volume to be mounted BEFORE the chkconfig service starts up.

But I do not want to add it in my /etc/fstab, as told in the forum below.
https://forums.aws.amazon.com/message.jspa?messageID=304528#304528

So I have added mount /dev/xvdf /data in my /etc/rc.d/rc.local , and I rebooted my system.

But apparently chkconfig services starts up BEFORE /etc/rc.d/rc.local, and so the MySQL &Redis startup fails.

I want to know where I can write an init script that is called BEFORE chkconfig service starts.

Thanks in advance.

Best Answer

As you might have noticed rc.local is usually the last script that is executed during the boot process. This is stated in the comments in the script.

Judging by the mention of chkconfig in your question I guess you're running either CentOS, Amazon's RHEL based Linux or another Red Hat (or Fedora) derivative. If that's the case then you can simply disregard what Cindy@AWS said in that thread.

Mounting of local filesystems in RHEL is done by the /etc/rc.sysinit script which mounts all filesystems that are not NFS, CIFS (SMB) or some other network-based filesystem. This is done by executing the following line in the script:

    action $"Mounting local filesystems: " mount -a -t nonfs,nfs4,smbfs,ncpfs,cifs,gfs,gfs2 -O no_netdev

This line executes mount and instructs it to try and mount all devices that don't match any of the nfs, nfs4, smbfs, ncpfs, cifs, gfs or gfs2 as their filesystem type. In addition to that it ignores all devices with _netdev in their options in fstab.

When mount tries to mount any filesystem that doesn't exist it doesn't block, but fails with the following error message:

# mount -a -t nonfs,nfs4,smbfs,ncpfs,cifs,gfs,gfs2 -O no_netdev`
mount: special device /dev/fhsd does not exist

In my case /dev/fhsd is a line in fstab that looks like this:

/dev/fhsd /mnt ext4 defaults 0 0

As you can see this failure is not blocking the mount process and the OS will not block waiting for the device, it will simply fail.

There is another script that takes care of mounting network-based filesystems in /etc/init.d/netfs and all filesystems that have _netdev in their options are handled by it.

There is a problem with missing devices in Ubuntu and you need to add nobootwait (also see this question about nobootwait and nofail on Unix.SE) to specify that the OS boot process should not fail if the device is missing, but under Ubuntu the mounting is performed by mountall(1).