Create a bootable USB stick with terminal UI display

Building It

As always, the listings for this article are available for download from the Linux Magazine web server [2]. Once you have the three files – cpchunks.go (Listing 1), drive.go (Listing 2), and isoflash.go (Listing 3) – in one directory, the first two lines of Listing 4 create the isoflash binary. Then, you need to call the program with sudo to have write permissions for the USB stick (last line).

Listing 4

Calling the Binary

$ go mod init isoflash
$ go build
$ sudo ./isoflash ubuntu.iso

Right after the program starts, it immediately instructs the user to plug in the USB stick (Figure 1). As soon as it finds the newly plugged in device, it starts to copy the data after confirmation from the user (Figure 2). It uses a progress bar to show the current state of affairs (Figure 3). After finishing, the UI reports that the action was successful (Figure 4). All done!

Figure 1: The Go program waiting for a USB stick to be inserted.
Figure 2: The 32GB stick I plugged in has been detected. The program is waiting for me to confirm.
Figure 3: Copying has started. A progress bar shows the number of bytes from the ISO file already copied to the USB stick.
Figure 4: The bootable USB stick now has all the required data and is ready for use.

Infos

  1. "Programming Snapshot: Progress Bar" by Mike Schilli, Linux Magazine, issue 220, March 2019, pp. 46-49, https://www.linux-magazine.com/Issues/2019/220/Progress-by-Installments/(language)/eng-US
  2. Listings for this article: ftp://ftp.linux-magazine.com/pub/listings/linux-magazine.com/239

The Author

Mike Schilli works as a software engineer in the San Francisco Bay area, California. Each month in his column, which has been running since 1997, he researches practical applications of various programming languages. If you email him at mailto:mschilli@perlmeister.com he will gladly answer any questions.

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Linux Magazine

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

  • Progress by Installments

    Desktop applications, websites, and even command-line tools routinely display progress bars to keep impatient users patient during time-consuming actions. Mike Schilli shows several programming approaches for handwritten tools.

  • Programming Snapshot – Bulk Renaming

    Renaming multiple files following a pattern often requires small shell scripts. Mike Schilli looks to simplify this task with a Go program.

  • Book Collector

    Mike Schilli does not put books on the shelf; instead, he scans them and saves the PDFs in Google Drive. A command-line Go program then rummages through the digitized books and downloads them as required.

  • Programming Snapshot – Go

    To find files quickly in the deeply nested subdirectories of his home directory, Mike whips up a Go program to index file metadata in an SQLite database.

  • Programming Snapshot – Go Photo Organizer

    In this issue, Mike conjures up a Go program to copy photos from a cell phone or SD card into a date-based file structure on a Linux box. To avoid wasting time, a cache using UUIDs ensures that only new photos are transferred.

comments powered by Disqus
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters

Support Our Work

Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.

Learn More

News