raspberry pi_如何将Raspberry Pi用作Mac的联网时光机驱动器

raspberry pi

raspberry pi

raspberry-pi-time-machine-mac

Why spend $300 on an AirPort Time Capsule when you can make one yourself with a Raspberry Pi and an external hard drive? It takes a little tweaking, but once it’s all set up, your Mac will back up automatically, without any effort on your part. No more having to plug a drive into your computer.

当您可以使用Raspberry Pi外部硬盘驱动器制作自己的产品时,为什么还要花300美元购买AirPort Time Capsule? 进行一些调整,但是一旦完成所有设置,您的Mac将自动备份,而无需您费力。 无需再将驱动器插入计算机。

Even better: when it comes time to restore files, you can unplug the hard drive from the Pi and plug it directly into your Mac, allowing you to recover from a total system failure using System Recovery. Similar hacks do not work this way.

更好的是:当需要恢复文件时,您可以从Pi上拔下硬盘驱动器,然后将其直接插入Mac,从而可以使用System Recovery从整个系统故障中恢复。 类似的黑客无法通过这种方式工作。

你需要什么 (What You’ll Need)

We’ve shown you how to back your Mac with Time Machine, and even how to perform Time Machine backups over the network. But in those tutorials, backing up over the network required another Mac acting as a server. So if you live in a single-Mac household, you might think your only option it to plug in a USB hard drive or buy a $300 Apple Time Capsule.

我们向您展示了如何使用Time Machine备份Mac ,甚至如何通过网络执行Time Machine备份 。 但是在这些教程中,通过网络备份需要另一台Mac作为服务器。 因此,如果您住在单Mac家庭中,您可能会认为唯一的选择是插入USB硬盘驱动器或购买300美元的Apple Time Capsule。

That’s not true. The Raspberry Pi connected to an external hard drive makes for a great improvised alternative to a Time Capsule or another Mac, and it’s much cheaper. (Yes, the Time Capsule does include router functionality, so it’s actually a decent price for what it offers–but this method lets you use whatever router you want, and offers more room for upgrades when your drive runs out of space.)

这不是真的。 连接到外部硬盘驱动器的Raspberry Pi可以作为Time Capsule或其他Mac的简易替代品,而且便宜得多。 (是的,Time Capsule确实包含路由器功能,因此实际上它提供的功能价格是合理的–但是此方法可让您使用所需的任何路由器,并在驱动器空间不足时提供更多的升级空间。)

This tutorial assumes you already know the basics of how to set up a Raspberry Pi. It also requires a little bit of equipment:

本教程假定您已经了解如何设置Raspberry Pi的基础知识。 它还需要一点设备:

  • A Raspberry Pi. Any model will do, but the current model is the Raspberry Pi 3 Model B.

    Raspberry Pi。 任何模型都可以,但是当前模型是Raspberry Pi 3 Model B。

  • An SD card, for the Raspberry Pi’s operating system. Older Raspberry Pis will use a standard SD card, while newer ones will require a microSD card, so make sure to get the right kind. Here’s a great list of cards tested to work well the Pi.

    SD卡,用于Raspberry Pi的操作系统。 较旧的Raspberry Pis将使用标准的SD卡,而较新的Raspberry Pis将需要microSD卡,因此请确保使用正确的SD卡。 这是一个经过测试可以很好地与Pi搭配使用的显卡的好清单

  • A Power supply for the Pi. The Pis power port is just microUSB, but we recommend getting a power supply designed for the Pi for reliable performance–this one from CanaKit works well.

    Pi的电源。 Pis的电源端口仅为microUSB,但我们建议您使用专门为Pi设计的电源,以获得可靠的性能-CanaKit的该电源可以很好地工作。

  • A wired network connection for your Pi (you could use Wi-Fi, but it takes more setup and wired is going to be much better for those big over-the-network backups)

    Pi的有线网络连接(您可以使用Wi-Fi,但需要更多设置,对于大型的网络备份,有线连接会更好)
  • An external hard drive, which you’ll connect to the Pi over USB. We recommend getting a desktop external hard drive with its own dedicated power supply, unless you have a USB-powered drive that’s been tested working with the Pi.

    外部硬盘驱动器 ,您将通过USB将其连接到Pi。 我们建议您使用带有专用电源的台式机外置硬盘驱动器,除非您具有经过测试可与Pi搭配使用的USB供电的驱动器。

You can get most of this stuff (and more) in one fell swoop with a good Raspberry Pi starter kit like this one, or you can buy them separately. Your call.

您可以使用类似这样的优质Raspberry Pi入门套件,一口气获得大部分(或更多)这些东西,也可以单独购买。 您的来电。

I found out about this method from a blog post by Caleb Woods, and filled in a few things that didn’t work for me by reading this post on Badbox.de. My sincere thanks to both of you.

我从Caleb Woods的博客文章中找到了关于这种方法的信息 ,并通过在Badbox.de上阅读了这篇文章 ,填补了一些不适用于我的东西 。 我衷心感谢你们俩。

One final note: this hack works quite well in my experience, but at the end of the day it’s still just that: a hack. For this reason, I recommend having some sort of backup besides this, preferably something offsite. (You should always have an offsite backup anyway, in case of fire or other natural disaster.)

最后一点:根据我的经验,这种技巧非常有效,但最终还是这样:一种技巧。 因此,我建议除此以外还应进行某种备份,最好是异地备份。 ( 无论如何 ,在发生火灾或其他自然灾害的情况下, 始终始终具有异地备份 。)

第一步:为Time Machine准备外部驱动器 (Step One: Prepare the External Drive for Time Machine)

The first thing you need to do is prepare the external drive to work with Time Machine. Plug the drive into your Mac, then launch Disk Utility. Select your external drive, then click the “Erase” button. You’re going to want to format the drive as “Mac OS Extended”, also known as HFS+.

您需要做的第一件事是准备将外部驱动器与Time Machine一起使用。 将驱动器插入Mac,然后启动Disk Utility 。 选择您的外部驱动器,然后单击“擦除”按钮。 您将需要将驱动器格式化为“ Mac OS Extended”,也称为HFS +。

time-machine-create-partition

Next, we’re going to want to ensure that your Raspberry Pi, and every device, will have permission to control the drive. Head to the Finder, then right-click the drive in the sidebar. Click “Get Info”.

接下来,我们将要确保您的Raspberry Pi和每个设备都具有控制驱动器的权限。 转到Finder,然后右键单击侧栏中的驱动器。 点击“获取信息”。

mac-finder-get-info

At the bottom of the window that opens, you’ll find the permission settings.

在打开的窗口的底部,您将找到权限设置。

mac-finder-permissions

Click the lock at bottom right, then enter your password. Next, check “Ignore ownership on this volume.” And with that, you’re ready to connect your external drive to the Pi.

单击右下角的锁,然后输入密码。 接下来,选中“忽略该卷的所有权”。 这样,您就可以将外部驱动器连接到Pi了。

第二步:在您的Pi上安装Raspbian并通过SSH连接到它 (Step Two: Install Raspbian on Your Pi and Connect to It Over SSH)

Next, you’ll need to set up your Raspberry Pi with Raspbian, as outlined in this article. We won’t detail the process here, since it’s a project in and of itself, so go check out that guide to get Raspbian set up on your Pi. I used Raspbian Core for my setup, as I’ve not connected the Pi to a display, but there’s no reason the full, GUI version of Raspbian wouldn’t also work.

接下来,您需要使用Raspbian设置Raspberry Pi,如本文所述 。 由于它本身是一个项目,因此我们在这里不详细介绍该过程,因此请查阅该指南以在您的Pi上设置Raspbian。 我使用Raspbian Core进行设置,因为我没有将Pi连接到显示器,但是没有理由说完整的GUI版本的Raspbian也无法使用。

Speaking of which: you have two choices when it comes to the rest of this tutorial. You could hook your Raspberry Pi up to a keyboard and monitor and set things up that way, or you can connect to your Pi over SSH and run every step from the comfort of your Mac. We think the SSH method is much easier than finding a random monitor, so here’s how to do that.

说到这:本教程的其余部分有两种选择。 您可以将Raspberry Pi连接到键盘并进行监视和设置,也可以通过SSH连接到Pi,并在Mac上舒适地运行每一步。 我们认为SSH方法比找到随机监视器要容易得多,因此,这里介绍了这样做的方法。

mac-raspberry-pi-ssh

Launch the Terminal on your Mac, then enter the following command:

在Mac上启动终端,然后输入以下命令:

ssh pi@192.168.1.11

ssh pi@192.168.1.11

Replacing 192.168.1.11  with the IP address of your Pi. You can find the IP address of any device connected to your network, including your Raspberry Pi, by heading to your router’s web interface.

用您的Pi的IP地址替换192.168.1.11 。 通过转到路由器的Web界面,您可以找到连接到网络的任何设备 (包括Raspberry Pi) 的IP地址

You’ll then be asked for a password for the default user, pi . The password for pi is, by default, raspberry .

然后,将要求您提供默认用户pi的密码。 pi的密码默认为raspberry

If you’re connecting to a fresh system for the first time, I suggest you configure a few things before proceeding. First, run sudo raspi-config and change your default password. You can also expand your default filesystem here, if you have a large SD card (though this is not necessary for this tutorial.) Your Raspberry Pi will restart, at which point you’re ready to get to work.

如果您是第一次连接到新系统,建议您在继续之前配置一些配置。 首先,运行sudo raspi-config并更改您的默认密码。 如果您有大SD卡,也可以在此处扩展默认文件系统(尽管对于本教程来说不是必需的。)您的Raspberry Pi将重新启动,此时您可以开始工作了。

第三步:安装外部驱动器 (Step Three: Mount Your External Drive)

Before you can set up your Time Machine, you need to mount the drive so your Raspberry Pi can read and write to it. Doing this requires installing some software. First, make sure all the software on the Pi is up to date. Run these two commands, one after the other:

在设置Time Machine之前,您需要安装驱动器,以便Raspberry Pi可以对其进行读写。 为此,需要安装一些软件。 首先,确保Pi上的所有软件都是最新的。 运行以下两个命令,一个接一个:

sudo apt-get update

sudo apt-get update

sudo apt-get upgrade

sudo apt-get upgrade

Next, install two packages: hfsprogs and hfsplus. These will let your Raspberry Pi read your Mac-formatted drive.

接下来,安装两个软件包:hfsprogs和hfsplus。 这些将使您的Raspberry Pi读取Mac格式的驱动器。

sudo apt-get install hfsprogs hfsplus

sudo apt-get install hfsprogs hfsplus

time-pi-install-hfs-plus

You now have software capable of mounting your drive, but it needs to know which drive to mount, so you’ll need to do some research. Start by launching Parted.

现在,您已经具有可以安装驱动器的软件,但是它需要知道要安装哪个驱动器,因此您需要进行一些研究。 首先启动Parted。

sudo /sbin/parted

sudo /sbin/parted

Next, type print to see a list of currently connected drives. You should see your external drive here.

接下来,键入print以查看当前已连接驱动器的列表。 您应该在这里看到外部驱动器。

time-pi-hard-drive

From this screenshot, we can see that my drive is a 164GB Maxtor drive (I’ll get a bigger one later, I promise.) The important bit of information here is /dev/sda. your drive will have a similar name, which you should write down.

从此屏幕截图中,我们可以看到我的驱动器是164GB的Maxtor驱动器(我保证以后会更大)。这里重要的信息是/dev/sda 。 您的驱动器将具有类似的名称,您应该写下来。

Next, look at the table below that block of text. In my case, it’s obvious that the second, larger partition is what I’m looking for. Therefore, I make note that the partition I want to mount is sda2. You might need a slightly different figure, if you have more than one drive or more than one partition on your drive.

接下来,查看该文本块下方的表。 就我而言,很明显,第二个更大的分区是我要寻找的。 因此,请注意我要挂载的分区是sda2 。 如果驱动器上有多个驱动器或多个分区,则可能需要稍有不同的数字。

Now that you have the information you need, type quit and press Enter. Next, we’re going to make a folder that will serve as our mount point…

现在,您已拥有所需的信息,键入quit并按Enter。 接下来,我们将制作一个文件夹作为我们的挂载点…

sudo mkdir -p /media/tm

sudo mkdir -p /media/tm

…and then add some information to the fstab file. Use this command to open a text editor:

…然后将一些信息添加到fstab文件中。 使用此命令打开文本编辑器:

sudo nano /etc/fstab

sudo nano /etc/fstab

Paste the following line into the document, replacing /dev/sda2 with your drive’s partition, if different from /dev/sda2.

将以下行粘贴到文档中,如果与/ dev / sda2不同,则将/dev/sda2替换为驱动器的分区。

/dev/sda2 /media/tm hfsplus force,rw,user,auto 0 0

/dev/sda2 /media/tm hfsplus force,rw,user,auto 0 0

time-pi-fstab

Once you’ve pasted the text, press Control+X to leave the editor, making sure to save when you do.

粘贴文本后,请按Control + X退出编辑器,并确保保存后再保存。

Then, mount the drive with:

然后,通过以下方式安装驱动器:

sudo mount -a

sudo mount -a

If you don’t see an error message, congratulations! You’ve successfully mounted your drive.

如果您没有看到错误消息,那么恭喜! 您已成功安装驱动器。

第三步:编译并安装Netatalk (Step Three: Compile and Install Netatalk)

Netatalk is a piece of software that simulates AFP, the network protocol Apple currently users for Time Machine backups. You can install an ancient version of Netatalk using sudo apt-get install netatalk , but I highly recommend that you do not do that. For (largely political) complex reasons, Debian–which Raspbian is built on–offers a very outdated version of Netatalk in its repositories. You can kind of get Time Machine to work using this outdated version of Netatalk, but in my experience it’s frustrating.

Netatalk是一款模拟AFP的软件,AFP是Apple目前用于Time Machine备份的网络协议。 您可以使用sudo apt-get install netatalk旧版本的Netatalk,但我强烈建议您不要这样做 。 出于(主要出于政治原因)复杂的原因,Raspbian构建于其上的Debian在其存储库中提供了非常过时的Netatalk版本。 您可以使用此过时的Netatalk版本使Time Machine正常工作,但以我的经验,这令人沮丧。

So, I recommend you compile the latest version instead. It is more of a hassle to install, but it’s worth it.

因此,我建议您改为编译最新版本。 安装起来比较麻烦,但是值得。

First, you need to install the dependencies. Here’s everything you need to install, in one command:

首先,您需要安装依赖项。 这是您需要在一个命令中安装的所有内容:

sudo aptitude install build-essential libevent-dev libssl-dev libgcrypt11-dev libkrb5-dev libpam0g-dev libwrap0-dev libdb-dev libtdb-dev libmysqlclient-dev avahi-daemon libavahi-client-dev libacl1-dev libldap2-dev libcrack2-dev systemtap-sdt-dev libdbus-1-dev libdbus-glib-1-dev libglib2.0-dev libio-socket-inet6-perl tracker libtracker-sparql-1.0-dev libtracker-miner-1.0-dev

sudo aptitude install build-essential libevent-dev libssl-dev libgcrypt11-dev libkrb5-dev libpam0g-dev libwrap0-dev libdb-dev libtdb-dev libmysqlclient-dev avahi-daemon libavahi-client-dev libacl1-dev libldap2-dev libcrack2-dev systemtap-sdt-dev libdbus-1-dev libdbus-glib-1-dev libglib2.0-dev libio-socket-inet6-perl tracker libtracker-sparql-1.0-dev libtracker-miner-1.0-dev

This might take a while to install. Next, download the latest version of Netatalk. As of this writing, that’s 3.1.10, though you may want to check netatalk’s home page to get the latest version number. Then, run this command to download it:

安装可能需要一段时间。 接下来,下载最新版本的Netatalk。 在撰写本文时,它是3.1.10,尽管您可能要检查netatalk的主页以获得最新的版本号。 然后,运行以下命令将其下载:

wget http://prdownloads.sourceforge.net/netatalk/netatalk-3.1.10.tar.gz

wget http://prdownloads.sourceforge.net/netatalk/netatalk-3.1.10.tar.gz

Replace the version number if you find a later version on their site.

如果在他们的站点上找到更高版本,请替换版本号。

Now, unpack the file you downloaded with:

现在,解压缩下载的文件:

tar -xf netatalk-3.1.10.tar.gz

tar -xf netatalk-3.1.10.tar.gz

Then switch to the new folder you just created.

然后切换到刚创建的新文件夹。

cd netatalk-3.1.10

cd netatalk-3.1.10

Next, you can configure all of netatalk’s settings before compiling the program, by using this command:

接下来,您可以使用以下命令在编译程序之前配置netatalk的所有设置:

./configure \
        --with-init-style=debian-systemd \
        --without-libevent \
        --without-tdb \
        --with-cracklib \
        --enable-krbV-uam \
        --with-pam-confdir=/etc/pam.d \
        --with-dbus-daemon=/usr/bin/dbus-daemon \
        --with-dbus-sysconf-dir=/etc/dbus-1/system.d \
        --with-tracker-pkgconfig-version=1.0

time-pi-compile-netatalk

Assuming you don’t see any error messages, you can move on to the next stage and run:

假设您没有看到任何错误消息,则可以进入下一阶段并运行:

make

make

This is going to take a while. You might as well make yourself a coffee, some scones, and a three course meal. A Raspberry Pi is not fast at compiling software.

这将需要一段时间。 您不妨自己煮咖啡,烤饼和三道菜。 Raspberry Pi编译软件的速度并不快。

When everything is done, you can finally install Netatalk:

完成所有步骤后,您最终可以安装Netatalk:

sudo make install

sudo make install

Wasn’t that fun? Quickly check that Netatalk is actually running:

那不是很有趣吗? 快速检查Netatalk是否正在实际运行:

netatalk -V

netatalk -V

You’ll see a bunch of information about your Netatalk setup. If everything looks good, let’s configure things!

您将看到有关Netatalk设置的大量信息。 如果一切看起来不错,让我们进行配置!

第四步:配置Netatalk (Step Four: Configure Netatalk)

Now that Netatalk is installed, you need to tell it to share your drive. First up, you’ll need to edit nsswitch.conf.

现在已经安装了Netatalk,您需要告诉它共享驱动器。 首先,您需要编辑nsswitch.conf

sudo nano /etc/nsswitch.conf

sudo nano /etc/nsswitch.conf

Here you need to add mdns4 and mdns to the line that starts with “hosts:”, so that it looks like this:

在这里,您需要在以“ hosts:”开头的行中添加mdns4mdns ,使其看起来像这样:

hosts: files mdns4_minimal [NOTFOUND=return] dns mdns4 mdns

hosts: files mdns4_minimal [NOTFOUND=return] dns mdns4 mdns

time-pi-fstab

This tweak means your Time Machine drive will show up in Finder’s sidebar as soon as you connect your Raspberry Pi to the network.

此调整意味着将Raspberry Pi连接到网络后,您的Time Machine驱动器将立即显示在Finder的侧栏中。

Next, you’ll need to edit afpd.service:

接下来,您需要编辑afpd.service

sudo nano /etc/avahi/services/afpd.service

sudo nano /etc/avahi/services/afpd.service

Copy this block of text and paste it into that file:

复制此文本块并将其粘贴到该文件中:

<?xml version="1.0" standalone='no'?><!--*-nxml-*-->
<!DOCTYPE service-group SYSTEM "avahi-service.dtd">
<service-group>
    <name replace-wildcards="yes">%h</name>
    <service>
        <type>_afpovertcp._tcp</type>
        <port>548</port>
    </service>
    <service>
        <type>_device-info._tcp</type>
        <port>0</port>
        <txt-record>model=TimeCapsule</txt-record>
    </service>
</service-group>

Among other things, this information makes your Raspberry Pi mimic an actual Apple Time Capsule, complete with the appropriate icon.

除其他外,这些信息使您的Raspberry Pi模仿实际的Apple Time Capsule,并带有相应的图标。

Finally, it’s time to set up your external drive as a network share.

最后,是时候将外部驱动器设置为网络共享了。

sudo nano /usr/local/etc/afp.conf

sudo nano /usr/local/etc/afp.conf

At the bottom of this document, paste the following text:

在此文档的底部,粘贴以下文本:

[Global]
  mimic model = TimeCapsule6,106

[Time Machine]
  path = /media/tm
  time machine = yes

You can put a different name than “Time Machine” between the second brackets, if you want. This will change the name of the drive you back up to, as shown in Finder and Time Machine itself.

如果需要,可以在第二个括号之间放置一个不同于“ Time Machine”的名称。 这将更改您备份到的驱动器的名称,如Finder和Time Machine本身所示。

Finally, go ahead and launch the network services. In order, run these two commands:

最后,继续并启动网络服务。 按顺序运行以下两个命令:

sudo service avahi-daemon start sudo service netatalk start

sudo service avahi-daemon start sudo service netatalk start

Your drive is now offered on the network. To make sure this happens every time you start up your Raspberry Pi, enter these commands, again, one after the other:

您的驱动器现在已在网络上提供。 为了确保每次启动Raspberry Pi时都会发生这种情况,请一次又一次输入以下命令:

sudo systemctl enable avahi-daemon sudo systemctl enable netatalk

sudo systemctl enable avahi-daemon sudo systemctl enable netatalk

We’re really close now!

我们现在真的要关闭了!

第五步:连接到您的时间机器 (Step Five: Connect to Your Time Machine)

Head to the Finder on your Mac and you should see your Raspberry Pi here.

转到Mac上的Finder,您应该在这里看到Raspberry Pi。

finder-raspberry-pi

You can actually connect from here, by clicking “Connect As” and entering the same username and password you use to connect over SSH.

您实际上可以从此处进行连接,方法是单击“连接为”,然后输入用于通过SSH连接的用户名和密码。

In my experience, however, Time Machine works better if you connect to the drive through its IP address, especially if you’ve set up static IP addresses with your router (which you probably should). To connect, open Finder, then hit Command+K on your keyboard.

但是,以我的经验,如果您通过驱动器的IP地址连接到驱动器,则Time Machine会更好地工作,尤其是如果您已经用路由器设置了静态IP地址 (您应该这样做)。 要进行连接,请打开Finder,然后按键盘上的Command + K。

time-machine-pi-ip-address

Once you’ve mounted the drive, head to System Preferences > Time Machine, then select the drive as your Time Machine backup.

安装驱动器后,转到“系统偏好设置”>“ Time Machine”,然后选择驱动器作为“ Time Machine”备份。

time-machine-working

The initial backup will run, and after that backups will happen every hour. You now have a networked Time Machine drive. Enjoy!

初始备份将运行,然后备份将每小时进行一次。 现在,您有一个联网的Time Machine驱动器。 请享用!

翻译自: https://www.howtogeek.com/276468/how-to-use-a-raspberry-pi-as-a-networked-time-machine-drive-for-your-mac/

raspberry pi

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值