How to erase disk from Terminal in MacBook pro

My MacBook Pro froze. I tried Fist aid, erase, and restore from disk until, but didn’t work. So I heard the only way to turn on the MacBook again is to erase/unmount disk through Terminal. I tried some commands from google, they weren’t recognized. Can you please tell me what is command to erase/unmount the disk from Terminal? My Mac is mid 2012.

MacBook Pro 13", macOS 10.14

Posted on Apr 23, 2019 6:27 PM

Reply
4 replies

Apr 24, 2019 12:57 PM in response to congzhen

There is no need to use Terminal at all in the normal course of maintaining your Mac.


But as mentioned, MacOS has checks to keep you from completely erasing the Drive that holds the running MacOS. I refer to this as "You cannot saw off the branch you are standing on."


Recovery HD aka 'OLD' Recovery or disk-based recovery (the only one present in Macs before about 2011) does not put up much of a fight, but if successful, you will have wiped out the only way to re-install MacOS except your original release DVD.


Internet Recovery, available in most Macs after about 2011, creates about 18 RAM disks for its work, and its code is in ROM. It does not care if you completely erase the boot drive -- it is not using the Boot Drive.

Apr 24, 2019 11:05 AM in response to congzhen

If you have the MBPro 13" (mid-2012) non-Retina model, then the hard drive cable may be failing. The hard drive cable on the model I mention is known to have a very high failure rate. If you still have the original hard drive, then it could also be starting to fail. If you take it to an independent Apple Authorized Service Provider, they can replace the hard drive cable for free under a special repair program and if the drive is failing, they may offer you third party SSD upgrade options.


Just be very careful using Ben's command line "dd" option as you can accidentally destroy data on the wrong device if you choose the wrong destination for "diskX". If your destination drive is an SSD, then you should not erase the whole SSD this way except to destroy the partition table as it will cause unnecessary excess wear on the SSD. Use Control + C to terminate the "dd" command early. Most people shouldn't need to use this option to erase a disk, but it is useful in some situations.

Apr 23, 2019 7:01 PM in response to congzhen

It depends. Are you attempting to erase the storage device that contains the MacOS operating system installation, or simply an external (i.e. USB) storage device? If the former, you'll need to enter recovery mode (by holding Command+R during the boot sequence) and use Disk Utility to erase the storage device. Whilst in recovery mode, you can also reinstall MacOS. Note that you'll lose all of your files and settings, so if you have a Time Machine backup, it may be worthwhile trying to restore the most recent working backup beforehand. If the latter, you can use the Terminal application to identify, unmount, and erase the storage device as follows:


sudo diskutil list
sudo diskutil unmountDisk /dev/diskX
sudo dd if=/dev/zero of=/dev/diskX bs=10m
sync


It will be quicker to simply erase the partition table on the storage device, but if you want to be thorough, this is the best approach. Once this process has completed, you should then be able to use Disk Utility to create a new partition table by formatting the storage device. To reiterate, you will lose all of your files and settings and they will be irrecoverable, so please ensure you have backed up your important data.


I hope the above helps you out.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

How to erase disk from Terminal in MacBook pro

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.