pratinav
Posts: 3
Joined: Thu Jun 30, 2016 12:38 pm
Contact: Website

A command-line tool to install disc images easily

Fri Jul 01, 2016 12:56 pm

2016-07-03 v1.1.1
  • - Added progress bar (pipe viewer)
    - Added pipe viewer to dependencies
    - Added an update option
    - Bug fixes
2016-07-02 v1.1.0
  • - Added disk and file verification
    - Major code refactoring and clean up
    - Errors are now outputted to stderr
    - Removed root requirement by default (any commands requiring root access while ask for passwords after command is run)
    - Added uninstallation option
    - Simpler installation
    - Bug fixes
2016-07-01 v1.0.0
First release!

Installing Operating Systems to SD Cards via the terminal can sometimes be quite irritating, or uncomfortable for command-line newbies, which leads many to install full blown applications, that are overkill just to install images.

So, a while ago, I wrote a small bash script to make life easier. And why not release it publicly? So I've released the script as a command line disc image installer https://github.com/pratinav/disc-image-installer with an installation script, a guide, and all that awesomeness.

This is an automation script, which mainly aims to make your life easier and save your time, and ISN'T a new application, aiming to compete with any existing applications.

NOTE- As of now, this script is only for Mac OS X. A Linux version may be released in the future.

It can install any disc image file (.img file) onto any flash media or storage device, so it's not only limited to raspberry pi OS installations.

Hope it helps! :D

PS- Please suggest a better forum for this post if you can, I'm kinda new around here :P
Last edited by pratinav on Sun Jul 03, 2016 8:11 am, edited 4 times in total.

Heater
Posts: 13933
Joined: Tue Jul 17, 2012 3:02 pm

Re: A terminal tool to install disc images onto SD Cards eas

Fri Jul 01, 2016 2:54 pm

What "bulky" software. I use dd. It's small, it's installed by default on every OS I use.

You script uses dd. Isn't just easier to use dd directly?

The script also reports "Image succesfully installed." even if the dd command fails!
Memory in C++ is a leaky abstraction .

User avatar
dasmanul
Posts: 502
Joined: Wed Sep 30, 2015 10:20 am
Location: Frankfurt, Germany

Re: A terminal tool to install disc images onto SD Cards eas

Fri Jul 01, 2016 3:08 pm

Heater wrote:The script also reports "Image succesfully installed." even if the dd command fails!
Actually, I think it doesn't.

pratinav
Posts: 3
Joined: Thu Jun 30, 2016 12:38 pm
Contact: Website

Re: A terminal tool to install disc images onto SD Cards eas

Fri Jul 01, 2016 3:42 pm

Heater wrote:What "bulky" software. I use dd. It's small, it's installed by default on every OS I use.
You script uses dd. Isn't just easier to use dd directly?
I don't think I was clear. What I meant by "bulky software" was full blown GUI applications, that are overkill for image writing.

Yes, dd comes pre-installed, but it can become cumbersome to write the whole command, or even remember it. This is an automation script, that removes even the little difficulty. A single command is still more efficient and saves time over a couple of commands. Besides, those who aren't veterans of the command line might be more comfortable with this script.
Heater wrote:The script also reports "Image succesfully installed." even if the dd command fails!
That doesn't seem right. I'll fix any bugs that come up after more testing. Thanks for the feedback.

Heater
Posts: 13933
Joined: Tue Jul 17, 2012 3:02 pm

Re: A command-line tool to install disc images easily

Fri Jul 01, 2016 4:07 pm

Sorry, I beleive you are right. There is an exit sneaked in there.
Memory in C++ is a leaky abstraction .

User avatar
kusti8
Posts: 3439
Joined: Sat Dec 21, 2013 5:29 pm
Location: USA

Re: A command-line tool to install disc images easily

Fri Jul 01, 2016 4:14 pm

I'm sorry but I don't see the point of the script. So instead of remembering to:
diskutil list
sudo dd bs=1m if=file.img of=/dev/rdisk2

You have to remember:
diskutil list
sudo installimg file.img /dev/disk2

How is that really any improvement? If you are going to use the command line you might as well use dd. Only a few more characters to type.
There are 10 types of people: those who understand binary and those who don't.

Peter Ryan
Posts: 39
Joined: Sat Mar 03, 2012 12:44 am
Location: UK

Re: A command-line tool to install disc images easily

Fri Jul 01, 2016 5:11 pm

kusti8 wrote:How is that really any improvement?
You get to learn about Github too? :D

stderr
Posts: 2178
Joined: Sat Dec 01, 2012 11:29 pm

Re: A terminal tool to install disc images onto SD Cards eas

Fri Jul 01, 2016 5:44 pm

pratinav wrote:
Heater wrote:Yes, dd comes pre-installed, but it can become cumbersome to write the whole command, or even remember it. This is an automation script, that removes even the little difficulty. A single command is still more efficient
Some thoughts whatever they might be worth:

1. I think the biggest fear with dd is accidentally overwriting the hard drive or some other device and not the actual sdcard itself. I don't have a mac recent enough to ever feel the need to turn it on so I don't know the answer, is /dev/rSOMETHING always an sdcard or can it be something else? The most important thing for your script, I think, is to do checks to prevent the user from accidentally dd-ing the wrong thing. If the /dev/r header on what they input does that, good. Still, is it possible to have more than one /dev/rSOMETHING device?

2. You tell them to run it as root but you are using sudo sometimes in your script for things that would otherwise need it and other times not.

3. You really should, I think, be giving your user an update of progress. Apparently some versions of dd now have some capacity like that built in, I haven't tried it, see for example, https://www.reddit.com/r/linux/comments ... _progress/ , but the usual means has been to use killall -USR1 although apparently that doesn't work on the mac, I have no idea, see https://www.upguard.com/commands/check- ... gress-os-x for a supposed work around.

4. If your code puzzles more than one person who replies, it could use some sort of explanation.

Code: Select all

dd bs=1m if=$2 of=/dev/r$1 || dd bs=1M if=$2 of=/dev/r$1 || dd bs=1m if=$2 of=/dev/$1 || dd bs=1M if=$2 of=/dev/$1 || { exit 1; }
That's a lot on one line, Heater missed the exit 1 at the end and I kept looking at it and trying to figure out why it was repeated but with the 1M and 1m different. The answer is that you are trying the same command up to four times before bombing out, which people keep claiming is the definition of insanity even though it isn't. Shouldn't the code be telling the user that it failed and that it is trying the next attempt?:

Code: Select all

dd bs=1m if=$2 of=/dev/r$1 || 
  echo "failed first attempt, trying again"; dd bs=1M if=$2 of=/dev/r$1 || 
  echo "failed second attempt, trying again"; dd bs=1m if=$2 of=/dev/$1 || 
  echo "failed third attempt, trying again"; dd bs=1M if=$2 of=/dev/$1 || 
  { echo "failed fourth attempt, exiting to command line."; exit 1; }

User avatar
PeterO
Posts: 5160
Joined: Sun Jul 22, 2012 4:14 pm

Re: A terminal tool to install disc images onto SD Cards eas

Fri Jul 01, 2016 5:48 pm

stderr wrote: The answer is that you are trying the same command up to four times before bombing out,
But it doesn't try the "same command" four times. First two try /dev/r$1 and last two try /dev/$1

It's still ugly code though !

PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

Heater
Posts: 13933
Joined: Tue Jul 17, 2012 3:02 pm

Re: A command-line tool to install disc images easily

Fri Jul 01, 2016 5:51 pm

When I plug an SD card into a reader on my PC i'm never sure what device it actually shows up as.

/dev/sda, b,c,x, y, z, whatever.

Always have to do a dmesg to check.

I'm always fearful of dd'ing to my root fs or something important. Is it actually possible to dd a mounted drive? Never tried.
Memory in C++ is a leaky abstraction .

stderr
Posts: 2178
Joined: Sat Dec 01, 2012 11:29 pm

Re: A terminal tool to install disc images onto SD Cards eas

Fri Jul 01, 2016 5:57 pm

PeterO wrote:
stderr wrote: The answer is that you are trying the same command up to four times before bombing out,
But it doesn't try the "same command" four times. First two try /dev/r$1 and last two try /dev/$1
It's still ugly code though !
I looked at that for some time and I thought I went through it bit by bit. I found the M and m difference but I missed the r and not r part. That seems like the user is guessing at what the right /dev is, which is not something I would get behind, unless I was very far behind it and running the other way.

pratinav
Posts: 3
Joined: Thu Jun 30, 2016 12:38 pm
Contact: Website

Re: A command-line tool to install disc images easily

Sat Jul 02, 2016 6:12 am

I see why some users would think dd is simple enough. In my opinion even the little keystrokes it saves, and other arbitrary commands (unmounting, ejecting), is worth it. But I do plan to on making the script more useful in subsequent versions, such as drive checking to prevent system drives to be wiped, progress bars etc.

Sorry about the ugly code, initially this script was meant for personal use, and I forgot to refactor some of the code for public release. Should be fixed in some time.

User avatar
r3d4
Posts: 968
Joined: Sat Jul 30, 2011 8:21 am
Location: ./

Re: A command-line tool to install disc images easily

Sat Jul 02, 2016 3:31 pm

Heater wrote:. Is it actually possible to dd a mounted drive? Never tried.
I think in the past i have manageed to do this. :cry: :roll:

Return to “General discussion”