¿Cuál es la forma correcta de expulsar un archivo APFS desde la línea de comandos?

Cree un APFS DMG usando la aplicación Disk Utility de Apple y llámelo test_apfs.dmg.

Uno puede montarlo con:

hdiutil attach -plist ~/Desktop/test_apfs.dmg

que proporciona la siguiente salida:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>system-entities</key>
    <array>
        <dict>
            <key>content-hint</key>
            <string>GUID_partition_scheme</string>
            <key>dev-entry</key>
            <string>/dev/disk2</string>
            <key>potentially-mountable</key>
            <false/>
            <key>unmapped-content-hint</key>
            <string>GUID_partition_scheme</string>
        </dict>
        <dict>
            <key>content-hint</key>
            <string>Apple_APFS</string>
            <key>dev-entry</key>
            <string>/dev/disk2s1</string>
            <key>potentially-mountable</key>
            <false/>
            <key>unmapped-content-hint</key>
            <string>7C3457EF-0000-11AA-AA11-00306543ECAC</string>
        </dict>
        <dict>
            <key>content-hint</key>
            <string>41504653-0000-11AA-AA11-00306543ECAC</string>
            <key>dev-entry</key>
            <string>/dev/disk3s1</string>
            <key>mount-point</key>
            <string>/Volumes/Untitled</string>
            <key>potentially-mountable</key>
            <true/>
            <key>unmapped-content-hint</key>
            <string>41504653-0000-11AA-AA11-00306543ECAC</string>
            <key>volume-kind</key>
            <string>apfs</string>
        </dict>
        <dict>
            <key>content-hint</key>
            <string>EF57347C-0000-11AA-AA11-00306543ECAC</string>
            <key>dev-entry</key>
            <string>/dev/disk3</string>
            <key>potentially-mountable</key>
            <false/>
            <key>unmapped-content-hint</key>
            <string>EF57347C-0000-11AA-AA11-00306543ECAC</string>
        </dict>
    </array>
</dict>
</plist>

Después de tratar de separarme con:

hdiutil detach /Volumes/Untitled

lista diskutil, devuelve:

/dev/disk2 (disk image):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        +100.0 MB   disk2
   1:                 Apple_APFS Container disk3         100.0 MB   disk2s1

/dev/disk3 (synthesized):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      APFS Container Scheme -                      +100.0 MB   disk3
                                 Physical Store disk2s1
   1:                APFS Volume Untitled                65.5 KB    disk3s1

y volviendo a la aplicación Disk Utility de Apple, veo el volumen Sin título en la lista, pero está atenuado.

Solo puedo expulsarlo por completo si hago lo siguiente:

hdiutil detach /dev/disk2

Entonces, el montaje es un comando, la expulsión total es dos.

¿Es esta la única forma correcta de expulsar este tipo de volumen desde la línea de comandos? Lo que me gustaría poder hacer es expulsarlo por completo con un solo comando. ¿Es eso posible?

Respuestas (1)

Utilice el siguiente comando.

diskutil eject disk2

En las páginas man de hdiutil, aparece lo siguiente:

 detach dev_name [-force]
            detach a disk image and terminate any associated process.
            dev_name is a partial /dev node path (e.g. "disk1").  As of
            Mac OS X 10.4, dev_name can also be a mountpoint.  If Disk
            Arbitration is running, detach will use it to unmount any
            filesystems and detach the image.  If not, detach will attempt
            to unmount any filesystems and detach the image directly
            (using the `eject' ioctl).  If Disk Arbitration is not run-
            ning, it may be necessary to unmount the filesystems with
            umount(8) before detaching the image.  eject is a synonym for
            detach.  In common operation, detach is very similar to
            diskutil(8)'s eject.

            Options:
            -force   ignore open files on mounted volumes, etc.

Entonces, la documentación indica que es posible que primero deba desmontar los sistemas de archivos. Supongo que esto es lo que hdiutil detach /Volumes/Untitledhizo el comando.

En las páginas man de diskutil, aparece lo siguiente:

 eject device
            Eject a disk.  Media will become offline for the purposes of
            being a data store for file systems or being a member of con-
            structs such as software RAID or direct data.  Additionally,
            removable media will become eligible for safe manual removal;
            automatically-removable media will begin its physical (motor-
            ized) eject sequence.

Aquí, no se menciona tener que ejecutar ningún otro comando primero.

Nota: Para que el diskutil eject disk2comando funcione, el Untitledvolumen no puede estar en uso.

Entonces, ¿lo que está diciendo es que se requiere que uno use dos o más comandos desde la línea de comandos para expulsar completamente un volumen APFS?