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.
$ 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.
After allowing it, you will be asked to restart, so restart it.
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
You can unmount it with the umount
command. When unmounted, ~/raspberrypi4
will revert to an empty directory.
$ sudo umount ~/raspberrypi4
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).
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.
-Reading and writing "ext4" on Mac
Recommended Posts