This page looks best with JavaScript enabled

Reading Btrfs Partition Files on MacOS

 ·  ☕ 3 min read

1. Background and Prerequisites

Compared with Ext4, Btrfs is a younger file system with more features to play with — snapshots, subvolumes, checksum self-verification, software RAID, and even transparent compression.

That said, if you do not have the operations capability behind you, it is best not to use Btrfs. This article records the process of pulling a Btrfs disk out of a Synology DSM system and reading its data.

In my DSM system, two disks form a RAID1 array using the Btrfs file system. I pulled one of the disks out and inserted it into another Apple machine.

There are also prerequisites here: the DSM version must be 6.2 or later, and the MacOS machine must have Parallels Desktop with an Ubuntu version of 18.04 or later installed.

If you have a Windows machine, you can also try reading the files with the WinBtrfs driver.

2. Mounting the Disk on MacOS

  • Check the newly inserted disk

You can see that MacOS cannot recognize the Btrfs file system directly. Ignore the disk3 shown in the image — that is a replacement screenshot; originally it was disk2.

  • Check disk information on MacOS
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
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_APFS Container disk1         1000.0 GB  disk0s2
...
/dev/disk2 (internal, physical):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:                                                   *4.0 TB     disk2
  • Use the PD command-line tool to mount the disk as a local file

Enter the Home directory

1
cd ~

Create a new disk pointing at the physical disk

1
/Applications/Parallels\ Desktop.app/Contents/MacOS/prl_disk_tool create -p --hdd disk2.hdd --ext-disk-path /dev/disk2

3. Mounting the Disk into the PD Ubuntu VM

Enter Ubuntu, shut down the host, then edit the virtual machine, add a hard disk, choose an existing disk, and select the HDD-format file from the disk2.hdd created above.

4. Reading the Btrfs Partition on Ubuntu

  • Switch to the root user
1
sudo -i
  • Install the basic software
1
apt-get install -y mdadm lvm2
  • Identify the file system

In the Disks tool, you can see the disk

Automatically mount the partition

1
mdadm -Asf && vgchange -ay

Check the /dev/md4 partition. If it is in the inactive state, unmount it and try again.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
mdadm -D /dev/md4

/dev/md4:
           Version : 1.2
     Creation Time : Thu Apr 30 20:16:28 2020
        Raid Level : raid1
        Array Size : 3902187456 (3721.42 GiB 3995.84 GB)
     Used Dev Size : 3902187456 (3721.42 GiB 3995.84 GB)
      Raid Devices : 2
     Total Devices : 1
       Persistence : Superblock is persistent

       Update Time : Sat Dec 18 07:38:07 2021
             State : clean, degraded
    Active Devices : 1
   Working Devices : 1
    Failed Devices : 0
     Spare Devices : 0

Consistency Policy : resync

              Name : DiskStation:4
              UUID : 9cf8faf4:c1c76801:3a4efd95:f021908b
            Events : 16609

    Number   Major   Minor   RaidDevice State
       -       0        0        0      removed
       1       8       21        1      active sync   /dev/sdb5
  • Mount
1
mount /dev/vg1/volume_1 /data

At this point, the data on the Btrfs disk partition is accessible under the /data directory in the Ubuntu system.

5. Mounting the Ubuntu Directory on MacOS to Access the Files

Accessing the data on the Btrfs disk partition from Ubuntu is not convenient enough, so here the directory inside PD Ubuntu is mounted into the MacOS system.

  • Install sshfs and its dependencies
1
brew install macfuse sshfs-mac curlftpfs-mac
  • Mount the Ubuntu system’s data directory into MacOS
1
sshfs shaowenchen@10.211.55.12:/data /Users/shaowenchen/Data
  • View the data on the Btrfs disk partition on MacOS

6. References


微信公众号
WRITTEN BY
微信公众号