Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

blockdev.formatted fails on entire drive3 #42397

Open
mbiokyle29 opened this issue Jul 19, 2017 · 9 comments
Open

blockdev.formatted fails on entire drive3 #42397

mbiokyle29 opened this issue Jul 19, 2017 · 9 comments
Labels
Bug broken, incorrect, or confusing behavior severity-medium 3rd level, incorrect or bad functionality, confusing and lacks a work around
Milestone

Comments

@mbiokyle29
Copy link

Description of Issue/Question

I am working in a master-less configuration, attempting to provision a Virtual Box CentOS VM using salt. I am attempting to use salt.states.blockdev.formatted to create an ext4 file system directly on a device (not on a device partition). The salt state fails to execute due to a prompt that mkfs produces when attempting to format an entire drive.

Here is my salt state:

/dev/sdc:
   blockdev.formatted

Here are the relevant debug logs:
Note: as far as I can tell blkid only works on partitions, hence the bad return code. As far as I can tell the salt state continues execution and run the mkfs command via cmd.retcode which blocks util the command returns, which will never happen.

[INFO    ] Running state [/dev/sdc] at time 11:56:22.386837
[INFO    ] Executing state blockdev.formatted for [/dev/sdc]
[INFO    ] Executing command 'blkid -o value -s TYPE /dev/sdc' in directory '/root'
[ERROR   ] Command 'blkid -o value -s TYPE /dev/sdc' failed with return code: 2
[ERROR   ] output:
[INFO    ] Executing command ['mkfs', '-t', 'ext4', '/dev/sdc'] in directory '/root'
# this hangs

Strace shows the mkfs waiting for input:

strace -p `pgrep mkfs`
Process 3965 attached
read(0,

If I run the command directly:

mkfs -t ext4 /dev/sdc
mke2fs 1.41.12 (17-May-2010)
/dev/sdc is entire device, not just one partition!
Proceed anyway? (y,n)

Finally, I think the solution is to not format unpartitioned drives and instead make partitions. But good to have in-place in case someone really wants to do this.

Versions Report

Salt Version:
           Salt: 2017.7.0

Dependency Versions:
           cffi: Not Installed
       cherrypy: Not Installed
       dateutil: Not Installed
      docker-py: Not Installed
          gitdb: Not Installed
      gitpython: Not Installed
          ioflo: Not Installed
         Jinja2: 2.8.1
        libgit2: Not Installed
        libnacl: Not Installed
       M2Crypto: Not Installed
           Mako: Not Installed
   msgpack-pure: Not Installed
 msgpack-python: 0.4.6
   mysql-python: Not Installed
      pycparser: Not Installed
       pycrypto: 2.6.1
   pycryptodome: Not Installed
         pygit2: Not Installed
         Python: 2.7.13 (default, Jul 12 2017, 17:32:34)
   python-gnupg: Not Installed
         PyYAML: 3.11
          PyZMQ: 14.5.0
           RAET: Not Installed
          smmap: Not Installed
        timelib: Not Installed
        Tornado: 4.2.1
            ZMQ: 4.0.5

System Versions:
           dist: centos 6.7 Final
         locale: UTF-8
        machine: x86_64
        release: 2.6.32-696.6.3.el6.x86_64
         system: Linux
        version: CentOS 6.7 Final
@garethgreenaway garethgreenaway added this to the Approved milestone Jul 20, 2017
@garethgreenaway garethgreenaway added Pending-Discussion The issue or pull request needs more discussion before it can be closed or merged Bug broken, incorrect, or confusing behavior labels Jul 20, 2017
@garethgreenaway
Copy link
Contributor

This is definitely a situation we should account for, there are several use cases for when you would want to format the entire drive and not use a partition. Initially I thought there could be a force option that would bypass the prompt, False by default. Unfortunately it doesn't look like there is a common flag among the mkfs tools that does this. The ext3 and ext4 tools have one, but the others do not.

@mbiokyle29
Copy link
Author

mbiokyle29 commented Jul 20, 2017

Here is the workaround I currently have:

format_dev_sdb:
  cmd.run:
    - stateful: True
    - name: |
        ext4_lines=$(file -sL /dev/sdb | grep ext4 | wc -l)
        if [ $ext4_lines -eq 0 ]; then
          yes | mkfs.ext4 /dev/sdb
          echo
          echo "changed=yes comment='drive /dev/sdb was formatted'"
        else
          echo
          echo "changed=no comment='drive /dev/sdb was already ext4'"
        fi
[root@dev ~]# file -sL /dev/sdb
/dev/sdb: data

[root@dev ~]# mkfs.ext4 /dev/sdb
mke2fs 1.41.12 (17-May-2010)
/dev/sdb is entire device, not just one partition!
Proceed anyway? (y,n) y
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
655360 inodes, 2621440 blocks
131072 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2684354560
80 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
	32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632

Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 22 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

[root@dev ~]# file -sL /dev/sdb
/dev/sdb: Linux rev 1.0 ext4 filesystem data (extents) (large files) (huge files)

The file command is able to detect the ext4 filesystem on the full device unlike blkid. Perhaps it makes sense to have a formatted_drive and formatted_partition as separate commands for clarity?

@dhs-rec
Copy link
Contributor

dhs-rec commented Apr 6, 2018

@garethgreenaway, mkfs.xfs doesn't care. However, it actually has a -force option to allow overwriting an already existing filesystem on the device.

@stale
Copy link

stale bot commented Jul 20, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

If this issue is closed prematurely, please leave a comment and we will gladly reopen the issue.

@stale stale bot added the stale label Jul 20, 2019
@dhs-rec
Copy link
Contributor

dhs-rec commented Jul 22, 2019

This is still a bug. Please reopen.

@stale
Copy link

stale bot commented Jul 22, 2019

Thank you for updating this issue. It is no longer marked as stale.

@stale stale bot removed the stale label Jul 22, 2019
@stale
Copy link

stale bot commented Jan 8, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

If this issue is closed prematurely, please leave a comment and we will gladly reopen the issue.

@stale stale bot added the stale label Jan 8, 2020
@dhs-rec
Copy link
Contributor

dhs-rec commented Jan 8, 2020

This is still a bug. Reopening...

@stale
Copy link

stale bot commented Jan 8, 2020

Thank you for updating this issue. It is no longer marked as stale.

@stale stale bot removed the stale label Jan 8, 2020
@sagetherage sagetherage added severity-medium 3rd level, incorrect or bad functionality, confusing and lacks a work around and removed Pending-Discussion The issue or pull request needs more discussion before it can be closed or merged labels Jun 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug broken, incorrect, or confusing behavior severity-medium 3rd level, incorrect or bad functionality, confusing and lacks a work around
Projects
None yet
Development

No branches or pull requests

4 participants