How to automatically mount/unmount disk on macOS/Linux

Regardless of whether it is Linux or Unix-based macOS, you can use mountthe command to mount the disk to mount the disk.

General status of mounts:

  1. View disk status
  2. mount disk
  3. read and write disk

The last is to unmount the disk.

Similar to Windows, macOS generally mounts mobile storage automatically; some Linux distributions also mount mobile storage (especially those with a GUI interface).

This time, ignore all the GUI interface and see how to operate on the command. Finally, let's take a look at how to automatically mount or unmount (unmount) the disk after booting.

view disk

macOS

To view the disk insertion status on macOS, use the command:

diskutil list

View disk status
The status after we plug in the U disk:
The status of plugging in the U disk
You can see that there is one disk4more IDENTIFIER. The physical interface plugged in is /dev/disk4.

Linux

Linux disk view, generally use fdiskthe command:

fdisk -l

View disk status
Plug in the U disk, check the end of the output, you can see our U disk device:
U disk device
as you can see, my U disk has four partitions.

mount disk

Regardless of whether it is Linux or Unix-based macOS, you can use mountthe command to mount the disk to mount the disk. Mount according to the disk location viewed above:

mount [参数] [需要挂载的分区] [Linux上挂载点]

First we look at macOS:
macOS mount
where:

  • -t: disk type
  • -o: Subsequent rw, autoand nobrowseare all added parameters by this synchronization mode.

The final command is:

sudo mount -t exfat -o rw,auto,nobrowse /dev/disk4 Downloads/MintimateDisk

Mounting result:
mount result
Look at our Linux again, this disk is relatively simple:
Mounting on Linux
Mounting on Linux

unmount disk

Uninstallation is simple.

First, look at macOS:

umount Downloads/MintimateDisk

unmount disk
Similarly, uninstallation on Linux is also very simple:

sudo mount /mnt/upan

Linux uninstall disk

Boot mount/unmount

Finally, let's see how to automatically mount and unmount disks at startup.
The first is to uninstall, which is generally used in macOS.

On the Intel version of macOS, you can choose to install a dual system. If you have installed a dual system, you may automatically mount the Windows disk partition after booting:
Disks automatically mounted by macOS
Auto-mount content:
auto mount
However, we cannot directly write to the Windows partition on macOS, and this is a bit dangerous. To this end, we can automatically uninstall after booting:
automatic uninstall
the operation is very simple, we write the uninstall command to /etc/fstab.
First, we view the disk details:

diskutil list

After that, find the Windows partition and use diskutil infothe command to view the details:

diskutil info 

View disk details
Depending on the disk Volume UUID, add to /etc/fstab. In this way, macOS will be automatically uninstalled:

UUID=5EE51E74-0E37-42FE-AC22-38184A510981 none ntfs noauto

edit fstab
Similarly, for Linux devices, if you want to automatically mount the U disk. First look at the UUID:

sudo blkid

UUID
Afterwards, we add proceeding:

UUID=67E3-17ED /mnt/upan vfat defaults 0 0

auto mount
However, Linux is more recommended to be configured in the startup service script:
Configured in the startup script
Advantages:

  • If the input command is wrong, the normal operation of the operating system will not be affected when Linux restarts

Guess you like

Origin blog.csdn.net/weixin_43890033/article/details/128279214