Mount: /dev/sdc is already mounted or /data/2 busy


#1

Hello all,

I’m using the following to mount disks on my nodes. I was expecting that if the disk was already mounted, Chef would output (up to date), but instead, it gives an error; “mount: /dev/sdc is already mounted or /data/2 busy”.

mount ‘/data/2’ do
device ‘/dev/sdc’
fstype ‘ext4’
end

Advise?

Thanks, Clay


#2

I’d say I’m surprised you’re mounting /dev/sdc, instead of /dev/sdc1 or another partition on /dev/sdc. I’d also check the output of “df” and “parted -l” to get a sense of whether the correct partition exists and is already mounted.


#3

This is how it’s done in the shell.

parted /dev/sdb --script – mklabel gpt
parted /dev/sdb --script – mkpart primary 0.00TB 3.00TB
parted /dev/sdc --script – mklabel gpt
parted /dev/sdc --script – mkpart primary 0.00TB 3.00TB
parted /dev/sdd --script – mklabel gpt
parted /dev/sdd --script – mkpart primary 0.00TB 3.00TB
parted /dev/sde --script – mklabel gpt
parted /dev/sde --script – mkpart primary 0.00TB 3.00TB
parted /dev/sdf --script – mklabel gpt
parted /dev/sdf --script – mkpart primary 0.00TB 3.00TB
parted /dev/sdg --script – mklabel gpt
parted /dev/sdg --script – mkpart primary 0.00TB 3.00TB
parted /dev/sdh --script – mklabel gpt
parted /dev/sdh --script – mkpart primary 0.00TB 3.00TB
mkdir /data
mkdir /data/1
mkdir /data/2
mkdir /data/3
mkdir /data/4
mkdir /data/5
mkdir /data/6
mkdir /data/7
mkfs.ext4 /dev/sdb -F
mkfs.ext4 /dev/sdc -F
mkfs.ext4 /dev/sdd -F
mkfs.ext4 /dev/sde -F
mkfs.ext4 /dev/sdf -F
mkfs.ext4 /dev/sdg -F
mkfs.ext4 /dev/sdh -F
mount /dev/sdb /data/1
mount /dev/sdc /data/2
mount /dev/sdd /data/3
mount /dev/sde /data/4
mount /dev/sdf /data/5
mount /dev/sdg /data/6
mount /dev/sdh /data/7

I dont want to get too complicated. I can format the disk on the node initially but would like to ensure they are mounted when I run chef client on the node.


#4

This is the relevant part for /dev/sdc

So yes, you’ve theoretically successfully created filesystems there. But it’s not clear, just from reading the script, that that you actually have created filesystems there, since your scripts don’t exit on failure of any particular line. Even your steps that create the mount points are vulnerable to failure if any stage has already created the directories: they’re not safely idempotent. there is also no point to creating the partitions, since you’re not using them for anything. You’re running mkfs.ext4 against the raw disk at /dev/sdc, not the partition at /dev/sdc1 which you created with the “mkpart primary” command.

If I may encourage you, spend some time writing a small subroutine, or module, that can check whether the filesystem is already mounted correctly, and if not creates the relevant filesystems and mountpoints safely. And if all you want to do is check the mount is done correctly, do a lightweight shell command: And not the witespace after the “/data/2”, to ensure the correct mountpoint.

  • grep '/dev/sdc /data/2 ’ /etc/mtab

#5

Sorry, accidentally included an irrelevant bit of content in my quoting!!!