Monday 29 June 2015

Booting from a USB stick via grub2

I made a USB stick using unetbootin, on a Linux machine, booted up, changing the boot setting in BIOS to boot from the stick, and yet no luck. The system booted off disk instead.

Thanks to others who have posted on this topic, I was able to boot from the USB stick using grub2. I’m recording what I did here for reference. The first section below gives the commands once I was in the grub2 command line. Below that is information about how to figure out the partition to boot from and what the commands are doing.

The grub2 commands

Using (hd1, mdsdos1) as the example partition, the summary of commands once you are in the grub2 command line:
  • root=(hd1, mdsdos1)
  • chainloader +1
  • boot

The general overview

  • boot up and launch the command mode of grub2
  • figure out what partition represents the bootable USB drive
  • set that partition as the root
  • load the bootloader of the USB stick so it will be used to boot from
  • boot from this loaded bootloader, i.e. the one on the USB stick

The grubby details

  • When you get to the grub2 screen on booting up, press c to get into command mode.
  • Type ls to list the partitions on the system.
  • List the files on the partitions to figure out which one is the USB stick. Your internal system will usually be (hd0,0), so try one of the others first. e.g. ls (hd1, mdsdos1)
  • When you figure out which partition is the one you want to boot from, set it as the root for example root=(hd1, mdsdos1)
  • Then load up the boot loader by typing chainloader +1. This allows the current bootloader (grub2 in this instance) to boot a second bootloader (here, the one you want on your USB stick). See: http://www.linux.com/learn/answers/view/919-what-is-chainloading-and-how-do-it-do-it
  • Type boot to boot from the USB stick.

Sunday 24 May 2015

Where is java on Mac Mavericks?

Sometimes you just need to know where java is on the system. I still struggle with this sort of thing on a Mac. So, for my own sanity in future, here is what I found:

Java seems to be put in different places depending on whether you've installed the JRE or the JDK, and also depending on what version you are looking for.

JRE

I recently installed just the JRE for java 1.8.0_40 using the dmg from Oracle. (Ye olde double-click and install method.) This placed java under:

/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/

JDK

Find the jdks on the system with:

/usr/libexec/java_home

or

/usr/libexec/java_home -v 1.8

found a directory where my jdks (previously installed) were located. These were under:

/Library/Java/JavaVirtualMachines/

Meanwhile, java 1.6 sdk is sitting under

/System/Library/Java/JavaVirtualMachines/

Setting the default jdk system wide

 (Answer provided by Hughes M. on https://stackoverflow.com/questions/21964709/how-to-set-or-change-the-default-java-jdk-version-on-os-x)
  • leave all JDKs at their default location, under /Library/Java/JavaVirtualMachines. The system will pick the highest version by default.
  • To exclude a JDK from being picked by default, rename its Contents/Info.plist to Info.plist.disabled. That JDK can still be used when $JAVA_HOME points to it, or explicitly referenced in a script or configuration. It will simply be ignored by system's java command.
System launcher will use the JDK with highest version among those that have an Info.plist file.
When working in a shell with alternate JDK, pick your method among existing answers (jenv, or custom aliases/scripts around /usr/libexec/java_home, etc).

 

Setting the default jdk - in a one-off sense

Locate the java versions on the system (see above).

export JAVA_HOME=`/usr/libexec/java_home -v 1.8.0_121`

 or, if the version is unique, you could use

export JAVA_HOME=`/usr/libexec/java_home -v 1.8`

But don't do that second version if you are planning on having later versions installed but not the default.


Sunday 15 March 2015

Using the alternatives system (update-alternatives, /etc/alternatives)

Yes, it’s basic. However, I found it challenging to find a page with exactly the info I was looking for. So I’m recording the things I wanted in a single page here.

General Background

The alternatives system is a way for several programs that are installed on your system and that carry out the same, or similar, functions to be listed as alternatives (for each other). One of the installed programs will be designated as the default for this set of alternative programs. Examples where this may be used would be text editors or java versions.

Management of what alternatives are listed and which is set as the default is handled by the update-alternatives command. (On some systems, the alternatives command could be used.) Each of the programs in a set of alternatives is assigned a priority level. The alternative with the highest priority level determines the default chosen when running in auto mode.

The update-alternatives command creates, removes, maintains and displays information about the symbolic links that make up the alternatives system.

More details

For systems supporting the alternatives feature, symlinks are created from
/usr/bin/ to /etc/alternatives/ . This latter link is a symlink to the real program, which is determined by the priorities of the alternatives available.

On a package-based system (e.g. Debian, Ubuntu), a package creator sets the priority level. So you have to hope that the creator of a package considers the impact of the priority they set.

Downsides

One downside to the use of alternatives is probably mostly felt by old-schoolers (aka me) who really want to know what it is that is launched when we launch a program. For example, “vi”. If I type “vi”, am I getting vi or vim or something else? In olden days, I could just see if there were symlinks, if so follow them, and I’d know. Now, you’d have to access the alternatives system and puzzle it out via priorities.*

*Well, take that with a pinch of salt! That is my understanding and could be wrong. Leave a comment if it’s wrong and you know it, please. :-)

Working with alternatives

  • update-alternatives
  • alternatives
  • galternatives - a graphical system on Debian for working with the alternatives system. (I have not tried this.)


Working with alternatives - java from scratch

The notes below were from a point in time where I had just installed a new jdk (jdk1.7.o_71) on a machine. I then needed to register java in the alternatives system, and then add other java functionality into alternatives.

I cannot guarantee all the information below is strictly correct, as I’m writing this from my notes made at the time I did this, but the general pattern is as it happened. Please refer to the man page for update-alternatives for the ultimate truth.
  • Enter the new jdk into the alternatives system:

     sudo update-alternatives --install /usr/bin/java java /opt/jdk1.7.o_71/bin/java 2
    
  • If java was not already in your alternatives system, you set up a new configuration for java by running:

    sudo update-alternatives --config 
    
    If java is already there, then use --set not --config. See bullet point below. 
    
  • Include jar processing and the java compiler in the alternatives system in a similar way to the above.

    sudo update-alternatives --install /usr/bin/jar jar /opt/jdk1.7.0_71/bin/jar  2
    sudo update-alternatives --install /usr/bin/javac javac /opt/jdk1.7.0_71/bin/javac 2
    
  • Set these as the defaults in the (existing) alternatives setup using –set

    sudo alternatives --set jar /opt/jdk1.7.0_71/bin/jar
    sudo alternatives --set javac /opt/jdk1.7.0_71/bin/javac
    

For java, you may then wish to set up some environmental variables as per usual. If you were just to do this for a given session (probably not what you want to do long term though), then you could just run these commands in the case of the java discussed in this section:

export JAVA_HOME=/opt/jdk1.7.0_71/
export JRE_HOME=/opt/jdk1.7.0_71/jre
export PATH=$PATH:/opt/jdk1.7.0_71/bin:/opt/jdk1.7.0_71/jre

Saturday 5 July 2014

Installing cherrytree on a Mac

Cherrytree is a terrific note taking software but it’s a big tricky to get installed on the Mac. Okay, not that tricky, but here we go…
I am working on Mac OS X 10.9.3.

The steps take here were suggested by zackpete on a cherrytree discussion list. Below is just a more expanded list of what I needed to do to follow that advice.

  1. As suggested on the MacPorts site, I installed Xcode and Xcode Command Line Tools.

    This took a surprising long time. Eventually, impatience won out, and once again I had cause to be grateful to those who take the time to document issues they see and ways to resolve things like this. Information on http://scheyeniam.blogspot.dk saved me, pointing out that I probably had a zombie storeagent process that needed to be killed. The steps I took here were:

    • Quit the Apple Store program.
    • Force killed the store agent process via the Activity Monitor. (Kill didn’t work, but if you come across this note, you should try an ordinary kill first.)
    • Restarted the Apple Store program.
    • Went to Purchases.
    • Clicked on the Resume button beside the Xcode app.

    At that point, the app installed really quickly.

  2. Agree to the Xcode license by opening and Terminal and running the command

    sudo xcodebuild -license

    Scroll to the end, reading all of it of course, and type in the word 'agree' if you agree.

  3. Install the Xcode Command Line Tools. I did this by using Spotlight to find Xcode, and then launching it. I was prompted to agree to install things that would allow me to run Xcode. So I agreed to that.
  4. I then had to run the command

    xcode-select --install

    To install the Xcode Command Line Tools.

    At this point, I'm not sure whether step 3 was necessary or not. But I'm too lazy to rip everything out and put it back to find out. Apologies!

  5. Install MacPorts as described on the MacPorts site.

  6. I think that XQuartz should be installed at this point. (I already have it installed, so no instructions are included here for this.)
  7. Update the MacPorts package index using the command

    sudo port selfupdate

  8. Install some dependencies. To do this, open a Terminal and use the command

    sudo port install python py27-pygtk py27-pygtksourceview p7zip py27-enchant

    The easiest way to ensure that the command "port" is on your PATH at this point (i.e. that the command called "port" can be found if you type in a command like the one above) is to open a new terminal window at this point.

    If you don't already have dbus-python installed, then you will need that.

    sudo port install dbus-python

    You then need to start up dbus using the following commands

    sudo launchctl load -w /Library/LaunchDaemons/org.freedesktop.dbus-system.plist
    launchctl load -w /Library/LaunchAgents/org.freedesktop.dbus-session.plist

    If you don't run those commands, you will likely see an error saying that dbus does not have enough memory.

  9. Download the latest cherrytree source code.
  10. Extract the source code using the following command in a Terminal

    tar xvfz cherrytree-version.tar.gz

  11. Move into the unpacked cherry tree directory

    cd cherrytree-version
  12. You need to fix a problem that exists in the file that you will use to install cherrytree with before progressing to the installation.

    Use your favourite text editing program and navigate to line 208. At the time of writing, this was the final line of the setup.py file.
    Hash out the that line so it looks like this:

    #subprocess.call(“update-desktop-database”)

  13. Run the following command to install cherry tree

    sudo /opt/local/bin/python2.7 setup.py install

  14. You need to run cherry tree with the MacPorts python. One way to do this is to explicitly use the full path to that python, for example, from within the cherry treefolder, you could run:

    /opt/local/bin/python2.7 cherrytree

    That's pretty inconvenient though. My choice is to set up an alias for cherry tree so that when I type the name, it calls the correct command.

    For whatever reason the install command in the step above did not end up with cherry tree going into /usr/local/bin. However, that's fine with me. I moved the installation directory to a convenient location, and then set up an alias for the command, putting in the full path to the cherrytree executable.

    alias cherrytree=“cd /Users//mySoftware/cherrytree–0.33.4; /opt/local/bin/python2.7 cherrytree”´

    The reasons for running cherrytree from within the source directory where it was built is because if I didn't, then I got an error:

    Traceback (most recent call last):
       File "/Users/<username>/mySoftware/cherrytree-0.33.4/cherrytree", line 65, in <module>
       f_main(args)
        File "/Users/btiwari/mySoftware/cherrytree-0.33.4/cherrytree", line 46, in f_main
           import main
         ImportError: No module named main
    

Other troubleshooting


If you see errors like the following when you try to launch cherrytree:

´raise ValueError, 'unknown locale: %s' % localename´

then you probably need to add locale settings. For example, the following could be added to your profile.

export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8

Mac - ironing out the little things

I just got a new Mac. This page is just to store the notes on things I had to do to get things working the way I wanted, or working at all.

Two finger scrolling


At first, I had no problems scrolling up and down in browser using the two finger scrolling action. Then suddenly it stopped working in Firefox although it worked in other applications that I happened to have open. I read some advice about turning off the smooth scrolling option in Firefox under Preferences | Advanced, but that made no difference.

The solution was to follow the advice in this video posted by Anson Alexander where I had to go to

System Preferences | Trackpad | More gestures

and turn off the option to Swipe between pages.

I definitely value up and down scrolling on a page far beyond swiping left and right, so if this is the price to pay to keep that working, so be it.

Thank you for the solution, Anson!

Using nvALT for Markdown editing, conversion to HTML and then posting in Blogger

It may or may not be the most direct way to do things, but steps I have used to post to this entry to this blog were:

  1. Create a note using Markdown in nvALT, a Mac-based note editor.
  2. Preview the note in html by using

    Preview | Save Preview in HTML

    I choose not to save it, which means I can just view it.
  3. Copy the HTML to the clipboard.
  4. Paste into the Blogger editor in HTML mode.
  5. If I’m keen, then test the weblinks in Blogger by switching back to Compose mode, clicking on the link and clicking on the option to Change.

The window that pops up gives you the opportunity to test the link.

That’s it.

Tips, tricks and gotchas?

  • If you forget to put in the http:// in your link, then blogger will add http://www.blogger.com to the start of your URL, thus breaking it real good.
  • Toggle on the Preview window by going to

    Preview | Toggle Preview Window
  • I had to change the settings in Blogger so that the paragraph tag in html was not changed just a br tag when I switched from HTML to Compose view. This used to be a general setting, but now it is changed by going in to a particular post, choosing Options there, and then selecting the option under Line breaks labeled Press “Enter” for line breaks.
  • For good measure, I should mention that I use SpiderOak Hive as a way to ensure that the notes I make in nvALT are available from all the systems I work on.
  • To get the ordered list above to allow me to put information across several lines into point 2, I had to indent (at least) eight spaces. Something nice and easy to forget, so I’ve logged it here.

Next steps?

It was thanks to posts by Michael Schechter at bettermess.com that I found nvAlt and thought to try out the route to note taking. He’s a big fan of the Byword editor and using that via nvALT, so that might be worth a look. On the other hand, some keyboard shortcuts and productivity aids might be where I should put in some time now.