There appears to be an undesired side effect to parted creating a new partition, if the partition previously existed it will be automatically mounted, even before it has been formatted.
This is troublesome for a script that would for example:
parted -sm /dev/sdb mklabel gpt
parted -sm /dev/sdb mkpart primary ext4 1 1.8T
mkfs.ext4 -L drive /dev/sdb1
mkfs fails here because the partition is mounted.
This behavior is observed in CentOS 7, when the target disk was previously formatted and mounted since last boot.
Unmounting, removing the entry in /etc/fstab and the mount point directory, still triggers the condition; the mount point will be created and the partition automatically mounted.
It isn't clear who creates the mount point directory or from where does parted take the info.
A reboot between the fstab clearing and parted call will workaround this issue. There are no documented parameters in parted concerning auto mounting.
So is this behavior normal for parted and is there a reliable way to prevent it from auto mounting?
/etc/fstab, you should remember that in CentOS 7 (and any distributions usingsystemd) you should remember to runsystemctl daemon-reloadafter modifying/etc/fstab, since you'll wantsystemd-fstab-generatorto rebuild the*.mountunit files located in/run/systemd/generator/*.mount. If you don't do that, the old*.mountunits generated from the previous/etc/fstabcontents will still be in effect.