A Pocketful of Perforce: Setting Up Perforce Services on a Raspberry Pi

Sep 22, 2014

Introduction

Is it feasible to use the Raspberry Pi as a Perforce Server?

In this article, we will set up a Raspberry Pi, using the Raspbian distribution, including the Perforce server and client, along with Git Fusion!

Once we have our Perforce server configured, we will import some projects and view the results from a client workstation.

Caveat Emptor

The Raspberry Pi is not an officially supported computing platform for Perforce products. This means that any experiments mentioned here should be considered as just that – experiments.

If you want to set up a real production Perforce server, use a supported platform.

Nuff’ said. Now let’s have some fun!

Why Pi?

Outside of the cool factor, are there any practical reasons you might want to use the Raspberry Pi with Perforce?

  • One obvious reason is to experiment with Perforce server configurations. Once you have an SD card with your base Perforce tools installed, you can easily duplicate it and then set up multiple servers in order to experiment with Perforce replication, edge, brokering, and other Perforce server technologies.
  • Use Git Fusion on your Pi to provide a Git server interface to Perforce, import your favorite Git-based open source projects, and share them with your friends. Use Perforce visual tools to view the Git sources, and experiment with horizontally scaling your Git repositories onto multiple Perforce replicas.
  • The Raspberry with a lightweight case weighs in at only about 3.5 oz., and so is ideal as a portable demo device. It has HDMI and Standard video outputs, and so can easily be hooked up to a projector in order to do training or demonstrations.
  • Run as a headless server once your complete your initial configuration. You don’t really need a desktop or keyboard when using the Pi as a server – ssh is all you need to maintain it, and you can use the p4 command or p4v and other Perforce visual tools to do source operations remotely.
  • Buy a couple, keep one at work, and one at home. Then you can carry your server back and forth on a tiny SD card.
  • For larger configurations, you can hook up an SSD drive to one of the Pi’s USB ports, or use a high performance USB stick for file storage.

In general, it is nice to have a standalone system, unencumbered by other requirements that often weigh down a laptop or desktop computing environment. If one of your experiments goes wrong, just write a new card and start over.

Tips on Setting up the Raspberry Pi Hardware

Selecting an SD Card

If you are unfamiliar with Pi quirks, one thing you want to do is to purchase a good quality SD card.

There are only two cards I have found that perform well with the Raspberry, and both carry the Sandisk label (SD or micro SD): 1) Sandisk Extreme, and 2) Sandisk Extreme Pro.

The Sandisk cards are the only cards I have tested that have reasonable random access read/write performance, which is critical to get good overall performance on the Pi.

If you use a different brand, be sure to benchmark it for random i/o performance. You may be surprised by how poorly most consumer SD cards perform on this benchmark.

If you decide to use a USB drive for your root file system, then the performance of the SD card is not so important, since it will only be used for the initial boot.

You will need a 4GB or larger SD card for the current Raspbian distribution.

Monitor

You will probably want a monitor or projector with an HDMI connector. You can get by with the RCA-style video composite if you do not have HDMI available.

Once you perform the initial setup, you can disconnect the monitor and access the Pi via ssh.

If you are lucky enough to have a monitor with a powered USB hub and an HDMI connector with audio, you can use it to both power the Pi and add in USB peripherals with a minimum of fuss.

Power

You will need a USB cable with a micro connector at one end to supply power to the Pi. This type of cable is used to charge many phones and tablets.

You will also need a 1 amp or better USB power supply. Lower amperage power adaptors can cause instability in the Pi. If you are planning to attach anything to the USB port, use a 2A power supply.

Keyboard and Mouse

It is helpful to have a low power USB keyboard for initial setup. After that, you can use ssh to access the Pi for most operations.

Most modern USB keyboards will draw .5A or less power, but beware of the old ones you have laying around – I once hooked up an old keyboard that drew nearly 1A, and it made the Pi unstable.

The keyboard is not essential if you know the IP address of the Raspberry Pi – you can ssh in and run sudo raspi-config from the terminal.

Wi-Fi or Wired

While it is tempting to add USB Wi-Fi adaptor to your Raspberry, the Wi-Fi transmitters pull a lot of power from the USB bus, and may cause the Raspberry to crash unless you add a powered USB hub for the Wi-Fi adaptor.

My advise its to stick with the built-in Ethernet connection, unless you are familiar with the Wi-Fi issue, or are planning on using a powered hub. Plug the Wi-Fi adaptor into the powered hub, not the Pi.

Note: at the time of this writing, the new Rev2 B+ Raspberry Pi had just been released. This model is largely unchanged, except that it now has 4 USB ports, and additional circuitry to protect the Pi from power hungry USB peripherals. You can add a beefier 2A power supply to power Wi-Fi and other peripherals, and configure the Pi to allow up to 1.2A to be drawn from the 4 USB ports (instructions below). This should make Wi-Fi more practical.

Overclock?

The Raspberry Pi CPU is an ARMv6 processor clocked at a stately 700 MHz. You may be tempted to clock it higher, and many users have reported success running it at up to 1GHZ. If you are inclined, go ahead and try it after you get the base install finished (you can do it easily from the raspi-config utility, which is run automatically the first time you launch Raspbian). Make sure you have an adequate power supply, and enough heat dissipation to support the higher speed. If it is unstable, back it down.

SSD?

It is possible to use the SD card to boot to a secondary SSD drive attached to one of the Pi’s USB ports. Should you do it?

Most SSD drives consume about 1A of power during write activity, which makes a USB hub mandatory for model A and B. However, the new B+ model can supply enough power if you configure the USB ports to supply up to 1.2A. This involves a simple configuration change to /boot/config.txt:

safe_mode_gpio=4
max_usb_current=1

You can easy install your Raspbian OS on a USB drive (see procedure below). The performance of the SSD drive will improve the overall performance of the Pi. I/O performance will still limited by the USB port, however, and so don’t expect SATA performance on your benchmarks.

You can also keep the base OS on your SD card, and just use the SSD drive for additional storage. This is simple and easy, and in terms of Perforce, would give you adequate storage to create a very large repository on more secure storage. However, you lose the benefit of having faster i/o for the root file system.

USB Stick?

Newer USB sticks have performance on a par with USB attached SSD drives, and they now come in larger capacities of 128GB or more. They also draw less current than SSD drives, and so provide a very nice alternative.

All procedures you can do for an SSD drive also apply to USB sticks. You will want to find a fast USB drive – I have tested the Sandisk Extreme sticks, and they benchmark well. Other brands are also good – check the reviews. In general, the newer USB sticks are much faster than previous generations.

Remember that USB ports on the Pi are clocked at USB 2.0 speeds (480 Mbit/s), and so that limitation will likely determine the maximum i/o rates you achieve when using the latest crop of speedy USB flash drives.

Installing the Perforce Server

The Git Fusion image I have prepared already contains the Perforce server and client, so you can skip this step if you are doing the next…

Otherwise, first prepare a stock Raspbian image, using the instructions here. Then download p4d and p4 Perforce server and command line executables from this location.

Note: the “el” binaries are for an ARM processor with software floating point. They will not take advantage of the hardware floating point on the Pi. This makes very little if any difference in performance, so not to worry.

For additional hints, please see my colleague Liz Lam’s earlier post on setting up p4d on the Raspberry Pi, entitled “Run P4D and Your Website on a Raspberry Pi”.

A Git Fusion Flavored Pi

Git Fusion is not officially supported on the Raspberry Pi, but it works fine, albeit quite a bit slower than on a supported 64-bit platform. So let’s give it a try!

To install Perforce with Git Fusion, just download the customized Raspbian image, copy it to an SD card, insert it in your Raspberry Pi, and apply power.

From this point, just follow the normal instructions for installing a Raspbian disk image located here - for example, on Mac OS X:

$ curl –O https://swarm.workshop.perforce.com/download/guest/russ_tremain/p4blogs/perforcefulpi/images/git-fusion-14-1-base-conf0.zip
$ unzip git-fusion-14-1-base-conf0.zip (or double-click in Finder)
$ diskutil list (to discover where the SD card is mounted.)
$ diskutil unmountDisk /dev/diskN  (unmount without eject!)
$ dd  bs=256k if=git-fusion-14-1-base-conf0.img of=/dev/rdiskN
$ diskutil eject /dev/diskN

Where N is the disk number. Note the use of the raw disk device in the dd command – this speeds the copy up quite a bit. Using this procedure, it takes me about 90 seconds to write the image to the SD card.

First Boot

The first time you boot your new Raspbian image, it is a good idea to hook up a monitor to observe the process (though it is not absolutely necessary, as long as you can figure out the IP address of the Pi).

The raspi-config screen will automatically launch. You will want to configure your time zone (under International), and set your Overclock parameters. I’ve had good luck with setting the maximum 1GHZ “turbo” overclock rate, but your mileage may vary.

If you are going to stay with the SD root file system, then you will also want to expand the file system, and raspi-config will do it for you. If you are planning on copying your root file system to a USB drive (see below), then don’t expand the file system – we will do this afterwards.

Moving Your SD Image to a USB Drive

Once you have your Raspbian image installed on the SD card, it is easy to move your root partition to an USB drive. As mentioned above, this will give you a significant boost in i/o performance.

Remember the caveats about undersupplying voltage to the USB device. I’ve had success with SSD drives on the new Raspberry B+, using a 2A power supply, and configuring the 1.2A limit for the USB ports (instructions above). You will need a powered USB hub for older Pi’s.

The boot partition must remain on the SD card – this is a peculiarity of the Raspberry Pi.

The procedure I followed is here.

Note that it is not necessary to change the swap size, or do some of the other steps listed. I also opted to use dd command to copy the root file system to the usb partition, and then resize it afterwards, which was very fast compared to the suggested method (rsync). For example, if your USB partition is /dev/sda1, the procedure would be:

$ sudo dd if=/dev/root of=/dev/sda1 bs=256k
$ sudo e2fsck -f /dev/sda1 (correct any minor errors, due to copying a live root)
$ sudo  resize2fs -p /dev/sda1 (expand the new root to the partition size)

I would recommend identifying your volume using the GUID as outlined in the procedure. Otherwise you will have to worry about Linux changing the name of your root partition if you plug in another USB devices, which will render the system unbootable.

If your system does become unbootable for any reason, just rewrite the SD card and start over – there is no way to edit the boot parameters from the Raspbian console. You can mount and edit the SD boot partition on another system if you know how, but it will probably take longer than just rewriting the card and editing the boot files from within Raspbian.

Installing P4V

If you have not installed P4V and P4 on your workstation, do so now. Both can be downloaded for free from our homepage - look for Clients & Integrations under Products.

Testing P4D on Your Git Fusion Pi

Now that you have your Pi all set up, you have the option to start adding source projects to your depot. Just set P4PORT to point to port 1666 on the Pi, for example:

Export P4PORT
P4PORT=raspberrypi:1666 (replace “raspberrypi” with correct host or IP address.)

Then fire up P4V on your workstation, create a client, and submit some content.

If you want to work directly on the Pi, there are three Linux accounts already set up: pi, git, and perforce. They all have the same password, which is raspberry – the default password for a new Pi. There is no security on the Perforce server initially, so in order to add a perforce account for yourself:

$ p4 –u super user –f <your name>

Alternatively, you can use Git to import your favorite open-source projects. For this, please see my earlier DevTalk, and in particular, the demo section where I import one of my open-source projects into Perforce using Git Fusion, and then proceed to split it up into multiple repositories for different engineering teams – a technique we call “slice and dice”. You might also find my blog series, “Using Git as an API for Perforce”, part one and part two, useful for exploring your new Git Fusion Pi.

Pi Squared

You’ve now set up one Raspberry Pi, but more importantly, you have a method for making another in about 90 seconds, by simply copying the Perforceful Raspbian image to another SD card, and booting up the new Pi.

Try setting up a second Pi as a replica server for the first one, using these instructions from the Perforce Administrator’s Manual.

Another idea is to point the Git Fusion on one Pi to use the Perforce server on the other Pi, so that they don’t compete with each other for system resources.

Finally, you may want to spend some time learning the commands to secure the Perforce server - for that, look for the p4 protect command, documented here, and also the section in the Git Fusion manual on “Setting up Users”, found here.

Summary

In this article, we set up a Perforce Server and Client tools, including Perforce Git Fusion, on a $35 ARM based computer. While not the most practical setup for a development team, the Pi performed adequately to support a portable development environment that can be carried around on a small SD camera card or USB thumb drive.

Setting up one Perforceful Pi is an excellent way to learn Perforce administration without impacting anyone else. Add another Pi, and now you have a cluster, where you can experiment with replication and other advanced server features. Of course, you could set up multiple VM instances, but somehow that just doesn’t seem to be as much fun.

By the way, if you every get tired of running Perforce on your Pi, you can always convert it to be an XBMC server and hook it up to the back of your HDTV. But that’s a story for another blog!

Posted In: 
perforce's picture
About the author:

Perforce’s version management technology increases productivity, improves software quality, and helps reduce the complexity of global environments. Our solutions scale up to meet the needs of the most demanding environments, yet remain simple and intuitive for individuals to use for their personal projects.

See all posts by