Author: awadelewis

  • Command Line Knowledge for macOS: “Burn” ISO to SD Card

    I have to live the “multi-operating system” life style. So. There are times where you find yourself dealing with install media that’s ISO image. And often enough, it’s my MBP that’s the only thing I’ve got connected to the network at the time.

    All right, I have to keep looking up the instructions for “burning” an ISO to removable storage so often that I just figure post them here and see if Google (or preferably, Duck Duck Go) will find them for me the next time I have to do this.

    The steps:

    1. Convert from iso to disk image format using hdiutil:
      
      hdituil convert –format UDRW -o ~/path/to/dest.img" ~/path/to/target.iso
      
       
    2. Use diskutil to find out where the removable device has been mounted into the file system.
      diskutil list
    3. Unmount the device using diskutil.
      diskutil unmountDIsk /dev/diskN
       
    4. Use dd to copy the disk image to the raw device. Note you’ll need admin access for this and do remember that dd is destructutive. THINK before hitting that enter key:
      sudo dd if=~/path/to/dest.img of=/dev/rdiskN bs=1m 
    5. Now eject the removable device:
      diskutil eject /dev/diskN

    Hopefully useful… Selah.

  • Command Line Knowledge for macOS: software update

    One of the leading reasons to dive into the command-line tools in macOS is automation.   Writing scripts that link with the Shortcuts stuff adapted from iOS means you can automate some things.

    For instance, there is a command-line tool that you can use to run software updates: software update.

    Consider:

    
    softwareupdate -l
    
    

    This gets you a list of available software just like what happens in System Preferences when you launch the Software Update preference pane. In both cases, the utilities are talking the softwareupdate daemon in the operating system.

    Next up, getting stuff installed:

    
    softwareupdate -I NAME
    softwareupdate --install name
    
    

    You replace NAME with one of the items from the list you asked for in the first step. Be careful there as macOS is very sensitive about names and format of names. You should quote the names and watch out for cases where the name has trailing spaces.

    The “-d” option will just download an update while including the “-a” option will install all available updates. One of the useful options for this command-line tool is “–install-rosetta”. This option tells macOS on Apple silicon Macs to install the Rosetta 2 hypervisor/emulator for Intel macOS applications. Include the –agree-to-license” option to agree to the software license agreement without user interaction.

    Selah.

  • Command Line Knowledge for macOS: diskutil

    I have found over the years that the Disk Utility app in macOS has become less and less useful to me over the years.   My guess has been the dev teams at Apple have trying to cut back on the ability of less informed to do unpleasant things to themselves using the tool.

    But with a little effort we find the macOS diskutil utility. This is also where we begin to see some the FreeBSD heritage in macOS as this is follows the FreeBSD “noun verb” UX for commands where you enter diskutil followed by a number of verbs that do the work.

    Let’s start with the list verb. Issuing the command:

    diskutil list
    

    Gets you a listing of currently mounted disks, partitions, and mount points. This is fun as you get a lot more detail about the internals of how APFS is blatting stuff through your disk. For instance, on my machine I have /dev/disk0 as the physical disk with an APFS container disk in a partition. That logic disk is mounted as /dev/disk3 with the multiple volumes in the container. This is far more detailed information than what you get from the user interface.

    The info verb gets you the details for a specific disk. Again, lots of detail but good for troubleshooting. The umount and umountDisk verbs are for un-mounting partitions and disks out of a file system while mount goes the other way. It’s important to understand that the eject verb is for removable devices and is the same action as ejecting a drive in Finder.

    All of the formatting and partition things you do in the GUI have corresponding verbs in the command-line tool. Do be careful as with great power comes with great responsibility. Think twice and then again before hitting that enter key.

    The jobby-job thing that I do to pay the bills requires me to do a bunch of system administration things. So, I’m often needing to “burn” a Linux installer to a USB key. Here we can use a combination of the diskutil and hdiutil command-line tools to automate that process.

    First, use the list verb to find the mount point for the USB device that’s your target device:


    diskutil list

    Now we can write a Bash script that will do the heavy lifting for us:

    
    ISONAME=$1
    DESTDISK=$2
    TMPIMG=“~/tmp/copytarget.img”
    hdiutil convert UDRW -o $TMPIMG $DESTDISK
    diskutil unmountDisk /dev/$DESTDISK
    dd if=$TMPIMG of=/dev/r$(DESTDISK) bs=1m
    diskutil eject $DESTDISK
    rm $TMPIMG 
    

    So, our little script takes two parameters: the filename of the Linux ISO and the base name of the disk mount point. This script first uses hdiutil to convert the ISO into a macOS disk image. I keep a temp folder in my home folder for these sort of things. We then unmount the external device and use the classic UNIX dd command to do a byte-by-byte copy to raw version of the mount point. After doing this, you need to eject the device.

    And that’s a quick summary of diskutil.

    Selah.

  • Command line knowledge for macOS

    Non-developer types (you know, you “normies” out there) tend to want to do everything using the mouse rather than the keyboard. Really true for people using macOS. Makes me hurt when I see it as there are many things easier to do with the command line than with multiple mouse clicks.

    This isn’t going to be series talking about how to do stuff in Bash or zsh using the Terminal application. Lots of introductions out on the Intertubes about Shell programming and how one can use it to automate for fun and profit. This series is going to point out things that about using the command line in macOS that you don’t often hear about.

    Like what things? Many of the tools you use to run macOS have lesser known command line interfaces. Classic examples are apps like Disk Utility and Software Update. Both have command line interfaces that allow you to do stuff in single commands that take multiple clicks in the GUI. That’s what we’re going to examine in this series of posts.

    But there are some things available to you in the Terminal app and with Bash and/or zsh that you can use to make your life easier. Drag and drop is supported by Terminal… dragging a folder icon from Finder to the Terminal’s Dock icon opens a new window in the app and changes the current working folder to that that folder. Dragging files onto a Terminal window inserts their paths separated by spaces.

    A really useful thing is the open command. Issuing the command by itself in a shell will open the current working folder in a Finder window. You can specify a file name as an option:

    open ~/Library/Preferences
    open ../..
    open /etc
    

    Provides a quick way to get to hidden folders when you need to do something “admin”-like on your machine.

    You can open a specific file, which will use the current association for that file type to open the file, or use the -a option to specify the app to use to open the file. You have the -e or -t options to open a file using TextEdit or your favorite editor.

    Really useful is the -f option which allows you to pipe text into the open command. This allows you to use open within shell pipelines, up to and including getting output from a command into a text editor.

    Lots of things that you can do here and Terminal’s linkages into Finder and the open command give you way to link the things you do in the Terminal with the windowing system and vice-versa. So go grab a good tutorial in the use of zsh and enjoy!

    Selah.

  • It’s time to fire this guy back up

    Time to start things back up with my blog. I’ve let my web presence and blog languish a bit. Been putting too much focus on the social media things, truth be told.

    So it’s time to start putting up some new content. Like what? Been having to do some work on NLP and am working on a couple of posts on setting up an environment for doing that. I’ve also been having to do some sysadmin things on Macs and have found lots of less known command-line tools that I think my notes would be helpful to someone else.

  • A Useful Little VirtualBox Trick

    I’m teaching a Security Fundamentals course this semester and we’ve gotten to the point where we’re talking network security. In particular, we’re talking about using Wireshark to monitor and trace networks. I’ve found an interesting and useful little feature in VirtualBox.

    Virtual Network Cards

    VirtualBox, like most virtual machine managers, emulates network interface cards. So… how can I go about tracing these interfaces? The neat feature is that we can use the command-line management tool to capture all traffic on one of these virtual interfaces.

    Step 1: Turning on network capture

    Let’s trace traffic on the first virtual network interface:

    VBboxManage modifyvm "ubuntu" -nictrace on -nictracefile1 vmtracefile.pcap"
    

    This turns on the tracing of the first network interface in the “ubuntu” virtual machine. At this point you start the VM and duplicate whatever situation you need to test.

    Step 2: Turning off network capture

    When you’re done, you turn off the tracing with the command:

    VBoxMange modifyvm "ubuntu" -nictrace off
    

    A few caveats

    Don’t forget to turn off tracing as it’s both a security risk and the trace files can get very large. The VirtualBox documentation suggests the use of snapshots in combination with this feature to keep track of what you’re doing and minimize the window in which tracing is left on.

    Lessons learned

    Look closely at the underlying command-line interfaces for your virtual machine manager. One can find many very interesting features and tools hiding underneath the covers of the GUI.

    Selah.

  • Something simple

    Late spring means strawberries in North Alabama. Strawberries require pound cake. They just do.

    Good thing is that pound cake is one of simplest things you can bake. I’ve seen a number of recipes similar to this one spread throughout the Internet. More importantly to me is that this is very similar to recipe that my Mom uses for her pound cake.

    Basic Pound Cake

    Ingredients


    1 1/3 c. butter, softened
    2 1/2 c. sugar
    6 eggs
    3 c. all-purpose flour
    1/2 c. buttermilk
    1 teaspoon vanilla extract

    Instructions

    Preheat oven to 325dF. Beat butter until creamy. Add sugar in portions, beating at medium until fluffy. Add eggs, 1 at a time, making certain that each egg is blended adding the next egg.

    Add flour and buttermilk, beginning and ending with flour, beating at low speed until just blended. Stir in vanilla.

    Pour into greased and floured tube pan. Bake for between 65 to 70 minutes. Test for doneness if toothpick comes out clean. Cool in pan for 10 to 15 minutes, remove from pan, and allow to cool for at least another 20 minutes before serving.

    Selah.

  • Spring. Something simple for the season

    Today’s Easter Sunday. Got me thinking back to my time working in Israel and remembered a chicken dish that I really liked at one of the restaurants in Tel Aviv. After some digging in my Israeli and Greek cookbooks, I’ve pulled together something I think might be close:

    Braised Chicken with Lemon, Orange, Garlic, and Olives

    4 bone-in, skin-on chicken thighs
    Salt and black pepper, to taste
    3 Tbs. olive oil
    6 garlic closes
    2 yellow onions, thinly sliced
    1 lemon, juiced, zested, peeled, and thinly sliced
    Juice from 2 tangerines
    1 tbs. dried basil
    1 tsb. oregano
    1 cup mixed, pitted olives
    

    Preheat oven to 375dF. Dry chicken and season with salt and pepper. In Dutch oven, heat olive oil over medium heat. Sear chicken until golden brown. Add garlic and zest of lemon. Cook until fragrant. Remove chicken and garlic from the pan and reserve.

    Add onions to pan and cook until wilted. Add lemon slices and cook for 2-3 minutes. Add lemon and tangerine juice, basil, and oregano and deglaze pan. Add lemon slices and olives and stir to combine. Nestle thighs skin skin side up onto onion mixture. Cover and bake for 40 to 60 minutes.

    Selah.

  • The pie whose name we cannot say on the Internet

    One of the student organizations at work put on a bake sale around campus this week. Someone had baked a Chocolate Bourbon Pecan Pie… some of you may know of it as being a pie named after an event of the sport of kings held in the great Commonwealth of Kentucky. However, I have to be rather evasive and not use the actual name as the original developers of the recipe are painfully protective of their trademark.

    No matter what, the pie itself was quite tasty; tasty enough that I went back through my files and dug out the recipe I had picked up from some Kentucky friends of mine. Their recipe is very similar to one I saw recently in Southern Living. Both recipes are very similar to the classic pecan pie recipe with the only real difference being the inclusion of chocolate when you put the pecans into the pie.

    Chocolate Bourbon Pie

    1/2 (15-ounce) package refrigerated piecrusts
    1 1/2 cups chopped pecans
    1 cup (6 ounces) semisweet chocolate morsels
    1 cup dark corn syrup
    1/2 cup granulated sugar 
    1/2 cup firmly packed brown sugar 
    1/4 cup bourbon or water
    4 large eggs 
    1/4 cup butter 
    2 teaspoons cornmeal
    2 teaspoons vanilla extract
    1/2 teaspoon salt 
    
    • Fit piecrust into a 9-inch deep-dish pie plate according to package directions; fold edges under, and crimp.
    • Sprinkle pecans and chocolate evenly onto bottom of piecrust; set aside.
    • Combine corn syrup and next 3 ingredients in a large saucepan, and bring to a boil over medium heat. Cook, stirring constantly, 3 minutes. Remove from heat.
    • Whisk together eggs and next 4 ingredients. Gradually whisk about one-fourth hot mixture into egg mixture; add to remaining hot mixture, whisking constantly. Pour filling into prepared piecrust.

    • Bake at 325° for 55 minutes or until set; cool on wire rack.
  • Jan 1st: just how much of a milestone is it?

    Thoughts on the passing of the old year and starting of the new year.

    It’s January 1st, 2015: New Year’s Day 2015 C.E. The start of a new year if you follow the Gregorian calendar. A time of renewal and starting fresh.

    Yet…

    It’s not really a day I use as a milestone. Other events have more significance in my life. From a work standpoint, it’s the Graduation ceremony in the Summer term that marks the passing of another academic year. In my personal life, it’s always been Homecoming events at Sewanee (or, as we called it in my more callow and younger days: “Fall Party Weekend”) that have marked off another year since Graduation forced my departure from Percy’s “Arcadia”.

    So, while today may notch another click in the years component in the odometer, it’s not much more beyond that for me.

    Selah.