How to access the contents of a Linux disk on a Mac (but read-only)

Introduction

I was playing with Ubuntu on my Raspberry Pi 4, but I accidentally made the OS unbootable. Before I reinstalled, I wanted to back up the data on the disk and I connected the SD card to my Mac, but I couldn't mount it.

$ diskutil list
# /dev/disk0 and/dev/disk1 is for macOS, so omit it

/dev/disk2 (external, physical):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:     FDisk_partition_scheme                        *63.9 GB    disk2
   1:             Windows_FAT_32 ⁨system-boot⁩             268.4 MB   disk2s1
   2:                      Linux ⁨⁩                        63.6 GB    disk2s2

# /dev/I found that disk2s2 is a Linux disk, but I couldn't mount it...
$ diskutil mount /dev/disk2s2
Volume on disk2s2 failed to mount
Perhaps the operation is not supported (kDAReturnUnsupported)
If you think the volume is supported but damaged, try the "readOnly" option

When I connect the SD card, / dev/disk2s1 is automatically mounted, but this is a system boot, so it is not the contents of Linux.

Upon examination, it seems that macOS does not support the Linux filesystem ** ext4 **. It seems that you need a tool called ex4fuse to be able to mount ext4, so this time I will show you how to install and use it.

environment

Installation

$ brew install --cask osxfuse
$ brew install ext4fuse

If the installation fails, you need to allow the application. If you see an item that is not allowed in "System Preferences"> "Security & Privacy"> "General"> "Allow Execution of Downloaded Applications", allow it. You must click the padlock at the bottom left in advance to allow it.

スクリーンショット 2020-12-17 0.04.12.png

After allowing it, you will be asked to restart, so restart it.

How to use

First, create a mount directory. In the example below, ~/raspberrypi4 is the mount destination.

$ mkdir ~/raspberrypi4

: warning: It is not recommended to mount to a core directory that originally exists in macOS, such as your home directory or desktop. This is because you will not be able to access the original directory until you unmount it.

Then find the disc to mount.

$ diskutil list
# /dev/disk0 and/dev/disk1 is for macOS, so omit it

/dev/disk2 (external, physical):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:     FDisk_partition_scheme                        *63.9 GB    disk2
   1:             Windows_FAT_32 ⁨system-boot⁩             268.4 MB   disk2s1
   2:                      Linux ⁨⁩                        63.6 GB    disk2s2

You'll see a few, but it's easy to tell which one is from an SD card (or USB stick, etc.) with Ubuntu (Linux) installed. In my environment, / dev/disk2 was the SD card disk.

Find the one whose TYPE is Linux. In the above case, the bottom disk2s2 is applicable. So it turns out that the disk to mount is / dev/disk2s2.

Once you know which disk to mount, run the following command: In addition, permission may be requested here as well. In that case, permission is given from the item of "System Preferences"> "Security & Privacy"> "General"> "Permission to execute downloaded application".

$ sudo ext4fuse /dev/disk2s2 ~/raspberrypi4 -o allow_other

/ dev/disk2s2 specifies the disk to mount, and ~/raspberrypi4 specifies the empty directory created earlier.

You should now have the contents of ~/raspberrypi4 as the contents of Linux.

$ ls ~/raspberrypi4
bin  boot  dev  etc  home  lib  lost+found  media  mnt  opt  proc  root  run  sbin  snap  srv  swapfile  sys  tmp  usr  var

Unmount

You can unmount it with the umount command. When unmounted, ~/raspberrypi4 will revert to an empty directory.

$ sudo umount ~/raspberrypi4

Disadvantage

You can mount a Linux disk this way for free, but keep in mind that it is ** read-only **. In other words, you cannot edit the files inside the mounted disc.

If you also want to edit, there is a GUI application called extFS for Mac by Paragon Software, but this is charged. If you really want to edit the contents of a Linux file on a Mac, you need to consider this, but if you do that, it seems better to mount it in another Linux environment (Of course, Linux can mount a Linux disk. Because).

Bonus: If you want to copy the entire disc

If you want to copy the entire disk in the SD card, you can use the dd command.

$ sudo dd if=/dev/rdisk2 of=~/raspberrypi4.img

For if =, specify the disk of the SD card of diskutil list. If / dev/disk2 is an SD card (or a USB stick, etc.), specifying/dev/rdisk2 instead of / dev/disk2 seems to be faster.

For of =, specify the destination path. In the above example, it is written to ~/raspberrypi4.img.

However, please note the following two points.

--Copying the entire disk takes up space on your Mac -It takes a lot of time

Copying the entire contents of a 64 GB SD card consumes 64 GB of Mac space. Also, it took ** 8 hours 27 minutes 54 seconds ** to copy the entire contents of the 64 GB SD card (the dd command execution time above).

Therefore, if you want to back up or retrieve only some files, it is safer to mount and retrieve them as introduced in this article.

Reference site

-Reading and writing "ext4" on Mac

Recommended Posts

How to access the contents of a Linux disk on a Mac (but read-only)
[Ubuntu] How to delete the entire contents of a directory
How to connect the contents of a list into a string
How to output the output result of the Linux man command to a file
[Introduction to Python] How to sort the contents of a list efficiently with list sort
Verification of how to periodically execute a script on a Linux server on Windows
How to play a video while watching the number of frames (Mac)
How to calculate the volatility of a brand
How to install Linux on a 32bit UEFI PC
How to access the global variable of the imported module
How to build a Python environment on amazon linux 2
[AWS] How to expand disk space on Amazon linux
A memo on how to overcome the difficult problem of capturing FX with AI
Avoiding the pitfalls of using a Mac (for Linux users?)
A memo on how to easily prepare a Linux exercise environment
How to register a package on PyPI (as of September 2017)
How to see the contents of the Jupyter notebook ipynb file
How to find the scaling factor of a biorthogonal wavelet
[Linux] [C / C ++] How to get the return address value of a function and the function name of the caller
Detailed explanation How to run the sample code of UNIX programming 3rd edition on Mac
How to easily draw the structure of a neural network on Google Colaboratory using "convnet-drawer"
How to display a specified line of a file or command result on Linux (sed, awk)
A story about porting the code of "Try and understand how Linux works" to Rust
How to install mysql-connector-python on mac
How to install VMware-Tools on Linux
How to install OpenCV on Mac
How to display a specified column of files in Linux (awk)
How to determine the existence of a selenium element in Python
A note on how to check the connection to the license server port
How to get the printer driver for Oki Mac into Linux
How easy is it to synthesize a drug on the market?
[EC2] How to install chrome and the contents of each command
How to check the memory size of a variable in Python
On Linux, the time stamp of a file is a little past.
How to check the memory size of a dictionary in Python
[TensorFlow 2] How to check the contents of Tensor in graph mode
[Linux] How to disable the automatic update of the /etc/resolv.conf file (AmazonLinux2)
How to find the memory address of a Pandas dataframe value
How to get the vertex coordinates of a feature in ArcPy
How to use Jupyter on the front end of supercomputer ITO
A command to easily check the speed of the network on the console
How to update the python version of Cloud Shell on GCP
Create a function to get the contents of the database in Go
[NNabla] How to remove the middle tier of a pre-built network
[Python] A program that rotates the contents of the list to the left
How to run the practice code of the book "Creating a profitable AI with Python" on Google Colaboratory
How to install drobertadams / toggl-cli on Mac
How to check the version of Django
How many bytes of files can be placed on a 50M disk?
[Linux] How to use the echo command
A quick overview of the Linux kernel
I want to use Linux on mac
How to use the Linux grep command
[Linux] Command to get a list of commands executed in the past
How to update php on Amazon linux 2
Semi-automatically generate a description of the package to be registered on PyPI
How to compare if the contents of the objects in scipy.sparse.csr_matrix are the same
How to erase Python 2.x on Mac.
How to display emoji on Manjaro Linux
[Java] [Linux] Investigating how the implementation of Java child processes on Linux is realized
[NNabla] How to add a quantization layer to the middle layer of a trained model