0

I am trying to create a shell script that does the following

  1. Checks if a block device has a file system on it.
  2. Mount filesystem.

I have something like this right now

ls -ltrh /dev/vdb
brw-rw---- 1 root disk 254, 16 Dec 15 21:09 /dev/vdb

So /dev/vdb is my block device. And my script is something along the lines of

if TEST-COMMAND-TO-CHECK-IF-VDB-ALREADY-HAS-FILESYSTEM-FORMATTED
   then
     sudo mkfs.ext4 /dev/vdb
   fi 
fi

mount | grep /mntpoint > /dev/null && exit 0 || sudo mount /dev/vdb /mntpoint

I am trying to find out a good command for testing if dev/vdb has filesystem formatted.

1

1 Answer 1

0

This seems to do the trick

fs=$(lsblk --output NAME,FSTYPE,LABEL,UUID,MODE |grep vdb |  awk '{print $2}')
if [ $fs == "ext4" ]; 
then
     sudo mkfs.ext4 /dev/vdb
else 
     echo "/dev/vdb is already formatted to ext4"
fi

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.