Mac的磁盘操作命令

默认情况下Mac系统安装时都会在当前磁盘新建600+MRecovery分区用于系统的re-install online,但鉴于我们所处的网络环境在线恢复功能在国内以其滴水般的速度形同鸡肋,该分区在开机时以option/ALT键触发的UEFI引导选项中可见,而系统中常用的Disk Utility工具无法显示该类型分区,虽说并不影响系统功能,但每次装机时看到磁盘容量已使用600+M的显示还是心里不痛快,为了实现对磁盘空间的完全控制,还是得使用终端命令配合图形化工具。

1. List ALL Disk/Partition

"diskutil list" + "df -h"

MAC:~ Bruce$ diskutil list
/dev/disk0 (internal, physical):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *1.0 TB     disk0
   1:                        EFI EFI                     209.7 MB   disk0s1
   2:                  Apple_HFS Sys                     500.0 GB   disk0s2
   3:                 Apple_Boot Recovery HD             650.0 MB   disk0s3
   4:                  Apple_HFS Data                    499.2 GB   disk0s4

MAC:~ Bruce$ df -h
Filesystem      Size   Used  Avail Capacity iused      ifree %iused  Mounted on
/dev/disk0s2   466Gi   14Gi  451Gi     4%  448882 4294518397    0%   /
devfs          181Ki  181Ki    0Bi   100%     625          0  100%   /dev
map -hosts       0Bi    0Bi    0Bi   100%       0          0  100%   /net
map auto_home    0Bi    0Bi    0Bi   100%       0          0  100%   /home
/dev/disk0s4   465Gi  953Mi  464Gi     1%     743 4294966536    0%   /Volumes/Data

上述可知分区/dev/disk0s3Recovery类型,默认不会被挂载到/Volumes下。

2. Monut/Unmount Partition

"diskutil mount /dev/xx" + "diskutil unmount /dev/xx"

MAC:~ Bruce$ diskutil list
/dev/disk0 (internal, physical):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *1.0 TB     disk0
   1:                        EFI EFI                     209.7 MB   disk0s1
   2:                  Apple_HFS Sys                     500.0 GB   disk0s2
   3:                 Apple_Boot Recovery HD             650.0 MB   disk0s3
   4:                  Apple_HFS Data                    499.2 GB   disk0s4

MAC:~ Bruce$ diskutil mount /dev/disk0s3
Volume Recovery HD on /dev/disk0s3 mounted
MAC:~ Bruce$ df -h
Filesystem      Size   Used  Avail Capacity iused      ifree %iused  Mounted on
/dev/disk0s2   466Gi   14Gi  451Gi     4%  448886 4294518393    0%   /
devfs          181Ki  181Ki    0Bi   100%     625          0  100%   /dev
map -hosts       0Bi    0Bi    0Bi   100%       0          0  100%   /net
map auto_home    0Bi    0Bi    0Bi   100%       0          0  100%   /home
/dev/disk0s4   465Gi  953Mi  464Gi     1%     743 4294966536    0%   /Volumes/Data
/dev/disk0s3   620Mi  510Mi  110Mi    83%      21 4294967258    0%   /Volumes/Recovery HD
MAC:~ Bruce$ diskutil unmount /dev/disk0s3
Volume Recovery HD on disk0s3 unmounted

3. Erase Partition

"diskutil eraseVolume Volume_type Volume_name /dev/xx"

MAC:~ Bruce$ diskutil eraseVolume HFS+ Data /dev/disk0s4
Started erase on disk0s4 Data
Unmounting disk
Erasing
Initialized /dev/rdisk0s4 as a 465 GB case-insensitive HFS Plus volume
Mounting disk
Finished erase on disk0s4 Data

diskutilMac的磁盘操作命令类似于fdisk,功能强大,详细信息可见https://developer.apple.com/legacy/library/documentation/Darwin/Reference/ManPages/man8/diskutil.8.html,但日常使用中只需要使用上述命令补充Disk Utility的短板即可实现对磁盘的全面操作。

你可能感兴趣的:(Tool)