01

0 74820 58049 3 US$ 15.99 CAN$ 17.99 Issue 206 Jan 2018

work with with work Stacer Clean up your Linux system Making Secure Boot Secure Making SAFER BOOT BOOT SAFER

ragment synthesizer qutebr Storyboarder CoreFreq F Tutorials ffmpeg • • • • 1.0 owser • FOSSPicks and lots of lots and timelyother tools useful and

DDoS Attack Avoiding a denial of service nightmare

MANAGER

JANUARY 2018 JANUARY USB PASSWORD PASSWORD USB

Build a stairway Build a stairway heaven to maker Pi FM Radio

 FOSS Communities Rights Equal Need

INSIDE! Double-Sided DVD Double-Sided

Automated Backup Tools

5

Phipps: Marketing Free Marketing Digitize Your LPs with Audacity Your Digitize

WWW.LINUXPROMAGAZINE.COM

startup process

Keeping control of the Keeping runs from the firmware

Add a custom app that Add a custom app that UEFI Tricks

• SAFER SAFER

BOOT

DVD FREE

LINUX PRO MAGAZINE ISSUE 206 JANUARY 2018 Safer Boot UEFI Shim TPM Backup Tools Stacer DDoS Attacks Pi FM Radio Volumio 2 FOSS Marketing Audacity ffmpeg

EDITORIAL Welcome TOMORROW’S NEWS Dear Reader,

When I started working for this magazine, way back in 2004, of lobbyists and marketing professionals who keep chipping Linux was really picking up momentum. That was back in away at public opinion when everyone else has gone back to those years when every year was supposed to be “the year of their day jobs. the Linux desktop,” and the Linux vs. Windows battle Software has no shape or solid edges. The value of a software was revving to a full burn. product is simply what whoever owns it says they will charge One of the best examples of the Linux juggernaut was the city you for it. If you try to buy a Windows desktop system as a of , which declared it would be transitioning all its single user, you get one price. If you buy a large number of li- computers to Linux in 2004. We at Linux New Media were censes, you get a different price, depending on how much Mi- particularly excited about this move because, at the time, the crosoft wants to close the deal. In the case of Munich, Micro- world headquarters of our small company was located in Mu- soft really really really didn’t want to see this major European nich, and our German colleagues were part of that ground- city become a test case for . swell of Linux support that launched the transition. Ultimately, though, one city flipping back to Windows isn’t Over the years, the City of Munich worked hard on Linux inte- such a big victory for – or a big defeat for Linux. Is a gration, even maintaining their own city government really the best place for Linux to make its (LiMux, an derivative) and building their own LibreOf- mark? Linux is secure and efficient, and it will save you fice extension set (WollMux). The move to Linux was officially money, but you have to tune in to it – you have to make a real completed in 2013, but the solution still never really settled in. effort to make it work in a world where Windows is still very Now, 13 years after the announcement that Munich was much the default for non-technical users. switching to Linux, they have decided they are switching back Linux has all kinds of success stories in the corporate sector, to Windows. The move has been brewing for some time, with where energy and innovation translate more fluidly into profit city officials signaling it might happen for a couple years. and career advancement. Companies like Red Hat, SUSE, Ca- What happened with Linux in Munich? It depends on who you nonical, and IBM make billions of dollars installing Linux sys- ask. In a blog post earlier this year, Björn Schießle of the Free tems (including Linux desktop systems) in Fortune 500 com- Software Foundation Europe wrote, “In 2014, Dieter Reiter panies around the world. On the server side, Linux is stronger was elected new mayor of Munich. He had referred to himself than ever, and even Microsoft has to acknowledge the impor- as ‘Microsoft fan’ even before he took office. He prides himself tance of Linux to the booming cloud and container business. with having played a major part in the decision to move the But really, regardless of how Munich or any other city Microsoft Germany headquarters to downtown Munich. He chooses to spend their IT budget, the truth is, all the things we started to question the LiMux strategy as soon as his term were fighting about back in 2004 were settled long ago. Desk- started, and asked Accenture, a Microsoft partner in the same top operating systems aren’t as important as we used to think building as Microsoft, to analyze Munich’s IT infrastructure.” they were. Microsoft doesn’t think Linux is a cancer anymore According to Accenture’s study (and to other observers), the (in fact, they say they love Linux), and everyone in IT is aware problems with Linux in Munich were mainly organiza- of the power and importance of Free Software. tional – not technical. Another issue identified by Linux crit- Like many in the Linux community, I have a feeling the people ics was the amount of city-government-related application of Munich are going to spend a lot more money in the long software that simply wouldn’t run on Linux, which meant run by climbing back into the proprietary software time ma- that the city found itself in the position of doing its own soft- chine, but hey, that’s tomorrow’s news. nnn ware development. (This, again, is not really a problem with Linux, but with the habits and priorities of the software de- velopment industry.) It probably would have helped if more cities had joined Mu- Joe Casad, Editor in Chief nich to spread the brainshare for development and imple- mentation knowledge. But then, the battle is never really over as long as a well-funded opponent has a stake in turning Info the tables. Environmental groups and historical preservation [1] LiMux: ://en.​­ wikipedia.​­ org/​­ wiki/​­ LiMux​­ groups have encountered the same scenario: Non-profit [2] WollMux: https://www.​­ wollmux.​­ net/​­ wiki/​­ Main_Page​­ communities can turn out lots of people with big hearts to [3] “What Happened in Munich”: wave placards, but a huge corporation can unleash an army https://fsfe.​­ org/​­ news/​­ 2017/​­ news‑20170301‑01.​­ en.​­ ​­

LINUX-MAGAZINE.COM | LINUXPROMAGAZINE.COM ISSUE 206 JANUARY 2018 3 LINUX MAGAZINE JANUARY 2018

WHAT'S INSIDE

This month we look at the Linux boot process and explore some COVER STORIES tools and tricks for better and safer startup, including the Shim first-stage bootloader and the Trusted Platform 14 UEFI 26 Trusted Platform Module The traditional BIOS dates back decades The Trusted Platform Module on your Module (TPM) chip. Other highlights and has not been able to keep up with computer’s motherboard could lead to include: the rapid development of PCs and better security for your Linux system. • DDoS Defense – Some laptops. Its powerful successor, UEFI, providers offer special takes over its tasks and provides more services aimed at thwarting features, more convenience, and better denial-of-service attacks. security. (page 46). • MakerSpace – Check out 20 Linux Secure Boot with Shim our articles on FM radio and The Shim bootloader lets Linux users regain some control over the Secure Boot Volumio audio playback on process. the Raspberry Pi. (page 58). Elsewhere up ahead, LinuxVoice looks at audio and video with Audacity and the FFmpeg command-line video editor, and Graham puts the focus on small stuff with minimal browsers NEWS REVIEWS and minimal text editors in this month’s FOSSPicks. 08 News 30 Automatic Backup • Samsung to bring Linux to the Backing up data is an unpopular task Galaxy phone that many users consider a chore. What • System76 releases Pop!_OS better reason for automation? We look • Linux comes to Windows at some command-line automatic SERVICE • Docker embraces Kubernetes backup tools. • We are under a Bad Rabbit 3 Comment attack 6 DVD 96 Featured Events 97 Call for Papers 11 Kernel News 98 Preview • I3C support • Fixing mmap() • Tracing RAM usage in OOM conditions

4 JANUARY 2018 ISSUE 206 LINUX-MAGAZINE.COM | LINUXPROMAGAZINE.COM LINUX MAGAZINE JANUARY 2018

IN-DEPTH MAKERSPACE

38 Stacer 58 Smart Cities Check out this handy graphical tool for Making the city of Messina, Italy, smarter cleaning up your Linux system. with open source and IoT.

60 Pi FM Radio TWO TERRIFIC Build a simple FM radio with a Raspberry DISTROS Pi, an RTL-SDR USB dongle, an LCD HAT, and some Python code DOUBLE-SIDED DVD! 64 Volumio 2 Volumio and a Raspberry Pi can add SEE PAGE 6 FOR DETAILS smart functions to any stereo system. The combination of smartphone control, a Raspberry Pi Display, and Volumio 70 Open Hardware – Signet 42 Programming Snapshot – outperforms many commercial solutions. At the intersection of free software and AI Sequences crowdfunding, a USB password manager Can intelligence tests devised by offers innovation in security. psychologists be cracked with modern AI state machines?

46 DDoS Defence To ward off DDoS attacks, websites and services often seek the protection of Internet giants, such as Amazon, but you have other ways to protect your connectivity.

50 Peek Create screencasts in the of an eye and then 75 Welcome 82 Digitizing Analog Music Media export them to This month in Linux Voice. Armed with the Audacity sound popular file editor, you can convert the analog formats. 76 The Universal Donor content of LPs, tapes, and cassettes Open source communities need to the digital world. 53 Charly’s Column – inxi equal rights. Charly’s latest tool may sound like the 86 FOSSPicks Teletubbies, but inxi provides detailed 77 Doghouse – FPGAs Graham looks at 1.0, and precisely controllable hardware Take some advice from Linus Min, Storyboarder, BorgBackup 1.1, and system usage information. Torvalds and learn how to program Argentum Age, and much more! an FPGA. 54 Command Line – Melt Whether you are an expert or a 78 OS Marketing beginner, you can learn to edit audio Marketing FOSS and video clips at the command line requires some with Melt. novel approaches compared with proprietary software. We 92 Tutorial – FFmpeg share our Sometimes video editing from the experiences. command line is better than using graphical tools.

LINUX-MAGAZINE.COM | LINUXPROMAGAZINE.COM ISSUE 206 JANUARY 2018 5 DVD This Month’s DVD On the DVD Ubuntu 17.10 Server and Desktop (64-bit) Ubuntu has come full circle and begins again at the top of the alphabet with Artful Aardvark. Version 17.10 is the last release before the 18.04 long-term support (LTS) version; as usual for semiannual releases, you get nine months of security and maintenance updates. This release features Linux kernel 4.13, which includes new KVM features and other enhancements. Instead of a partition, swap is now a file that scales to your needs. The Live Desktop version now comes with Gnome Shell and GDM as the default display manager. Wayland is the default display server, but the older display server is still available by choosing Ubuntu on Xorg from the cog on the login screen. Gnome Shell features a new settings application and a mov- able dock. Note that “USB printers do not get set up automatically and IPP-over-USB does not work at all. Please set up your USB printer using Devices | Printers” in Gnome Settings. For driver- TWO TERRIFIC less printing, connect your printer over Ethernet or WiFi or not DISTROS upgrade to 17.10 until the problem is fixed [3]. DOUBLE-SIDED DVD!

Additional Resources [1] Desktop: https://www.​­ ubuntu.​­ com/​­ ​ desktop/­ 1710​­ [2] Server: https://www.​­ ubuntu.​­ com/​­ ​ download/­ server​­ [3] Release notes: https://wiki.​­ ubuntu.​­ ​ Defective discs will be replaced. Please send an email to [email protected]. com/­ ArtfulAardvark/​­ ReleaseNotes​­

6 JANUARY 2018 ISSUE 206 LINUX-MAGAZINE.COM | LINUXPROMAGAZINE.COM

NEWS Updates on technologies, trends, and tools

THIS MONTH’S NEWS

Linux on Galaxy 08 • Samsung to Bring Linux to the Galaxy Phone

Ubuntu-Based Pop!_OS 09 • System76 Releases Pop!_OS • Linux Comes to Windows Samsung to Bring Linux to the Galaxy Phone • More Online The same year Canonical decide to pull out of the consumer space, Samsung is bringing a pure desktop Linux experience to PCs. Unlike Apple, Google, or Micro- Kubernetes Orchestrator 10 • Docker Embraces soft, Samsung doesn’t have any tightly integrated offering for professionals who Kubernetes need a desktop to get work done. Samsung came out with DeX, an accessory for Samsung Galaxy phones that connects with a monitor and offers a desktop-like in- • We Are Under Bad Rabbit Attack terface. It’s an experience similar to Ubuntu Dock or Motorola Atrix Webtop. However, the desktop experience was subpar compared with Mac OS or Windows. Samsung is now looking at desktop Linux for DeX. “Installed as an app, Linux on Gal- axy gives smartphones the capability to run multiple operating systems, enabling de- velopers to work with their preferred Linux-based distributions on their mobile devices. Whenever they need to use a function that is not available on the smartphone OS, users can simply switch to the app and run any program they need to in a Linux OS environment,” Samsung said in a press release. Samsung is quite ambitious about the project; the company is also luring developers, a market that already has a strong hold on desktop Linux. “Now developers can code using their mobile on-the-go and seamlessly continue the task on a larger display with Samsung DeX,” said the company. While it’s currently in the trial phase, Samsung plans to bring DeX to larger dis- plays. If it does gain mindshare, Samsung might even consider desktop Linux- powered laptops. One advantage Samsung has over traditional desktop Linux distributions is that Sam- sung owns the entire hardware chain, from touchscreen to storage. It will be relatively easier for Samsung to offer a fully polished desktop Linux experience compared with a community-based distro, where developers either rely on reverse engineering or are at the mercy of hardware vendors to offer drivers. Desktop Linux users may finally see the year of Linux. “Linux on Galaxy is made even more powerful because it is DeX- enabled, giving developers the ability to create content on a large screen, pow- ered only by their mobile devices. This represents a significant step forward for soft- ware developers, who can now set up a fully func- tional development environment with all the advantages of a desktop setting that is accessible anytime, anywhere. Samsung Linux on Galaxy is still a work in progress,” said Samsung. If you are interested in an early notification of availability, please sign up: https://seap.samsung.com/linux-on-galaxy.

8 JANUARY 2018 ISSUE 206 LINUX-MAGAZINE.COM | LINUXPROMAGAZINE.COM NEWS Linux News

MORE ONLINE System76 Releases Pop!_OS System76, one of the few hardware vendors that sell systems preloaded with Linux, Linux Magazine has released the final version of Pop!_OS, their own Ubuntu-based distribution. www.linux-magazine.com System76 CEO and founder Carl Richell told us in an interview that the OS is the re- sult of customer feedback. What makes Pop!_OS different from many other Linux Paw Prints • Jon “maddog” Hall distributions is that System76 sells Linux hardware, so they do have a very trusted Subutai: Peer-to-Peer, Private, Secure, Stable Cloud Software that Gives You Control channel of customer feedback. I have been using the equivalent of “Open System76 caters to professionals who use desktop Source” since 1969. I have never personally Linux for their workloads. In a press release, System76 used software from Apple or Microsoft either said that the OS is geared toward users in STEM, com- at home or (unless circumstances forced puter scientists, makers, and developers. During the re- me) at work. I resisted using closed-source lease of 3D-rendering software as open source, Pixar de- software of every type. velopers were spotted using System76 machines running . ADMIN HPC Pop!_OS is seen as a System76 response to Canonical’s http://hpc.admin-magazine.com/ withdrawal from the consumer space. Richell said that their current focus is on offering Exploring AMD’s Ambitious ROCm Initiative a very stable and minimalistic experience around Ubuntu and Gnome to cater to its Joe Casad customers. AMD’s ROCm platform brings new freedom Contrary to , Pop!_OS will be based on the latest Ubuntu instead of the and portability to the GPU space. long-term support (LTS) version. Richell said that they have been working with Ubuntu for more than 12 years, and they have all the needed expertise to keep up with It’s the Little Things • Jeff Layton Several very sophisticated tools can be used to Ubuntu. The good news is, now that Unity is discontinued, Ubuntu will focus on a rock manage HPC systems, but it’s the little things solid base that can be used in enterprise setups. Because Gnome is already mature, that make them hum. Here are a few favorites. it’s more predictable than Unity, making the job of System76 developers easy to tack to slow-moving stable targets. ADMIN Online The primary focus of System76 will be to offer a very polished experience on the http://www.admin-magazine.com/ machines, including hardware support and optimization. System76 is also working on Getting Data from AWS S3 via Python Scripts setting up their own manufacturing unit, where they will build desktops and laptops Mike Schilli in-house. Data on AWS S3 is not necessarily stuck there. Even though Pop!_OS is designed for System76 machines, it’s freely available for If you want your data back, you can siphon it anyone to use. out all at once with a little Python pump. You can download it from GitHub: https://github.com/pop-os. Credential Management with HashiCorp Vault Matthias Wübbeling Linux Comes to Windows Admin teams can use secret sharing to cen- trally manage shared access to user accounts Microsoft has announced that Windows Subsystem for Linux (WSL, also known as and services. HashiCorp Vault is one of the Bash on Windows) is now out of beta. With Windows 10 Fall Creator update, every few tools that has proven effective when it Windows user will be able to use the feature. However, WSL is not enabled by default. comes to implementing this solution. Users have to enable it from the Settings turn Windows features on or off feature. Microsoft will offer supported Linux distributions from the Windows Store, so A Hands-on Look at Kubernetes with OpenAI there is no need to install them manually. Some of the supported distros include Jonas Schneider openSUSE, SUSE Linux Enterprise, and Ubuntu. Fedora is expected to arrive For research into deep learning algorithms that automatically acquire new skills, OpenAI soon. Microsoft will offer official support for these distributions in partnership with operates some of the largest Kubernetes the respective distribution. clusters worldwide, with up to 36,000 CPU Customers can now run multiple Linux distributions, which means they can use cores. We look at some practical experience commands, utilities, and tools specific to different distributions. with the container management system. Although WSL is still in the works, it now supports USB mounts that gives develop- ADMIN DevOps Focus ers access to USB devices from Linux. http://www.admin-magazine.com/DevOps Microsoft is also bringing WSL to Win- DevOps with DebOps • Martin Loschwitz dows Server and Azure Cloud. “Using Ansible is a simple and sensible automation WSL, Windows Server administrators, solution as long as you don’t need to spend a DevOps engineers, developers, etc., will lot of time creating new roles and playbooks. be able to run their favorite Linux tools, DebOps is a convenient collection of Ansible apps, and scripts, alongside their favorite playbooks for -based Linux systems.

Image © Sergei Popov, 123RF.com Image © Sergei Popov, Windows admin tools. This will make it

LINUX-MAGAZINE.COM | LINUXPROMAGAZINE.COM ISSUE 206 JANUARY 2018 9 NEWS Linux News

easier than ever before to automate, control, manage, and deploy an ever broader portfolio of technologies and tools atop Windows Server,” wrote Microsoft Program Manager Rich Turner in a company blog. WSL is intended for developers who need native Linux tools to run and manage their Linux systems on Azure and other clouds; officially, it’s not intended for desktop users.

Docker Embraces Kubernetes At DockerCon Europe, Solomon Hykes, the founder of Docker, announced support for Kubernetes as an orchestration platform alongside Swarm, it's own orchestration tool. “The addition of Kubernetes as an option alongside Swarm gives our users and cus- tomers the ability to make an orchestration choice with the added security, manage- ment, and end-to-end Docker experience that they’ve come to expect from Docker since the very beginning. We look forward to working with the Kubernetes community to help users, partners, and customers achieve the full benefits of the containerization revolution,” said Hykes. The company said that through its integration with Docker EE, Kubernetes will be available across certified infrastructure platforms, including multiple Linux distributions (SLES, CentOS, RHEL, Ubuntu, ) and Windows, as well as all cloud platforms, including AWS and Azure. Developers running Docker on Mac and Win- dows will be able to use features like multistage builds and application composition (Docker Com- pose) in container development and have them run consistently from development all the way to pro- duction. Developers have the flexibility to write their applications in Docker and can choose their orchestrator without requiring any additional modification. In an interview with Linux Pro, Hykes said that Docker will continue to engage with the Kubernetes community as a good citizen.

We Are Under Bad Rabbit Attack A new variant of the NotPetya worm, dubbed Bad Rabbit, is wreaking havoc on Win- dows systems across the globe. The attack initially targeted Russian and Ukrainian cor- porate networks, but it has now spread across the globe inflecting Turkey, Bulgaria, Japan, Germany, Poland, South Korea and even the United States. US-CERT, a US agency responsible for mitigating cyber threats, has released an alert, “US-CERT has received multiple reports of ransomware infections, known as Bad Rab- bit, in many countries around the world. A suspected variant of Petya, Bad Rabbit is ransomware – malicious software that infects a computer and restricts user access to the infected machine until a ransom is paid to unlock it. US-CERT discourages individu- als and organizations from paying the ransom, as this does not guarantee that access will be restored. Using unpatched and unsupported software may increase the risk of proliferation of cyber security threats, such as ransomware.” Researchers at Kaspersky Lab said that the ransomware dropper was distributed with the help of drive-by attacks. “While the target is vis- iting a legitimate website, a malware dropper is being downloaded from the threat actor’s infra- structure. No exploits were used, so the victim would have to manually execute the malware dropper, which pretends to be an Adobe Flash installer,” said Orkhan Mamedov, Fedor Sinit- syn, and Anton Ivanov of Kaspersky Lab. Kaspersky Lab suggests disabling WMI on Windows systems to stop Bad Rabbit from dig-

ging burrows in your networks. 123RF.com Image © Phil Wohlrab,

10 JANUARY 2018 ISSUE 206 LINUX-MAGAZINE.COM | LINUXPROMAGAZINE.COM NEWS Kernel News Zack’s Kernel News Chronicler Zack Brown reports on the latest news, views, dilemmas, and developments within the Linux kernel community. By Zack Brown

I3C Support of its current state when calling the I3C be used to match drivers instead of the Boris Brezillon posted some patches to API. However, Boris indicated he’d be compatible string or driver-name used for implement a portion of the I3C core in- fine with changing that. He’d mainly I2C devices. frastructure. This is a wholesale upgrade done it as a shortcut. So, as you can imagine, dealing with of the I2C protocol for communications Among the missing API calls, Boris an I3C bus is really different from dealing through serial ports. A lot of sensor de- left out hot plugging support, which with an I2C bus. vices use serial communications, be- might be a deal-breaker for some users. Boris added, “Of course, I can move cause it’s a simple two-wire interface. Of course, the missing APIs would all all the code in drivers/i2c/, but that However, as that simplicity brings a pro- be added later as the I3C code was won’t change the fact that I3C and I2C liferation of sensor devices, it becomes fleshed out. buses are completely different with little more important to manage the increased Wolfram Sang took a look at the code, to share between them.” bandwidth and interrupt needs they cre- but had no serious objections and gener- Arnd didn’t want to let the idea go ate. I3C is designed to do that. ally approved the patches. quite yet, though. He agreed that there Boris’ approach would transparently Arnd Bergmann asked why Boris had were reasons to oppose extending I2C to handle I2C backward compatibility for created a whole new subsystem for cover I3C as well, but he felt there were minimal user pain, but he also made cer- I3C, instead of simply extending the also reasons to go through with it, even tain compromises that would make existing I2C code to support I3C as if it involved creating an ugly mess be- using his APIs more difficult, and he left well. Boris replied: hind the scenes. He said, “there is value a fair chunk of the I3C API unimple- I3C and I2C are really different. I’m in representing the physical bus hierar- mented for now, although he intends to not talking about the physical layer chy in the software model, and if I2C fill it out in the future. here, but the way the bus has to be han- and I3C devices can be attached to the One implementation compromise was dled by the software layer. Actually, I same host bus, a good abstraction to require user code to run in a non- thin[k] the I3C bus is philosophically should show them under the same par- atomic context (i.e., only when the cur- closer to auto-discoverable buses like ent. This is true for both the kernel rep- rent process can be interrupted by some- USB than I2C or SPI. resentation (in sysfs and the data struc- thing else). That’s a slight annoyance, Indeed, all I3C devices can be discov- tures) as well as the device tree binding because it requires user code to be aware ered and do not need to be described at (assuming we will need to represent I3C the board level (using DT, board files, devices at all). The two don’t have to ACPI, or whatever). Also, some I3C de- use the same model, but it’s easier if vices are hot pluggable, and most impor- they do.” tantly, all I3C devices describe themselves He also added, “We have discussed during the discovery procedure (called whether I2C and SPI should be merged DAA in the I3C world). into a single bus_type in the past, as a lot There is some kind of “device class” of devices can be attached to either of concept. In the I3C world it’s called DCR them. If it’s common enough for I3C de- (Device Characteristic Register), but it vices to support an I2C fallback mode, plays the same role: It’s a set of generic having a common bus_type might notice- interfaces devices have to comply with ably simplify device drivers by only re- when they declare themselves as being quiring a single i2c_driver structure. compatible with a DCR ID (like acceler- Simplifying many drivers a little bit can ometer, gyroscope, or whatever). […] in turn offset the added complexity in Author Devices also expose a 48-bit Provisional the subsystem.” The Linux kernel mailing list comprises the ID which is made of sub-fields. Two of Boris didn’t really see the benefit of core of Linux development activities. Traffic them are particularly interesting: the these ideas and expressed surprise that volumes are immense, often reaching manufacturer ID and the part ID, which I2C and SPI might ever be merged. He 10,000 messages in a week, and keeping are comparable to the vendor and prod- asked Arnd for an explanation, and Arnd up to date with the entire scope of development is a virtually impossible task uct ID in the USB world. replied, “well, we never changed it, so at for one person. One of the few souls These three [pieces of] information least the work required to merge the two to take on this task is Zack Brown. (DCR, ManufacturerID, and PartID) can was considered too much to justify any

LINUX-MAGAZINE.COM | LINUXPROMAGAZINE.COM ISSUE 206 JANUARY 2018 11 NEWS Kernel News

advantages.” But he described the ratio- case[s] is to connect an I3C device on an painful; it will take forever to trickle this nale as simplifying kernel build-time I2C bus and let it act as an I2C device,” through all architectures (especially with config options. He said: which Wolfram agreed made it more the various 32-bit architectures having The main problem with having one likely that a device would one day imple- all kinds of different granularities for the driver that can operate on different bus ment both protocols. offset) and then the various C libraries, types (I2C plus either SPI or I3C) is the At some point, Boris took a whack at never mind applications.” handling for the various combinations in merging I2C and I3C, but he found it Christoph suggested just using an ex- configurations (e.g., I2C=m, SPI=y). difficult to conceptualize a workable de- isting __MAP_VALID hack as a workaround. The easy case is having a module_init sign. He also added, “It’s kind of hard Dan replied, “I agree with the mess and function that registers two device drivers, to design something when you don’t delays it causes for other archs and libc, but that requires having a Kconfig depen- have real devices. I guess I can mimic but at the same time this is for new appli- dency on both subsystems, and you can’t I2C for now and make it evolve based cations and libraries that know to look for use the module_i2c_driver() helper. on users’ needs.” the new flag, so they need to do the extra The second way is to have a number of Elsewhere, Greg Kroah-Hartman asked work to check for the new syscall.” #ifdef and complex Kconfig dependen- Boris to split the documentation out from Regarding the possibility of using __MAP_​ cies for the driver to only register the de‑ the patch and submit it separately, to VALID, he also pointed out that “any vice_driver objects for the buses that are make the code slightly easier to go new mmap flag with this hack must be enabled. This is also doable, but every- through, but he also did go through the documented to only work with MAP_ one gets the logic wrong the first time. code and offered several technical criti- SHARED and that MAP_PRIVATE is silently What we end up doing to work around cisms, which Boris then said he’d address. ignored.” this for other drivers is to have the base Greg also deduced from a missing data However, he said he wasn’t totally op- driver in one library module, and separate type that Boris had never actually tested posed to doing things this way if it modules for the bus-specific portions, removing an I3C device once it had been turned out not to be too onerous. which can then use module_i2c_driver installed. Boris replied, “You got me, Christoph went digging around in the again. There are many instances for com- never tried to remove a device.” He mmap code and thought he found a way to bined I2C/SPI​ drivers in the kernel, and it asked some technical questions about avoid the problem with ignoring MAP_ works fine, but it adds a fair bit of over- how best to handle that case. PRIVATE. In which case, he felt it cer- head compared to having one driver that At this point, the discussion veered off tainly beat the hell out of adding a new would, e.g., use regmap to abstract the dif- into technical locking issues, as Greg and system call. ferences in the probe() function and other- Boris worked on resolving the need to re- However, Kirill A. Shutemov looked at wise keeps everything in one place. move devices from a running system. Christoph’s discovery and felt that cer- This made sense to Boris, and he There was no ultimate resolution to tain architectures, in particular PA-RISC, could see the value of having a single any of the questions raised in the discus- wouldn’t be able to support the fix subsystem, but he still hated the ugliness sion, but it seems clear that Boris’s first Christoph had in mind. Christoph re- of the potential merged implementation. attempt will probably be reworked to fit joined, “I’d be happy to say that we He asked, “Can’t we solve this problem Greg and Arnd’s objections. It also should not care about PA-RISC for persis- with a module_i3c_i2c_driver() macro seems like the task might be bigger than tent memory. We’ll just have to find a that would hide all this complexity from Boris had first anticipated, and he may way to exclude PA-RISC without making I2C/I3C​ drivers?” not have the physical equipment he life too ugly.” Kirill hated this idea, Wolfram, who had earlier approved needs. (He remarked at one point, “all though, saying that system call inter- Boris’s patches, felt that merging I2C my tests have been done with dummy/​ faces should be universal and not have with I3C was possibly significantly dif- fake I3C slaves emulated with a slave different behaviors depending on which ferent from merging I2C with SPI. In the IP.”) So, although it seems like I3C will machine they were run on. latter case, there was a decent likelihood definitely be getting into the kernel The debate continued, although it that the system might only have one or sooner rather than later, there are still seemed to be getting further afield from the other, in which case supporting both some significant hurdles to overcome. the original issue. Eventually Dan would cover the most possibilities. But brought the conversation back around to he doubted there was any hardware cur- Fixing mmap() the real question, saying: rently implementing both I2C and I3C. Dan Williams had a thorny conundrum. The problem here is that to support And since the I3C code was backward The mmap() system call didn’t validate new the mmap flags the arch needs to find compatible with I2C, that seemed to ob- unknown flags, which meant that any a flag that is guaranteed to fail on older viate the need for a merger – the user modern new mmap behaviors that didn’t kernels. Defining MAP_DIRECT to 0x8 on could simply plug the I2C device into the work on older systems couldn’t have a PA-RISC doesn’t work because it will sim- port and use it. graceful failover. Dan wanted to imple- ply be ignored on older PA-RISC kernels. Boris replied that although he didn’t ment a new system call, mmap3(), that However, it’s already the case that sev- know of any devices implementing both would validate all flags. eral archs have their own sys_mmap entry protocols at the moment, “the spec There were a couple of problems. For points. Those archs that can’t follow the clearly describe[s] what legacy/​static ad- one thing, Christoph Hellwig pointed out common scheme (only PA-RISC it seems) dresses are for and one of their use that “Adding new syscalls is extremely will need to add a new mmap syscall. I

12 JANUARY 2018 ISSUE 206 LINUX-MAGAZINE.COM | LINUXPROMAGAZINE.COM NEWS Kernel News think that’s a reasonable tradeoff to around would only work for certain that program to output only data about allow every other architecture to add this cases – or if it could be fixed to work for unreclaimable slabs. This, he said, support with their existing mmap syscall all cases, there was still a single holdout would at least allow the user to trouble- paths. architecture that wouldn’t go along with shoot the problem and possibly find a Helge Deller objected to this plan, say- it. Choosing to break ABI compatibility way to deal with it properly. ing, “I don’t want other architectures to for that one case was a nonstarter be- Michal Hocko had no objection to the suffer just because of PA-RISC. But add- cause the whole point was not to do that patch going into the kernel, but he did ing a new syscall just for usage on PA- in the first place. note that Yang’s code might produce a RISC won’t work either, because nobody Of course, many parts of the kernel metric ton of output, on top of the al- will add code to call it then.” would love the opportunity to break ready highly verbose OOM killer report. Helge proposed breaking the ABI for ABI compatibility, but this seems to be As such, he suggested leaving the fea- PA-RISC in this case. This, he said, one of the most sacrosanct elements of ture disabled by default. would allow a proper fix without having the kernel. Almost the only thing capa- Yang disagreed, saying the output to do any major contortions. He added ble of trumping ABI compatibility is a would only be produced in the event of that there were not a lot of PA-RISC security hole. Security trumps all. But catastrophic failure and not as a part of users, anyway, and that most of them one of these days, it would be wonder- normal operations. He added that the updated their kernels regularly, because ful to have a special ABI-breaking ker- code could easily add a file to the proc of all the recent fixes that had gone into nel release, where every part of the filesystem (procfs), to control the the code. kernel is free to break the ABI for just amount of output, even under that cir- However, Dan replied, “The whole that one time. Oh the feeding frenzy! cumstance. point is to avoid an ABI regression and Oh the carnage! And afterward … oh Michal said he didn’t care that much the chance for false positive results. the regret! Oh the recrimination! It about this particular issue, because We’re immediately stuck if some appli- would be glorious. “most OOM reports I have seen were cation was expecting 0x8 to be ignored, simply user space pinned memory.” He or conversely, an application that abso- Tracing RAM Usage was fine leaving the output more ver- lutely needs to rely on MAP_SYNC/MAP_ in OOM Conditions bose rather than less. DIRECT semantics assumes the wrong Yang Shi was annoyed when his kernel They kept talking, and eventually they result on a PA-RISC kernel where they ran out of memory, and the out-of- seemed to reach a compromise when are ignored.” memory (OOM) killer couldn’t find a Yang suggested, “Maybe we can set a The debate petered out at that point, process to kill to stave off the kernel unreclaimable slab/total​ mem ratio. For and it’s not yet clear what solution panic. If there’s no process to kill, how example, when unreclaimable slab size they’ll ultimately use for mmap(). I found could the system be out of memory? It >= 50% total memory size, then we print it interesting to watch how each pro- turned out that the system had put all out slab stats in OOM? And, the ratio posed solution ran into its own stum- its memory into unreclaimable slabs. might be adjustable in /proc.” bling blocks. New system calls take time Yang posted a patch to add a new ‑U op- This made sense to Michal, and the to trickle down. The proposed work- tion to the slabinfo program to cause thread came to an end. nnn COVER STORIES UEFI

Customizing the UEFI boot process Smart Startup The traditional BIOS dates back decades and has not been able to keep up with the rapid development of PCs and laptops. Its powerful successor UEFI takes over its tasks and provides more features, more convenience, and better security. By Maik Brüggemann and Ralf Spenneberg

ince 1981, PCs have booted with the help of the Basic Input/Output System (BIOS). Over the years, different manufacturers have continued to expand the BIOS firmware system, but even after all this time, the BIOS system is dif- ficult to adjust and still does not support 64-bit operation. SBack in the late 1992, Intel launched a new initiative to replace the venerable BIOS system with a 64-bit alternative. This Extensible Firmware Interface (EFI) initiative became the Unified EFI (UEFI) Forum in 2005. In addition to Intel, AMD, Microsoft, HP, and other prominent vendors contributed to the UEFI project. UEFI describes the interface between a computer’s firmware and operating system. Like BIOS, the UEFI implementation initializes the hardware components to prepare the launch of the operating system. However, UEFI natively supports 64-bit architec- tures, enables graphical user interfaces, and can protect against malicious software by only allowing signed operating systems (a feature that has come to be known as Secure Boot). If you are using a Linux system that is preconfigured with sup- port for UEFI and Secure Boot, you don’t have to think about it very much unless you need to customize or troubleshoot the boot process. But if you want to dig deeper, you will find that UEFI is quite versatile and powerful. This ar- ticle takes a closer look at the UEFI boot process and shows how you can use UEFI to add a custom application that runs independently of the operating system. Boot Phases UEFI firmware is modular and ex- tensible. When it wakes up, the firmware runs through various stages in a strict chronological order (shown in Figure 1). The first phase is known as the Security (SEC) phase. However, the name is unfortunate because very few secu- rity-relevant actions occur in this first phase – for instance, the UEFI firmware does not use this phase to check signatures. Essentially, the SEC phase initializes the CPU with hardware-spe- cific code. The CPU loads the code directly from flash memory. RAM is not yet available at this time. Instead, the UEFI firmware uses the temporary mem- ory of the CPU cache as RAM. The SEC phase transfers phase size and location of this temporary storage, as well as optional information about the CPU, to the Pre- EFI Initialization (PEI) phase. The PEI phase initializes the main memory, as well as hardware components that are required for the next

14 JANUARY 2018 ISSUE 206 LINUX-MAGAZINE.COM | LINUXPROMAGAZINE.COM COVER STORIES UEFI phases. PEI Modules (PEIMs) provide APIs (PEIM-to-PEIM in- the UEFI applications that must run. The hardware manufacturers terface, PPI). The PEIM dispatcher is responsible for loading frequently provide some UEFI applications, such as diagnostics or and running the PEIMs. It investigates the PEIMs’ dependen- recovery applications. You can add additional applications your- cies, loads them into the now available main memory, and self and integrate them in the boot process. runs them in a specific order. The OS bootloader is a special application. The system typically In addition to initializing basic hardware components, the loads it and launches it from the EFI system partition (/boot/efi). UEFI firmware also reads a structured collection of codes and By launching the OS bootloader, the boot process transitions to data, known as the firmware volume location. This data is typi- the Transient System Load (TSL) phase. If the system uses Secure cally stored in flash memory and includes device drivers for Boot, its signature would be tested in this phase. Unsigned code the next phase. After the dispatcher has run most of the neces- will not run. The TSL phase ends on calling the ExitBootSer‑ sary PEIMs, it finally looks for the Driver Execution Environ- vices() function. This call thoroughly cleans up the memory and ment (DXE) initial program load (IPL) PEIM. This last PEIM only leaves the specially marked interfaces in the memory that then transfers the execution to the following DXE phase. need to be available at operating system run time. In the DXE phase, most of the necessary system initialization After calling ExitBootServices(), the system is in the Run then follows. Like the PEI phase, the DXE phase also has a dis- Time (RT) phase; the operating system is running and can in patcher, which loads DXE drivers from the firmware volume loca- turn access the UEFI run-time services. After the RT phase, the tion and runs them in the desired order. The DXE drivers initialize system enters the After Life (AL) phase with the termination of all required hardware components and register or use protocols. the operating system. This is intended for an orderly shut- Protocols provide the text output to the console or access to down. However, it is hardly used. the PCI devices. If a protocol is only available before the oper- ating system launches, it is known as a boot service. A protocol UEFI Run-Time Services and Variables that you can access them while the operating system is running UEFI run-time services are UEFI functions that can be used at op- is called a run-time service. erating system run time. For this purpose, a UEFI driver registers After the dispatcher has loaded all drivers, it continues with the as a run-time service and creates an entry in the run-time services Boot Device Selection (BDS) phase. The BDS phase runs the UEFI table. During the boot process, the operating system is given this Boot Manager. NVRAM variables tell the Boot Manager which table. The table gives the operating system access to the real-time UEFI applications must be launched. The operating system can in- clock; the OS can trigger a platform reset, access variables in the fluence these variables through a run-time service and determine NVRAM, or initiate a firmware update.

Figure 1: The UEFI boot process runs through a series of phases.

LINUX-MAGAZINE.COM | LINUXPROMAGAZINE.COM ISSUE 206 JANUARY 2018 15 COVER STORIES UEFI

While most run-time services are only accessible to kernel GRUB is stored. The system first runs the UEFI implementation drives on a Linux system, access to the NVRAM variables and of GRUB in the BDS phase. GRUB, in turn, launches the Linux the firmware update function are exported to userspace by the kernel. You can add new boot variables or change the boot order Linux kernel. The Linux kernel makes UEFI variables accessi- with the efibootmgr command. ble in userspace via the UEFI variable filesystem (efivarfs). While the boot variables are freely adjustable, write ac- Linux distributions launched by UEFI integrate the filesystem cess to other variables is restricted. They include, among under /sys/firmware/efi/efivars. others, the PK, KEK, DB, and DBX variables. These variables You can list all available variables via: store the public keys for signature verification within the scope of Secure Boot. ls /sys/firmware/efi/efivars If an attacker can change these variables, they can also by- pass or switch off Secure Boot. Therefore, only signed data can You can read UEFI variables like normal files. The following be stored in these variables. The UEFI implementation verifies command outputs the contents of a variable: the signature of the transferred public key and only allows the write operation if the signature is trustworthy. cat /sys/firmware/efi/efivars/variable_name Update Capsule on the console. However, the stored information is available in Another interesting UEFI run-time service bears the name Update a machine-readable format; the output of the cat command is Capsule. The operating system can use this service to transfer data often fairly cryptic. blocks to the UEFI firmware. The operating system stores the data You can write or delete these variables as you would a in memory and shares the location with firmware via the Update normal file. But deleting a variable can be fraught with dan- Capsule service. A system reset is then triggered. The computer ger. Previously, a rm‑rf / would result in not just all the files restarts. UEFI now accesses the provisioned data block. on the hard drive being deleted but all UEFI variables too. The service is used primarily to run updates of the UEFI However, some buggy UEFI implementations expected cer- firmware. The advantage of this procedure is that the firm- tain variables. If these variables were deleted, the computer ware can handle the actual update process. You don’t need no longer launched and you had to send the motherboard to any proprietary tools, which are usually only available on be repaired. Windows. Current Linux kernels therefore protect most of the variables The standardized UEFI interface makes firmware updates in- with the immutable flag: dependent of the operating system. For example, Microsoft uses this process to provision surface tablets with new firm- lsattr PKDefault‑8be4df61‑93ca‑11d2‑aa0d‑00e098032b8c ware via Windows Update. Apple also uses this process for cer- ‑‑‑‑i‑‑‑‑‑‑‑‑‑‑‑‑‑‑ PKDefault‑8be4df61‑93ca‑11d2‑aa0d‑00e098032b8 tain MacBooks. At present, Linux users can only use the up- date function in conjunction with a few systems. In addition to Thus, accidental deletion or modification is ruled out. In prac- Microsoft and Apple, Dell is the only big manufacturer that of- tice, you cannot directly access the variable via commands fers firmware updates in the Update Capsule format. such as cat. Instead, you need to use special programs such as Like the UEFI variables, the Linux kernel exports the update efibootmgr that let you edit the group of boot variables. interface to the filesystem. The /sys/firmware/efi/esrt direc- The BDS phase is controlled by the boot variables. A variable tory contains the EFI System Resource Table (ESRT). The ker- starting with Boot000 represents an entry in the UEFI Boot Man- nel generates an input for each device that can be updated via ager. The value of the variable specifies the location of a UEFI ap- the Update Capsule interface. The fwupdate tool lists these de- plication that is bootable during the BDS phase. The Boot‑ vices. The tool is installed using: Order‑GUID variable determines the order in which the applica- tions must be launched. The efibootmgr program manages these sudo apt‑get install fwupdate variables at the command line. The command in Listing 1 displays the current configuration of the BDS phase. The command generates a list of all Update Capsule-capable Listing 1 shows two entries. The entry known as debian is devices in the system: right at the front in the boot order and is therefore run first. The entry points to the EFI system partition (/boot/efi), on which fwupdate ‑‑list

Listing 1: BDS Phase Configuration If there is an Update Capsule-compatible firmware for the de-

01 # efibootmgr ‑‑verbose vices listed, it can be installed as follows:

02 BootCurrent: 0003 fwupdate ‑‑apply=guid‑of‑hardware firmware.cap 03 Timeout: 1 seconds

04 BootOrder: 0003.0002 Unfortunately, as previously mentioned, only a few manufac- 05 Boot0002 Hard Drive BBS(HD,,0x0) turers support this functionality to date. However, it shows 06 Boot0003* debian HD(1, GPT, what advantages the standardized UEFI interface has over pro- cf2d93bb‑3cd3‑4903‑9b7ccbfc697f7aae, 0x800, 0x1dc800)/File(\EFI\debian\grubx64.efi)..BO prietary BIOS implementations.

16 JANUARY 2018 ISSUE 206 LINUX-MAGAZINE.COM | LINUXPROMAGAZINE.COM COVER STORIES UEFI

Custom Code Listing 2: Copying Firmware Files

The EFI Developer Kit II (EDK II) is used for developing 01 mkdir ~/efibin UEFI applications. It is the current reference implementation of 02 cd ~/efibin the UEFI specification and is used by many manufacturers as 03 cp ~/src/vUDK2017/Build/OvmfX64/DEBUG_GCC5/FV/OVMF_CODE.fd . the basis for their own firmware. To avoid developers having to 04 cp ~/src/vUDK2017/Build/OvmfX64/DEBUG_GCC5/FV/OVMF_VARS.fd . constantly reboot their computers to test their own applica- tions, it makes sense to work in Qemu. EDK II includes every- thing you need to generate complete UEFI firmware and re- (Listing 2). Using the following command, you can launch a launch under Qemu. virtual machine and run the firmware: First, you need to install some dependencies. On Ubuntu 4.16, use the following command: Qemu‑system‑x86_64 ‑drive if=pflash,format=raw,U file=OVMF_CODE.fd ‑drive if=pflash,format=raw,file=OVMF_VARS.fd

sudo apt‑get install build‑essential uuid‑dev U iasl git gcc‑5 nasm If Qemu displays a logo with the words TianoCore for a short time and then launches the UEFI shell (Figure 2), the whole The easiest way to pick up the last stable release of EDK II is process was successful. via GitHub: For the first attempts with your own UEFI applications, you can use the Hello World application from the MdeModule as a tem- mkdir ~/src plate. The correct file can be found in MdeModulePkg/Application/ cd ~/src HelloWorld/HelloWorld.c. This file, which is shown in Listing 3, git clone https://github.com/tianocore/edk2.git vUDK2017 was expanded and now implements a simple variant of the Hangman game. The user has to guess the word penguin and After downloading, first compile the base tools: thus quit the application. The entry point of the application is the UefiMain function cd ~/src/vUDK2017 (Line 8). UefiMain has two transfer arguments. ImageHandle is a make ‑C BaseTools handle for the process itself and not interesting for the Hello World application. However, the second argument SystemTable If everything worked, the EDK is ready for use. The source code is a central data structure of the UEFI environment. SystemTable is organized in packages. The MdeModulePkg and MdePkg pack- now provides the application with access to protocols that have ages are important because they implement the actual UEFI been previously registered in the DXE phase. Specification. The code is largely architecture independent. To In Line 21, the program uses the Simple Text Output Protocol generate firmware capable of running on a specific platform, the via SystemTable. The protocol has a function known as firmware requires platform-specific code. The EDK provides this ClearScreeen. As the name suggests, this call clears the output code for Qemu. The Ovmf package internally builds on the Mde console. This is followed by some output implemented by the packages and adds the Qemu specific parts. print function. Under the hood, the print function also uses the In order for the Ovmf package to create an EDK, you need to Simple Text Output protocol. Line 32 relies on the WaitForEvent edit the ~/src/vUDK2017/Conf/target.txt file. Specify the Ovmf service. With its help, the program waits for the occurrence of package as the ACTIVE_PLATFORM: certain events, in this case for a key press (WaitForKey). After the event occurs, the ReadKeyStroke function returns the pressed key. ACTIVE_PLATFORM = OvmfPkg/OvmfPkgX64.dsc The following for loop checks whether the character matches one of the expected characters. The entire process is In addition, you need to adapt the architecture and the com- repeated by the do‑while loop until the user has guessed all piler tool chain you will be using. On an x64 Ubuntu 04.16 sys- the letters correctly. The program then outputs the word you tem, use the following values: are looking for and then waits for a subsequent key press be- fore it quits. TARGET_ARCH= X64

TOOL_CHAIN_TAG= GCC5

Once the target platform is set, launch the first build process:

source edksetup.sh

build

The build takes a few minutes and stores the complete firmware in the ~/src/vUDK2017/ Build/OvmfX64/DEBUG_GCC5/FV directory. To test the UEFI firmware using Qemu, copy the required firmware files into a new directory Figure 2: The UEFI shell is launched.

LINUX-MAGAZINE.COM | LINUXPROMAGAZINE.COM ISSUE 206 JANUARY 2018 17 COVER STORIES UEFI

Listing 3: Hello World! You have to extend the Ovmf package

01 #include in order for the Hangman program to be

02 #include included in the next build. In the ~/src/ file, 03 #include vUDK2017/OvmfPkg/OvmfPkgX64.dsc add the [Components] section and a refer- 04 #include ence to the Hello World application: 05

06 EFI_STATUS [Components] 07 EFIAPI MdeModulePkg/Application/U 08 UefiMain ( HelloWorld/HelloWorld.inf 09  IN EFI_HANDLEImageHandle,

10  IN EFI_SYSTEM_TABLE *SystemTable The HelloWorld.inf file describes the 11  ) application and instructs the EDK to 12 { automatically generate makefiles. In 13  UINTN Index; the base directory of the EDK, launch 14  EFI_INPUT_KEY Key; the build process for the Hello World 15  CHAR16 *result = L"pinguin"; application: 16  CHAR16 *state = L"______";

17  UINTN Attempt = 0; source edksetup.sh 18 build 19  do { 20  Attempt++; The build stored the generated UEFI bi- 21  SystemTable‑>ConOut‑>ClearScreen(SystemTable‑>ConOut); nary HelloWorld.efi in the ~/src/Build/ 22 OvmfX64/DEBUG_GCC5/X64 directory. To test 23  Print(L"Welcome to Hangman!\n"); the application, copy it to the efibin di- 24  Print(L"Attempt: %d\n\n\n", Attempt); rectory and relaunch Qemu: 25

26  // print found characters cd ~/efibin

27  for(UINTN i=0; i

28  Print(L"%c ", state[i]); DEBUG_GCC5/X64/HelloWorld.efi . 29  } 30 When launching, extend the command 31  // read characters from keyboard to launch the Qemu system by the hda 32  SystemTable‑>BootServices‑>WaitForEvent(1, parameter. This parameter integrates the &SystemTable‑>ConIn‑>WaitForKey, &Index); efibin directory into the virtual machine 33  SystemTable‑>ConIn‑>ReadKeyStroke(SystemTable‑>ConIn, &Key); as a FAT-formatted hard drive. The full 34 command is: 35  // check if pressed key is in result

36  for(UINTN i=0; i

38  state[i] = result[i]; file=OVMF_CODE.fd ‑drive U

39  } if=pflash,format=raw,U

40  } file=OVMF_VARS.fd ‑hda fat:~/efibin 41  } while(StrCmp(result, state) != 0); // repeat until all characters are found UEFI directly supports the FAT filesystem 42 and therefore has access to the Hello 43  // print final result World application. After launching the 44  SystemTable‑>ConOut‑>SetCursorPosition(SystemTable‑>ConOut, 0 , 4); UEFI Shell, enter Hello World to launch 45  for(UINTN i=0; iBootServices‑>WaitForEvent (1, copy them to the EFI system partition of &SystemTable‑>ConIn‑>WaitForKey, your computer: 51  &Index);

52 sudo cp ~/efibin/HelloWorld.efi U 53  return EFI_SUCCESS; /boot/efi/ 54 }

18 JANUARY 2018 ISSUE 206 LINUX-MAGAZINE.COM | LINUXPROMAGAZINE.COM Similar to the Qemu environment, you can manually launch the application in the UEFI implementation of the motherboard using the UEFI Shell. After resetting the computer, you then have to press one of the function keys to interrupt the normal boot process and instead launch the UEFI Shell. Which key has to be pressed depends on the UEFI implementation of the motherboard. Once you are in the UEFI Shell, you can simply call the application by typing HelloWorld. Alternatively, you could set up an automatic launch of the application. You must configure the UEFI Boot Manager via the UEFI variables. The easiest way to do this is with the efiboot‑ mgr program. The program generates new boot variables in the efivar filesystem and thus an entry in the UEFI Boot Manager. However, before this step, you should ensure that a recovery CD is ready, with which you can repair a potential misconfigu- ration. To generate a new entry, transfer the create argument to the Efibootmgr. A label gives the entry an intuitive name; the loader parameter displays the path to the UEFI application:

efibootmgr ‑‑create ‑‑label U

"Hangman" ‑‑loader HelloWorld.efi

If successful, the system responds with:

BootCurrent: 0000

Timeout: 2 seconds

BootOrder: 0000.0001

Boot0000* debian

Boot0001* Hangman

Currently, the boot sequence still defines that the entry with the debian label will start. The efibootmgr ‑‑bootnext 0001 command changes this order for the next boot to the entry with the number 0001. If you now reboot the computer, the UEFI firmware runs the Hello World application once only. Conclusion This example basically shows how to develop and run UEFI programs. You are not restricted to simple text input and out- put. UEFI allows you to introduce a graphical user interface, access a TCP/​IP network, or access a USB stick. The versatile UEFI environment lets you run even complex applications in- dependently of the operating system. nnn

Figure 3: The Hangman word-guessing game with UEFI control.

LINUX-MAGAZINE.COM | LINUXPROMAGAZINE.COM COVER STORIES Linux Secure Boot with Shim

Linux control over Secure Boot Better Boots The Shim bootloader lets Linux users regain some control over the Secure Boot process. By Eva-Katharina Kunst and Jürgen Quade

he UEFI Secure Boot feature ensures that only software with a valid digital signature launches on a computer. UEFI searches for Authors a bootloader on the SSD or hard disk, verifies the digital signa- Eva-Katharina Kunst has been a Linux fan ture from one of the certificates stored with UEFI, and, if the since the beginnings of open source. Tdigital signature is valid, loads and activates the code. Jürgen Quade is a professor at Niederrhein The bootloader searches for the operating system, verifies the digital University in Krefeld, Germany. The fourth edition of their co-authored book Linux- signature, and launches the operating system. Once the operating system Treiber entwickeln [Developing Linux is launched, it only loads kernel modules and drivers that have a valid digital Drivers] was published late in 2015. signature.

Figure 1: The certificate store used in a Secure Boot-protected computer. DBX is the forbidden signatures database.

Figure 2: The Ubuntu Secure Boot process runs through a series of stations.

20 JANUARY 2018 ISSUE 206 LINUX-MAGAZINE.COM | LINUXPROMAGAZINE.COM COVER STORIES Linux Secure Boot with Shim

Recovering Autonomy Shim lets large distributors such as Ubuntu, SUSE, and Red Hat win back control of hardware. Using the Canonical certificate stored in Shim, for instance, Ubuntu dis- tros sign the GRUB 2 bootloader. The firmware boots Shim, Shim boots GRUB 2, and GRUB 2 boots the operating system (Figure 2). The user doesn’t notice Secure Boot at first. For example, if you install Ubuntu on a computer with Secure Boot enabled, the installation routine places the signed Shim boot- loader and GRUB 2 on the SSD or hard disk and installs the digitally signed ker- nel, along with verifiable modules and driv- ers. If Secure Boot is not enabled, the operat- ing system installer copies the various compo- nents onto the computer without a digital signa- ture. Switching Off If you try to install VirtualBox on a Secure Boot Linux machine, the host computer might object and refuse to load the necessary kernel module because it has no valid digital signature. This behavior occurs in all third-party packages that provide their own modules or drivers. With physical access to the computer, you can in- elegantly deactivate the verification of digital signatures by the Linux kernel with Shim by typing the command: The idea is that, if all components only load code sudo mokutil ‑‑disable‑validation from trustworthy sources, it is much more difficult for malware authors hid- The mokutil tool requires you to enter a one-time password. ing away in the grubby corners of the Internet to smuggle After that, mokutil does not deactivate the check itself, but it their software into the boot process. sets up the Shim bootloader so that it asks for the password One problem with UEFI Secure Boot for Linux developers at the next reboot and performs the desired configuration and users is the control that Microsoft maintains over the sys- after the correct password is input. After a reboot, Shim ex- tem. Microsoft's market power means that every hardware pects you to enter the one-time password within a short manufacturer burns its own certificate as a Platform Key (PK), time frame. and then the Microsoft certificate is securely deposited into the In Shim, select Change Secure Boot state in the selection Key Exchange Key (KEK) database and (authorized) database box (Figure 3). After entering the previously defined one- (DB) key on the motherboard (Figure 1). Therefore, x86 PCs and laptops initially only boot software with a signature by the grace of Microsoft. Shim: An Alternative Approach The thought of the Linux kernel needing a digital signature from Microsoft was too much for many Linux users, so Mat- thew Garrett created a program called the Shim bootloader, an open source alternative that integrates its own certifi- cates. Ubuntu, Red Hat, SUSE, and Debian generate their own versions of Shim that include certificates issued by their companies. Verisign/Symantec​ digitally signs the bootloader in Micro- soft’s stead so that the UEFI firmware will load Shim. Once Shim is loaded, it operates independently of the Microsoft veri- fication chain. Shim has built-in certificate management that lets the owner of the computer store certificates called machine Figure 3: Quick and insecure: In Shim, the signature owner keys (MOKs). check can be disabled.

LINUX-MAGAZINE.COM | LINUXPROMAGAZINE.COM ISSUE 206 JANUARY 2018 21 COVER STORIES Linux Secure Boot with Shim

time password, the compulsory verification of digital signa- tures is deactivated. However, deactivating verification means that you lose the protection offered by Secure Boot. (You can also switch off Secure Boot directly in the UEFI setup.) Creating Your Own Certificate A better way to add some flexibility to your Secure Boot con- figuration is to store your own certificates in the kernel and sign the modules yourself. The problem is that the new key must be signed with a key whose signature already exists in the certificate store, and only the key of the distributor – Ca- nonical – is in the certificate store. Because the private key is (one hopes) known only to Canonical, you can’t make modi- fications. To solve this problem, you must generate the kernel yourself and store the certificate used in the Shim bootloader as a MOK. Figure 4 shows the procedure. First, you have to generate the new key pair. Second, the private key signs your or third-party modules. The third step is to secure the private key, and the fourth step is to give Shim the public key as the MOK. When you reboot, the Shim certificate manager pops up; use the certificate manager to validate and import the Figure 4: If you have physical access to the computer, certificate. After the next startup, Linux can use the signed you can integrate your own certificates. The not-partic- modules. ularly-intuitive individual steps toward this objective To generate the required key pair at the command line, use are summarized here. the following long command:

Keys, Passwords, and Certificates Even the experts sometimes use the terms key, password, recipients. The public key is worthy of its name because it and certificate incorrectly. A key is a byte sequence for en- does not have to be kept locked up and can be transported crypting data. If your encryption algorithm uses block en- safely. cryption, the key has a length of one block. In the case of Key with a Fob. It makes sense to add information about the character-by-character encryption, the ideal key is as long as owner to the public key and sign it all digitally so that it is the character string you are encrypting; otherwise, the key is tamper-proof. This digitally signed combination of metadata used repeatedly. (name, company, address) plus the public key is known as a Password or Key. A password is a character string that pro- certificate (Figure 5). duces a key. For example, if you generate an infinitely long Whether the public key comes alone or as a certificate, the key using a pseudo-random number generator, you can use owner needs to protect it because of its importance. It is the initialization value of the random number generator as a quite common to encrypt it symmetrically and secure it with password. a password. In symmetric encryption, a single key is used both to encrypt and to decrypt. The key is a shared secret – a secret known to all encrypters and decrypters. It is often necessary to transport the key to the receiver, which creates the risk that a third party will read the key. Asymmetric encryption, on the other hand, relies on a mathemati- cally coherent key pair. The private key is used for decryption and digi- tal signing. A third party requires the public key for encrypting and for verifying a digital signature. Using symmetric encryption, you can digitally sign data, and you can Figure 5: A certificate comprises a public key, metadata about the owner of encrypt specifically for individual the private key, and a digital signature.

22 JANUARY 2018 ISSUE 206 LINUX-MAGAZINE.COM | LINUXPROMAGAZINE.COM COVER STORIES Linux Secure Boot with Shim

openssl req ‑new ‑x509 ‑newkey rsa:2048 U Listing 1: Signing the VirtualBox Module ‑keyout ownerkey.priv ‑outform DER U #!/bin/bash ‑out ownerkey.der ‑nodes ‑days 36500 U for drivername in vboxdrv vboxnetflt vboxnetadp vboxpci ‑subj "/CN=Machine Owner Key of My Company/ do

sudo /lib/modules/$(uname ‑r)/build/scripts/sign‑file Now in the current directory are the private key (ownerkey.priv) sha256 ./ownerkey.priv ./ownerkey.der $(modinfo ‑n and the certificate with the public key (i.e., the owner certificate $drivername) ownerkey.der). (See also the “Keys, Passwords, and Certificates” done box.) You need to keep the private key safe, because anyone who can read it can use it for digital signing. It makes sense to A simple command hands over the sample signature, which move the private key onto an external drive, such as a USB you do not need to protect against unauthorized access, to stick. Additionally, we recommend that you encrypt the USB Shim’s certificate manager: stick using an encryption tool such as VeraCrypt [1]. sudo mokutil ‑‑import ownerkey.der Self-Signing Modules Unsigned modules must be digitally signed, for which you can As usual, after a reboot, you have to enter a one-time pass- use the sign‑file command of the kernel build system. The word within a short time window to enable certificate man- command is in the kernel sources, and you can call it as follows: agement. To activate the recently created certificate (Figure 6) in Shim, sudo /lib/modules/$(uname ‑r)/build/scripts/sign‑file U choose Enroll MOK. View Key checks the key, and the two steps sha256 ./ownerkey.priv ./ownerkey.der after choosing the Continue menu item finally activate it. Back on Linux again, the command Using the script from Listing 1, you can sign all VirtualBox modules. The $(modinfo ‑n vboxdrv) loop returns the path to mokutil ‑‑list‑enrolled the VirtualBox module (e.g., to vboxdrv.ko). Alternatively, if you want to self-sign your kernel module, specify the path, in- outputs a list of registered certificates, including self-generated cluding file name of the module. certificates. The command to load the VirtualBox kernel module COVER STORIES Linux Secure Boot with Shim

sudo modprobe vboxdrv

now runs successfully. However, be careful: With each up- date of the kernel, you have to digitally sign the new mod- ules by again accessing the (one hopes) well-secured private key. Incidentally, the command

sudo mokutil ‑‑delete ownerkey.der

tells the Shim certificate manager to remove a certificate from certificate management during the next reboot – as always under the protection of a one-time password. The menu item in Shim is Delete MOK. More Secure Is Not 100% Secure Installing the Shim UEFI bootloader and, with all the effort it involves, signing the kernel and its modules certainly makes the computer more secure. It is far more difficult for script kid- dies and hackers to install and launch malicious software on the computer. However, you have no reason to celebrate when you look at, and into, the various certificate stores on the com- puter: As the manufacturer of the computer, Microsoft, Veri- sign, Symantec, and Canonical now have branches into the “secure” machine (Table 1). First, it would be naive to believe that all employees in all companies are immune to the offer of doing someone a little favor in exchange for an impressive number of bitcoins. Sec- ond, the consequences of a letter from a national security organization, subject to confidentiality clauses and penal- ties, could force companies to make concessions in terms of data protection. In the end, only one Public Key Infrastruc- ture (PKI) is secure, and that’s the one that you operate yourself. If you store your own key in UEFI, blacklist the existing keys, compile and self-sign the bootloader, compile and self- sign the kernel, and then do the same with all the modules and drivers, you can put considerably more trust in your system. If you have even higher security demands, the next step is to secure the individual applications running on your system. nnn

Table 1: Who Controls What Component Sample Signature Signatory UEFI (PK, KEK, Manufacturer, Microsoft (2x) – DB) Shim Distributor (e.g., Ubuntu) Microsoft (Verisign/​ Symantec) grubx86.efi Distributor (e.g., Ubuntu) Distributor

Linux Kernel Distributor (e.g., Ubuntu) Distributor

Figure 6: (a) Shim lets you enable a self-generated certifi- Info cate. The issuer of the digital certificate can tell at a [1] VeraCrypt (encrypts background memory): glance (b) that the certificate (c) really is their own. (d) https://veracrypt.​­ codeplex.​­ com​­ Choosing Continue starts activating the certificate for the boot system, (e) proceeds with a functional but fairly unnecessary security prompt, and (f) ends with the entry Find us on Facebook of the previously stipulated one-time password. http://www.facebook.com/linuxpromagazine

24 JANUARY 2018 ISSUE 206 LINUX-MAGAZINE.COM | LINUXPROMAGAZINE.COM

COVER STORIES Trusted Platform Module

Security with the Trusted Platform Module Trusted Computing The Trusted Platform Module on your computer’s motherboard could lead to better security for your Linux system. By Matthew Garrett

he security of any operating system (OS) layer depends on the security of every layer below it. If the CPU can’t be trusted to execute code correctly, there’s no way to run secure software on that CPU. If the bootloader has been tampered with, you cannot trust the kernel that the bootloader boots. TSecure Boot allows the firmware to validate a bootloader before executing it, but if the firmware itself has been backdoored, you have no way to verify that Secure Boot functioned correctly. This problem seems insurmountable: You can only trust the OS to verify that the firmware is untampered with if the firmware itself has not been tampered with. How can you verify the state of a system without having to trust it first? The answer lies in a set of technologies collectively referred to as Trusted Com- puting. A consortium of companies called the Trusted Computing Group [1] main- tains the specifications related to Trusted Computing. At the heart of the Trusted Computing environment is a small hardware component called a Trusted Platform Module (TPM). The TPM is a chip connected by bus to the system motherboard, and sometimes it can be retrofitted as a module (Figure 1). TPMs are not fast or powerful – almost anything that can be done on a TPM can be done much faster on the CPU. Neither can the TPM see what’s happening on the rest of the system; TPMs know only what the rest of the computer chooses to tell them. However, it’s how TPMs make use of this information that makes them so power- ful. TPMs have a collection of registers called Platform Configuration Registers (PCRs). (See the box titled “Writing to the TPM.”) When the system is reset, these registers are set to 0. During the boot process, the system will generate crypto- graphic hashes of the boot components and pass these hashes to the TPM. Any modifications to the boot components will change the values of these hashes, and consequently change the values recorded by the TPM. This process is referred to as “measurement,” and a boot that occurs in this way is a Measured Boot.

Writing to the TPM When new values are given to the TPM, they are not written directly to the PCRs. Instead, the PCR will be set to a value determined by the combination of the PCR’s current value and the new value given to it. If the component to be measured is the string Hello world, and the PCR’s current value is c72bf7f5a487b1e75819b5b1d1644ded23c10967, the new value would be:

SHA1(c72bf7f5a487b1e75819b5b1d1644ded23c10967 || SHA1("Hello world"))

In other words, the SHA1 (a cryptographic hash) of Hello world is appended to the current value of the PCR, and the PCR is then set to the SHA1 of that concatenated value. This means that the order of measurements matters; measuring Hello moon and then mea- suring Goodbye sun will result in a different PCR value than measuring Goodbye sun and then Hello moon.

26 JANUARY 2018 ISSUE 206 LINUX-MAGAZINE.COM | LINUXPROMAGAZINE.COM COVER STORIES Trusted Platform Module

When an application asks for something to be encrypted with this key, it can specify a set of PCR values to be asso- ciated with the encrypted material. When it comes to decryption time, if those PCR values do not match, the TPM will refuse to decrypt the material. If you use the TPM to encrypt your disk encryption key, your machine will refuse to boot if any of the boot process is modified [2]. If you’re using UEFI instead of BIOS, use the verifier_tpm_module branch of GRUB [3] instead of TrustedGRUB2. When configured this way, a system that’s been tam- pered with will simply refuse to boot, although it doesn’t prevent an attacker with physical access from obtaining your passwords. They can simply remove your hard drive and replace it with one that boots normally even if the boot process has been modified. When you try to log in, it simply saves your password and sends it to the attacker. One approach for avoiding this is tpmtotp [4], which uses the time-based one-time password (TOTP) proto- col used by websites for two-factor authentication (2FA). A secret is encrypted on the TPM and can only be decrypted if Different components are the PCR values match. The secret is then displayed in the measured into different PCRs form of a QR code that can be enrolled into a regular 2FA (Table 1). Each component is measured before it starts exe- application. On boot, the system decrypts the secret and cuting and, in turn, measures the next component before exe- uses that in combination with the current time of day to dis- cuting it, starting with the CPU measuring the firmware. If the play a six-digit value. The user compares this value to the firmware has been tampered with, PCR0 will be different. value their phone is displaying. If they match, the user Even if the firmware then lies about the measurements of all knows that the system is trustworthy and can enter the later components (by pretending the values are correct even password safely. (See also the box titled “RAM Option.”) though they’ve been tampered with), the value of PCR0 will Of course, even legitimate updates of the boot components still be different. By looking at the PCR values and comparing will change the values of the PCRs. Updating GRUB will them with expected values, you can tell whether any part of the boot process has been compromised. Table 1: PCRs But how do you look at those values? If the OS has PCR Measurement been compromised, you can’t trust the OS to give you the PCR0 System firmware actual values stored in the TPM. You need more help from PCR1 System firmware configuration the TPM itself. This brings me to the next piece of function- PCR2 Plugin card firmware ality that TPMs provide – the ability to generate and store PCR3 Plugin card firmware configuration encryption keys. PCR4 Partition table and bootloader When a TPM is initialized, it generates a key called the PCR5 Bootloader configuration Storage Root Key (SRK). This key never leaves the TPM, and the OS has no way to access it. When an application asks PCR6 Suspend and resume events the TPM to generate a key, the TPM does so and gives the PCR7 Secure Boot configuration public and private halves back to the application. However, before handing back the private half, the TPM en- crypts it with the SRK. The private key can only be used by passing it back to the TPM, which will then decrypt it and store it in the TPM’s internal RAM. Any material that’s been encrypted with the public half of the key can only be decrypted by the TPM that can read the corresponding private key: If you have a TPM key pair and someone steals your hard drive, the thief will have no way of using those keys be- cause they can only be decrypted by the TPM that generated them. Figure 1: LetsTrust provides an attachable TPM 2.0 module for the Raspberry Pi.

LINUX-MAGAZINE.COM | LINUXPROMAGAZINE.COM ISSUE 206 JANUARY 2018 27 COVER STORIES Trusted Platform Module

RAM Option bootloader; and third, you must have the necessary user- space tools. The TPM can be enabled in your system firm- An alternative approach is to use the TPM’s small quantity of ware menu – consult your system documentation to find non-volatile RAM. You can configure the system so that the non- out how. For bootloaders, right now you’ll need to use a volatile RAM is only readable if the PCR values match – if they modified version of GRUB 2 [6]. Finally, you’ll need to in- don’t match, then attempting to read will fail. This approach al- stall TrouSerS (the TPM daemon and library) and the tpm- lows a secret to be stored directly without having to worry about tools package. You need to take ownership of your TPM by encryption. The downside to this technique is that the amount of running: nvram available is quite limited.

sudo tpm_takeownership ‑z change the value of PCR4, for instance, which introduces a great deal of fragility into the system: Regular security updates If you get an error saying “The TPM target command has been may render a system unbootable. One way around this is to use disabled,” this means that the TPM has already been enabled. the TPM in conjunction with Secure Boot. In this mode, only If you didn’t do this, you can reset the TPM by running PCR7 is used. The firmware records the fact that Secure Boot is enabled into PCR7 and then measures each Secure Boot key echo 14 >/sys/class/tpm/tpm0/ppi/request that is used during the boot process. Modifying the bootloader or kernel would require the attacker to disable Secure Boot or as root and then rebooting. The firmware will then ask whether to add new signing keys, so it would change the value of PCR7. you want to clear the TPM. Follow the instructions given and Legitimate updates will be signed with the same key, so it try taking ownership again. won’t change the value. This gives users much greater confi- dence that they can use TPMs safely without having to worry TPM 1.2 and TPM 2 about their system breaking unexpectedly. Recent systems frequently ship with TPMs that conform to TPM encryption keys are not restricted to the boot process. version 2 of the specification. Version 2 is an improvement It’s possible to generate SSH keys that are tied to the TPM [5], in several ways, including support for more modern and se- giving enhanced protection. If someone manages to steal your cure hash algorithms. Unfortunately, support for TPM 2 de- private SSH key, they will still be unable to log in to your sys- vices in Linux is still maturing, and most of the software de- tem unless they have access to your TPM to decrypt it. scribed in this article is only compatible with the older ver- sion, TPM 1.2. TPMs and DRM Some systems ship with TPM 1.2 on the motherboard, but When Trusted Computing first appeared in the mid-2000s, people also implement TPM 2 in the form of an emulated TPM run- were greatly concerned that TPMs could be used to restrict access ning on the Management Engine integrated into the CPU. In to websites or services if the user wasn’t running the right version that case, check the system settings for a reference to “Intel of Windows. The biggest concern was remote attestation. Each PTT,” “Intel Platform Trust Technology,” or “Firmware TPM” TPM has a key called an endorsement key (EK). A remote site can and disable it. ask the OS to perform remote attestation, at which point the OS Some vendors have taken an alternative approach and ship a asks the TPM for the current PCR values and encrypts them with hardware TPM on the motherboard that can be flashed be- the EK. The remote site decrypts them, looks at the PCR values, tween versions 1.2 and 2.0. Dell does this on the XPS 13. and decides to grant access depending on the values provided. Check with your system vendor to find out whether your TPM Two big problems prevent this from being a real concern. can be downgraded to 1.2. First, for this to be viable, the remote site has to know that the EK is really from the TPM. More modern TPMs include an EK Conclusion certificate that provides a chain of trust from the TPM to the Making good use of a TPM under Linux still involves a lot of TPM manufacturer, which means that a remote site can verify manual work, but the results can be extremely worthwhile. that the PCR values came from a TPM; however, they have no Plenty of work is going on to integrate this functionality into way of knowing which TPM unless the user has already regis- distributions so that users can benefit from these security fea- tered this association in some way – which ties to the second tures without having to be experts. With luck, everyone will be problem: Nothing prevents a user from adding a second TPM using TPMs in the near future. nnn to a system, programming the PCRs with “good” values, and then performing remote attestation with the second TPM. Info Because of these problems (and other privacy concerns), re- [1] Trusted Computing Group: https://trustedcomputinggroup.​­ org/​­ mote attestation has never been used outside specific corporate [2] Using TPM for encryption: or special case deployments, and this is unlikely to change in https://github.​­ com/​­ fox‑it/​­ linux‑luks‑tpm‑boot​­ the future. Enabling your TPM does not put you at risk of hav- [3] GRUB: https://github.​­ com/​­ mjg59/​­ grub​­ ing your freedoms infringed. [4] tpmtotp: https://github.​­ com/​­ mjg59/​­ tpmtotp​­ Using Your TPM [5] Using the TPM chip to secure SSH keys: Using a TPM requires a few requirements. First, the TPM https://github.com/ThomasHabets/simple-tpm-pk11 must be enabled; second, you must have an appropriate [6] GRUB 2: https://​­github.​­com/​­mjg59/​­grub/​­tree/​­verifier_tpm_module

28 JANUARY 2018 ISSUE 206 LINUX-MAGAZINE.COM | LINUXPROMAGAZINE.COM

REVIEWS Automatic Backup

Automate data backup at the command line Automatic Backup

Backing up data is an unpopular task that many users – and even some administrators – consider a chore, prompting us to take a look at some command-line automatic backup programs. By Erik Bärwaldt

inux users have access to numer- in terms of features are quite consider- Server vs. Desktop ous backup tools. Administrators able (see Table 1 for an overview). Not Home users often store large volumes of who like working with SSH appre- every program is suitable for every appli- data on their computers, similar in vol- ciate that servers of any size and cation scenario. In this article, I investi- ume to those found on servers in small Ldesign can be backed up with command- gate which tools work for which envi- businesses. High-definition video collec- line programs. However, the differences ronments. tions, as well as audio files with lossless compression and photo Table 1: Command-Line Backup Tools folders, are real mem- Attic bup Duplicity rdiff-backup rsnapshot ory hogs. New data is Local backup Yes Yes Yes Yes Yes often added, but once Backup via SSH Yes Yes Yes Yes Yes stored, the data hardly Verification Yes Yes Yes Yes Yes (logfile) ever changes. Encryption Yes Yes Yes No No On the other hand, Cloud services No No Yes (Amazon, Rackspace) No No you will also often find small files (such as Include/exclude​ directory Yes Yes Yes Yes Yes correspondence, ta- Time-controlled Yes* Yes* Yes* Yes* Yes* bles, presentations, Front ends available No Yes Yes No Yes and databases) on Incremental backups Yes Yes Yes Yes No server systems. These Differential backups No No No No No data collections are Manual full backup Yes Yes Yes Yes Yes constantly changing FUSE-mount possible Yes Yes No Yes No through modifications, *Backups scheduled with the cron daemon. such as newly created Stock, 123RF.com Lead Image © Tezz

30 JANUARY 2018 ISSUE 206 LINUX-MAGAZINE.COM | LINUXPROMAGAZINE.COM REVIEWS Automatic Backup records or added documents. Accord- Differential backup strategies are more Attic requires Python v3.2 or greater ingly, backup strategies must take exist- likely to be used for databases that have and openSSL in a version greater than ing data resources into account to guar- relatively few large files and moderate 1.0.0. Because the software also lets you antee rapid reconstruction in the event regular modifications, whereas incre- mount a backup set in user space, the ll- of data loss. mental backups are better suited to typi- fuse package from the Python treasure cal office environments. Regardless of trove has to be installed to provide this Differential vs. Incremental which you choose, you should always function. Administrators distinguish three backup run at least one full backup per week. After a successful installation, you strategies: full backup, differential Desktop users who want to back up first have to initialize a backup reposi- backup, and incremental backup. The their own databases without root privi- tory. This is achieved with the com- full backup, a copy of the existing data, leges do not have a huge choice of mand: is always the first backup in any plan – backup software for the command line, subsequent backups follow as differen- which obviously requires some knowl- attic init //U tial or incremental backups. Whereas edge of the command syntax. For users, it .attic differential backups always save is important to be able to run a backup as changes since the last full backup, in- smoothly and reliably as possible. The Several directories can then be backed cremental backups only save modifica- end user will only use the backup soft- up in an archive (which should be spe- tions relative to the last backup of any ware – and actually perform the backup – cially created) in this repository. Attic kind. if it is quick and easy to use. does not enable encryption by default. The differential backup procedure re- Ideally, the same software can be used The names for these archives can be quires more space for individual backups, for mixed environments with both a freely selected. The following command but in an emergency, only the full backup backup server and additional desktop backs up the directories: and the last backup will help you recover backups by users. Using the same soft- the entire database. Although the incre- ware saves you the hassle of having to attic create //U mental method uses less disk space, all know the syntax of two programs – and .attic::U incremental backups need to be re-in- thus avoids any associated errors. /U stalled in the correct sequence during the / restore starting from the full backup. If a Attic <[...]> small backup is missed, the database is The Attic backup program, which is writ- no longer reconstructible. ten in Python, can be found in the reposi- Before selecting a command-line tories of some Linux distributions, such If the data must be encrypted, then the backup software, I recommend initially as , openSUSE, ROSA, or Slack- performing a careful analysis of your ware Linux; it can be installed conve- ‑‑encryption=passphrase|keyfile data collection and data growth, so you niently using the respective package man- do not accidentally select a program that agers. The project page also provides the parameter command must be added. is unsuitable for your specific IT envi- source code for download. Detailed docu- I recommend using the weekday as ronment. mentation is also available [1]. the archive name for regular backups of

Figure 1: Attic provides clear-cut data for the latest backup.

LINUX-MAGAZINE.COM | LINUXPROMAGAZINE.COM ISSUE 206 JANUARY 2018 31 REVIEWS Automatic Backup

the same directories, which quickly cies appear, you can perform repairs by ever, they first must have been generated gives you the correct sequence of back- repeating the command with the added with the date parameter. ups during a restore. The first backup in ‑‑repair parameter. a repository can take a long time to com- bup plete for large data volumes, but subse- Restore The bup (short for backup) program has quent backups will be far quicker be- To restore an archive, use the extract op- been in development and maintained for cause Attic saves them incrementally tion by entering seven years, and it has established itself (i.e., only modified or newly added data in small IT environments owing to its is included in the backup). attic extract //U speed and efficiency [2]. The software is If you want to monitor the backup .attic:: available from the repositories for imme- run, you can display the most important diate installation on many major Linux data for the backed up archive using the which starts the recovery of the entire distributions. ‑‑stats parameter. Attic not only lists archive content to the original storage Bup already differs from other backup the directories and the required time for path. The software lists the individual tools in that it uses the Git packfile for- the backup run, but also the number of files. The target path can be changed by mat instead of traditional TAR or ZIP ar- files backed up and the volume of data. an additional path specification, and you chives. The software is very flexible in It shows both the original and the com- can exclude parts of the archive from the terms of handling: For example, bup ar- pressed backed up data volumes, so you restore action. chives can be mounted as filesystems in can keep track of data compression effi- Of course, Attic can also store backups user space. Even backing up entire ISO ciency (Figure 1). on a remote server and retrieve them images, which often contain several gi- In contrast to many other backup during a restore. It expects the same syn- gabytes of data, is no problem for the tools, Attic provides a convenient ap- tax as for a local backup; you address software. However, using the Git packfile proach to listing archive content. For this the server as follows: format does require setting up a reposi- purpose, enter the following command tory first. at the prompt: @:U For an overview of the software’s nu- .attic merous command parameters, call the attic list ‑v //U program at the prompt without any op- .attic:: However, enabling encryption is recom- tions. Bup then lists the most important mended when creating repositories on parameters in short form. You can also The software then lists all the content, server systems. Attic uses 256-bit AES find detailed documentation on the proj- including file size, owner, and file per- for encryption and HMAC-SHA256 for ect site [3]. For local backups on the missions. Subdirectories are automati- verification. Attic encrypts the data be- desktop, the program has Gtk3 and - cally included, and it shows the absolute fore storing it in the archive. based graphical front ends, which makes paths. the backup process easier for inexperi- Automated enced users. These are available from Verifying the Archive The software supports backup runs that the bup homepage. In the same easy way, you can check are controlled and automated by cron data integrity with the Attic backup pro- jobs. To prevent the number of existing Usage gram. The command repositories from getting out of hand in To create a backup, you first need to ini- the long run, Attic provides the prune pa- tialize the backup directory using the attic check //U rameter to let you define the storage life command sequence: .attic of older repositories. This option deter- mines a maximum number of archives BUP_DIR=/ bup init checks the repository and all its ar- to be kept in the repository. You can de- chives. The status is then output as a fine whether these are archives created Next, index the directory to be backed short message (Figure 2). If inconsisten- hourly, daily, weekly, or monthly. How- up with the command:

bup index ‑ux /

If no corresponding directory variable is defined, the ‑d parameter must also be specified with the path for the backup set. Otherwise, bup saves the backup set in the hidden .bup subfolder in your home directory. After indexing, perform the backup with:

Figure 2: At a glance, you can see whether all the data was stored bup save ‑n U correctly. /

32 JANUARY 2018 ISSUE 206 LINUX-MAGAZINE.COM | LINUXPROMAGAZINE.COM REVIEWS Automatic Backup

lar for larger data- bases. Signatures en- sure data integrity, even in insecure en- vironments. That said, Duplic- ity does require a fair amount of user Figure 3: With bup, data is backed up in a few steps. training because of its very complicated In the event of missing directory vari- Extras parameters [5]. Alternatively, graphical ables, the path to the backup set must Bup provides some little extras to front ends (e.g., Déjà Dup [6]) that oper- also be specified with a prefixed ‑d pa- check the integrity of backup sets. One ate more intuitively are recommended, rameter. The set name can be optionally of the most important goodies in prac- especially in smaller environments or for defined and is used to identify the cor- tice is probably the option to mount a desktop backups, even though they fall rect set for recovery if several backups backup in user space like a conven- well short of reproducing Duplicity’s full exist on the same target media. tional drive. The python-fuse package functionality. The software does not sup- During the first backup run, bup cre- must be installed, and a mount direc- port differential backups. ates a full backup, which can take some tory must be created. The set is then Duplicity is suitable for backing up in- time depending on the original data vol- integrated into the existing system by dividual folders, but not for creating ume. The runs that follow only create in- using: complete system images. (Programs like cremental backups, which is much Clonezilla [7] are better suited to this faster. bup ‑d U purpose.) In doing so, the program Keep in mind that before an additional fuse stores the backed-up data in volumes. backup run you have to re-index after For local backups, you also need to spec- each change to the original content for You can then proceed to use the target ify the absolute path, so the data is the software to detect changes. directory and its content like any con- stored in the correct target folder. If you want to store the backup on a ventional drive. remote server, in the simplest of cases, Key Service you would enter the following command Duplicity To let Duplicity play to its strengths (en- sequence: Duplicity [4], which is available as a bi- crypted backups), you first have to gen- nary package for almost all common erate a GPG key or already be in posses- bup save ‑r @ U Linux distributions, is very flexible in sion of one. Entering gpg ‑‑gen‑key at ‑n U terms of supported storage locations. the prompt generates a new key in just a / Not only can you save backups locally, few steps, and you can also define the but also on FTP or SSH servers in the in- key strength (Figure 5). In this case, a full backup is run for the tranet. Additionally, Duplicity supports The passphrase you specify when gen- first pass, and the subsequent backups Windows shares and WebDAV storage. erating a key also provides increased se- are incremental (Figure 3). If such central storage options are not curity: If the key is lost, third parties Bup also supports backing up a re- available, Duplicity can store the back- cannot simply decrypt the archive be- mote machine to a local machine. To ups in the cloud. For this option, it sup- cause the passphrase is requested when do this, enter the bup on command fol- ports Amazon’s S3 cloud and Rack- restoring the database. Particularly para- lowed by the server address and the space cloud solutions. One of the noid users can also digitally sign their ar- target directory on the local system. unique selling points of Duplicity is en- chives so that the data integrity of the Also, an indexing run must be per- cryption: All files can be encrypted with backup volumes can be checked at a formed beforehand. GnuPG (GPG) and stored safely in a later time. To verify existing backup sets, use the cloud, without curious outsiders being In the simplest case, specify the fol- bup ls command to list the individual able to view them. lowing command for a local backup: files. The columns give you a clear over- The software takes a very professional view (Figure 4). approach to creating backups: The first duplicity / U pass is a full backup, which it bundles file:// Reverse Gear into a TAR ar- Restoring backups is just as easy for chive. The pro- users: After specifying the backup set gram then uses path, use the restore parameter instead incremental back- of save, followed by the set name and ups, which saves the path specification. Another option not only storage here is to restore individual subdirecto- space, but also Figure 4: A simple display of the backed up data ries from the set. time – in particu- makes it easier for admins to check the backup.

LINUX-MAGAZINE.COM | LINUXPROMAGAZINE.COM ISSUE 206 JANUARY 2018 33 REVIEWS Automatic Backup

Restore Data recovery is just as easy: Duplicity is activated without any additional pa- rameters; only the source and target paths need to be swapped. Alterna- tively, you can also specify a different target path. The archive is only un- packed after entering the passphrase, so unauthorized persons cannot access the data without knowing the pass- word. Using the verify and ‑‑compare‑data parameters, you can test the integrity of your backups in a simple way. This test is possible even if the volumes are in a cloud. Particularly for documentation purposes, it is recommended to use the additional ‑v parameter (verbosity level), and to replace the x placeholder Figure 5: A key can be created in just a few minutes. with one of the numbers 4, 8, or 9 to obtain meaningful information. The After prompting you for the passphrase these using the ‑‑exclude parameter. data can then be saved in the specified twice, the software creates the backup in Several directories that you do not want file using the ‑‑log‑file the target directory. backed up can be added in a space-sepa- parameter. To save data on an FTP server, call rated list. Excluding individual directo- the software using the command: ries is useful, especially for subfolders rdiff-backup that contain, for example, temporary, Rdiff-backup [8] is another popular tool duplicity / U cache, or logfiles. for backing up at the command line. The ftp://@/U However, caution is required when program is maintained in the reposito- backing up the root directory: The /proc ries of virtually all major Linux distribu- directory must be excluded; otherwise, tions. The software is extremely easy to The passphrase is also requested here be- Duplicity will freeze. Conversely, the use: To produce a local backup of a di- fore saving; you can work around the ‑‑include parameter can include addi- rectory or directory tree at the prompt, prompt by prefixing the sequence FTP_ tional folders in the backup. type: PASSWORD= to the backup com- mand. In both cases, Duplicity automati- cally checks to see whether a full backup already exists in the target path. If this is not the case, it automatically creates the full backup during the first pass. With the second pass, it creates an incremental backup (Figure 6). Manual Trigger An increasing number of incremental backups accumulates over time, espe- cially if you automate the backup runs. Because these need to be restored in se- quence from the last full backup, it is a very good idea to create a new full backup regularly to minimize the num- ber of incrementally backed up archives. Duplicity launches into a full manual backup when started with the full pa- rameter. The incremental parameter manually triggers an incremental backup. If specific directories are to be ex- cluded from the backup, you can specify Figure 6: Duplicity also provides information about the backup.

34 JANUARY 2018 ISSUE 206 LINUX-MAGAZINE.COM | LINUXPROMAGAZINE.COM REVIEWS Automatic Backup

rdiff‑backup U server. To run a backup over SSH, at the verbosity level. The software then out- remote client prompt enter: puts all the processed files. Addition- ally, after launching the backup, vari- This creates a full backup that the ad- rdiff‑backup @ abled and disabled parameters (Fig- tools just as easily as using a conven- ure 7). tional folder hierarchy, using only on- This command backs up the source di- The ‑‑compare and ‑‑list‑increments board Linux tools. rectory from the server on the local cli- parameters provide information about Subsequently backups made by rdiff- ent. If the backup also includes files to the modified files and the different backup contain deleted or older ver- which only root has access, you will backup points. Using the command sions of the changed files. The latest need to log in with the appropriate privi- versions of the changed files all end up leges. rdiff‑backup-statistics U in the full backup, just like new files, so you always have the current status of Displays the backup. Regular backups only save Rdiff-backup, like all other tools being you can also retrieve statistical data for older versions of the database. The ad- reviewed here, has a collection of param- the backup directory (Figure 8). vantage of this special form of incre- eters for managing backups. To view the mental backup, known as reverse delta, content of a backup, enter Exceptions is that you do not have to fight your As with other backup programs, you can way through several incremental back- rdiff‑backup ‑l also exclude files or directories from the ups to restore a complete database. backup. This can be beneficial, for ex- at the prompt. ample, if the backup path includes direc- Servers Because rdiff-backup does not output tories for temporary files that you don’t Using rdiff-backup, you can also back up status messages during the backup want to save. In such cases, use the servers in the intranet. Note that you do runs, it also makes sense to enter the ‑‑exclude parameter to exclude individ- need to install the application on the ‑v6 parameter to switch to the highest ual files.

Figure 7: rdiff-backup gives you far more information than other backup programs – if you tell it to do so.

LINUX-MAGAZINE.COM | LINUXPROMAGAZINE.COM ISSUE 206 JANUARY 2018 35 REVIEWS Automatic Backup

If you need to exclude complete direc- regularly initiates the backup. Manual Configuration tories from the backup run, you can use backup runs are not intended. The soft- After the installation, you need to con- the ‑‑exclude‑filelist parameter; you ware takes all its information from a figure the program, which is available need to specify a file containing the configuration file. from the repositories of practically all paths of the files to be excluded. The file Because rsnapshot works with hard major Linux distributions. To do this, has to be created manually. , the backups always have to end up call the /etc/rsnapshot.conf file, which on the same file- Restore system. Other- To restore backed-up files from the ar- wise, the tool chives, you don’t need to invoke rdiff- would have to cre- backup again: If you need to restore your ate a space-con- data collection from the current archive, suming full you can simply copy the data from the backup. There- backup directory. The Linux cp com- fore, rsnapshot is mand helps you do this; you need to more suited to specify the archive option. The easiest servers on small form is: networks or to local workstations cp ‑a // U than to extensive // storage setups. However, the tool, To access old backup files, the software of- which is written fers two options: You can either access the in Perl, only stores incremental files from the rdiff-backup a configurable program, or you can use rdiff-backup-fs, number of back- which must be installed separately as an ups, so the storage external package, to mount the backup ar- space remains chive as a conventional filesystem. manageable, even The rdiff-backup-fs [9] package (the with short backup Figure 8: One of the various statistical data displays name can differ among distros) is main- intervals. makes it easier for you to check the backups. tained in some software repositories of major Linux distributions, but it can also be picked up from the project website. For direct access, use the ‑r parameter (short for “restore as-of”) followed by a date. For example, you need the follow- ing command sequence to restore a 10-day-old backup from a server to a local directory on a client:

rdiff‑backup ‑r 10D U

:://U

The detailed documentation [10] lists various application scenarios that makes the somewhat unusual nomenclature understandable. rsnapshot As the name suggests, rsnapshot is a tool for creating complete snapshots of a filesystem [11]. It can create both local snapshots and use SSH to create snapshots of remote systems. The Rsync tool creates backups in which hard links replace unchanged files. Rsnapshot actually only writes modified data in the backup. The cron daemon Figure 9: rsnapshot is set up with a configuration file.

36 JANUARY 2018 ISSUE 206 LINUX-MAGAZINE.COM | LINUXPROMAGAZINE.COM REVIEWS Automatic Backup

can be edited easily with any standard Use the Interval parameter to specify shot, this factor limits the applications to text editor. the defined interval in the configuration Linux and related systems. nnn Because the numerous options are file (i.e., hourly or daily). You do not easily accessible, thanks to detailed have to specify source and target directo- Info comments, the configuration does not ries, because rsnapshot takes this infor- [1] Attic: https://attic‑backup.​­ org/​­ ​ pose unsolvable problems, even for in- mation from the configuration file. installation.­ html#​­ installation​­ experienced users. Note that the differ- Because rsnapshot does not store its [2] bup on GitHub: ent options need to be separated by backups in archives or its own formats, https://github.​­ com/​­ bup/​­ bup​­ tabs. Also, path specifications must al- the data is directly accessible and can be [3] bup documentation: ways end with a slash. easily copied back for recovery. After a https://bup.​­ github.​­ io/​­ man.​­ html​­ The configuration file not only lets you successful test run, you can set up the [4] Duplicity: http://duplicity.​­ nongnu.​­ org​­ specify the source and target directories required cron jobs. [5] Duplicity documentation: http://​ and list included or excluded files, it also duplicity.­ nongnu.​­ org/​­ duplicity.​­ 1.​­ html​­ contains a schedule for a backup plan. Conclusions [6] Déjà Dup: Moreover, settings can be defined to The backup solutions explored here are https://launchpad.​­ net/​­ deja‑dup​­ back up a remote server via SSH or han- all reliable and stable. They are suitable dle an LVM network. Settings for the for backing up both local systems and [7] Clonezilla: http://clonezilla.​­ org​­ snapshot retention period (Figure 9) are servers. However, if you want to out- [8] rdiff-backup: also important. source your backup archives into the http://www.​­ nongnu.​­ org/​­ rdiff‑backup/​­ The configuration file is quite exten- cloud, most programs will not be appro- [9] rdiff-backup-fs: https://github.​­ com/​­ ​ sive, so you can validate it after a modi- priate because of their lack of encryption rbrito/­ rdiff‑backup‑fs​­ fication. To do this, enter the rsnapshot support. In a public cloud, you will not [10] rdiff-backup documentation: configtest command at the prompt want to store your backups without en- http://www.​­ nongnu.​­ org/​­ rdiff‑backup/​­ ​ with administrative privileges. The Syn- cryption. examples.­ html​­ tax OK output signals a consistent con- Additionally, some candidates have [11] rsnapshot: http://rsnapshot.​­ org​­ figuration. A cron or anacron job then poor to simply catastrophic documenta- [12] rsnapshot FAQ: launches the software automatically. A tion. In part, the existing description http://rsnapshot.​­ org/​­ faq.​­ html​­ predefined sample configuration is does not list func- available in the /etc/cron.d/rsnapshot tion parameters or file on some distributions, and its data sample applica- can be adapted to suit your individual tions, and the man needs. A FAQ [12] provides more infor- pages are terse mation. 10-liners. Conse- quently, develop- Rotation Keeps Data ers should not ex- Under Control pect their pro- The rotation principle helps you keep grams to be the number of backups manageable in widely accepted line with your needs. You can use the by users whose configuration file to define intervals at time and patience which backups are created and specify are limited. how many backups must be retained for These backup each interval. The retain parameter in solutions, most of the /etc/rsnapshot.conf file uses time which are devel- parameters such as daily or hourly fol- oped for Unix- lowed by a number to configure both. style operating For example, daily retain 5 means systems, also ex- that a daily backup launches, and the hibit some design last five daily backups should be kept. In weaknesses, in further lines, additional intervals can be that they may not defined in the same way, each with its always work in own number of backups to be retained, heterogeneous en- making rsnapshot very flexible in terms vironments. For of use. example, hard After completing the configuration, links cannot be launch a first test run by entering the fol- used on all plat- lowing command: forms or with all filesystems. For a rsnapshot ‑v tool like rsnap-

LINUX-MAGAZINE.COM | LINUXPROMAGAZINE.COM ISSUE 206 JANUARY 2018 37 IN-DEPTH Stacer

Convenient system clean-up with Stacer Janitorial Services

Stacer is a handy graphical tool for cleaning up your Linux system. By Ferdinand Thommes

lassic command-line utilities on the Electron framework [4] and can After downloading the AppImage, I are considered the go-to tools be used for building cross-platform distributed it to various virtual machines for system administration, but apps on the basis of JavaScript, HTML, running Ubuntu, Linux Mint, Mageia, some powerful graphical tools and CSS. Skype for Linux and the Atom , Apricity OS, and openSUSE Calso are available for monitoring and op- editor, Franz messenger, and Darktable and tried a static installation with Siduc- timizing a Linux system. One of those image processing tool are some of the tion (Debian Unstable). Stacer ran on all tools is Stacer, which lives on GitHub better known representatives of the the distributions tested. On systems with [1]. Sourceforge [2] also offers sources framework. KDE Plasma desktop, however, you need for compiling, as well as a DEB packages for 32- and 64-bit systems and an AppI- mage for 64-bit machines. In this article, I take a close look at the Stacer AppIm- age version. (See the box titled “AppIm- age” for more on the AppImage format.) What Is Stacer? Stacer was designed for Ubuntu but works with any distribution, with a Lead Image © konstantynov, 123RF.com Lead Image © konstantynov, couple of restrictions. The application, created by GitHub developers, is based

AppImage If AppImage [3] does not mean anything to you, you’re not alone. Other cross-dis- tribution packaging alternatives, such as Snap and Flatpak, have received much more attention. AppImage, which has been under development since 2004 (ini- tially known as Klik and later as Portable- LinuxApps), is relatively unknown. The apps packaged in AppImage format run Figure 1: Among other things, the Stacer start screen displays animated without installation. CPU, Memory, and Disk Space gauges.

38 JANUARY 2018 ISSUE 206 LINUX-MAGAZINE.COM | LINUXPROMAGAZINE.COM IN-DEPTH Stacer to launch Stacer as root because of a kdesu authorization error. Before the first start, you need to make the AppImage executable, which you can do as a user working in the directory where the package is located; then, run Stacer from the same directory:

$ chmod a+x Stacer‑1.0.6‑x86_64.AppImage

$ ./Stacer‑1.0.6‑x86_64.AppImage

A message tells you that the setup rou- tine is adding the application to the menu and putting an icon on the desk- top, which is the only way in which the application changes your computer. Al- ternatively, you can launch Stacer, like all AppImage applications, by double- clicking on the executable file.

Graphically Managed Figure 2: In the System Cleaner section, you can get rid of temporary Stacer welcomes you with a modern win- files, caches, and old logfiles. dow featuring six tabs: Dashboard, Sys- tem Cleaner, Startup Apps, Services, Unin- staller, and Resources (Figure 1). The win- dow is static, which means you can nei- ther increase nor decrease its size. The program always starts with the Dashboard, which only provides infor- mation and does not allow any interac- tion. The Dashboard gives you a ani- mated view of CPU, Memory, Disk Space, and network interface utilization, as well as information about the in- stalled processor and operating system. Figure 3: In the Startup Apps section, you can add and remove applica- System Cleaner tions to be launched at boot time. The System Cleaner (Figure 2) helps you ditch the ballast: This is where you can remove unnecessary log or cache files and empty the trash can on your system. In the initial state, Stacer does not provide any data for trash disposal; you first need to enable the desired cate- gories and then launch a system scan. Caution is advisable in the App Cache tab: Deleting here could slow down ap- plication launch, and you should pro- ceed with caution when it comes to the logs and keep at least the current X.org log and the Apt and logfiles. Num- bered logs are always older and can typi- cally be disposed of without any worries. Apps and Services In the Startup Apps tab, you can view the applications the system launches at boot time (Figure 3) and set up new Figure 4: Consider carefully starting and stopping services to avoid startup apps. This is especially handy if endangering the running system.

LINUX-MAGAZINE.COM | LINUXPROMAGAZINE.COM ISSUE 206 JANUARY 2018 39 IN-DEPTH Stacer

you work with different distributions: ing a particular service. A word of cau- point and click to uninstall and remove. You do not always need to think about tion: If you shut down the wrong service Stacer does not list basic packages, to where you need to set up applications here, you can look forward to a reboot. keep users from pulling the rug out from that run at boot time on the respective under their own feet. systems, and you can also tell Stacer to Out! The uninstaller works perfectly with lock an application for the next start as a Like the first tab, the last two tabs are Ubuntu and Apricity OS, but not with test, without having to plumb the depths purely informative: As the name sug- any other distribution tested in the lab. of the Control Panel. gests, the penultimate tab, Uninstaller, Rummaging around the bug reports on Starting and stopping system services lets you remove packages (Figure 5). You GitHub revealed an announcement stat- is just as easy in the Services tab (Fig- will find many of the applications in- ing that Stacer can only handle this func- ure 4). A search function facilitates find- stalled on the system here, and you can tion on Ubuntu and (on which Apricity OS is based). Failure to uninstall here is not really tragic, be- cause it makes more sense to delete packages with your distribution’s pack- age manager anyway. Colorful Plots The Resources tab displays the last 30 seconds of CPU, RAM, and network ac- tivity (Figure 6). If you have four, eight, or more cores, Stacer shows them indi- vidually in contrasting colors. To view each plot separately, press the Cpu His- tory button, for example. Conclusions All tasks handled by Stacer can be run at the command line, with standard graphi- cal tools, or even with the use of com- petitor products such as BleachBit [5], but not with the same graphical appeal. Stacer looked best on Apricity OS [6] be- Figure 5: The Uninstaller section only works on Ubuntu and Arch Linux cause it perfectly matches the modern distros and their derivatives. appearance of this Arch Linux-based dis- tribution. Delivery as an AppImage lets you dis- tribute Stacer to multiple distributions in a single package; additionally, you save yourself the installation overhead. How- ever, the AppImage weighs in at more than 50MB, and the executable file is around 75MB after unpacking; the com- plete package tips the scales at 130MB. Keep in mind when using Stacer that you could shoot yourself in the foot with poorly considered actions. nnn

Info [1] Stacer: https://github.​­ com/​­ oguzhaninan/​­ Stacer​­ [2] Download: https://sourceforge.​­ net/​­ ​ projects/­ stacer/​­ files/​­ v1.​­ 0.​­ 6/​­ [3] AppImage: https://en.​­ wikipedia.​­ org/​­ wiki/​­ AppImage​­ [4] Electron: https://electron.​­ atom.​­ io​­ Figure 6: In the Resources section, you can open selected objects (e.g., [5] BleachBit: https://www.​­ bleachbit.​­ org​­ the CPU) and view animations of all the cores individually. [6] Apricity: http://www.​­ apricityos.​­ com​­

40 JANUARY 2018 ISSUE 206 LINUX-MAGAZINE.COM | LINUXPROMAGAZINE.COM

IN-DEPTH Programming Snapshot – AI Sequences

Teach Neural Networks to identify sequences of values First Things First 2, 5, 7, 10, 12 – and what number comes next? Mike Schilli tests whether intelligence tests devised by psychologists can be cracked with modern AI Networks. By Mike Schilli

eural networks do great things In a neural network, the learning algo- comes after 12. In the first learning step, when it comes to detecting pat- rithm adjusts internal weights based on in the first row of the matrix, it learns terns in noisy input data and as- the training data. However, once these that the combination 2, 5, 7 is always signing unambiguous results to weights are deter- them.N If a dozen people with different mined, they won’t handwriting enter the letters A or B in a change anymore form, a trained network can identify at run time and with almost 100 percent certainty what thus cannot ac- they wrote. Or consider pattern recogni- count for temporal tion systems for identifying the license changes in the plates of passing vehicles: Aren’t these input data, be- technical miracles? They extract the dig- cause the machine its from a camera feed so that the De- doesn’t remember partment of Transportation knows ex- any previous state. actly who is going where. Recurrent neural Once a neural network is done learn- networks (RNNs) ing, it always assigns the same result to maintain internal the same input data, but when it comes connections back to tasks that need to determine the next to the input, and value in time-discrete value sequences, thus a result can neural networks often fail to deliver per- influence the next fect results, especially if the input signal input vector, but is subject to variations of unknown peri- this does not help odicity. a simple network identify temporal Figure 1: An intelligence test asking the candidate to patterns that ex- complete a sequence of numbers [1]. tend over several cycles.

At the Psychologist’s A somewhat entertaining example of predicting sequences are intelligence tests (Figure 1) performed by psycholo- gists, where the candidate is asked to de- termine the number that comes next in a numeric sequence. Any Figure 2: Input and output values school kid can tell that 2, 4, 6 is for training the LSTM network. followed by 8, but what comes next after the se- Author quence 2, 5, 7, 10, 12? Mike Schilli works as a software engineer Figure 2 shows two in the San Francisco Bay area, California. learning steps and a test Each month in his column, which has step for a Long Short- been running since 1997, he researches Term Memory practical applications of various (LSTM) network programming languages. If you go to that I want to teach mschilli@perlmeister.​­com he will gladly which number answer any questions.

42 JANUARY 2018 ISSUE 206 LINUX-MAGAZINE.COM | LINUXPROMAGAZINE.COM IN-DEPTH Programming Snapshot – AI Sequences

Figure 4: Temporally consecutive input values initially only change the current internal status and pro- Figure 3: Structure of the LSTM cell. Source: Wikipedia duce output every three time steps. followed by 10. The second row assigns Unlike the neural network, not every ried over memory state that an output a result of 12 to the subsequence 5, 7, input value produces an output value; value (y(1)) is produced. 10, therefore examining a window instead, the LSTM keeps track of the cur- shifted by one step. The LSTM network rent state in a hidden memory cell (Fig- Reshaping Matrixes uses this training data to adjust the pa- ure 4). It is only after receiving the third To implement the LSTM network, List- rameters of its internal cells (Figure 3). snippet of input and evaluating the car- ing 1 [2] uses the Python keras library [3].

Listing 1: iq

01 #!/usr/bin/python3 32 X=np.append(X, chunk[:‑1])

02 import numpy as np 33 y=np.append(y, chunk[‑1])

03 from sklearn.preprocessing \ 34

04 import StandardScaler 35 X=X.reshape((‑1,input_size,1))

05 from keras.models import Sequential 36 y=y.reshape((‑1,1))

06 from keras.layers import Dense, Activation 37

07 from keras.layers import LSTM 38 model = Sequential()

08 import os 39 model.add(LSTM(

09 40 5,input_shape=(input_size,1)))

10 os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' 41 model.add(Dense(1))

11 42 model.add(Activation("linear"))

12 def window(npa, n=2): 43 model.compile(loss="mean_squared_error",

13 for start in range(npa.size‑n+1): 44 optimizer="rmsprop")

14 yield npa[start:start+n:1] 45 model.fit(X,y, epochs=500, verbose=0)

15 46

16 input_size=3 47 print("\nresults:")

17 48 for input in X:

18 seq= np.array( 49 input=input.reshape(1,input_size,1)

19 [2,5,7,10,12]).astype('float64') 50 pred=model.predict(input)

20 51 print(scaler.inverse_transform(

21 print("learn input: " + str(seq)) 52 input.reshape(‑1,1)))

22 53 print(scaler.inverse_transform(

23 scaler = StandardScaler() 54 pred.reshape(‑1,1)))

24 seq = seq.reshape(‑1,1) 55

25 seq = scaler.fit_transform(seq) 56 test = seq[‑input_size::1]

26 seq = seq.reshape(‑1) 57 print(scaler.inverse_transform(

27 58 test.reshape(‑1,1)))

28 X=np.array([]) 59 test=test.reshape(1,input_size,1)

29 y=np.array([]) 60 y1=model.predict(test)

30 61 print(scaler.inverse_transform(

31 for chunk in window(seq, n=input_size+1): 62 y1.reshape(‑1,1)))

LINUX-MAGAZINE.COM | LINUXPROMAGAZINE.COM ISSUE 206 JANUARY 2018 43 IN-DEPTH Programming Snapshot – AI Sequences

array structure back into a one-dimen- Activation function, which sets the re- sional vector. sponse curve of the neurons used inter- nally to linear, because this achieved the Counting Games best results in testing. Called with an array like [3,4,5,6,7] (Figure 6), the script in Listing 1 rela- Off We Go! tively accurately produces the next se- The compile() method then readies the quence number (7.84 instead of 8). List- learning model for processing, deter- ing 1 breaks down the series of numbers mines mean_squared_error (deviations with the window function defined in from optimal learning success are mea- line 12 into sliding windows of four sured according to the mean square ([3,4,5,6], [4,5,6,7]); it stores the first method) as the learning parameter, and Figure 5: A NumPy array assumes three elements in the input vector X and sets rmsprop, a common method for neu- various dimensions with reshape(). the last element in the result vector y. ral networks, as the algorithm optimizer. To prevent the LSTM network’s internal Line 45 then calls the model’s fit() Because many of its functions expect weight adjustments from going haywire, method, passes the learning data to it, data in the form of matrixes of varying the StandardScaler from the sklearn li- and stipulates the number of learning it- shapes and sizes, it makes sense to run a brary normalizes the original input values erations as epoch = 500. In my lab, a lower quick tutorial of the reshape() function to small positive and negative floating- number affected the results negatively, exported by the NumPy array library point numbers around zero for both the but larger values of epoch did not achieve first. A one-dimensional NumPy array input and the result vector, the latter con- any greater learning success, since the (i.e., a vector) is converted by reshape(), taining the anticipated correct results re- system reached a steady state afterward, as shown in Figure 5, to matrixes of pre- quired for supervised learning. and the learning process visibly stagnated defined dimensions. The fit_transform() method then ap- at a constant value for the loss function. The first parameter passed to re‑ plies the scaling procedure and standard- The section starting in line 48 of List- shape() is the number of elements in the izes the data. Later, before it comes to ing 1 then monitors the predictions with first dimension, followed by the number printing the results, inverse_transform() the model in the current phase in the in the second, and so on. Because the turns the tables and maps the data back training, both for the training data and number of elements is implicitly deter- to the original scale for an edifying in- for previously unseen sequences that the mined by the number of remaining ele- spection. system needs to guess without prece- ments after defining deeper dimensions, Lines 38 to 45 stack the individual lay- dence in the training data. the former is often stated as ‑1. Then, ers of the LSTM network on top of one Figure 7 shows that the network does a the library fills the matrix with what’s another. First, the LSTM core layer is good job, even for cyclic data (1,​2,3,​ 1,​ ​ left over. added in lines 39 and 40, with five inter- 2,3), regardless of the length of the signal Called with just one parameter (re‑ nal neurons. It is followed by the con- period, which is a major advantage over shape(‑1)), the method converts a nested nected output layer of type Dense and the traditional neural networks, for which

Figure 6: The LSTM network handles a simple Figure 7: In a cyclic sequence, the algorithm predicts sequence relatively accurately. the next values more or less correctly.

44 JANUARY 2018 ISSUE 206 LINUX-MAGAZINE.COM | LINUXPROMAGAZINE.COM IN-DEPTH Programming Snapshot – AI Sequences

you have to state the periodicity in ad- pip3 install ‑‑user keras pandas U Online Example vance for reliable predictions. tensorflow sklearn numpy Mike Schilli demonstrates the example sudo apt‑get install python‑tk in a screencast (in German) at: Fast as a Snail http://www.​­ linux‑magazin.​­ de/​­ Ausgaben/​­ ​ You need to install the following libraries The TensorFlow back end used by keras 2017/­ 10/​­ plus​­ from the Python treasure trove to be able is not exactly speedy; it took a good 10 to install the keras library: seconds for the program to get going and start the training in length, a count of three thus needs on my five-year- to be added to predict the next num- old PC. ber: 15 is the correct result. The net- At the end of work tended toward 14 most of the the day, the net- time, so it cannot compete with human work did not per- intelligence (as of yet). nnn form particularly well in the intelli- Info gence test (Fig- [1] Number sequence test: ure 8; see also the https://www.​­ fibonicci.​­ com/​­ ​ “Online Example” numerical‑reasoning/­ ​ box). As you will number‑sequences‑test/­ easy/​­ have guessed, [2] Listings for this article: you need to alter- ftp://ftp.linux-magazine.com/pub/list‑ nately add 3 and ings/linux-magazine.com/206/ 2 to the existing numbers in the [3] Brownlee, Jason. Long Short-Term 2,5,7,10,12 se- Memory Networks with Python: Ma‑ Figure 8: The LSTM network did not do well in the ries. Since the chine Learning Mastery. 2017, intelligence test, because it failed to identify the jump from 10 to https://machinelearningmastery.​­ com/​­ ​ different growth rates. 12 was two units lstms‑with‑python/­ IN-DEPTH DDoS Defense

Providers that protect against DDoS attacks Shielded To ward off DDoS attacks, websites and services often seek the protection of Internet giants, such as Amazon, but you have other ways to protect your connectivity. By Konstantin Agouros

istributed Denial of Service The DDoS Family Finally, in sophisticated attacks against (DDoS) attacks are a plague Roughly three categories of DDoS attacks vulnerabilities in applications, attackers with consequences just as hor- can be distinguished. Flooding, as the often don’t even need the first D in DDoS. rific as ransomware attacks. As method described above is known, oc- As a penetration tester, I once encoun- Da blackmail scheme, a targeted attack, or curs when a large group of computers tered a search function in a web portal a form of virtual vandalism, a swarm of send many large data packets to a vic- that was implemented in and attackers floods a website with an influx tim, exhausting the bandwidth or load- launched a gigabyte-scale subthread for of requests in an attempt to shut it ing the infrastructure to its full capacity each search. A script with 10 queries per down. In the past, attackers often used from the excessive number of individual second paralyzed the entire platform. reflection attacks, which involve an at- packets. tacker sending several packets with the In a state exhaustion attack, firewalls Building Floodwalls IP address of the victim as the sender to or load balancers maintain a state for The firewall is regarded as a standard servers, which then acknowledge the re- each connection and enter these states tool in network defense. However, be- quests with long answers. Because of the simultaneously in a table. Keeping many cause it only uses the data of a single spoofed IP address, however, these mas- connection attempts open will quickly package as a criterion for allowing or re- sive responses go to the victim’s address. fill this table; Linux acknowledges full jecting connections – not the quantity Even companies with Internet connec- tables with the message nf_conntrack: and volume of packets – the firewall is tivity in the 10 to 40Gbps range can be table full, dropping packet. If a customer easily negotiated. Better firewalls (as in powerless against attacks with several tries to access your website at this stage, the Linux kernel) provide features for hundreds of gigabits per second band- their request is rejected. I am aware of controlling the bandwidth per connec- width. An Internet search with the key- cases in which an attack with a band- tion, but the CPU handles these and not words “biggest DDoS” regularly shows width of 2Mbps was enough to take the network hardware. new and increasing values for such at- down a network behind a firewall. SYN A separate class of devices filters like a tacks; the peak is currently around flooding does the same thing with the firewall, but as a function of the quantity 1Tbps. With the Internet of Things, at- kernel’s TCP connection table. In the of packets (total and per connection). tackers can now choose platforms that course of the three-way handshake when Dedicated application-specific integrated are much easier to use; for example, establishing a connection, the attacker circuits (ASICs) or field-programmable hacked surveillance cameras, refrigera- only sends the first packet, which means gate arrays (FPGAs) define rules in the tors, and cheap routers have been re- an entry has been created for the con- hardware, but the devices are quite ex- sponsible for recent attacks. In this arti- nection. Once the table is full, any sub- pensive. If you want to intercept attacks cle, I look at methods, providers, and the sequent connection attempts receive a of 150Gbps, you are looking at a six-fig-

costs of protecting your connectivity. Connection Refused response. ure sum. Lead Image © Igor Stevanovic, 123RF.com

46 JANUARY 2018 ISSUE 206 LINUX-MAGAZINE.COM | LINUXPROMAGAZINE.COM IN-DEPTH DDoS Defense

Unfortunately these approaches are of out the attacked target IP address (or net- happen on the DNS level. If the attack little help if the defender of the network work block), either by creating access con- is directed against www.example.com, is sitting at the narrow end of the pipe. trol lists (ACLs) on the routers or by defin- you can redirect the DNS entry to an IP Before the device starts to filter, the pipe ing a null route with the Border Gateway in the scrubbing system. However, it is already blocked. Although the mea- Protocol (BGP) [4]. This entry in the rout- takes a while for the rest of the Inter- sures protect the infrastructure, neither ing table rejects all packages trying to net to discover the change. Admins the internal network nor the company reach the attacked IP address on the router need to keep the time-to-live for DNS website can be reached from outside. upstream. As a result, the attacked server requests low, so name server caching Basically, the defense must be imple- is still offline, but the rest of the line re- does not delay the redirection. mented in two steps: First, you need to mains free. On the other hand, routing protocols identify an attack as such; second, you The BGP flowspec [5] extension, (usually BGP) can redirect traffic. Note need to divert the attack traffic. You can which allows admins to distribute ACLs that this does not work with individual detect attacks by reference to various pa- containing target ports and protocols via IPs, but only with full network blocks. rameters: the BGP protocol, is more surgical. If a The advantage is that these path changes • The quantity and size of packets per Network Time Protocol (NTP) reflection propagate more quickly on the network. source and target port or IP address. attack sends many packets to UDP port • The quantity and size of packets within 123 on the server and the upstream The Narrow End a single connection; because a connec- router only blocks it, third parties can Defenses against state exhaustion at- tion usually comprises just one request still reach the server via ports 80 and 443 tacks can also be implemented on the and one response packet, 20 request (TCP); however, few router manufactur- narrow end of the line. If Netfilter is packages are already suspicious. ers support this strategy. used as a firewall, the first step is to • The totals of these data. Generally speaking, hardly any provid- check the net.netfilter.nf_conntrack_ ers let a customer distribute filter rules max (or /proc/sys/net/netfilter/nf_conn‑ Collecting Data of this kind to its routers. If the provider track_max) system parameter, which Only a few protocols and applications has a powerful DDoS appliance, it will specifies the maximum number of con- follow static rules. If up to 100 requests route the customer’s infected traffic nections. The default value varies be- per hour is usually normal in a web through and enable matching rules so tween 32768 and 65536, which an at- store, that number might multiply that only the desired data reaches the tacker can exhaust relatively quickly. quickly in the pre-Christmas period or victim. You can use sysctl ‑w to increase this during marketing campaigns. Regular The defenses against flooding must be value up to 2GB. However, the machine shifts in values according to the time of made at the thick end of the pipe (i.e., does need to have enough physical day or day of week are also common. the provider side) or at the data center memory to store this number of entries. Statistics programs can discover what is where your web pages are hosted. This An entry consumes a good 300 bytes (in normal and plot it against a timeline. If begs the question as to the bandwidth of reality, it is somewhat more complicated; deviations from the norm then emerge, the data center’s Internet connection. A a blog post [6] describes it more accu- they can be classified as an attack. 40Gbps connection may be completely rately), meaning that more than 700GB Two approaches allow for collecting sufficient for normal operation of a data of RAM would be needed for the 2 bil- traffic data: (1) Installing a device inline center, but attacking it is child’s play in lion entries. According to the cited page, (i.e., using two cables) that acts as a the DDoS world. I have experienced an the kernel can handle 1.7 million entries bridge between the inside and outside. attack on a customer of more than with around 512MB set aside for connec- The device then records all data in pro- 200Gbps against a single server, without tion tracking, which is quite a few orders miscuous mode and thus collects statis- any commercial interests being involved. of magnitude greater than the default tics. (2) Connecting such a device to the value. mirror port of a switch so that a failure Data Scrubbing The kernel can use SYN cookies to de- does not interrupt the connection. Individual providers offer their cus- fend against SYN flooding. The server Another option is to use NetFlow [1], tomers DDoS protection for a charge. sends a response but does not create an sFlow [2], or Ipfix (Internet Protocol Some purchase expensive hardware entry in the table. In SYN flooding at- information export) [3]. These pro- that can do this and then rent it out to tacks, the third packet is missing. If it tocols provide the sought-after connec- customers. does arrive, the server recognizes the sit- tion data (with different levels of detail). Cloud mitigation is most common, uation and creates the entry. To make Network components such as routers or wherein a dedicated provider “scrubs” this possible, the kernel constructs the switches send statistics to a receiver, the traffic by running a farm of anti- sequence numbers so that it recognizes which then carries out the statistical DDoS appliances in a broadband-con- them in the ACK packet. analysis and alerting. nected data center to which the victim’s DDoS appliances can do this, too, but traffic is rerouted for cleaning and then also offer the ability to work as TCP Switching to Defense routed back again to the target through a proxies, which means that they first Mode tunnel. complete the handshake acting as prox- Defensive measures consist of blocking There are two options for redirecting ies and only open the connection to the unwanted traffic. Usually, the admin filters the traffic. On the one hand, it can server if it actually works. Most modern

LINUX-MAGAZINE.COM | LINUXPROMAGAZINE.COM ISSUE 206 JANUARY 2018 47 IN-DEPTH DDoS Defense

firewall systems can also use this ap- protect your own network connection in Link11 proach. another way, you cannot fight off tar- Link11 [10] also offers protection by BGP, Defenses against more powerful at- geted attacks. by DNS redirection, and by connecting tacks also exist at the same level. For directly to host service provider data web applications, a reverse proxy, such Arbor Appliance centers. The licensing differs in the DNS as an Apache with mod_security, can fill Arbor [9] produces DDoS detection and and BGP versions, but both define clean the breech. The module makes it possi- defense systems with its own hardware. traffic as a 95th percentile of normal traf- ble to provide rules for, and limit the The company provides traffic scrubbing fic (without attacks). number of, requests per source IP ad- systems in data centers in the US, Eu- On DNS, Link11 counts how many IP dress. However, you have to configure rope, and Asia. The service only defends addresses it protects on the original sys- this by hand for each URL. against attacks detected by the customer. tems, with clean traffic speed levels of DDoS appliances allow you to set lim- Licensing depends on the bandwidth 25, 50, 100, 150, and 250Mbps. In the its at the transaction level, but you of clean traffic. If a customer has a case of BGP, the size, in terms of a net- should first check with the manufactur- 1Gbps line, they pay for the 1Gb pack- mask, counts as a parameter, and the ers as to which protocols they support. age. Additionally, Arbor offers packages count starts with a /24 network as the A10 Networks [7] even offers to enable for a monthly fee or for defense against first. The second is again the protected Captchas dynamically when a threshold 12 attacks per year. The packages each bandwidth (Link11 differentiates be- is exceeded and then only allow further include the protection of a /24 network, tween symmetric and asymmetric rout- requests to the affected source address including five DNS names, and are ex- ing); the scales are 250, 500, and in question once a human user has been pandable. Arbor lets you link triggering 1,000Mbps. confirmed by the Captcha. of the defenses to your appliance. If an attack is detected, the Cloud defense is Akamai AWS Shield triggered and provides reports for the at- Akamai [11] operates one of the largest The Amazon Web Services (AWS) Shield tacks. content delivery networks (CDNs) [8] provides protection against DDoS at- tacks (Figure 1). The Standard protection is available to any AWS customer. The product includes detection of network flow data and automatic mitigation of DDoS attacks against SYN flooding or UDP reflection attacks. However, you do not receive information about a success- ful defense. If you choose the AWS Shield Advanced product, you receive the following additional features for around $3,025 per month plus charges for data transfer: • In addition to connection data at the network level, Amazon collects and analyzes transaction logs at the appli- cation level. • Access to advanced scrubbing capaci- ties. • Notification of attacks on ISO Layers 3 and 4, as well as data about the type of attack. • Reports for ISO Layers 3, 4, and 7. • Incident management by the Amazon DDoS response team. • If necessary, manual mitigation. • Manual analysis after the attack. • Reimbursement for costs incurred by the attack associated with CloudFront, Route 53, and ELB services. Of import is that Amazon only protects what runs on Amazon. Although it is possible to protect data traffic on your own servers using services such as Figure 1: Amazon protects customers against DDoS attacks – to an extent. CloudFront or a reverse proxy and to For more protection, you will have to dig very deeply into your pockets.

48 JANUARY 2018 ISSUE 206 LINUX-MAGAZINE.COM | LINUXPROMAGAZINE.COM IN-DEPTH DDoS Defense

Figure 2: Akamai, known for its global CDN, provides customers with protection against attacks for a fee.

worldwide and uses its network to away from Amazon completely, you your options beforehand. Link11 and offer DDoS protection in the cloud. In need to look around for another provider Arbor offer emergency links on their web- addition to the DNS and BGP variants, in terms of DDoS protection. sites in the event of an attack. For those Akamai sells proxy protection, which The information in this article can at risk, there is no time to lose. nnn places your individual applications probably steer you in the right direction, (e.g., ports on IP addresses) under but it does not present a universal solu- Info their protection. tion. Because the pricing structures dif- [1] NetFlow: https://en.​­ wikipedia.​­ org/​­ wiki/​­ ​ Like Link11, the Prolexic Connect fer considerably between providers, you Netflow­ product provides data centers with the should first analyze your own threat sit- [2] sFlow: http://www.​­ sflow.​­ org​­ option to slip under the wing of CDN uation closely. Have you already experi- [3] Ipfix: https://tools.​­ ietf.​­ org/​­ html/​­ rfc7011​­ (Figure 2). Like Link11, Akamai struc- enced attacks or been threatened with tures the billing model as a subscription attacks? If so, was the entire company [4] Border Gateway Protocol: https://tools.​­ ​ and uses the 95th percentile of clean or threatened or just one department? In ietf.­ org/​­ html/​­ rfc1772​­ normal incoming traffic to calculate a the latter case, even Amazon can be use- [5] Flowspec: https://tools.​­ ietf.​­ org/​­ html/​­ ​ price. In the BGP variant, the number of ful, especially if the volume of regular rfc5575­ /24 networks and the number of pro- traffic is not too high. [6] Netfilter Conntrack memory usage: tected sites still play a role. Even if you do not take precautions https://johnleach.​­ co.​­ uk/​­ words/​­ 372/​­ ​ against DDoS attacks with specific mea- netfilter‑conntrack‑memory‑usage­ Conclusions sures, you should at least have a contin- [7] A10: https://www.​­ a10networks.​­ com/​­ ​ If you run your infrastructure with AWS, gency plan up your sleeve and discover products/­ thunder‑series/​­ ​ you will be grateful for the basic protec- ddos‑detection‑protection‑mitigation­ tion provided. Advanced protection is Author [8] AWS Shield: https://aws.​­ amazon.​­ com/​­ ​ quite pricey, though. You should con- Konstantin Agouros works as Head of Open en/­ shield/​­ sider whether Amazon’s presence is so Source Projects at Matrix Technology AG, relevant for your business that it justifies where he and his team advise customers [9] Arbor: https://www.​­ arbornetworks.​­ ​ on open source and cloud topics. His new a premium of more than $3,025 per com/­ ddos‑protection‑products​­ book, Software Defined Networking: SDN- [10] Link11: https://www.​­ link11.​­ com/​­ en/​­ month. The option to pay per attack can Praxis mit Controllern und OpenFlow [Prac- quickly have an adverse effect on the tice with Controllers and OpenFlow], is pub- [11] Akamai: https://www.​­ akamai.​­ com/​­ us/​­ ​ purse of the victims. If you want to get lished by De Gruyter. en/­ resources/​­ ddos.​­ jsp​­

LINUX-MAGAZINE.COM | LINUXPROMAGAZINE.COM ISSUE 206 JANUARY 2018 49 IN-DEPTH Peek

Record screencasts with Peek on Gnome In the Can A screencast shows what happens on the desktop. Peek lets you create screencasts in the blink of an eye and export them to popular formats. By Christoph Langner

s the famous saying goes, a pic- video by the software when you click Re- You can open these formats – in a ture is worth a thousand words. cord. After pressing Stop (Figure 1), Peek style typical of modern Gnome applica- But how many words can a immediately saves the results on the tions – from the application menu next video save you? A million, hard disk. to the Activities button in the desktop’s Amaybe? In many situations, a short The program has supported real video header bar. Then adjust the additional screencast­ (i.e., a video of desktop formats (e.g., WebM and MP4) since ver- parameters, if necessary, such as the events) gives a far better explanation of sion 1.0.0, which was released in March Delay in seconds before the recording a problem or an action than wordy text 2017. To set the output format, as shown starts and the Framerate, or influence with images. A wide range of tools is in Figure 2, click on the Peek icon in the the size of the recording with Resolution available for this purpose. upper left corner and choose Preferences. downsampling. The range extends from Simple- ScreenRecorder [1] to recordMyDesk- top [2]. Compared with these candi- dates, the fairly recent Peek [3] has a very small feature set, but the program is not trying to compete with the more established applications. Originally, it simply recorded the desktop as a GIF, thus producing videos that were easy to embed into web pages. However, Peek now also supports more traditional video formats such as WebM and MP4. Recording the Desktop In terms of the interface, Peek is deliber- ately oriented on the LICEcap [4] screen- cast tool for Windows. The program shows a scalable transparent window that is always in the foreground on top of all your other applications. Everything Figure 1: Before recording, a programmable timer counts down the

inside the window frame, is grabbed as a screencast, giving you time to arrange everything. 123RF.com Lead Image © Roman Fedin, 123RF,

50 JANUARY 2018 ISSUE 206 LINUX-MAGAZINE.COM | LINUXPROMAGAZINE.COM IN-DEPTH Peek

Listing 1: Add PPA

sudo add‑apt‑repository ppa:peek‑developers/stable

sudo apt update

sudo apt install peek

cording by an in- What is currently causing Peek diffi- teger factor. culties is the change to the new display server, Wayland. For security reasons, Installation Wayland isolates individual applications Peek’s first com- on the desktop from each other. Software mits date back to is not allowed to read the content of an- December 2015; other program’s window. Thus, screen- Figure 2: You can select the video format in the Peek since then, the de- shots of the entire desktop are no longer preferences dialog. In addition to GIF, Peek supports veloper has worked easily achievable. WebM and MP4. quite actively on However, Peek is not the only applica- the program. At the toin facing this problem; other screen- For the GIF format, especially, you beginning of 2017, the work started to shot tools, such as Shutter [6], are also should keep in mind that it was not origi- pick up speed: Changes to the code ap- affected. Additionally, Wayland no lon- nally designed for recording: Recording peared daily on GitHub. As a fairly young ger delivers absolute coordinates on the the entire desktop in full HD at 30 frames program, it is not currently found in the position of the application window, per second (FPS), will result in huge files. repositories of the major distributions. which – at least theoretically – puts it in Therefore, choose only the snippet However, Ubuntu has a Personal Pack- a position to arrange windows on round that you actually want to view later. age Archive (PPA) repository (Listing 1). or curved 3D displays. When scaling the window, the size dis- On Arch Linux, you can simply install Unless you launch Gnome under the play can help you align the frame pre- the application from the Arch User Re- classic X server via the display manager cisely (Figure 3). Additionally, you can pository (AUR) [5]. For other distribu- using Gnome on Xorg, Peek therefore reduce the framerate to about 10fps, tions, such as Fedora, Debian, or , needs to revert to the XWayland [7] and, if necessary, use the Resolution the developer provides instructions for compatibility layer, which now hap- downsampling option to scale the re- installation on the project page. pens automatically when you start

Figure 3: The scalable frame with a size display helps you align the area for the recording.

LINUX-MAGAZINE.COM | LINUXPROMAGAZINE.COM ISSUE 206 JANUARY 2018 51 Input Visualization If you want to demonstrate a certain step to your viewers, rather than just grabbing a video of a program, it is useful to see input and mouse clicks. Linux offers two applica- tions to help you with this include key-mon [8] and screenkey [9]. Key-mon simply dis- plays a small window with an iconized mouse and the Ctrl, Alt, and Shift keys. However, screenkey displays all input from the keyboard in a bar. The applications can complement each other, if necessary. On one hand, key-mon illus- trates mouse actions. Starting the program with the command

key‑mon ‑‑visible_click draws a red circle around the mouse cursor, even for clicks. On the other hand, screen- key helps you with entries such as Ctrl+C or helps improve the viewer’s understanding of the commands (Figure 4).

Figure 4: key-mon and screenkey help you visualize mouse clicks and keystrokes in a video.

Wayland; however, if needed, you can Info call the application directly under [[1] SimpleScreenRecorder: http://www.​­ ​ XWayland with: maartenbaert.­ be/​­ simplescreenrecorder​­ [2] recordMyDesktop: http://​ GDK_BACKEND=x11 peek recordmydesktop.­ sourceforge.​­ net​­ [3] Peek: https://github.​­ com/​­ phw/​­ peek​­ After fulfilling this condition, working with the program is very easy: Launch, [4] LICEcap: http://www.​­ cockos.​­ com/​­ ​ align the frame, and record the screen- licecap­ cast. For more tips on screencasts, check [5] Peek in the AUR: https://aur.​­ archlinux.​­ ​ out the “Input Visualization” box. org/­ packages/​­ peek​­ [6] “Shutter does not work in Wayland”: Conclusions https://bugs.​­ launchpad.​­ net/​­ shutter/​­ ​ The enhancement list, a roadmap for +bug/­ 1502263​­ Peek on GitHub [10], lists a large num- [7] XWayland: https://wayland.​­ ​ ber of innovations and ideas for the fu- freedesktop.­ org/​­ xserver.​­ html​­ ture of the tool. The most important of these has already been implemented in [8] key-mon: https://code.​­ google.​­ com/​­ ​ the form of support for a genuine video archive/­ p/​­ key‑mon​­ format (WebM), but other useful fea- [9] screenkey: https://github.​­ com/​­ wavexx/​­ ​ tures, like the ability to pause the record- screenkey­ ing, a picker for selecting a screen area, [10] Future improvements: https://github.​­ ​ or a progress bar when rendering the re- com/­ phw/​­ peek/​­ issues?​­ q=is%3Aissue+​­ ​ cording, are still on the roadmap. nnn is%3Aopen+­ label%3Aenhancement​­

LINUX-MAGAZINE.COM | LINUXPROMAGAZINE.COM IN-DEPTH Charly’s Column – inxi

The sys admin’s daily grind: inxi Info Tubbies The name of the tool that columnist Charly Kühnast recommends this month may sound like the Teletubbies, but it is but far from infantile when it comes to functionality. In fact, inxi provides detailed and precisely controllable hardware and system usage information for the host computer. By Charly Kühnast

very admin knows how to retrieve and shell processes). If I want to see a Memory Details information about the system on few details, the ‑F parameter provides Running with root privileges, inxi tells which they are working. How information on the video and audio me more about the RAMe: Apparently many cores does the CPU have? hardware, partitioning, RAID, tempera- four 2GB DDR modules are plugged into Ecat /proc/cpuinfo! Is eth3 a gigabit inter- tures, and fan speeds (Figure 1). my test machine and clocked at face? ip l sh! But instead of many tools, If I’m only interested in a particular 1600MHz – yes, this is a fairly ancient you can just use one: inxi [1]. component, I can target this with spe- beast (Figure 2). The ‑c4 parameter Suppose I need an overview of a ma- cific parameters, such as ‑C, ‑A, and ‑G, shown in Figures 1 and 2 is responsible chine with which I don’t normally work. which stand for information on the CPU, for the color scheme. The default color Then, I call inxi without any parameters audio, and graphics, respectively. Infor- scheme is not easily legible on termi- and get some basic information about mation on the RAM is returned after a nals with a light background, but the hardware (CPU, clock speed, RAM, (lowercase!) ‑m, which takes some get- thanks to the plethora of options from and disk size) and the system (kernel ting used to. ‑c1 to ‑c32, selectable sets are available to suit your taste. I can even talk inxi into a spot of simple pro- cess monitoring. If I want to know which five (this is the default value) processes are currently hogging the most RAM, inxi ‑t m will help me find out. If I want to see the top 10 processes, I enter ‑t m10. If I hear the CPU fan humming, on the other hand, I just need to replace the m with a c to view the pro- cessor load. You can also Figure 1: “Extensive” is probably the best description of what inxi bundles into its system overview here. combine the two: inxi ‑t cm 10 returns the top 10 RAM and CPU hogs. At the end of this infor- mative newscast on the computer, I’ll take a quick look at the weather: inxi ‑w Berlin, Germany tells me what the situation looks like outside the Figure 2: If you give inxi root privileges, you are rewarded with precise information on the computer’s memory banks. server room. nnn

AUTHOR INFO Charly Kühnast manages Unix systems in the data center in the Lower Rhine region of Germany. His [1] inxi: https://github.​­ ​ responsibilities include ensuring the security and availability of firewalls and the DMZ. com/­ smxi/​­ inxi​­

LINUX-MAGAZINE.COM | LINUXPROMAGAZINE.COM ISSUE 206 JANUARY 2018 53 IN-DEPTH Command Line – Melt

Playing and editing audio-visual from the command line Melt

Whether you are an expert or a beginner, you can learn to video, audio, or audiovisual clip, edit audio and video clips at the command line with Melt. enter:

By Bruce Byfield melt CLIP

hen free software users cies, and, second, it works with exist- A window opens for the video. It will be think of Melt, they usually ing multimedia libraries and applica- blank for an audio-only file and, of think first of GCC MELT [1], tions. These characteristics are possible course, have no sound for a video-only the popular extension sys- because of Melt’s modular design and file. When all clips have played, regard- temW to the GCC compiler. However, its high-level bindings for major pro- less of their format, you will have to Melt, the command-line multimedia gramming languages like C++, Java, close the window manually (Figure 1). player [2], is just as interesting in its Lua, Perl, PHP, Python, Ruby, and Tcl. Multiple files can be entered with a own right, because it supports every Additionally, Melt is thoroughly mod- space between them. Options for each file file format you can imagine, and prob- ern, making use of multicore proces- follow immediately after its name. Alter- ably a few that you haven’t. Admit- sors and GPU processors. natively, you can use ‑group immediately tedly, Melt’s non-standard syntax takes Functionally, Melt is a full-featured after the basic command to apply options a bit of learning, but as a command, it editor that can customize both audio to all the listed files. For example, can be as simple or as complex as you and video clips in detail, either for one- choose to make it. time playback or for permanent melt ‑group in=0 out=25 CLIP1 CLIP2 Melt is part of the Media Lovin’ Tool- changes. Strictly speaking, Melt was kit (MLT) [3], a cross-platform multi- originally a test tool for the MLT frame- will play the first 25 frames of CLIP1 media framework designed for televi- work. However, its versatility means and then the first 25 frames of CLIP2. sion. Two characteristics make Melt that, in a few small circles, Melt has be- Deciding exactly which frames to play, stand out: First, it has few dependen- come that most free software of applica- of course, requires some experimenta- tions: A command-line tool for pur- tion. Author poses that are usually expected only in The group settings apply until the next Bruce Byfield is a computer journalist and a desktop environment. These days, ‑group option is entered in the com- a freelance writer and editor specializing Melt is often found by itself in the re- mand, so if you want to play the first 25 in free and open source software. In positories of major distributions. frames of CLIP1 followed by the whole of addition to his writing projects, he also CLIP2, the command would be: teaches live and e-learning courses. In his spare time, Bruce writes about Northwest Basic Playback coast art. You can read more of his work at Like most commands at the prompt, melt ‑group in=0 out=25 CLIP1 U

http://​­brucebyfield.​­wordpress.​­com Melt begins simply enough. To play a ‑group CLIP2 Lead Image © Okea, 123RF.com

54 JANUARY 2018 ISSUE 206 LINUX-MAGAZINE.COM | LINUXPROMAGAZINE.COM IN-DEPTH Command Line – Melt

Services and Filters For simple play- back, the options listed above are usually enough. However, the melt command also in- cludes a wealth of advanced options for what the MLT documentation re- fers to as “ser- vices.” If you want to add Figure 1: Melt opens a window in which to run a video. a service to all the clips specified in the In effect, this command creates a new, versely, ‑video‑track or ‑hide‑audio command, enter empty group for the second clip. How- plays the video portion of a clip without ever, you could add a different range of the accompanying sound. ‑group ‑filter SERVICE frames to play for the second clip: Besides in= and out=, you can modify playback with several other options. If at the end of the command. For instance, melt ‑group in=0 out=25 CLIP1 U you are experimenting with exactly to play all the clips in the same directory ‑group in=35 out=60 CLIP2 what frames to use with in= and out=, without color, enter: adding ‑progress will give you a graph- When playing an audiovisual clip, you ical representation of the file that is melt ‑group in=0 out=25 CLIP1 U can play the audio only by using either currently playing. You can also loop ‑group in=35 out=60 CLIP2 U ‑audio‑track or ‑hide‑video. Con- playback with ‑repeat TIMES. ‑group ‑filter greyscale IN-DEPTH Command Line – Melt

Do not forget to include ‑group, or else tion, followed by the service may be affected by options ‑mixer TRANSITION. for the last-named clip. • "profiles": How a However, if you want the service to be clip is processed, used only by a specific clip, enter the op- such as the frame tion resolution and scan rate. If not ‑attach SERVICE:ARGUMENT NAME=VALUE specified, the characteristics of after the clip, just as you would any the clips them- other option. selves are used. Melt supports hundreds of services, so Beginners can you might often want to run the ‑query generally ignore option first to see what services are these services. available. To reduce the length of the • "presets": Play- Figure 2: The start of the list of audio formats sup- output, you can run back options and ported by Melt, as shown by the query option. formats. Again, melt ‑query SERVICE‑TYPE beginners might want to ignore these ‑serialise FILENAME.melt services. to see a group of related services (Fig- • "formats": Audio, video, and audiovi- To play back the saved command struc- ure 2). Even then, you will probably sual formats supported by Melt. For- ture, run it in Melt as though it is just want to filter the command with |less to mats can be specified to force Melt to another supported format. You can add make it readable. use a clip when it is having trouble another clip by including ‑track CLIP to Note, too, that many services are listed identifying its format. Many listed for- the same command. by ‑query with a prefix, although all fil- mats are likely to be known only by Advanced users may want to learn ters are entered in a melt command with- experts. about MLT’s XML format [4], which out the prefix. Additionally, the bare list • "audio_codecs": Audio formats sup- uses the same components as the melt may not tell you very much, so after you ported by Melt. Use this setting with command to save complex playback op- locate a possibly useful service, run ‑query rather than formats to reduce tions. Note, though, that the online MLT the size of the list displayed. documentation presupposes a knowl- ‑query SERVICE = ID • "video_codecs": Video formats sup- edge of audiovisual matters and might ported by Melt. Use this setting with be only intermittently useful, unless to receive more detailed information ‑query rather than formats to reduce you are willing to look elsewhere con- about the arguments and values that a the size of the list displayed. stantly for definitions or to experiment particular service supports. If more de- Unless otherwise specified above, you until you understand. tailed information is not available for a can run any of these types of service, by Most users, though, should find a service, Melt simply displays the list of entering the name of the type followed basic knowledge of Melt more than available services, organized by type. by the service (e.g., ‑process NAME). enough to begin using it. Like all au- The following service types can mod- Although Melt can be run with only diovisual editors, including those that ify the ‑query option: a basic knowledge of its command run on the desktop, Melt is very much • "consumers": The application or utility structure, these lists of services reveal what you make it. The MLT website that plays clips, such as XML or JACK. exactly how complex the command admits to a few gaps in functionality, If no consumer is specified, the default can be. Very likely, the average user such as the ability to add a watermark is SDL. does not use half of the available ser- to every frame. However, for the most • "filters": Frame modifiers that change vices, but if you are an expert in audio- part, Melt can meet the needs of not how audio or visual are displayed. No video matters, Melt can probably ac- only users who want nothing more filter affects the files – only how they commodate your needs as well as than simple playback, but also more are displayed. Examples include satura- those of a beginner. advanced users who want to edit play- tion, volume, and watermark. back in more elaborate ways. nnn • "producers": Software playback librar- Last Words ies or components, or else wrappers As you can imagine, the melt command Info for hardware drivers. can be complex by the time you are [1] GCC MELT: http://gcc‑melt.​­ org/​­ • "transitions": How playback moves finished. Any given instance can [2] Melt: https://www.​­ mltframework.​­ org/​­ ​ from one clip to another – for instance, quickly become so complex that recre- docs/­ melt/​­ luma, a change in brightness achieved ating its structure may be more than [3] Media Lovin’ Toolkit: by specifying a grayscale bitmap, or you are eager to attempt. You can al- https://www.​­ mltframework.​­ org​­ matte, a brief overlay of the two clips. ways use Bash history, but in the long When adding a transition to a com- run, you can save the command struc- [4] MLT XML: https://www.​­ mltframework.​­ ​ mand, use ‑mix LENGTH to set its dura- ture with: org/­ docs/​­ mltxml/​­

56 JANUARY 2018 ISSUE 206 LINUX-MAGAZINE.COM | LINUXPROMAGAZINE.COM

MAKERSPACE Smart Cities MakerSpace Smarter with open source Too Clever

Making the city of Messina, Italy, smarter with open source and IoT. By Swapnil Bhartiya

magine you are driving downtown that collects data through Internet of in the middle of the night. Rows of Things (IoT) devices spread across the red lights shine ahead. Traffic is city. That data is then analyzed to find thin, almost non-existent, and you the solutions to different problems. Take, wish you could turn all the red lights green for example, potholes. If sensors in- I and arrive home earlier. stalled in vehicles or on mobile devices What if you could pull carried by people with the appropriate your phone out, auto- app can notify the municipality of the matically connect to the pothole locations, these potholes could nearby lights, and turn be fixed. If the city can monitor the air, them green? acoustic pressure, brightness, humidity, That’s precisely and other environmental aspects, offi- what a team at the cials could improve the quality of life. University of Messina, Italy, tried to do. “It SmartMe.IO worked. It was very Traditionally, solutions to these prob- precise in real time, lems start with municipalities; however, but there are so many they don’t usually have the resources or rules, laws, and regu- incentives to invest in IT to find solu- lations to comply tions. SmartMe.IO, an academic spin-off with before even being consid- born out of a team of researchers from ered for actual usage in the streets,” said the Mobile and Distributed Systems Lab Giovanni Merlino, research fellow in the (MDSLab) at the University of Messina, Department of Engineering, University tries to change that by coming up with of Messina. Merlino delivered a talk vendor-neutral, open source solutions about his team’s work at the Boston that can help a city “on a shoestring OpenStack Summit 2017. budget.” Messina is one of the largest cities on SmartMe.IO kick-started a smart city- the island of Sicily and is home to more related crowdfunded project [1] aimed at than 300,000 inhabitants. A city that size encouraging “a conversation with the has its own set of civil challenges – envi- municipality of Messina in order to spur ronmental pollution, wear and tear on the creation of a novel virtual ecosystem roads, safety and security of citizens, based upon the paradigm of the Internet traffic monitoring and optimization, and of Things.” potholes. This SmartMe.IO initiative started with The modern way of solving these some prototypes that used Arduino-

problems is by building an infrastructure based sensors to collect environmental 123RF.com Kiselev, Lead Image © Andrey

58 JANUARY 2018 ISSUE 206 LINUX-MAGAZINE.COM | LINUXPROMAGAZINE.COM Smart Cities MAKERSPACE data, such as humidity, brightness, and work on Arancino. More than 100+ IoT happens on the edge device and only carbon dioxide level. However, they devices spread across the city are ac- statistical data is sent to the server. didn’t want it to remain a research proj- tively collecting valuable data. Once again, it’s all powered by open ect. They wanted to expand and scale it source, with the use of Darknet on the out so that it could serve people beyond Virtual Points cameras to protect privacy. the city of Messina. The team ran a suc- In addition to the physical boxes on the cessful crowdfunding project to grow the map are virtual boxes, which represent Future project. points of interest that could be either The next plan for the project is to offer In a nutshell, the SmartMe.IO project landmarks or most-clicked areas. These complete end-to-end solutions, all the has three core components: IoT or edge areas won’t have any physical boxes in- way from Arancino boxes to the cloud, devices scattered across the city to col- stalled. so interested parties don’t have to worry lect different kinds of data, an Infrastruc- “The virtual box would then be just about the infrastructure and can con- ture as a Service (IaaS) platform to col- flagged/​labeled/​colored differently to let sume the data that they need. lect and process the data, and data pro- the user know data is extrapolated/​pre- The SmartMe.IO team is also working cessing to offer more refined services to dicted, but not actually sampled. The on using mobile devices like smart- the city and other stakeholders. predictive engine analyzes and correlates phones to expand their scope. To make time series from neighboring boxes (say, the project financially sustainable, Stack4Things four or more surrounding the location of SmartMe.IO is planning to sell services, The SmartMe.IO team created a fully the virtual one) and predicts expected consulting, and integrated systems. open source framework called Stack4Th- values of homogeneous metrics (say, hu- What they are not selling is datasets; at ings, which is a complete solution to midity values from four neighboring hu- the moment, data is meant to be open. manage the fleet of IoT devices remotely. midity sensors), or even heterogeneous The SmartMe.IO platform is part of the The framework has two agents: one for ones (say, temperature values from a Fiware [4] community, a European ini- the server side and one for edge devices. mix of neighboring and/​or co-located tiative to “build an open sustainable eco- The server/cloud-side​ agent is called Io- humidity/​brightness sensors). Use cases system around public, royalty-free and Tronic [2], and the node-side (IoT edge [include] faulty sensors (incomplete implementation-driven software plat- device) agent is called Lightning-Rod. time series) [and] sparsely covered form standards that will ease the devel- IoTronic is an IoT resource manage- areas,” said Merlino. opment of new Smart Applications in ment service for OpenStack Cloud, tradi- multiple sectors.” tionally known for hyperscale cloud CKAN The SmartMe.IO efforts are a great ex- computing and massive infrastructure. The third, and the most important, part ample of how open source technol- SmartMe.IO wanted to build an IaaS-ori- of the equation is data. The SmartMe.IO ogies enable ented solution for these IoT devices, an platform uses open source CKAN [3] anyone in infrastructure that can be scaled on the data management software to manage the world to basis of demand. At the same time, they the collected data, which is openly avail- come up wanted to expand the scope of Open- able to developers in raw format and can with inno- Stack beyond the data center, toward the be downloaded for use. vative so- management of sensing and actuation The real value add-on of SmartMe.IO lutions to resources. Initially, the software was is extrapolating that data and offering their prob- written in Node.js, but the researchers meaningful metrics so the municipality lems. As have been porting it to Python to make it can correlate data to understand, for ex- the proj- OpenStack compliant. The cloud cur- ample, the cause of pollution and miti- ect ma- rently runs in the University data center. gate it. tures, it On the client side, Lightning-Rod runs However, SmartMe.IO is not stopping holds so many possibili- on edge devices powered by single-board at running the cloud and managing the ties, such as helping cities cope with pol- computers like Raspberry Pi, running a IoT devices. They want to make these lution, infrastructure management, wear customized version of the OpenWrt/​ devices smarter, so they can offer more and tear of roads, water leakage, wildfire LEDE flavor of Linux developed in- value. Now they have started to use control, traffic control, security at public house, an environment common to all cameras with these devices to offer places, and more. nnn the supported SmartMe.IO edge devices. smart camera services, such as help These edge devices are called Arancino with head counts in crowded places. Info and are armed with a wide range of Some projects are already running in [1] SmartME project: smartme.unime.​­ it​­ commodity sensors to collect different places like airports to assist in safety [2] IoTronic: kinds of data. The University once and security. However, cameras in- https://github.​­ com/​­ openstack/​­ iotronic​­ hosted one of the Arduino labs. As the crease the risk of privacy invasion. To lab was shut down, the university ab- mitigate such concerns, SmartMe.IO is [3] CKAN: https://ckan.​­ org/​­ sorbed the human expertise from the pushing machine learning to these de- [4] Fiware: https://www.​­ fiware.​­ org/​­ ​ lab, bringing valuable resources to the vices so that no image is sent to or devguides/­ hosting‑​­ your‑​­ application‑​­ on‑​­ ​ SmartMe.IO team that enabled them to saved on the server. Data processing a‑f­ iware‑​­ cloud/​­

LINUX-MAGAZINE.COM | LINUXPROMAGAZINE.COM ISSUE 206 JANUARY 2018 59 MAKERSPACE Pi FM Radio MakerSpace Build an FM radio using an RTL-SDR dongle Pi FM Radio

Low-cost RTL-SDR dongles can read frequencies between 24 and 1,766MHz. We built a simple FM radio with a Raspberry Pi, a USB dongle based on the RTL2832U chipset, an LCD HAT, and some Python code. By Pete Metcalfe

M radio projects that use supports SDR, and the RTL-SDR [1] USB chipsets with a low-level In- dongles based on the RTL2832U chipsets ter-Integrated Circuit (I2C) in- are well-priced at $10-$15. terface, like the RDA5807M SDRs have a large list of supported ap- and TEA5767, can work, but I found plications; some of the cooler projects thatF both solutions have some draw- include tracking airplanes, free-to-air TV, backs. The RDA5807M chip is poorly and monitoring satellite data. documented, with only Arduino C li- braries, and the TEA5767 chip has no Getting Started volume control. To install the basic software, enter: Software-defined radio (SDR) offers a higher level interface that allows access sudo apt‑get install rtl‑sdr to mixers, filters, amplifiers, modulators/​ demodulators, and detectors on the For my tests, I used a basic Raspberry hardware. A wide range of hardware Pi 1 Model B, but I also tested it on the Rasp Pi versions 2 and 3 and on an old, low-end PC running . An important difference between the RTL-SDR dongle and an FM tuner mod- ule is that the FM tuner module needs the speakers to be directly connected to the tuner module. When you are using the RTL-SDR dongle, the audio is gener- ated on the Raspberry Pi (or PC), so you will use the sound output of your computer. For my Raspberry PI setup, I used powered speakers (Figure 1), and for my laptop testing I used the internal speakers in the laptop. The RTL-SDR dongle includes an ex- ternally connected antenna; if possible, you should try to place this antenna

Figure 1: FM radio hardware setup. close to a window. Lead Image © margaritatkahcenko, 123RF.com

60 JANUARY 2018 ISSUE 206 LINUX-MAGAZINE.COM | LINUXPROMAGAZINE.COM Pi FM Radio MAKERSPACE

The rtl_fm command- line utility is an FM de- modulator that is used to read and sample a se- lected fre- quency. If you are look- Figure 2: raspi‑config Advanced | Audio option. ing to do more serious applications, see the GNU Radio Project [2]. A number of options can be passed to rtl_fm; the key ones are the frequency (‑f), the sample rate (‑s), and the out- put rate (‑r). The output of rtl_fm needs to be directed to an audio player program. I used aplay, which is a com- mand-line Advanced Linux Sound Ar- chitecture (ALSA) player, but other players could be used. I matched the sample rate (‑r) for aplay with the rtl_ fm output sampling rate and used the 16-bit little-endian (S16_LE) aplay sam- ple format (‑f). The syntax with the options required to play an FM radio station at 107.9MHz is as follows:

rtl_fm ‑f 107.9e6 ‑s 200000 ‑r 48000 | U

aplay ‑r 48000 ‑f S16_LE

The rtl_fm application needs to be stopped when you want to play a new radio station. If rtl_fm is running in the background, the ps command can be Figure 3: RTL-SDR dongle on a Lubuntu laptop. used to find process IDs. The kill com- mand can then be used to terminate the task. An example of finding and termi- nating the rtl_fm task is:

pi@raspberrypi:~ $ ps ‑e | grep rtl_fm

1709 pts/0 00:00:33 rtl_fm

pi@raspberrypi:~ $ kill 1709

pi@raspberrypi:~ $ ps ‑e | grep rtl_fm

pi@raspberrypi:~ $

Adjusting the Volume For Raspberry Pi applications, you can force the audio connections to use either the HDMI port or the phone jack on the Pi in raspi‑config by selecting the Ad- vanced menu option and then Audio (Figure 2). You have a few ways to adjust the audio volume. One method is to use the amixer utility. To change the audio out- Figure 4: LCD FM radio control.

LINUX-MAGAZINE.COM | LINUXPROMAGAZINE.COM ISSUE 206 JANUARY 2018 61 MAKERSPACE Pi FM Radio

Listing 1: Command-Line FM Radio Utility Python Test Program # FM_radio.py For my basic testing, I created a simple Python command-line application that # simple FM radio test utility using a RTL SDR dongle I could run on both my Raspberry Pi and on my old laptop running Lubuntu import subprocess, signal, os, time (Figure 3). A few Python libraries were used, in- def newstation(station): cluding the subprocess library to global process, stnum launch rtl_fm and return a process ID, # create a rtl_fm command line string and insert the new freq the os library to kill a process, and the

part1 = "rtl_fm ‑f " time library to add a delay (sleep), so

part2 = "e6 ‑s 200000 ‑r 48000 ‑ | aplay ‑r 48000 ‑f S16_LE" the rtl_fm task was given enough time to shut down cleanly before restarting. cmd = part1 + station + part2 A newstation() function was created to stop a running rtl_fm FM station and print ('Playing station :', station) then restart it with a new FM station frequency, and a setvolume() function # kill the old fm connection if it was running was created to pass new volume set- if process != 0: tings to amixer. process = int(subprocess.check_output(["pidof","rtl_fm"] )) To run the test program (Listing 1) [3], print ("Process pid = ", process) I entered the command,

if process != 0:

os.kill(process,signal.SIGINT) $ python FM_radio.py Simple FM radio test program time.sleep(2) # wait 2 seconds to restart rtl_fm

which then accepts a volume level as a # start the new fm connection percentage (e.g., 50%) or a radio station print (cmd) frequency (e.g., 107.9). process = subprocess.Popen(cmd, shell=True) Raspberry Pi FM Radio For the Pi FM radio project in this arti-

def setvolume(thevolume): cle, I tried a few different arrangements,

# pass the new volume setting to the amixer command but I found that an LCD HAT (hardware

os.system('amixer sset "PCM" ' + thevolume) attached on top) with buttons (Fig- ure 4) worked best. However, other op- print ('volume = ' , thevolume) tions such as a PiFace digital HAT (Fig- ure 5) or a button HAT could also be # Simple FM radio test program used. process = 0 The LCD Python libraries will vary ac- cording to the hardware used; however, print ("Simple FM radio test program\n") most LCD HATs are based on the while True: Adafruit libraries [4].

answer = raw_input( "Enter a radio station (i.e. 107.9) or volume (i.e. 50%): ")

if answer.find('%') > 0:

setvolume(answer)

else:

newstation(answer)

put volume on the Pi (or laptop) speak- ers, the Pulse Code Modulation (PCM) device is addressed. An example using amixer to set the volume to 70 percent would be:

amixer sset "PCM" 70% Figure 5: PiFace FM radio control.

62 JANUARY 2018 ISSUE 206 LINUX-MAGAZINE.COM | LINUXPROMAGAZINE.COM Pi FM Radio MAKERSPACE

Listing 2: Pi FM Radio with an LCD HAT The Python code for the LCD HAT #!/usr/bin/python (Listing 2) is based on the simple test code with some additional logic for an # PI_FM_radion.py ‑ FM Radio with an LCD Shield for controlling the stations and volume LCD button interface and some pre- defined radio frequencies. The main code import os, subprocess, signal loops through, looking at each of the but- import time tons with the lcd.is_pressed() function. import Adafruit_CharLCD as LCD The LCD.UP and LCD.DOWN buttons are used for volume control, and the LCD.LEFT and

def newstation(direction): LCD.RIGHT buttons cycle through the pre-

global stnum, stations, process defined radio stations. The lcd.clear() and lcd.message() functions show the new radio station information on the LCD print 'stnum=',stnum,'direction=',direction HAT. In my testing, I used a 0.25-second delay on all the button presses, although part1 = "rtl_fm ‑f " you might need to tune this value for part2 = " ‑s 200000 ‑r 48000 | aplay ‑r 48000 ‑f S16_LE" your hardware and usage.

if (stnum + direction < (len(stations) )) and (stnum + direction > ‑1): Summary stnum = stnum + direction Creating a homemade FM radio is just one of the many interesting applications print('Playing station :', stations[stnum]) for SDR utilities and the low-cost RTL- cmd = part1 + stations[stnum] + part2 SDR dongle [5]. In the future, I would if process != 0: like to add a Python Tkinter or web in- process = int(subprocess.check_output(["pidof","rtl_fm"] )) terface to my FM radio application. nnn print "Process pid = ", process os.kill(process,signal.SIGINT) Listing 2: Pi FM Radio with an # start the new fm connection LCD HAT (continued)

print cmd while True: #look for button presses

process = subprocess.Popen(cmd, shell=True) if lcd.is_pressed(LCD.UP):

setvolume(5)

time.sleep(0.25)

def setvolume(voldif): if lcd.is_pressed(LCD.DOWN): setvolume(‑5) global thevolume time.sleep(0.25) if (thevolume + voldif > 0) and (thevolume + voldif <100): if lcd.is_pressed(LCD.LEFT): thevolume = thevolume + voldif newstation(‑1) os.system('amixer sset "PCM" ' + str(thevolume) + '%') lcd.clear() print 'volume = ' , thevolume lcd.message(sinfo[stnum])

time.sleep(0.25)

if lcd.is_pressed(LCD.RIGHT):

lcd = LCD.Adafruit_CharLCDPlate() newstation(1)

lcd.clear()

# Add your own stations and station info lcd.message(sinfo[stnum])

stations = ['95.3e6','94.7e6','102.9e6','107.9e6'] time.sleep(0.25)

sinfo = ['95.3 country', '94.7 light','102.9 easy','Y108 Rock\nHamilton ']

thevolume = 40 #initial volume Info [1] About RTL-SDR:

stnum = 1 #pick a starting station http://www.​­ rtl‑sdr.​­ com/​­ about‑rtl‑sdr/​­

process = 0 [2] GNU Radio: https://www.​­ gnuradio.​­ org/​­

newstation(0) [3] Code for this article:

lcd.message(sinfo[stnum]) ftp://ftp.linux-magazine.com/pub/list‑ ings/linux-magazine.com/206/ setvolume(thevolume) [4] Adafruit libraries: https://github.​­ com/​­ ​ adafruit/­ Adafruit_Python_CharLCD​­

print 'Press Ctrl‑C to quit.' [5] See more of Pete’s Projects: https://funprojects.​­ blog​­

LINUX-MAGAZINE.COM | LINUXPROMAGAZINE.COM ISSUE 206 JANUARY 2018 63 MAKERSPACE Volumio 2 MakerSpace The Volumio 2.0 web-based audio player Playback

Volumio and a Raspberry Pi can add smart functions to any stereo system. Whether playing diverse audio formats or streaming Spotify, the combination of smartphone control, a Raspberry Pi Display, and Volumio outperforms many commercial solutions. By Christoph Langner

ld-fashioned AM and FM with network access and a Spotify con- radio has been out for years: nection. In combination with a Rasp- Nowadays, a radio must be berry Pi and the original Raspberry Pi able to receive digital audio Display, the solution is bound to impress and be web-enabled to stream music with its ease of use and elegance. fromO Spotify and other providers. How- ever, the devices that were conceived by Volumio 2.0 former audio giants such as Sony and Since the end of 2016, Volumio 2 has Panasonic are often fraught with quirky been available as a significantly up- controls. Virtually no Internet radios dated version that introduces various come with large displays and precise innovations and eliminates numerous touchscreens. The fun only begins errors [2]. In contrast to the first edi- when you can control the radio with a tions of the software, Volumio 2 has ac- mobile phone or tablet app. In this cate- quired a plugin interface, a hotspot fea- gory, network loudspeakers (e.g., by ture, and a revised interface. Sonos or Raumfeld) are achieving mas- Volumio 2 for the Raspberry Pi is sive sales. based on the current Raspbian Jessie. Legacy hi-fi systems – without a dis- Volumio supports other single-board play or network connection, but with ex- computers in addition to the Rasp Pi, cellent sound that cost an arm and a leg such as the Odroid-C1/​C2 and the just a few years ago – are still in exis- CuBox-i. An image for classical Intel tence in many living rooms. If you do PCs has Debian underpinnings. To use not want to exchange your precious am- the software, you store the Volumio plifier for the latest technology, you will image on an SD card, as you would a find a convenient and elegant upgrade Raspbian image, and boot the Rasp Pi solution with the Volumio [1] distribu- from it. The card should have at least tion. The Linux-based digital audio 4GB of free space; if it also needs to player software is easy to set up and store part or practically all of your converts any radio or stereo system with music collection, you will have to di-

a line-in socket into a “smart radio,” mension it accordingly. Lead Image © donatas1205, 123RF.com

64 JANUARY 2018 ISSUE 206 LINUX-MAGAZINE.COM | LINUXPROMAGAZINE.COM Volumio 2 MAKERSPACE

drop-down. The automati- cally rebuilds the page in the selected language after you click Save. You can also select or drop different background images and color schemes for the web interface in this dialog. The easiest way to add music is on a USB storage device loaded with MP3 files. In addition to MP3, Volumio sup- ports the AAC, ALAC, FLAC, WAV, and PLS formats. The software automatically mounts the medium; you can then ac- cess your music by clicking Browse in the main window and then using the Music Library | USB menu. Alternatively, you can use Samba to upload data di- rectly to Volumio Rasp Pi memory. The URL is smb://volumio​ . The Rasp Pi interface has poor net- work throughput because the network Figure 1: The Volumio web front end in a web browser. module has to share an internal USB in- terface with the USB ports, so transfer- After installation and the first launch, to log in to the system from a network ring a large music collection can take a the web interface of the Volumio Rasp Pi with while to complete. If you are an impa- interface can be accessed using any tient user, you might prefer disconnect- Apple computer and most Linux systems ssh [email protected] ing the Rasp Pi from the mains, remov- from the URL http://volumio.local​ or by ing the memory card from the device, typing in the IP address of the Raspberry or, alternatively, with the corresponding and reading it in a card reader on your Pi directly. IP address in place of volumio.local. PC. Volumio searches for new tracks in Because Volumio does not explicitly Both the password and login are volu- the volumio_data drive in the /dyn/data/ display the IP address on the screen dur- mio. The root account is disabled as in INTERNAL/ folder. The partition uses the ing the boot procedure, you have to read other Linux distributions, but you can ext4 Linux filesystem. it from the configuration interface of gain administrative rights by prefacing a your WiFi router or use a network scan- command with sudo. Strengthened ner such as Fing for Android [3]. Linux Volumio offers a command-line inter- Volumio plays sound through the head- users can run arp‑scan, face: Using commands on the Volumio phone socket of the Raspberry Pi by machine such as volumio pause or volu‑ default. The socket can be connected $ sudo arp‑scan ‑‑localnet | U mio volume 50, you can address the to the stereo system line-in with an grep Raspberry player without a web or Music Player RCA cable. Alternatively, you can send 192.168.111.195 b8:27:eb:66:ab:44 U Daemon client. Typing volumio ‑‑help audio to the HDMI output from the Raspberry Pi Foundation displays an overview of all commands. Playback menu. Volumio also supports many digital-to-analog converter (DAC) which you can install from your distribu- GUI HATs, or Raspberry Pi GPIO exten- tion’s , if necessary. The most important functions of the web sions. They provide far better audio If you have connected the Volumio interface may well be self-explanatory quality and more audio outputs (e.g., Rasp Pi to a monitor, you will only see a (Figure 1): At top center is the button for Toslink) than the Raspberry Pi with login prompt immediately after installa- Play/Pause;​ the buttons on either side let standard tools. Audiophile fans might tion. In the basic configuration, Volu- you jump to the next or previous track in even want to upgrade the Rasp Pi with mio is aimed at users who want to con- the playlist. Under the buttons are the a tube amplifier [4]. trol the audio player through the net- names of the current track and album. If you are working with a Rasp Pi 3 or work. However, a graphical interface The gauge on the left is a timeline of the have connected a compatible USB WiFi can be installed easily when setting up current track that you can use to jump to dongle to an older Rasp Pi, Volumio au- the software. any point; the gauge to the right is for tomatically sets up a hotspot. The SSID volume control. is Volumio and the access password is Command Control To change the language in Volumio, volumio2 (Figure 2). You can give Because of the full-fledged Linux un- open the sidebar by clicking the gear friends and acquaintances at a party ac- derpinnings, Volumio natively provides icon in the right corner. Choose Appear- cess to your music collection from their an automated SSH server with authen- ance | Language and select your lan- cellphones, without having to reveal tication via public keys, allowing you guage of choice in the Select Language your home network (Figure 3). The

LINUX-MAGAZINE.COM | LINUXPROMAGAZINE.COM ISSUE 206 JANUARY 2018 65 MAKERSPACE Volumio 2

hotspot settings can be changed under system can be made “smart” very easily Network | Hotspot Settings, if necessary. and controlled conveniently on the You can also completely disable WiFi 7-inch touchscreen. access. In the basic setting, a monitor con- nected to the Volumio Rasp Pi does not Display display anything apart from the launch The creators of Volumio primarily have messages at boot time and the login users in mind who want to connect the prompt. The system does not even pro- Rasp Pi to their stereo and hide it behind vide a graphical desktop environment. a hi-fi system. The system can then be However, additional functions (e.g., controlled from a smartphone or from screen output) can be installed easily the web browser on a PC. In combina- through the Plugins entry in the sidebar. tion with the official Raspberry Pi Dis- The currently available plugins can play and a suitable housing, the stereo be displayed in various categories in

Figure 2: Guests can log in to the Volumio machine from their cell- phones and be DJs at your party.

Figure 4: Plugin management lets you supplement Volumio with addi- tional features, like support for the Raspberry Pi Display.

Figure 3: The web interface shrinks to suit smartphones, allowing easy control of Volumio Figure 5: The Touch Display plugin is optimized for the official Rasp- from a cellphone. berry Pi Display but also works with other monitors.

66 JANUARY 2018 ISSUE 206 LINUX-MAGAZINE.COM | LINUXPROMAGAZINE.COM Volumio 2 MAKERSPACE the Search Plugins tab. The Touch Dis- play Plugin is found under Miscellea- nea [sic], and you can install the mod- ule on the system by pressing Install. Behind the scenes, Volumio installs the X server and browser from the Raspbian system’s package man- ager – the process takes several min- utes (Figure 4). Make sure you discon- nect any keyboards from the system before installing; otherwise, the instal- lation routine will hang. Finally, you still need to activate the plugin. To do so, switch to the In- stalled Plugins tab and slide the Touch Display controller to On. Directly after Figure 6: You need a device password from the settings of your Spo- doing so, the software launches the tify account to integrate Spotify with Volumio. graphical environment with the Volu- mio web page, which keeps screen dis- lists hits from the catalog of the music Linux distributions. Volumio enhances tractions from interfering with your lis- service under Spotify Artists (Figure 7). the server by adding a web front end tening pleasure and prevents the Rasp The integration of other music services, and optimizes the service for interac- Pi from being used or misused for such as Amazon Prime or Google Play tion with a small computer like the other purposes (Figure 5). The plugin Music, has been considered, but so far Raspberry Pi. configures the system so that the Volumio does not support alternative Volumio also can be controlled using graphical environment loads automati- providers. classic MPD clients [7], which are cally, even when restarted. available for all major operating sys- Substructure tems and for iOS and Android [8] mo- Spotify Technically, Volumio is not based on bile devices (Figure 8). However, weak- Installing the Spotify plugin from the software developed completely in- nesses still exist in daily use. Although plugin manager is just like installing house, but on the Music Player Dae- Volumio access to legacy mounted the touchscreen function. By outsourc- mon (MPD) [5] music server, which media (i.e., USB or the network share) ing the Spotify function to an exten- has been around for years and is de- can be controlled nicely by the MPD sion, the developers can respond signed to be controlled through client client, Spotify does not appear in the quickly to changes in the service and programs. The project wiki explains list. Additionally, local media collide only need to update the plugin. After the complete architecture [6]. MPD is with Spotify streams during playback; installation, activate the extension in found in the repositories of many for example, while playing a song on the Installed Plugins tab. The Settings button then appears, from which you can enter your Spotify access data – not your “normal” Spotify data, but a special device password that you will find on the Spotify web page: Log in there and then open your Account over- view. Lower down on the page, you will find the Set device password op- tion. The subsequent dialog shows your device username. After pressing the button, Spotify emails you an indi- vidual password (Figure 6). You need to enter this data in the Spotify plugin on Volumio. After opening your music library from the Browse tab on the main screen, you can access your music col- lection in the Spotify entry. Volumio in- stalls your own playlists as well as those offered by the service, shows new releases, and filters by genre and mood. Figure 7: Volumio seamlessly integrates Spotify into the system. How- When browsing, Volumio separately ever, this only works in the web interface.

LINUX-MAGAZINE.COM | LINUXPROMAGAZINE.COM ISSUE 206 JANUARY 2018 67 MAKERSPACE Volumio 2

Spotify in the web front end, you can wrote this article, Sound@home was start playing a second song from the only optimized for Volumio 1.55, al- MPD client. though the application worked with the The Volumio web app (available in current version of the audio sever – with some countries, but not the US at this limitations. Not until August 2017 was a time), which Volumio itself offers in the version strictly for Volumio 2 released Google Play Store, also shows some [10]. The new version now has an auto- weaknesses [9]. Although, it can con- configuration mechanism for multiple nect to the Volumio Rasp Pi, the display rooms, YouTube plugin support, speed remains blank. Bad reviews from other improvements, and a long click function users confirm this problem. To control for manual configuration (Figure 9). Volumio from a smartphone or tablet, you will want to ignore the various Conclusion apps and open the Volumio web front Volumio has undergone many improve- end in a browser. ments since the first versions. Accom- panied by a fast Rasp Pi 3, the Rasp- Multiroom berry Pi Display, a case, and an output Compared with commercial multiroom device, the combination creates a web stereo systems like Sonos or Raumfeld, radio that beats most of the commercial Volumio playback cannot be synchro- alternatives by miles. Volumio can be nized across several rooms. However, a operated quickly and conveniently – multiroom system based on the Rasp- whether by gesture, web browser, or berry Pi is what many Rasp Pi fans de- smartphone app. Additionally, the core components from the project’s sire. Volumio does not offer this feature audio player plays back music from GitHub account [11], where you can also itself, but developers of the Android app local and network sources in various report bugs and submit your own sug- Sound@home for Volumio is committed formats and supports the widely used gestions for improvement. Answers to to resolving this problem. Spotify streaming service. your questions about configuration and However, the app was having a hard Volumio has grown an active devel- controlling Volumio are available from time keeping pace with the speed of oper community. You can pick up the the forum on the Volumio community Volumio development. At the time I source code for the interface and the website [12]. nnn

Info [1] Volumio: https://volumio.​­ org​­ [2] Volumio 2 shop: https://volumio.​­ org/​­ ​ volumio‑2‑stable‑release/­ [3] Fing: https://play.​­ google.​­ com/​­ store/​­ apps/​­ ​ details?­ id=com.​­ overlook.​­ android.​­ fing​­ [4] Tube amplifiers for the Rasp Pi: http://www.​­ pi2design.​­ com/​­ 502hta.​­ html​­ [5] MPD: https://www.​­ musicpd.​­ org​­ [6] Volumio architecture overview: https://​ github.­ com/​­ volumio/​­ Volumio2/​­ wiki​­ [7] MPD clients: https://www.​­ musicpd.​­ org/​­ clients/​­ [8] M.A.L.P.: https://play.​­ google.​­ com/​­ store/​­ ​ apps/­ details?​­ id=org.​­ gateshipone.​­ malp​­ [9] Volumio web app: https://play.​­ google.​­ com/​­ store/​­ apps/​­ ​ details?­ id=com.​­ volumio.​­ moritz.​­ ​ volumiowebapp_release­ [10] Sound@home for Volumio: https://play.​­ google.​­ com/​­ store/​­ apps/​­ ​ details?­ id=com.​­ digx.​­ soundhome​­ Figure 8: Volumio can also be controlled by MPD clients like Figure 9: The Android app [11] GitHub: https://github.​­ com/​­ volumio​­ M.A.L.P. for Android. However, Sound@home for Volumio auto- [12] Volumio forum: Spotify integration is missing. configures multiple rooms. https://volumio.​­ org/​­ forum​­

68 JANUARY 2018 ISSUE 206 LINUX-MAGAZINE.COM | LINUXPROMAGAZINE.COM

MAKERSPACE Open Hardware – Signet MakerSpace Signet password manager Let’s Get Physical

At the intersection of free software and crowdfunding, a USB password manager offers an innovation in security. By Bruce Byfield

mall, crowdfunded businesses sumer electronic devices, particularly creating innovative open hard- devices where security and privacy are ware are becoming one of the desirable.” technological trends of the last few years. For instance, Key­ Introducing Physical boardSio­ [1] is shipping its first ergo- Security nomic, customizable keyboard, while Signet consists of a USB device (Figure 1) Purism [2] is gaining a reputation for and a software client for Android, GNU/​ its high-end laptops and is currently Linux, OS X, or Windows (Figure 2). building the security-conscious Li- Like any setup designed for security, brem 5 phone. More recently, after a Signet is based on encryption – specifi- successful fundraising campaign [3], a cally, the AES-256 standard [6] with ci- two-person startup called Nth Dimen- pher blockchaining [7] for authentica- sion [4] is releasing Signet, a USB de- tion and encryption of the database. vice for managing passwords that The encryption for each database entry brings a few new twists to security. is encrypted as a blockchain with Neils Nesse, the founder of Nth Di- unique initial blocks, which eliminates mension, writes that, “I have been a the possibility that similar blocks might user and advocate of free and open be used for more than one entry and source software for my entire adult life, makes cracking more difficult. although I haven’t made many contri- However, the use of an external device butions so far outside of a few bug and the exchange of information be- fixes and releasing some small graph- tween the device and the client allows ics-related libraries on GitHub [5]. I for a number of unique security features started developing Signet soon after I (Figure 3). Placing the password man- made a DIY hardware password man- ager on a USB thumb drive provides ele- ager using some instructions online. It ments of physical security – an aspect of worked okay, but the user experience security that is so simple that it is often had a lot of pain points, and the device overlooked. Unless the Signet device is had limited portability. I didn’t find plugged into the system, access to the in- any other open source offline hardware formation it manages – such as logins, password manager options that I liked, bookmarks, contacts, and credit card so I resolved to create my own. In the numbers – is inaccessible. That means

long term, I plan to produce other con- that a system can be secured simply by 123RF.com Lead Image © Anja Kaiser,

70 JANUARY 2018 ISSUE 206 LINUX-MAGAZINE.COM | LINUXPROMAGAZINE.COM Open Hardware – Signet MAKERSPACE

the chip from using its hard- ware debug mode and to prevent the activation of the factory boot mode. Additionally, any firmware up- dates can only be applied by unlock- ing the device first. In theory, the Figure 1: The first part of Signet is an external USB data might be device, which must be present for a login to work. cracked by a brute-force at- removing the device and carrying it tack [8], but as Nesse points out, such around with you. an effort would be “impractical.” Signet Even when Signet is available, the uses scrypt [9], an algorithm that is so information it manages can only be ac- memory-intensive that each attempt at cessed by pressing the device’s button. authentication takes hundreds of milli- When the device receives any com- seconds. For a legitimate user who is au- mand that is “sensitive” – that is, any thenticating once, this delay hardly mat- command that reveals private informa- ters. However, since a brute-force attack tion or is destructive – the button flashes, and the command is sup- pressed until either the button is pressed or the time to press the button expires and the command is rejected. This arrangement means that cracking Signet’s database is of no use by itself. Moreover, Nesse says, “if there is any malicious software on the system you are using, it can only intercept data when you request it, rather than it being potentially able to get a complete copy all at once.” The main potential vulnerability oc- curs only if you back up Signet’s data- base to the USB device. Even then, the Figure 2: The second part of Signet is a software client. database is encrypted. However, even this vulnerability can be avoided by backing up the Signet database else- where. Nesse recommends that other “removable media backup are probably the most secure, provided you don’t use the drive you select on unsecured systems.” Moreover, Signet’s hardware design choices provide additional security. In- formation is stored inside the micro- controller’s on-chip flash memory, which, according to Nesse, can only be attacked “by desoldering the memory chip and reading out the memory con- tents in a separate circuit.” Further- more, the microcontroller and ARM- based chip have a memory protection Figure 3: Both the Signet USB device and the software client are mode that can be enabled to prevent required to log in to protected data.

LINUX-MAGAZINE.COM | LINUXPROMAGAZINE.COM ISSUE 206 JANUARY 2018 71 MAKERSPACE Open Hardware – Signet

by definition requires multiple guesses both work and school systems, often Next Steps of the password, unless an obvious pass- with proprietary operating systems. Nth Dimension has exceeded its fund- word is used, the delay soon mounts up, This reality forces a choice between raising goal of $2,000 by over 500 hun- and any attack would take too long to not logging in outside of the home, dred percent. As a result, Nesse is cur- have much chance of success. choosing duplicated or easy to remem- rently taking a break from his day job to Still another aspect of physical secu- ber passwords to make the password fulfill the campaign’s stretch goals. rity is that the device’s encryption key manager less essential, or making cop- These goals include command-line tools, is randomly generated by three differ- ies of their password database. Signet, which should be ready for the first ship- ent sources of random data: the hard- on the other hand, takes away the in- ment of Signet, and browser plugins, ware random number generator on the centive to accept these kinds of secu- which Nesse expects to be ready by early microcontrollers, random data from the rity risk factors.” 2018. Nesse also hopes eventually to add host, and random data generated by Moreover, a password manager in- support for GPG encryption, which measuring variation on two different stalled on the same system as the data “would allow Signet to manage the en- oscillators in the microcontroller. it is protecting is only as secure as the cryption of media and communications, These multiple sources not only help system itself. The introduction of a se- keeping sensitive private encryption keys to ensure that the encryption key is cure external device makes an intru- off the host system.” truly random, but it also means that sion much more difficult. Signet re- Other enhancements Nesse hopes to both the Signet device and its devices duces the risk even further by receiv- add at an unspecified future date are a on the system must be present to ac- ing only a set of metadata when data- feature that indicates password cess information. bases are unlocked – not a complete strength and the ability to start the cli- To further add to the security, Signet copy of the database. ent automatically when the USB device also has restrictions that prevent two Similarly, while cloud storage or ser- is inserted. “Other than that, I’m pretty programs from accessing the USB de- vices are convenient for users who regu- happy with the desktop experience,” vice at the same time. Because of this larly work from more than one system, as he says. “I’ve been using Signet per- restriction, communication between Nesse notes, “the question is whether or sonally in various forms almost a year, the device and the client software is not it makes sense to store all of your so when things happen that bother me, not encrypted. “This might seem like passwords and other identifying informa- I fix them fast.” an oversight,” Nesse says, “but if the tion outside of your physical control.” Whether Nth Dimension will be a system you are using is compromised, Unless you use some additional security success remains to be seen, although then the communication link between measures such as Least-Authority File the number of backers for its fundrais- the device and the application is hardly Store (LAFS) [10], only one source needs ing campaign gives the new company a the only place where the data could be to be cracked for an intruder to have com- chance for at least modest success. intercepted. A keylogger could capture plete access to your data – and you may However, whether or not Nth Dimen- the data as it’s being typed into the not know what has happened until long sion is a financial success, in Signet, GUI, or when the USB keyboard func- after the fact, if ever. “It’s difficult to de- the company has already proved itself tion of the device types some private termine the likelihood of this happening,” a source of technological innovation – data. Even if encryption was used, the Nesse says, “but every service I’ve looked and one that wouldn’t exist without client’s key could be extracted from into has a spotty track record.” the intersection of free software and RAM at run time, or the client could be True, as Nesse admits, Signet is also a crowdfunding. nnn replaced with a hacked client. The only single source for your data. However, way to really counter [these possibili- he adds, “it’s a physical one, and you Info ties] is by limiting the types of data can study or even modify how it [1] Keyboardio: https://shop.​­ keyboard.​­ io/​­ you access on systems that you have works,” since it is open source. Any at- [2] Purism: https://puri.​­ sm/​­ less trust in.” tack “would still require the attacker to [3] Crowdfunding campaign: get a hold of your device or gain access https://www.​­ crowdsupply.​­ com/​­ ​ Advantages over Local and to the backup of the device’s data. Even nth‑dimension/­ signet​­ Cloud Password Managers if you are being personally targeted, it’s [4] Nth Dimension: http://nthdimtech.​­ com/​­ As Nesse notes, both hard drive and a risky operation. Going after all or a [5] GitHub repositories: cloud-based password managers are significant number of Signet users https://github.​­ com/​­ nthdimtech​­ widely used. However, Signet has advan- would be even more difficult and im- [6] AES-256: https://en.​­ wikipedia.​­ org/​­ wiki/​­ ​ tages over both. practical,” because each Signet device Advanced_Encryption_Standard­ “For a user who keeps their offline would have to be cracked individually. [7] Cipher block chaining: https://en.​­ wikipedia.​­ org/​­ wiki/​­ Block_​­ ​ database only on their home systems By contrast, a cloud database is central- cipher_mode_of_operation#​ CBC​­ and secures them well,” Nesse says, ized, and the sheer number of users [8] Brute-force attacks: https://en.​­ ​ “the physical security offered by Sig- makes it a far better target for an in- wikipedia.­ org/​­ wiki/​­ Brute‑force_attack​­ net might not matter as much. How- truder. Nor do users have anything be- [9] LAFS: ever, many people have to use a num- yond a vendor’s assurances about a https://en.​­ wikipedia.​­ org/​­ wiki/​­ Scrypt​­ ber of computes and networks that cloud database’s security, especially if it [10] scrypt: they don’t have much control over: uses proprietary software. https://tahoe-lafs.org/trac/tahoe-lafs

72 JANUARY 2018 ISSUE 206 LINUX-MAGAZINE.COM | LINUXPROMAGAZINE.COM

INTRODUCTION LINUX VOICE

Linux has a way of keeping things real. You can pay a lot for proprietary software if you listen to the people who sell it, but before you flash your debit card, be sure you can’t find a free Linux tool that does the same thing. The Universal Donor 76 Simon Phipps Multimedia tools are an especially lucrative market for Open source communities need equal rights. software vendors. If you come from a Windows or Mac environment, you can pay hundreds of dollars for audio Doghouse – FPGAs 77 Jon “maddog” Hall and video applications. What better reason to turn to Take some advice from Linus Torvalds Linux, where similar tools are free and learn how to program an FPGA. and often easier to use. This OS Marketing 78 month we explore some audio Mike Saunders and video tools for the Linux Marketing FOSS requires some novel environment, including the approaches when compared with proprietary software. We share our experiences. Audacity sound editor and the convenient FFmpeg Digitizing Analog Music Media 82 Mario Blättermann command-line video- Armed with the Audacity sound editor, you editing utility. can convert the analog content of LPs, tapes, and cassettes to the digital world. FOSSPicks 86 Graham Morrison Graham looks at qutebrowser 1.0, Min, Storyboarder, BorgBackup 1.1, Argentum Image © Olexandr Moroz, 123RF.com Moroz, Image © Olexandr Age, and much more! Tutorials – FFmpeg 92 Paul Brown Sometimes video editing from the command line with FFmpeg is better than using graphical tools.

LINUX-MAGAZINE.COM | LINUXPROMAGAZINE.COM ISSUE 206 JANUARY 2018 75 LINUX VOICE NEWS NEWS ANALYSIS The Linux Voice view on what’s going on in the world of Free Software.

Opinion The Universal Donor

Open source communities need equal rights. BY SIMON PHIPPS

Simon Phipps few people reacted negatively to Some members of the Apache Soft- is a board member my article on why Public Domain ware Foundation (ASF) describe this con- of the Open Source Initiative, the Open ASoftware (PDS) is broadly unsuit- dition as “being a universal donor” of Rights Group, and The able for inclusion in a community open software. The ASF has rigorous rules Document Foundation source project. Most argued that be- concerning the licensing of all the soft- (makers of LibreOffice). cause public domain gave them the ware they maintain. They require contrib- rights they need where they live (mostly utors to confirm the originality or prove the USA), I should not say it was wrong to origin of their contributions and to grant use it. to the ASF as a legal entity unrestricted That demonstrates either parochial- copyright and patent rights. They prohibit ism or a misunderstanding of what use of licenses that might require code public domain really means. It should recipients to take further licensing ac- not be used for the same reason code tions – this even means banning some known to be subject to software pat- OSI-approved licenses such as the GPL. ents should not be used – namely that They have recently also banned use of only code that, to the best efforts pos- additional patent statements that modify sible, can be used by anyone, any- rights under otherwise acceptable li- where, without the need to censes (the recent Facebook ask permission (e.g., by example was the origin of buying a patent license) this). They permit public or to check if it’s domain code, but only needed (e.g., is that after a large amount of PDS code public do- due diligence to ensure main here?) to be everyone has the neces- used in an open sary rights. Their goal is source project. Public to ensure all known ob- domain fails the test for stacles to use, improve- multiple reasons: global dif- ment, and sharing are re- ferences in copyright terms, moved in advance, so that their copyright as an unalienable moral own community can innovate freely and rather than as a property right, and so that unknown others can freely use more. Apache code. Yes, public domain may give you the PDS per se breaks this condition of being rights you need. But in an open source proj- a universal donor. While there is a good ect, it’s not enough for you to determine chance that many contributors will dis- you personally have the rights you need. In cover they have sufficient rights, the prob- order to function, every user and contribu- lem is that every one of them has to make of the project needs prior confidence their own local determination. That breaks that they can use, improve, and share the the community. It’s not enough that you code, regardless of their location or the use have the rights you need; in a community, to which they put it. That confidence also everyone needs those rights, and by includ- has to extend to their colleagues, custom- ing public domain code, you give everyone ers, and community as well. a burden rather than a benefit. nnn

76 JANUARY 2018 ISSUE 206 LINUX-MAGAZINE.COM | LINUXPROMAGAZINE.COM DOGHOUSE – FPGAs LINUX VOICE MADDOG’S

DOGHOUSE Jon “maddog” Hall is an author, educator, computer scientist, Take some advice from Linus Torvalds and learn how to and free software pioneer who has been a passionate program an FPGA. BY JON “MADDOG” HALL advocate for Linux since 1994 when he first met Linus Torvalds and facilitated the port of Linux to a 64-bit system. He serves as president of Linux Field-programmable gate arrays International®.

was at LinuxCon in Beijing, China, this year, and Linus Tor- FPGAs are not just about speed of computation; they can valds was being interviewed onstage. During the inter- be used to reduce the cost of energy, as well. If your main I view, Linus said that if he were starting over in FOSS CPU has to run for a long time to solve a problem, it may use today, he might not create a kernel but instead, learn how to a lot of electrical power. But if the FPGA can do the calcula- program a field-programmable gate array (FPGA). I found this tion quickly, then the main CPU might be able to go into interesting. “standby” mode and use less electrical power. What is an FPGA? Traditional central processing units (CPUs) The Mars Rover was designed a long time ago, and al- and graphics processing units (GPUs) are made of fixed circuits though it does have regular CPUs on board, they are rela- designed by computer engineers that form an “instruction set.” tively slow and consume a lot of power. On the other hand, This instruction set tells the hardware to do certain things when the Rover has a significant number of FPGAs on board that an instruction (designated by a program) is executed. All of this do the “heavy lifting,” which allows it to reduce its overall is controlled by a clock that acts like a drum keeping a beat and use of electricity by turning the FPGAs off when they are makes sure that everything works in harmony. not in use. However, another way of building a computational unit is People are often confused by the term “real time.” To me to build specialized circuitry that always processes data in a real time means that the computation occurs as the data particular way – like “hard coding” the circuitry. Once the cir- comes in. If you are not doing the data processing in real cuitry is set, there is only one thing that circuitry can do. Be- time, then the data has to stop or be buffered until the pro- cause the circuitry does not necessarily have to follow a cessing element can “catch up.” In most data processing, this “drumbeat,” it can often solve that particular problem 10, 20, causes a backlog that may never be overcome. FPGAs can be or even 100 times faster than a traditional CPU or GPU. used to keep this data flowing, so you never have to stop the Of course, most of us do not want to buy a computer for data flow. every single problem we want to solve, so the programmer is FPGAs can have another useful function, particularly in able to change the program on the FPGA to solve different embedded systems. Many GPUs have proprietary, binary- problems. One moment, the FPGA might be compressing an only firmware that can prevent new versions of the kernel image; the next moment it might be encrypting (or decrypt- from working unless the firmware is updated. I call these “bi- ing) a stream of data. If you combine one (or more) FPGAs in nary blobs.” I was lamenting to Professor Marcelo Zuffo of a system along with a CPU and GPU, the FPGAs can offload a the University of Sao Paulo that many 3D functions (particu- lot of processing from the main processing units, allowing larly “simple” ones) could be done by an FPGA and therefore them to do more varied tasks while the FPGA does the com- eliminate the need for proprietary GPU binary blobs. Three putation it was programmed to do. months later, two graduate students had programmed an Programming an FPGA does not follow the same proce- FPGA to run all of the OpenGL test suites. By using an FPGA dural logic that programming a CPU or GPU normally does. for simple 3D and 2D graphics processing, embedded sys- Special languages and tool chains are used to build the pro- tems do not suffer when companies drop support for their gram, and it does take some study to learn how to use them. GPUs (or the operating system that is using the GPUs). Also, in the past, FPGAs were very expensive (and large), so One last idea on GPUs is using them for crypto-currency not too many people learned how to program them. Now they mining. While your main CPU is running the system, your are inexpensive and getting more inexpensive by the day. FPGA can be taking care of the mining process. Some companies are now building FPGA functionality into Therefore, I recommend finding an inexpensive FPGA and their Systems on a Chip (SoCs). learning to program it. Don’t let Linus have all the fun! nnn

LINUX-MAGAZINE.COM | LINUXPROMAGAZINE.COM ISSUE 206 JANUARY 2018 77 LINUX VOICE OS MARKETING

How to Sell Open Source

Marketing FOSS requires some novel approaches compared with proprietary software. We share our experiences.

BY MIKE SAUNDERS ou’ve heard this sentence so many times: products to the right people. As you become more “Free and open source software like Linux experienced, you can work more closely with Y doesn’t need a marketing department!” To product developers to shape the final result. some extent, there’s some truth to it: People learn Now, imagine you have the same role, but about FOSS thanks to word-of-mouth and grass- within an open source project (or a company roots movements. Many of us discovered Linux that sells FOSS). Some of your responsibilities from friends and colleagues or from reading will be the same, but others will differ signifi- about it in online discussions, rather than from cantly. For instance, when an open source pro- flashy TV adverts. We keep using it because we gram is being developed by a large community like it, not because our brains are being toyed with. of volunteers around the world, you can’t easily We’ll keep using, promoting, and supporting Linux shape its development. Sure, you can do market regardless of what happens to the companies de- research and find out what features people veloping and using it. need – but then what? Post them on a mailing On the other hand, Linux and FOSS exist in a list and see what happens? When developers highly competitive (and often unpleasant) mar- are scratching their own itches and not being ket. If you want it to grow, you need to consider paid by you, it’s harder for you to push develop- the marketing strategies and approaches that ment in the direction you want. the competitors are using and combat the “fear, Similarly, if you’re not selling the software as a uncertainty, and doubt” that’s often spread by product but rather support contracts and other groups and individuals that want to cause FOSS services around it (like many notable FOSS- harm. You want to present the software you friendly companies), then your approach has to love in a positive light, even when things are not change. And on top of that, you don’t just want going so well (e.g., with the Heartbleed security end users to try your product, you want potential vulnerability). contributors to get involved, as well. So your mar- Marketing open source is something everyone keting job ends up stretching out into community can do, whether it’s using social media effectively, outreach and management. creating videos or infographics to explain FOSS, or attending events and giving talks. Over the next Classic Example 1: IBM few pages, I’ll examine some of the traditional ap- Back in the late 1990s, GNU/​Linux was emerging proaches to software marketing, look at examples as a decent server operating system and gaining from and IBM, and provide some tips that some use in small companies and ISPs, but it you can use. still lacked major commercial backing. Various companies in the FOSS ecosystem supported Open vs. Closed it – such as Red Hat – but they were small fries Imagine you’re a newly appointed marketing man- at the time. Linux was still very much the domain ager for a proprietary software company. What’s of geeks and hackers, and it didn’t have the your responsibility? Well, you’ll want to examine image or money behind it to really take off. your current product portfolio and see how those That is, until IBM got involved. In 2000, IBM products fit into the market (e.g., who they’re tar- made a major announcement: The company geting, whether there are growth opportunities, would spend $1 billion on Linux development and whether the pricing is right). You will also look over the next year [1]. The reason? According to at products in development and see what oppor- IBM chief executive Louis Gerstner at the time: tunities are ahead. You can then work on market- The company “is convinced that Linux can do for ing materials to describe, promote, and sell your business applications what the Internet did for

78 JANUARY 2018 ISSUE 206 LINUX-MAGAZINE.COM | LINUXPROMAGAZINE.COM OS MARKETING LINUX VOICE networking and communications.” IBM already had its own gamut of operating systems, includ- ing a flavor of Unix called AIX, but it was showing serious commitment to the open source fledg- ling by making the decision to back Linux. While that $1 billion went toward improving GNU/​Linux and other FOSS tools, IBM also started marketing Linux. Most notably, in 2004, the com- pany produced a 90-second video advertisement called “Prodigy” that can still be found on YouTube today [2]. In the video, a small boy is sitting alone in a white room (see Figure 1). Over the 90 seconds, various famous people approach the boy and offer him advice in all walks of life – even Muham- mad Ali makes an appearance, telling the kid: Figure 1: IBM’s “Prodigy” “Speak your mind. Don’t back down.” While all of 2006. (It peaked at 32 percent in 2009.) Of advert in 2004 introduced this is going on, two unidentified observers are course, other factors were involved as well, but Linux to millions of people making notes. At the end of the video, one asks it’s a great example of how a FOSS project can across the USA. the other: “What’s his name?” The response is: “His reach out to a wider audience in a clear, targeted, name is Linux”; then the advert ends. and effective way. The video is striking and creative, and it takes a novel approach to marketing software. IBM didn’t Risky Approaches shy away from positioning Linux as the young and When advocating and marketing open source relatively inexperienced contender, but it focused software, it’s very tempting to make bold claims on its ability to learn and absorb information (i.e., and sweeping generalizations. How many times through the open source community). have you heard the statement “Open source is What’s especially notable is the positioning of more secure than proprietary software” (or some this advert. This wasn’t some cute in-joke for variant on that), for example? You know there’s geeks at a conference or shown internally at IBM some truth in that statement; history has demon- meetings. No, it was shown during the 2005 Super strated again and again that proprietary software Bowl – one of the most viewed events in the is often riddled with security holes that are ex- world. IBM was reaching out way further than ploited by not-so-nice people for years before they pointy-haired IT bosses. IBM wanted everyone to become public. know that it was serious about Linux. However, you have to be careful. You can say Figure 2: Mozilla reached “open source is more secure,” and then something out to disgruntled web - Classic Example 2: Firefox like Heartbleed [3] happens (Figure 3). If you’re out ers with a two-page advert Still, IBM was focused on large Linux deployments of the loop, Heartbleed is a whopping security vul- in The New York Times. in enterprises. If you want an example of con- sumer-oriented FOSS marketing, you can turn to the Mozilla Foundation’s spectacular push for the mass market in 2004. Firefox 1.0 had just been re- leased, was still hugely domi- nant, and Firefox was seen as a way to introduce the masses to FOSS – ideally setting them on the path to explore more and maybe even try Linux in the end. The Mozilla Foundation set up a site called Spread Firefox and sourced donations to be used for marketing. The end result was a two-page ad- vert in The New York Times (see Figure 2) that asked readers if they were “fed up” with their web browser – and showed them an alternative. Fi- nally, they added some quotes from users, a snippet of information about the software, and a download URL. The advert obviously had an effect: Firefox tri- pled its market share over the following 18 months, breaking the 10 percent mark in June

LINUX-MAGAZINE.COM | LINUXPROMAGAZINE.COM ISSUE 206 JANUARY 2018 79 LINUX VOICE OS MARKETING

nerability in the OpenSSL For this reason, many IT purchasing people talk crypto library, which is about total cost of ownership (TCO). How much used pretty much every- will it actually cost to use program X, given the re- where. The bug was dis- quired hardware changes/upgrades,​ staff retrain- closed in 2014, and vast ing, and support costs? In the short term, this numbers of websites doesn’t always look so great for Linux and FOSS – were affected. It was so if a large company is already using a proprietary bad that the OpenBSD system, perhaps getting large discounts for bulk folks forked the library to purchases, then a switch to a FOSS solution could do a massive cleanup, in initially be very costly. the form of LibreSSL. So you need to bear this in mind when market- Most importantly, ing FOSS. Don’t just say “Linux is free,” because though, those of us pretty much every large deployment will require who’d trotted out the support of some kind, whether from the likes of mantra “open source is Red Hat, SUSE, or Canonical or from in-house IT more secure” ended up staff. A better approach is to say: “Over the long Figure 3: Be careful when with egg on our faces. run, Linux/​FOSS can reduce the total cost of own- marketing FOSS using “it’s Yes, we still believed that statement, on the whole, ership, with no need for license fees, along with more secure” arguments! but Heartbleed provided nay-sayers with a big improved reliability and security.” Again, you may Things like Heartbleed can chunk of ammunition: Open source is also inse- have to qualify the “reliability” and “security” parts still happen. cure, open source has had vulnerabilities sitting in somewhat, but it’s the right way to sell FOSS. the code for years, and so forth. Also on the subject of support: A good market- Therefore, it’s important to state that open ing strategy is to highlight that, with FOSS, you source itself doesn’t just magically make things often have many more choices for support. As an secure; rather, it’s the development process. You example, if a company has thousands of PCs run- could even argue that OpenSSL was barely open ning Microsoft Office and a serious bug is affect- source to begin with – yes, the code was there, ing many users, what can the company do? Call but hardly anyone was working on it, and those Microsoft, maybe spend some more money, and who poked around inside tended to run away hope that it gets fixed in the next release? If that screaming. The oft-quoted line “Given enough doesn’t work, they’re up a certain creek without eyeballs, all bugs are shallow” didn’t really apply the slightest hint of a paddle. here. Contrast this with a company that deploys Li- With this example in mind, you shouldn’t say breOffice: If a bug is affecting workers, the com- “open source is more secure”; instead, clarify it pany can choose from many certified develop- somewhat: “Open source development pro- ers [4] and hire one to (one hopes!) fix it. Sure, it cesses generally lead to more secure software.” still costs money, but the company is not reliant It’s not as snappy, and it leads to more questions, on a single vendor and can shop around for solu- but it’s more honest. I think the same phrasing tions (including local ones). It’s the free market at should be applied in terms of reliability as well – work – so much for FOSS being anti-capitalist, as Linux adherents know that GNU/Linux​ is pretty some people used to say! rock solid, but they need to remember that other users may be affected by corner case bugs. As What Can You Do? tempting as it is to poke fun at Microsoft for Many FOSS projects are in desperate need of mar- “blue screens of death,” Linux is not competing keting. Maybe their website is subpar, with no against Windows ME any more. Windows has proper information on what the app actually does plenty of problems, and I’m glad Linux can avoid (alarmingly, a common occurrence). Maybe the them, but for many users, it’s pretty reliable. project is making great progress but is not com- municating this effectively with the outside world. Money, Money, Money Perhaps the project could reach out to new users Another area where caution is required is price. and potential contributors via social media, Red- Yes, GNU/​Linux is free – as in beer – to obtain, but dit, or Hacker News, but nobody involved has the many other factors come into play when deter- skills or know-how. mining how much it really costs. For instance, if Of course, most FOSS projects don’t have the you need to replace a piece of hardware for some- budget to hire a full-time paid marketing person, thing that’s Linux compatible, that bumps up the but if you’re interested in this field, dive in and price. If you want to deploy Linux (or other open offer to help. As with all things in FOSS, you don’t source software, such as LibreOffice) in a large need to be an expert in the field – any help is ap- company or government body, end users might preciated. Plenty of books are out there that pro- need training – which also affects the end price. vide an introduction to marketing, and you can

80 JANUARY 2018 ISSUE 206 LINUX-MAGAZINE.COM | LINUXPROMAGAZINE.COM OS MARKETING LINUX VOICE

web and print materials [6] (Figure 4). Fedora, meanwhile, has a marketing team that’s based around a mailing list [7]; in LibreOffice, there’s a small community working on presentations, press releases, and other materials (Figure 5), and it or- ganizes through calls once a month [8]. Of course, in the process, you’ll build experi- ence that you could potentially use in a paid mar- keting job some day, and if you end up rich with your own private island, don’t forget about the humble Linux Magazine writers who set you off on your new career path. nnn

Info [1] IBM and Linux: https://www.​­ cnet.​­ com/​­ news/​­ ​ ibm‑to‑spend‑1‑billion‑on‑linux‑in‑2001/­ [2] IBM “Prodigy” advertisement: https://www.​­ ​ youtube.­ com/​­ watch?​­ v=s7dTjpvakmA​­ [3] Heartbleed: http://heartbleed.​­ com​­ [4] Certified LibreOffice developers: http://www.​­ documentfoundation.​­ org/​­ ​ gethelp/­ developers/​­ Figure 4: Mozilla’s marketing community even has its own mascot. [5] Mozilla marketing guide: https://wiki.​­ mozilla.​­ org/​­ MarketingGuide​­ take those basic skills and techniques and apply [6] Mozilla web and print materials: https://wiki.​­ ​ them to the open source projects you use and mozilla.­ org/​­ Marketing:Firefox_Materials​­ want to support. [7] Fedora marketing: You can also look at the materials and pro- cesses used by large and established FOSS proj- https://fedoraproject.​­ org/​­ wiki/​­ Marketing​­ ects. For instance, the Mozilla community has a [8] LibreOffice marketing: https://wiki.​­ ​ marketing guide [5] and other materials, including documentfoundation.­ org/​­ Marketing​­

Figure 5: Look at existing FOSS projects for inspiration – for example, the leaflets produced by LibreOffice’s marketing team.

LINUX-MAGAZINE.COM | LINUXPROMAGAZINE.COM ISSUE 206 JANUARY 2018 81 LINUX VOICE DIGITIZING ANALOG MUSIC MEDIA

Needlework – Digitize your LPs and cassettes with Audacity

Armed with the Audacity sound editor, you can convert the analog content of LPs, tapes, and cassettes to the digital world. BY MARIO BLÄTTERMANN

he good old vinyl LP is currently experienc- Recording in Progress ing a revival – you will even see hipsters After launching Audacity, first select File | New T listening to cassettes – but it is not a good Project and click to save. Next, click the Record idea to expose these treasures to the ravages of button in the toolbar and start playback on the time: Audacity helps you archive analog music in a cassette deck or lower the stylus onto the LP. In digital format on your hard drive. principle, you can now grab a cup of coffee while you wait for the recording to complete. However, Analog you might want to take the time to watch the two In their day, records and cassettes were undoubt- green level indicators at the top right: If they de- edly milestones in the development of music flect too far to the right and turn red, you either media. Many of us still have shelves full of these need to reduce the signal intensity from the ampli- now archaic sound storage media in the attic or fier or use the slider in Audacity and then restart basement. Whereas vinyl LPs are seeing a grow- the recording to avoid distorting the sound. ing community of friends flocking back to the fold, In general, you need to do this only once, unless the miniature version of the reel-to-reel audiotape you change your setup. To help you find a peak has shrunk virtually to irrelevance. level, it makes sense to listen to particularly loud You might already have replaced many of your sections up front and then record them for test pur- old treasures with CDs, but some old recordings poses. In this way, you can prevent distortion with- mastered in professional recording studios were out having to discard the entire side of an LP. When probably only ever available on LP. Certainly pri- you are done (Figure 1), you can click the Zoom In vate recordings, demos, and local productions of and Zoom Out icons in the toolbar to enlarge the re- your school band are consigned to the medium of cording and check certain areas in more detail. their era. Therefore, it is important to preserve these treasures against decay. Spring Cleaning As analog, mechanically scanned recordings, LPs Professional deliver noise in addition to the payload signal. The easiest way to convert your material to digital is to connect an analog player directly to a digital Connection recorder. Quite a few all-in-one devices on the The classical record player, with a needle market that play records have a memory card slot that follows a record’s groove and converts and often even a cassette drive. The quality of the its deflections into audio signals, outputs a hardware components are typically entry level to signal so weak that it cannot be fed directly middling, and the ability to influence the output is into the line input of a sound card. Although usually around zero. some turntables have a built-in preamp, you These limitations often result in unacceptable will typically need an amplifier with a phono quality, so it makes more sense to connect your input socket. If you don’t have one, a special turntable or cassette deck to the sound card of USB preamplifier is a passable solution – a PC or a USB adapter, which ideally often also especially for laptops, which often no longer includes a matching preamplifier (see the “Con- support line input. Typically, you need to en- nection” box). able such an external sound card in the sys- For recording, you also need sound editor soft- tem’s sound settings or switch to an alterna- ware, such as the open source tool I use in this ar- tive input. Cassette decks do not need a pre- ticle, Audacity [1]. Audacity comes with both basic amplifier; their output can be fed directly to a recording tools and functions for restoring and op- line input. timizing the quality of a recording.

82 JANUARY 2018 ISSUE 206 LINUX-MAGAZINE.COM | LINUXPROMAGAZINE.COM DIGITIZING ANALOG MUSIC MEDIA LINUX VOICE

Figure 1: After recording, zoom out once again for a general overview.

Frequently played records pop, crackle, and dis- Because an LP is an analog recording, automatic tort the signal because of dirty grooves. Cleaning routines will always find life hard. No automatic with an antistatic brush before playing helps, but recipe can remove the typical crackle of vinyl. The other tricks can trim an old recording for a Effect | Noise Reduction option built into Audacity cleaner sound (see the “New for Old” box). will achieve moderate improvements, but don’t be Scratches will be unimpressed by all of these ef- surprised if the program first asks for a noise pro- forts, and the best cleaning will not prevent the re- file: The spectral composition of noise is so diverse sulting pops. Pops are visible as short spikes in the that it is difficult for Audacity to assess it correctly. view window; the levels climb steeply and stand out clearly in the wave plot. To correct, select the New for Old appropriate section with the mouse and zoom the view with the Zoom In icon in the toolbar, by select- Besides the obligatory brush, you have other ing View | Zoom In, or with Ctrl+1 until the scratch is ways of removing dirt. One method is to shown as a single pulse (Figure 2). This works best place in front of the pickup arm another arm using View | Zoom to Selection to fit the highlighted that uses a fine brush to apply a special liquid area to the view and dragging the markers even fur- in the region about to be played back. The ther with the mouse. typical vinyl pops can be reduced signifi- Now use the Effect | Fade Out function to iron cantly in this way. The liquid evaporates with- out the scratch virtually. Applying the effect out any residue; however, the LP plays back once only will not knock the unwanted peak flat when wet and will sound more weathered straightaway; as a rule, you need to repeat the than when played dry. procedure several times, but when you are done, Another alternative is to use a “disk washer,” the pop and crackle in the recording should dis- in which two brushes running through dis- appear completely. Be sure to interrupt your tilled water with a detergent clean the record. work occasionally and save the project to avoid Covers protect the label, and the record is not data loss. played when wet but is left to dry first. Alternatively, Audacity offers a semi-automatic For very stubborn areas in which dirt cannot scratch removal tool; just select Effect | Click Re- be removed in the ways already described, moval (Figure 3). A little tuning of the default val- you can use a compound found in specialty ues usually results in clearly audible improve- stores that coats the record and then is ments, but the results can hardly compare with pulled off when dry – like a facial mask – the manual scratch removal method described along with dirt particles that adhere to it. The first, because Audacity lets too many scratches dried film is water soluble and can be reused pass. Excessive values can even affect the at least a couple of times after boiling in sounds of the percussion section if the click re- water (although the manufacturers do not moval algorithm is overly rigorous, so you should advertise this option). be careful when using this function.

LINUX-MAGAZINE.COM | LINUXPROMAGAZINE.COM ISSUE 206 JANUARY 2018 83 LINUX VOICE DIGITIZING ANALOG MUSIC MEDIA

Figure 2: A scratch is clearly visible with extreme zoom.

the magnetized tape and has a much smoother frequency spectrum.

Sound Development In addition to noise removal, Audacity can digitally equalize the frequency response. A rumble filter, which minimizes the low-frequency noise of the Figure 3: Audacity can smooth out scratches in a semi- turntable drive is a typical example. Under Effect | automatic process, but the effect has its limitations. Equalization is a settings window (Figure 4), in which you can select from several equalizer pro- Mark a small noisy area in front of or between files. Rumble, for example, is a high-pass filter that tracks, and click on Get Noise Profile. Audacity then attenuates low frequencies. If the preset 100Hz stores the profile in the project. Next, select Edit | swallows too much bass, you can change the Select | All to select the entire recording on which to curve by dragging it with the mouse to find a work- apply the effect. able compromise. Do not delude yourself: The record will not The Recording Industry Association of Amer- sound as fresh is it did when you first picked it up ica (RIAA) standardized the distortion of the fre- from the store. Crackling is far too inhomoge- quency response caused by nonlinear move- Figure 4: A Rumble filter is neous for this method; however, you will achieve ment of the stylus across an LP; many, but not useful if the amplifier does far better results when processing audio tapes, all amplifiers compensate for this. To improve not have a high-pass filter. because their noise is created by the low speed of the audio recording, you should take a look at the RIAA equalization curve [2], which reduces the trebles and boosts the bass. What sounds better in the end is up to you. The standardized fre- quency adjustment does not necessarily repre- sent the best choice. Since the mid-1960s, Dolby Laboratories has developed various procedures to get rid of tape hiss that have consistently improved over the de- cades. Noise contains especially high frequen- cies, so the signal in this area is raised and low- ered during playback, depending on the input level, which also reduces noise. Dolby SR (spec- tral recording), used in studio work, is capable of reducing the noise level by up to 25dB. The equalizer is also interesting for tape recordings. A cassette recorded with a Dolby method [3] skews the frequency response when played back

84 JANUARY 2018 ISSUE 206 LINUX-MAGAZINE.COM | LINUXPROMAGAZINE.COM DIGITIZING ANALOG MUSIC MEDIA LINUX VOICE with a Dolby-enabled playback device. However, Rolling up the recording from the back is also a Audacity does not offer a profile for this purpose. very convenient way to split live albums without For the appropriate standards, see a discussion losses. For the penultimate title, just drag the end of Dolby noise reduction online [4]. marker of the last track forward with the mouse to the beginning of the new track. In this way, the Divide and Conquer start marker for the first track you stored be- On an LP, but not a cassette, you can see the comes the end marker for the new track. breaks between tracks with the naked eye. How- ever, when you digitize an LP, the breaks vanish, Secret Code giving you an album of a single file. Thus, the re- Formerly, digital players obtained information cording needs to be split into individual tracks. about the artist, album, and track from the file The timeline above the recording view helps you name. The related album cover was only dis- find the breaks. If the album cover lists play times, played if it was provided in the folder. These days, you can easily calculate where you need to insert details of the recording are saved as metadata your virtual knife. Simply click on the view and stored directly in the audio file. When exporting to drag while holding down the mouse button to ex- such formats, a corresponding editor pops up pand a section corresponding to the desired track. (Figure 5); you then can add information such as Drop-offs in the recording level also give you the title, artist, album, release year, and more. clues, but they can be misleading, especially with By default, the dialog only lists a couple of tags; if live albums. you want more, you also need to have a good knowl- In practice, the best approach has proven to be edge of metadata standards for the desired format. starting at the end of the recording. It is easier to Additionally, the editor is not particularly useful if you listen to just a few seconds than a whole track, want to edit an entire album. Tracks exported from just to keep the fade-out at the end of the track. the same project appear over and over again with Once you have found the end, drag the opposite the same tags as the file saved previously. In many edge of the highlighted area to where you think cases, it makes sense to export the recordings with- the track starts. You can find the exact starting out the metadata and add the metadata later with a point by briefly listening in and moving the marker specialist tool such as EasyTag [5]. as needed. Once the selection fits the bill, export the cur- Conclusions rent title to a standard format for audio players. With relatively little effort, you can rescue LPs and File | Export Selected Audio opens a file dialog that tapes as MP3 or FLAC files for a new life in the saves the selection as an uncompressed WAV file digital world. Some caveats still apply; for exam- by default. At bottom right, you can select addi- ple, the metadata editor is not always practical. tional codecs, such as Ogg Vorbis and MP3. When The wxGTK basis of the program is also notice- you select these options, additional options ap- ably ugly in some places. The shift from Gtk2 to pear, such as Bit Rate Mode and Quality. If you Gtk3 occasionally causes display glitches. prefer to use an exotic encoder, choose (external Alternative candidates are few and far between. program) instead of a listed codec, where you can EKO [6] and similar simple sound editors are of specify a custom command to be executed on the limited use for this job. Only KWave [7] offers command line for an external application. functionality similar to Audacity; otherwise, you will be hard pressed to find a better audio editor in the repositories. nnn

Info [1] Audacity: http://www.​­ audacityteam.​­ org​­ [2] RIAA equalization: https://en.​­ wikipedia.​­ org/​­ ​ wiki/­ RIAA_equalization​­ [3] Noise reduction systems: https://en.​­ ​ wikipedia.­ org/​­ wiki/​­ Dolby_Laboratories​­ [4] Dolby profiles: http://hyperphysics.​­ phy‑astr.​­ ​ gsu.­ edu/​­ hbase/​­ Audio/​­ tape5.​­ html​­ [5] EasyTag: https://wiki.​­ gnome.​­ org/​­ Apps/​­ ​ EasyTAG­ [6] EKO: http://semiletov.​­ org/​­ eko/​­ Figure 5: The metadata editor is sufficient but cannot com- [7] Alternative KWave: https://www.​­ kde.​­ org/​­ ​ pete with specialist tools. applications/­ multimedia/​­ kwave/​­

LINUX-MAGAZINE.COM | LINUXPROMAGAZINE.COM ISSUE 206 JANUARY 2018 85 LINUX VOICE FOSSPICKS

Sparkling gems and new releases from the world of FOSS Picks Free and Open Source Software Graham tears himself away from updating Arch Linux to search for the best new free software. BY GRAHAM MORRISON

Minimal browser qutebrowser 1.0

ince starting to use qutebrowser some integration, and also because the entire appli- much more stable, is that QtWeb­ time ago, it’s done nothing less than cation is so lightweight. If you’ve yet to use it, Engine is now the default back- S change the way I think about Linux and the release of version 1.0 is the best excuse end rendering engine. This means user interface design. The minimal, shortcut- yet to brush up on your Vim skills. sites like Facebook, GitHub, driven approach it uses for everything, based After two successful crowdfunding cam- Gmail, TweetDeck, and Google on Vim key bindings that many of us are al- paigns to fund development, qutebrowser 1.0 Docs will work without complain- ready familiar with, saves you time and mental is the rationalization of everything that’s gone ing, and very few sites are now in- energy; it helps you navigate the web quickly, into development up to this point, and in par- compatible. Also included is the removes distractions, and feels amazingly in- ticular, the re-implementation of its consider- spell checking that comes with tuitive. Even with only a few Vim commands able configuration framework. Unfortunately, the QtWebEngine, although you’ll committed to memory, it’s enough to launch this means you can’t migrate your own set- need to run a Python setup script new tabs, yank URLs, open hints for links tings automatically as you update from an first to download your required across a page, and save bookmarks. Chro- older version. This is important because one dictionaries and run a configura- mium and Firefox plugins do similar things, of qutebrowser’s strengths is that almost any- tion command. Afterward, spell- but qutebrowser beats these with its level of thing can be reconfigured through the use of ing errors will be highlighted just the :set command as they are in Chromium, an es- and quickly stored sential feature for terrible spell- with the :save com- ers – whether you’re firing off a mand. However, tweet or writing an email – and bookmarks and something you don’t realize you browsing history are rely on until it’s missing. Along- retained from the old side these changes, there are lots version, and a new of new configuration options to diff view will show play with and an entirely updated you the differences history database, which can now between your old pre store your entire browsing history 1.0 configuration and or, optionally, a specific number of the new one. This entries or none at all. And that’s makes it relatively the brilliant thing about qutebro- easy to copy your old wser; not only is it powered by settings over to the Vim shortcuts (by default) and new format, and the light on system resources, but it new configuration file can be reconfigured very easily to 1. DuckDuckGo. Press o and type a search query. The results will load immedi- is much easier to edit perform almost any function you ately. Add !g to search Google. 2. Tabs: Tabs can be saved, moved, and now and create yourself need a browser to perform. The pinned. 3. Hints: These quick shortcuts live on your home row and make naviga- than the old one. only exception is a plugins inter- tion quick, easy, and mouseless. 4. Config diff: Go to qute://​configdiff to see The other major face, which will hopefully come your old configuration differences. 5. New config: Configuration has been over- addition for the 1.0 with the next major update. hauled for this release. 6. Command completion: Just like Vim, use help and release, besides the completion to configure and use your environment. 7. Save. Automatically or manu- dozens of small fixes Project Website ally save and restore your session. that help to make it https://​­www.​­qutebrowser.​­org/

86 JANUARY 2018 ISSUE 206 LINUX-MAGAZINE.COM | LINUXPROMAGAZINE.COM FOSSPICKS LINUX VOICE

Minimal browser Min

e’re hopefully entering pect, and the user interface is a new era of web focused on search results. Start Wbrowsing, one where typing almost anywhere, and content, privacy, and navigation you’ll get suggestions in real are the focus, rather than inces- time, usually from the very top sant advertising, notification pop- of the main window. Results are ups, location requests, and videos delivered via DuckDuckGo by that automatically play. Members default, a search engine that fi- Remove the bloat from your web surfing with a powerful, quick, and of this vanguard are simple, dis- nally seems to be finding its minimal browser. traction-less web browsers, such own strengths. Multiple tabs as qutebrowser (see opposite), can be created, but these can shortcuts and even swipe ges- the wonderful on also be grouped into “tasks,” tures for navigation. The only Android, and this new browser which are a great way of man- slight downside to Min is that simply called Min. Min gets this aging work and personal pages, it’s written atop Electron with right from the first launch, which for example. Tabs can even be Java­Script and CSS, but the sensibly asks whether you want viewed as a list. At the other speed and efficiency of the ap- to block ads, trackers, scripts, and end of the scale, a distraction- plication gives none of this even images. You can also enable free mode can be enabled to away, and the design makes it a very useful dark mode, which focus on a single tab and dis- definitely worth a look. even many full-fat browsers can’t able the creation of any more, offer yet. which is useful if you don’t want The browsing experience is to be tempted by Reddit. Plus, Project Website equally honed, as you might ex- there are plenty of keyboard https://​­minbrowser.​­github.io/​­ ​­min/

Backup BorgBackup 1.1

orgBackup is a com- hasn’t been seen before. This mand-line backup tool, process, combined with client- B but it has some special side encryption and compres- abilities that make it a better sion, makes BorgBackup an ex- choice than tar cvzf, for exam- cellent tool that could just pull ple. In particular, it calls itself a you away from your “it will “deduplicating backup pro- never happen” apathy. gram.” What this means is that Unlike rsync, BorgBackup it aims to store only the couldn’t be easier to use. You changes in a file, rather than first initialize a backup reposi- Although the command-line interface is a bit austere, a separate web multiple complete iterative du- tory with the init command, as interface can be installed and used as a graphical user interface. plicates – much as rsync does you would with git, and then when copying a directory from create a backup job using a mand, and the incremental backup will start automati- one location to the next. This is source and destination path. cally, saving only the changes into the repository. It obviously much more efficient The backup will then proceed works excellently, and this release is a major update. on storage space and band- silently, unless you ask for More than 60 contributors have helped with new fea- width, and many other backup ‑‑stats and ‑‑progress as addi- tures that include the ability to remove files from an ex- tools use a similar mechanism. tional arguments, and you have isting archive, automatic compression, more encryption Beneath the shell, BorgBackup many other options to use to methods, and better logging, plus plenty of speed and does this deduplication by split- fine-tune both the backup and security enhancements. ting a file into chunks, generat- the listing and restoration of ing a hash for that chunk, and files. To create another backup, Project Website only storing a chunk if its hash simply execute the same com- https://​­www.​­borgbackup.​­org/

LINUX-MAGAZINE.COM | LINUXPROMAGAZINE.COM ISSUE 206 JANUARY 2018 87 LINUX VOICE FOSSPICKS

Minimal text editor micro

eeping with the minimalist graph (Ctrl+Q). The help documen- theme, micro attempts to tation is short, but comprehensive, K do the same for text edit- and even includes a tutorial. ing as Min attempts to do with web A minimal interface doesn’t mean browsing. Launching it from the minimal functionality. Split views command line gives you the first are easily accessed via the auto- clue: It runs within your terminal completing command mode, and environment, just like Vim or Nano, micro has support for more than rather than in an application win- 75 languages. The syntax high- Excellent split view and syntax highlighting functionality in a static dow like Gedit or Kate. It’s also a lighting for these languages ap- binary smaller than 10MB. static binary that can be run in pears instantly and happens auto- place if you’re happy to trust the matically, depending on the file control changes, and it’s easy to build; this means you can keep it type you’re editing. Even though write your own. Micro might not on a USB stick or email attachment typing and editing speed is difficult replace something like Vim or and simply execute this single file to measure and can often be sub- Emacs, but it’s a very useful addi- when you need its text editing abili- jective, micro feels very quick in- tion when you need a small editor ties. Like Vim and unlike Nano, deed. Because the key bindings that doesn’t compromise on though, you can’t immediately see can be modified easily, it can be speed or function. The only editor how it performs simple operations, made to feel almost like any famil- that gets close to this functionality such as quit, but this is easily dis- iar editor. LUA-written plugins can and form is Textadept. coverable by pressing the F1 key to even be used to add features, such access the built-in help. How to as code snippets, spelling, in-line Project Website quit is mentioned in the first para- editor configuration, and version https://​­micro‑editor.​­github.io​­

Minimalist text editor Textadept

ot many other software is done with just a handful of lan- categories offer such guages. And you can do more N breadth of choice as text with those languages in Textad- editors. Of course, the old stal- ept than you can with Min. warts are still causing trouble and Textadept is certainly mature. discussion, but there’s also a con- It’s now 10 years old, with a re- stant supply of new pretenders, lease every two months for more each attempting a different take than six years. It can be run ei- How many editors take less than 15MB and can have variable font on entering one letter at a time. ther as a curses binary within the sizes in unlimited horizontal and vertical split views? Textadept, like Min and micro, is command line or as an applica- aiming for the minimalist dollar, tion within its own window. The yellow pages within magazines, promising speed and distraction- executable is around 5MB and this feature is essential. Auto- free design without sacrificing es- can be run off a USB stick, with a completion works with symbols sential features. Thankfully, it promise to consume a mere within the files you’re editing, as does have a different emphasis 15MB of RAM. Into this tiny well as symbols for the language from Min, in an attempt to be an space, it’s not only capable of you’re working with, complete editor for programmers. It doesn’t cramming in the lighting fast with links to the API documenta- support quite as many languages, syntax highlighting but, more im- tion. It’s also almost entirely key- with around 100 languages cur- portantly, code completion, too. board driven, completely them- rently supported for syntax high- For those of us without photo- able, and well documented. lighting purposes, but such large graphic memories, or perhaps numbers don’t really mean much getting on a little, from the time Project Website when 90 percent of programming when source code was printed in https://​­foicica.com/​­ ​­textadept/

88 JANUARY 2018 ISSUE 206 LINUX-MAGAZINE.COM | LINUXPROMAGAZINE.COM FOSSPICKS LINUX VOICE

Email client Geary 0.12

ffline email clients are now part of the Gnome project, still important and should which is exactly where a project O remain important, de- as good as Geary deserves to be. spite many of us using web- The best thing about Geary is that based email clients for our day-to- it uses Vala/Gtk+,​ showing the day email needs. They’re essential best of Gnome’s capabilities. Its if you want to back up your email, slick design is better than the for example, which is something equivalent web client and will dis- you should be doing, but they’re play more information, more effi- Geary eases the transition from web email by looking slick and also useful productivity tools, ciently. The transitions, for exam- cleverly grouping conversations. keeping you away from the temp- ple, are wonderful, and the way the tation of a browser or constant top bar is used as a toolbar and lots of much needed stability and updates. The problem is that the menu holder keeps everything improves rich text message com- popularity of web-based email cli- looking clean, even on a KDE desk- position considerably. The best ents has come at the cost of top with an entirely different win- feature, though, is that you can desktop clients, with most popu- dow manager. Like Gmail, which now press Ctrl+? (Shift+/​) to see a lar Linux clients going the same you can integrate seamlessly, crib sheet of shortcuts for which- way as the awesome Eudora. clever keywords can be used to ever mode you’re in, helping you Geary, after spending months in group and search your inbox, and learn your way around the applica- what felt like suspended anima- conversations are grouped verti- tion effortlessly. tion, is proving the exception with cally, making Geary one of the only this update, released almost 18 offline Linux email applications to Project Website months after version 0.11. It is do this well. This new update adds https://​­github.com/​­ ​­GNOME/​­geary

Story planning Storyboarder

irst, despite this project still in its infancy, perhaps with describing itself as “open some proper support and discus- F source,” it’s not open sion, the developer may be con- source enough to satisfy the vinced to open source the project Open Source Initiative definition. properly in future. It’s MIT with a few exceptions to Storyboarding is the process stop you making money off the of sketching out your plan for a code. These exceptions were story across different pages, cre- motivated by the developer’s bad ating a primitive cartoon script experience with someone forking that a director might use to orga- Plan each shot of your next YouTube masterpiece with a great piece the project and removing refer- nize the shots for a film, includ- of (almost) open source software. ences to the company that devel- ing composition, locations, and oped the software and is per- movement. Storyboarder helps through your ideas in the flow of thought, rather than cre- haps why you need to enter an you do this with various drawing ate a masterpiece out of each frame. You can “play” email address to get a download, tools and pens, much as you can through the pages to see how it feels and obviously edit even when the code is hosted on with Krita or Gimp, along with ad- and reorder the boards as you see fit. The application has GitHub. Despite this, the project ditional fields to describe a shot a professional feel, even with its link to Photoshop, and is is still worth the attention be- or the dialog. The application a great way of planning out a short film or animation proj- cause it’s a brilliant way for chil- does try to keep things simple, by ect, especially if you’re teaching about film or showing dren in particular to experiment only offering a restricted palette children how to plan their next project. with stories and storyboards, and and a few tools, but it’s not in- there’s very little software like it tended to create the final output. Project Website for Linux. Because the project is You really just want to move https://​­github.com/​­ ​­wonderunit/storyboarder​­

LINUX-MAGAZINE.COM | LINUXPROMAGAZINE.COM ISSUE 206 JANUARY 2018 89 LINUX VOICE FOSSPICKS

CPU monitor CoreFreq

his wouldn’t be FOSS­Picks the number of instructions per if I didn’t look at a perfor- cycle or second, IPS, IPC, or CPI, C- T mance monitoring tool or states, thermal monitoring, and two, and this one is rather good. the output from various perfor- CoreFreq is a CPU performance mance counters. monitoring tool that specifically This level of CPU intrusion targets relatively modern hard- comes at a cost, and that’s mainly CoreFreq displays an unparalleled amount of information about your ware. Your CPU needs to be run- paid via the authority required by CPU, as well as the way it’s being used by your applications and ning a 64-bit operating system and CoreFreq to run. Not only does it operating system. be either an Intel Atom, Core 2, Ne- need its own daemon with root halem, Sandy Bridge, or better. credentials, it also needs its own tween various modes and display vari- AMD users just need a CPU from kernel module. This is understand- ous parameters, and there’s a primitive the 0Fh family (AMD K8 Hammer) able considering the way the moni- display manager for showing details and later. The reason for these re- tor works, but it’s worth consider- such as CPU topology and hardware quirements is that CoreFreq prom- ing if you’re running the monitor on info above the monitor. Additional de- ises a high degree of precision and a critical machine. With everything can also be viewed directly with is specifically written to monitor built, installed, and running, the de- additional command-line arguments, modern CPU technologies such as fault view looks much like the mon- making CoreFreq one of the most SpeedStep (EIST), Turbo Boost, itor in htop. Each core gets its own comprehensive tools for monitoring Hyper-Threading (HTT), and Base histogram, alongside a table that your CPU that you can install. Clock. It can also deliver high lev- lists many of the statuses men- els of detail about the code run- tioned previously. A menu system Project Website ning through your CPU, including can also be used to switch be- https://​­github.com/​­ ​­cyring/CoreFreq​­

Granular audio synthesizer Fragment

itting into the niche audio sual because inputs can be im- category for this month is ages, videos, and sound, essen- F Fragment, a “collaborative tially shaders in GLSL, and it’s gran- cross-platform audiovisual live ular because the output is gener- coding environment with pixels ated by taking small samples of based real-time image-synth ap- those various inputs, processing proach to sound synthesis.” To them, and outputting them again make sense, that sentence really as a cloud of sounds mixed to- needs to be broken apart and the gether. Fragment is as compli- Use the power of your GPU to generate weird and wonderful words looked at individually, but cated as it sounds and especially sounds. this confusion of words is itself an difficult to get your head around accurate reflection of the complex- with the little supporting documen- using either OSC or MIDI, although ity and capabilities of the software. tation or examples provided. But Firefox doesn’t yet support MIDI. You Essentially, Fragment makes Fragment “sounds” fantastic, from can then edit and add to the code in sounds, but those sounds are pro- ethereal pads and ambient ab- real time, and the sound will change. grammed rather than dialed in, and stracted textures to metallic per- This is the collaborative part, and you you can share the programming cussion and additive sine waves. can play around with the synth online task in real time with collaborators, Fragment is slightly unusual in without having to install it. Load up editing the text as you perform. that, although it does run locally, it’s some images, add them as inputs in The audio is generated from pixel built with various web technologies the code, and play with the processing. data produced by your code, which and is accessed via a browser like is pushed through OpenGL Shad- Chromium or Firefox. You run the Project Website ing Language (GLSL). It’s audio/vi​ - code and send notes to the synth https://​­www.​­fsynth.com/​­

90 JANUARY 2018 ISSUE 206 LINUX-MAGAZINE.COM | LINUXPROMAGAZINE.COM FOSSPICKS LINUX VOICE

Collectable card game Argentum Age

espite the incongruity, with variable abilities and roles computer- and tablet- to play, which are then played D based card game within the board game’s wider growth appears to match the rules and context. One card type growth of the physical variety; could be used to summon a yet, very few open source card specific offensive creature, for games exist, usually because example, while another may ex- they depend on excellent assets, pand the number of cards you Not many CCGs have such beautiful and accomplished artwork. and the artists behind those as- can hold. These attributes are sets aren’t typically as well common to most CCGs, but it’s cludes a single-player campaign versed in the advantages of the context – the story – and mode, so you can experiment open source as developers. Ar- the game rules that make them with your own cards within the gentum Age’s assets are almost specific to any one game. In Ar- confines of an unfolding story. an exception, released under a gentum Age, village size corre- However, you can also take your mixture of CC BY-NC-ND, GPL, sponds to the size of your hand, skills online and pit your deck and CC0, but the assets are for example. It can be quite against real people, complete more open than many similar complex to get started and to with inline chat and an entire on- games, and content and licens- understand many of the rules, line community. ing could change. but it’s also deeply satisfying Collectable card games (CCG) when you’ve mastered a specific are a specific genre wherein the deck you’ve tailored to your par- player collects and creates their ticular style. One great thing Project Website own deck of cards, each card about Argentum Age is that it in- http://​­argentumage.​­com/

CLI cube NRubik

ubik’s Cube and its mul- ways likely to be best, virtual tifarious copies and vari- recreations in software present R ations are as popular as their own challenges as you try ever, because it’s perhaps one of to transpose your knowledge the best toys invented. Oddly onto a two-dimensional (2D) satisfying to move, seemingly projected image that is much accessible to start, and yet chal- more mentally challenging than lenging to solve. Even when the original. you’ve mastered the basics of Several good cube applica- Don’t let the click of solving the cube, you quickly get tions for the desktop range from turning a real cube stop you to turn each row, as well as obsessed with shortening your 2D to OpenGL-based 3D, which you from solving this mix up the cube. These controls time, perhaps starting with five can be the easiest to use, as you immortal puzzle in the are all you need to create a solu- minutes with an aim to get from drag your mouse across the vari- office. tion. Although it’s difficult even random to solved in less than 30 ous layers to mimic the move- with a memorized set of se- seconds. All solutions require ment of your fingers. The prob- quences, the challenge is per- good memory, problem solving, lem is that you usually can’t see fectly in keeping with what dexterity, and perseverance, and the reverse sides very quickly. makes the challenge of the cube this is why perhaps the cube is This isn’t a problem with NRubik, so long lived. still so popular. With so many however, because it runs from distractions, focusing on solving the command line, using curses a cube for a few minutes is a to display a simple planar view of wonderful reset switch, and a virtual cube. All the controls are Project Website while the physical cube is al- displayed onscreen and allow https://​­github.com/​­ ​­cheertarts/​­nrubik

LINUX-MAGAZINE.COM | LINUXPROMAGAZINE.COM ISSUE 206 JANUARY 2018 91 LINUX VOICE TUTORIALS – FFMPEG Video Wizardry

Linux has some excellent graphical video-editing tools, but sometimes working from the command line with FFmpeg is just better.

BY PAUL BROWN ow much better? Well, it makes stuff You can apply filters to whole audio or video easier to batch process, for starters. streams or only to certain parts, use them to H Say you have to change every instance merge several streams into one in interesting of “Bill” in a 100-page text file to “Gary.” Sure, ways, and do much more. you could use the search-and-replace feature in To illustrate how filters work, I’ll show you how your text editor. That would work if you only had to use a logo to watermark a video. You can see one file, but what would you do if you had a file- the logo in Figure 1. It is a PNG with a transparent system with hundreds of files scattered all over background. I’ll assume the video you’ll be using is the place? You would never consider seriously a 720p (1280x720) MP4 video called example.mp4. trawling through every directory and subdirec- There are several ways you can carry out this tory, opening each file in turn, and clicking task, but the FFmpeg filter page mentions the through the search-and-replace process, would overlay filter, and that seems to be the most you? A Bash script using find and sed would be straightforward way to go. the way to go. In the instruction The same goes, believe or not, for video editing. You can do dozens, nay, scores of things with your ffmpeg ‑i example.mp4 ‑i LM_logo.png U videos, without ever having to open a graphical ‑filter_complex "overlay" U video-editing application. All you need is FFm- ‑codec:a copy example_marked.mp4 peg [1]. You’ve probably used FFmpeg before for convert- FFmpeg takes two inputs, the example.mp4 video ing video and audio files between formats. In its file and the LM_logo.png file, and outputs them to- simplest form, that is what it does. The instruction gether – the second placed on top of the first – to example_marked.mp4. Figure 2 shows the result. ffmpeg ‑i input.mp4 output.webm Of interest is the ‑filter_complex construct, which sits between the inputs and the output. converts an MP4 video file into a WebM video file. Within ‑filter_complex, you can string filters to- However, FFmpeg can do much more than that. gether, and they will be applied one after the other It can be used to change the frame rate, switch in to one stream, the other, or both. and out audio and subtitle tracks, and even cut up Although this is a step in the right direction, the and re-arrange­ sequences within a movie. result isn’t very subtle. The logo is in the wrong place. Instead of the upper-left corner, it would be Inserting a Watermark better in the lower right, like most channel logos One of the most powerful FFmpeg features is its on TV. effects pipeline [2], or “filters,” as they are known Fortunately, most filters can take parameters, by FFmpeg users. and overlay can too:

ffmpeg ‑i example.mp4 ‑i LM_logo.png U

‑filter_complex "overlay=W‑w‑10:H‑h‑10" U

‑codec:a copy example_marked.mp4

When you pass a parameter to a filter, you do so using the = syntax. In this case, Figure 1: The logo for watermarking your video. you pass to overlay the horizontal position and

92 JANUARY 2018 ISSUE 206 LINUX-MAGAZINE.COM | LINUXPROMAGAZINE.COM TUTORIALS – FFMPEG LINUX VOICE

then the vertical position, separated by a colon (:), of the top layer (containing the logo). FFmpeg also provides a convenient way to pass the width and height of each layer to the overlay filter: W is the width of the first input (the bottom layer), and w is the width of the second input (the top layer). This means that W‑w‑10 will place the top overlay layer 10 pixels from the left-most edge of the bottom video layer. The same goes for H‑h‑10, but in the vertical axis (see Figure 3). However, the logo is still way too big. You can solve this by adding a new filter and chaining it to overlay:

ffmpeg ‑i example.mp4 ‑i LM_logo.png U

‑filter_complex "U

[1:v] scale=150:‑1 [ol], U [0:v] [ol] overlay=W‑w‑10:H‑h‑10" U Figure 2: The movie marked with a gigantic watermark. ‑codec:a copy example_marked.mp4

Several new things are going on here. First, no- tice the new scale filter, which changes the scale of a video stream by taking a new width and height separated by a colon. If you want to make sure FFmpeg keeps the proportion correct, pass one of the parameters and then ‑1 as the other. In the example above, you tell scale to make the stream 150 pixels wide and to scale its height proportionally. But, what video stream are you talking about? The FFmpeg instruction above has two inputs: ex‑ ample.mp4 and LM_logo.mp4. How do you specify which one you want to scale? Well, that is the pur- pose of [1:v]. In the filter_complex string, you can specify the input on which you want to oper- ate with a number and the type of stream. Inputs start from 0, so the first input (example.mp4) is 0, and the second input (LM_logo.png) is 1. The letter Figure 3: You can place your logo by passing the x and y position as parameters to overlay. tells the filter on what kind of stream it should op- erate. A PNG image only has a visual/​video com- ters indicates that the output from the first ele- ponent, so you tell scale to use [1:v]. It is totally ment of the string is piped to the second element, possible that other types of inputs have more which means you could have used components. For example, the example.mp4 input has video and audio components. To apply an ef- [0:v] overlay=W‑w‑10:H‑h‑10 fect to the audio, you would use [0:a]; if it has built-in subtitle tracks to which you want to apply instead of an effect, you would use [0:s], and so on. At this stage, it is worth mentioning that FF­ [0:v] [ol] overlay=W‑w‑10:H‑h‑10 mpeg allows you to label your streams, which is what [ol] is doing: You apply a scaling effect to and the result would have been the same. [1:v], and then (so you can refer to the scaled However, as your filter_complex string be- stream later and not the original input) you give it comes more complex, you will discover that label- a name: [ol] (for overlay layer – the name can be ing streams is not only a helpful memory aid, but anything you want). also essential to achieving the result you desire. As you can see in the fourth line of the code The end result is that LM_logo.png is shrunk above, you use the video stream from the first down to a reasonable size and then overlaid in the input ([0:v]) and overlay the scaled image ([ol]). bottom right-hand corner of the frame, as shown The comma separating the scale and overlay fil- in Figure 4.

LINUX-MAGAZINE.COM | LINUXPROMAGAZINE.COM ISSUE 206 JANUARY 2018 93 LINUX VOICE TUTORIALS – FFMPEG

different kinds of blending algorithms to your lay- ers. You can use addition, subtraction, XOR, and so on, which makes blend much more versatile than overlay. The caveat, though, is that blend requires the streams you are merging to be the same resolu- tion and have the same storage aspect ratio (SAR), which is the dimension of the pixels that make up a frame expressed as a ratio. In modern digital formats, pixels are usually perfectly square; that is, they have a ratio of 1:1. If you are not sure of your clips’ SARs, you can use FFmpeg’s ffprobe command to find out what they are:

ffprobe example.mp4

The output returns a resolution of 1280x720 pix- els and a SAR of 1:1, as expected. The command Figure 4: The logo is now placed and scaled thanks to the overlay and scale filters. ffprobe LM_logo.png Blending In Overlaying is fine if you are okay with an opaque logo returns a resolution of 800x314 pixels and a SAR obscuring part of your video, but if you want some- of 2515:2515, which means you have to increase thing that will not keep your viewers from seeing all the resolution of the top layer to 1280x720 pixels the action, a translucent logo is the way to go. and, although 2515:2515 is the same as 1:1, FF­ To do this, you have to shift gears and use the mpeg doesn’t know that, so you also will have to blend filter, instead of overlay, which lets you apply correct the SAR. If you simply scale up your logo and change its Listing 1: Translucent Logo SAR with setsar=sar=1, as in Listing 1 (one com- mand broken into multiple lines), it works, but you

01 ffmpeg ‑i example.mp4 ‑i LM_logo.png get what you see in Figure 5.

02 ‑filter_complex " Even if what you see in Figure 5 is not what you

03 [1:v] scale=1280:720, setsar=sar=1 [lo]; want, take a look at the code, because it intro-

04 [0:v] setsar=sar=1, format=rgba [bg]; duces several new and interesting features. First, notice you have three blocks of filter chains on 05 [bg][lo] blend=all_mode=addition:all_opacity=0.5, format=yuva422p10le lines 3, 4, and 5 separated by semicolons. A semi- 06 " colon between blocks of filters indicates that each 07 ‑codec:a copy example_marked.mp4 block is not related to the next, because line 3 ap- plies filters to the logo (input 2), line 4 applies fil- ters to the video (input 1), and line 5 is where the result of both filtered streams are merged. More specifically, line 3 scales the logo (input 2) up to 1280x720 pixels and changes its SAR to 1. Line 4 makes sure the video’s SAR is correct by setting it to 1, as well, and converts each frame to the RGBA color space, so they can be melded with the logo without causing any strange color ef- fects. Finally, on line 5, you use the blend filter on the output from lines 3 and 4 and convert the blended layers to a video-friendly color space. The blend filter can take more than one parame- ter. In fact, it can take more than a dozen [3], so in- stead of just placing the parameters in order one after another and separating them by colons, as was done with scale, you will want to refer to the name of the parameter explicitly to avoid becom- ing confused. You do this by pairing off each pa- Figure 5: A translucent logo blended into the video. rameter name with its value, as shown in Figure 6.

94 JANUARY 2018 ISSUE 206 LINUX-MAGAZINE.COM | LINUXPROMAGAZINE.COM TUTORIALS – FFMPEG LINUX VOICE

In this case, you are passing an option that speci- fies how you want to merge each pixel using the blend parameter all_mode and telling it what the opacity of each pixel has to be (0.5 is 50% opaque) with the blend parameter all_opacity. Notice how you are now confidently using cus- tom labels to describe each filtered input by using [bg] for the background video and [lo] for the logo overlay. As mentioned earlier, this is not exactly the de- sired outcome. Again, you want the logo to be Figure 6: Passing several parameters with their names to a filter. down at the bottom right-hand corner tucked away inconspicuously, not splattered all over the video obscuring the action. Fortunately, FFmpeg provides yet another filter that helps with this problem: pad [4] allows you to resize the frame around the image, filling in the new space with a color or alpha transparency. Listing 2 shows how this works. All the changes happen on line 3, where you re- size the logo to make it smaller with the scale filter you used before. Then you create a “padding” around it, to make the frame 1280x720 pixels. As with overlay, you can decide where to place the original image within the padded frame, either by using numbers or playing with the built-in variables: ow (the padded width of the frame), iw (the original width of the image), oh (the padded height of the frame), and ih (the original height of the image). As with the overlay example, ow‑iw‑10:oh‑ih‑10 places the logo 10 pixels to the left of the frame’s right- Figure 7: An overlaid translucent logo gives a touch of class to your videos. most edge and 10 pixels up from the frame’s bot- tom-most edge. avoid having to run power-hungry graphical appli- Finally, to make sure nothing funny happens to cations and wasting time manually placing and fil- the colors when you merge the logo layer with tering and then rendering your clips. the video layer, you convert the color space of FFmpeg is also very mature at this stage and is the padded frame to rgba with the format filter. probably much stabler than most graphical video Figure 7 shows the outcome of running this in- editors, which means you will avoid the frustration struction, which is exactly what you want. of crashing apps. Because it is a command-line tool, it allows you to batch process scores of vid- Conclusion eos in one go, with no need for human supervi- Info All of these command-line manipulations might sion. It also allows you to ship this kind of cycle- [1] FFmpeg: http://​ seem like overkill, and there is no denying FF­mpeg’s consuming work off to a headless server, freeing ffmpeg.­ org/​­ steep learning curve, to say the least, but that is in up your workstation for more important things, part because video editing is a complex art. like playing games or browsing the web. [2] List of FFmpeg ef- However, the payback is immense. By handing Regardless of how you look at it, using FFmpeg fects: https://​ off trivial and repetitive tasks to FFmpeg, you can for automated video editing is win-win-win. nnn ffmpeg.­ org/​­ ​ ffmpeg‑filters.­ html​­ Listing 2: Positioned and Scaled [3] The many parame- ters of blend: 01 ffmpeg ‑i example.mp4 ‑i LM_logo.png https://ffmpeg.​­ org/​­ ​ 02 ‑filter_complex " ffmpeg‑filters.­ ​ 03 [1:v] scale=150:‑1, pad=1280:720:ow‑iw‑10:oh‑ih‑10, setsar=sar=1, format=rgba [lo]; html#­ ​ 04 [0:v] setsar=sar=1, format=rgba [bg]; blend_002c‑tblend­ 05 [bg][lo] blend=all_mode=addition:all_opacity=0.5, format=yuva422p10le [4] The pad filter: 06 " https://ffmpeg.​­ org/​­ ​

07 ‑codec:a copy example_marked.mp4 ffmpeg‑filters.­ ​ html#­ pad‑1​­

LINUX-MAGAZINE.COM | LINUXPROMAGAZINE.COM ISSUE 206 JANUARY 2018 95 SERVICE Events FEATURED EVENTS Users, developers, and vendors meet at Linux events around the world. We at Linux Magazine are proud to sponsor the Featured Events shown here. For other events near you, check our extensive events calendar online at http://linux-magazine.com/events. If you know of another Linux event you would like us to add to our calendar, please send a message with all the details to [email protected].

Black Hat Europe Embedded Linux Open Networking Date: December 4–7, 2017 Conference Summit Date: March 12–14, 2018 Date: March 26–29, 2018 Location: London, England Location: Portland, Oregon Location: Los Angeles, California Website: https://www.blackhat.com/ Website: http://events.linuxfoundation. Website: http://events.linuxfoundation. Tune in to the very latest in research, development, and trends in informa- org/events/embedded-linux-conference org/events/open-networking-summit- north-america tion security over four days – two days The Embedded Linux Conference is a of deep technical hands-on Trainings vendor-neutral technical conference Join business and technical leaders (skill building for both offensive and for companies and developers using across enterprise, cloud, and service defensive hackers) and two days of the Linux in embedded products. ELC has providers to share information, research and vulnerability disclosures a large collection of sessions dedi- highlight innovation, and discuss the in Briefings (latest information on cated exclusively to embedded Linux future of open networking and security risks and trends). and embedded Linux developers. orchestration.

Events Black Hat Europe December 4–5 London, England https://www.blackhat.com/ LinuxLab 2017 December 6–7 Florence, Italy https://2017.linux-lab.it/ KubeCon and CloudNativeCon December 6–8 Austin, Texas http://events.linuxfoundation.org/events/ North America kubecon-and-cloudnativecon-north-america AGL Showcase at CES 2018 January 9–12, 2018 Las Vegas, Nevada http://events.linuxfoundation.org/events/ agl-showcase-at-ces-2018 Enigma 2018 January 16–18, 2018 Santa Clara, California https://www.usenix.org/conference/ enigma2018 FAST '18 February 12–15, 2018 Oakland, California https://www.usenix.org/conference/fast18 Open Source Leadership Summit March 6–8, 2018 Sonoma Valley, California http://events.linuxfoundation.org/events/ open-source-leadership-summit Embedded Linux Conference March 12–14, 2018 Portland, Oregon http://events.linuxfoundation.org/events/ embedded-linux-conference OpenIoT Summit March 12–14, 2018 Portland, Oregon http://events.linuxfoundation.org/events/ openiot-summit NSDI '18 April 9–11, 2018 Renton, Washington https://www.usenix.org/conference/nsdi18 heise Security Tour 2018 April 10, 12, 18, Numerous European cities https://www.heise-events.de/securitytour 24, and 26, 2018 Open Networking Summit March 26–29, 2018 Los Angeles, California http://events.linuxfoundation.org/events/ open-networking-summit-north-america 2018 HPC for Wall Street April 16, 2018 New York, New York http://www.flaggmgmt.com/linux/ Cloud Foundry Summit April 18–20, 2018 Boston, Massachusetts https://www.cloudfoundry.org/event/ North America nasummit2018/ Images © Alex White, 123RF.com

96 JANUARY 2018 ISSUE 206 LINUX-MAGAZINE.COM | LINUXPROMAGAZINE.COM SERVICE Contact Info / Authors CALL FOR PAPERS We are always looking for good articles on Linux and the The technical­ level of the article should be consistent with tools of the Linux ­environment. Although we will consider what you normally­ read in Linux Magazine. Remember that any topic, the following themes are of special ­interest: Linux Magazine is read in many ­countries, and your article • System administration may be translated into one of our ­sister publications. There- fore, it is best to avoid using slang and idioms that might • Useful tips and tools not be understood by all readers­­­­. • Security, both news and techniques Be careful when referring to dates or events in the future. • Product reviews, especially from real-world experience Many weeks could pass between your manuscript submis- • Community news and projects sion and the final copy reaching the reader’s hands. When If you have an idea, send a proposal with an ­outline, an esti- submitting proposals or manuscripts, please use a ­subject mate of the length, a description of your background, and line in your email message that helps us identify your mes- ­contact information to edit@​linux-magazine.com. sage as an article proposal. Screenshots and other support- ing materials are always welcome. Additional information is available at: http://www.linux-magazine.com/contact/write_for_us.

NOW PRINTED ON recycled paper from 100% post-consumer waste; no chlorine bleach is used in the production process.

Contact Info

Editor in Chief www.linuxpromagazine.com – North America Joe Casad, [email protected] www.linux-magazine.com – Worldwide Managing Editor While every care has been taken in the content of Rita L Sooby, [email protected] Authors the magazine,­ the publishers cannot be held respon- Localization & Translation sible for the accuracy of the information contained Konstantin Agouros 46 Ian Travis within it or any consequences­ arising from the use of Erik Bärwaldt 30 News Editor it. The use of the disc provided with the magazine or Swapnil Bhartiya any material provided on it is at your own risk. Swapnil Bhartiya 8, 58 Copy Editor Copyright and Trademarks © 2017 Linux New Mario Blättermann 82 Amy Pettle Media USA, LLC. Layout No material may be reproduced in any form what- Paul Brown 92 Dena Friesen, Lori White soever in whole or in part without the written per- Zack Brown 11 Cover Design mission of the publishers.­ It is assumed that all cor- Dena Friesen respondence sent, for example,­ letters, email, Bruce Byfield 54, 70 faxes, photographs, articles, drawings,­ are sup- Cover Image plied for publication or license to third parties­ on Joe Casad 3 © Maksym Yemelyanov and Chainat, 123RF.com a non-exclusive worldwide basis by Linux New Advertising – North America Mark Crutch 75 Media USA, LLC, unless otherwise stated in writing. Ann Jesse, [email protected] Matthew Garrett 26 phone +1 785 841 8834 Linux is a trademark of Linus Torvalds. Advertising – Europe All brand or product names are trademarks Jon “maddog” Hall 77 Brian Osborn, [email protected] of their respective owners. Contact us if we Charly Kühnast 53 phone +49 89 99 34 11 48 haven’t credited your copyright; we will always correct any oversight. Publisher Eva-Katharina Kunst 20 Brian Osborn, [email protected] Printed in Nuremberg, Germany by hofmann Christoph Langner 50, 64 Marketing Communications infocom GmbH on recycled paper from 100% Gwen Clark, [email protected] post-consumer waste; no chlorine bleach is Vincent Mealing 75 Linux New Media USA, LLC used in the production process. Pete Metcalfe 60 616 Kentucky St. Distributed by Seymour Distribution Ltd, United Lawrence, KS 66044 USA Kingdom Graham Morrison 86 Customer Service / Subscription LINUX PRO MAGAZINE (ISSN 1752-9050) is pub- Simon Phipps 76 For USA and Canada: lished monthly by Linux New Media USA, LLC, 616 Kentucky St., Lawrence, KS, 66044, USA. Periodi- Email: [email protected] Jürgen Quade 20 cals Postage paid at Lawrence, KS and additional Phone: 1-866-247-2802 mailing offices. Ride-Along Enclosed. POSTMASTER: Mike Saunders 78 (Toll Free from the US and Canada) Please send address changes to Linux Pro Magazine, Fax: 1-785-856-3084 Mike Schilli 42 616 Kentucky St., Lawrence, KS 66044, USA. Ralf Spenneberg 14 For all other countries: Published monthly in Europe as Linux Magazine Email: [email protected] (ISSN 1471-5678) by: Sparkhaus Media GmbH, Ferdinand Thommes 38 Phone: +49 89 99 34 11 67 Zieblandstr. 1, 80799 Munich, Germany.

LINUX-MAGAZINE.COM | LINUXPROMAGAZINE.COM ISSUE 206 JANUARY 2018 97 NEXT MONTH Approximate Issue 207 Jan 13 UK / Europe Feb 09 USA / Canada Mar 12 Australia Issue 207 / February 2018 On Sale Date Compilers

Software development as we know it today wouldn’t exist without the amazing tool that is the real interface between the human and computer. Next month we look at compilers. Image © pratyaksa, 123RF.com

Preview Newsletter The Linux Magazine Preview is a monthly email newsletter that gives you a sneak peek at the next issue, including links to articles posted online. Sign up at: www.linux-magazine.com/newsletter

98 JANUARY 2018 ISSUE 206 LINUX-MAGAZINE.COM | LINUXPROMAGAZINE.COM