Table Of Contents


A resource defines the desired state for a single configuration item present on a node that is under management by Chef. A resource collection—one (or more) individual resources—defines the desired state for the entire node. During every chef-client run, the current state of each resource is tested, after which the chef-client will take any steps that are necessary to repair the node and bring it back into the desired state.

Use the mount resource to manage a mounted file system.


The syntax for using the mount resource in a recipe is as follows:

mount "name" do
  attribute "value" # see attributes section below
  fstype "type"
  action :action # see actions section below


  • mount tells the chef-client to use the Chef::Provider::Mount provider during the chef-client run for all platforms except for Microsoft Windows, which uses the Chef::Provider::Mount::Windows provider
  • name is the name of the resource block; when the mount_point attribute is not specified as part of a recipe, name is also the directory (or path) in which a device should be mounted
  • attribute is zero (or more) of the attributes that are available for this resource
  • fstype is the file system type; this attribute is required
  • :action identifies which steps the chef-client will take to bring the node into the desired state

For example:

mount node['mysql']['ec2_path'] do
  device ebs_vol_dev
  fstype "xfs"
  action :mount


This resource has the following actions:

Action Description
:mount Default. Use to mount a device.
:umount Use to unmount a device.
:remount Use to remount a device.
:enable Use to add an entry to the file systems table (fstab).
:disable Use to remove an entry from the file systems table (fstab).


Order matters when passing multiple actions. For example: action [:mount, :enable] ensures that the file system is mounted before it is enabled.


This resource has the following attributes:

Attribute Description
device Required for :umount and :remount actions (for the purpose of checking the mount command output for presence). The special block device or remote node, a label, or a uuid to be mounted.
device_type The type of device: :device, :label, or :uuid. Default value: :device.
domain Microsoft Windows only. Use to specify the domain in which the username and password are located.
dump The dump frequency (in days) used while creating a file systems table (fstab) entry. Default value: 0.
enabled Use to specify if a mounted file system is enabled. Default value: false.
fstype Required. The file system type (fstype) of the device.
mount_point The directory (or path) in which the device should be mounted. Default value: the name of the resource block. (See “Syntax” section above for more information.)
mounted Use to specify if a file system is already mounted. Default value: false.
options An array or string that contains mount options. If this value is a string, it will be converted to an array. Default value: defaults.
pass The pass number used by the file system check (fsck) command while creating a file systems table (fstab) entry. Default value: 2.
password Microsoft Windows only. Use to specify the password for username.
provider Optional. Use to explicitly specify a provider. (See “Providers” section below for more information.)
supports A Hash of options for supported mount features. Default value: { :remount => false }.
username Microsoft Windows only. Use to specify the user name.


Where a resource represents a piece of the system (and its desired state), a provider defines the steps that are needed to bring that piece of the system from its current state into the desired state.

The chef-client will determine the correct provider based on configuration data collected by Ohai at the start of the chef-client run. This configuration data is then mapped to a platform and an associated list of providers.

Generally, it’s best to let the chef-client choose the provider and this is (by far) the most common approach. However, in some cases specifying a provider may be desirable. There are two approaches:

  • Use a more specific short name—yum_package "foo" do instead of package "foo" do, script "foo" do instead of bash "foo" do, and so on—when available
  • Use the provider attribute to specify the long name as an attribute of a resource, e.g. provider Chef::Provider::Long::Name

This resource has the following providers:

Long name Short name Notes
Chef::Provider::Mount mount The default provider for all platforms, except for Microsoft Windows.
Chef::Provider::Mount::Windows mount The default provider for the Microsoft Windows platform.


The following examples demonstrate various approaches for using resources in recipes. If you want to see examples of how Chef uses resources in recipes, take a closer look at the cookbooks that Chef authors and maintains:

Mount a labeled file system

mount "/mnt/volume1" do
  device "volume1"
  device_type :label
  fstype "xfs"
  options "rw"

Mount a local block drive

mount "/mnt/local" do
  device "/dev/sdb1"
  fstype "ext3"

Mount a non-block file system

mount "/mount/tmp" do
  pass     0
  fstype   "tmpfs"
  device   "/dev/null"
  options  "nr_inodes=999k,mode=755,size=500m"
  action   [:mount, :enable]

Mount and add to the file systems table

mount "/export/www" do
  device "nas1prod:/export/web_sites"
  fstype "nfs"
  options "rw"
  action [:mount, :enable]

Mount a remote file system

mount "/export/www" do
  device "nas1prod:/export/web_sites"
  fstype "nfs"
  options "rw"

Mount a remote folder in Microsoft Windows

mount "T:" do
  action :mount
  device "\\\\\\folder"

Unmount a remote folder in Microsoft Windows

mount "T:" do
  action :umount
  device "\\\\\\D$"

Stop a service, do stuff, and then restart it

The following example shows how to use the execute, service, and mount resources together to ensure that a node running on Amazon EC2 is running MySQL. This example does the following:

  • Checks to see if the Amazon EC2 node has MySQL
  • If the node has MySQL, stops MySQL
  • Installs MySQL
  • Mounts the node
  • Restarts MySQL
#  the following code sample comes from the ``server_ec2`` recipe in the following cookbook:

if (node.attribute?('ec2') && !['mysql']['ec2_path']))

  service "mysql" do
    action :stop

  execute "install-mysql" do
    command "mv #{node['mysql']['data_dir']} #{node['mysql']['ec2_path']}"
    not_if do['mysql']['ec2_path']) end

  [node['mysql']['ec2_path'], node['mysql']['data_dir']].each do |dir|
    directory dir do
      owner 'mysql'
      group 'mysql'

  mount node['mysql']['data_dir'] do
    device node['mysql']['ec2_path']
    fstype "none"
    options "bind,rw"
    action [:mount, :enable]

  service "mysql" do
    action :start



  • the two service resources are used to stop, and then restart the MySQL service
  • the execute resource is used to install MySQL
  • the mount resource is used to mount the node and enable MySQL