Showing posts with label Ubuntu. Show all posts
Showing posts with label Ubuntu. Show all posts

Tuesday, June 18, 2019

Setting up an RStudio server on Amazon Web Services

I have sometimes used using Amazon Web Services to outsource some very computationally intensive analyses, such as for my paper last year on species distribution modeling.  Here's a quick guide to setting it up.

I first set up an Amazon Elastic Cloud Computer (EC2) instance with the latest Ubuntu following these instructions. 

Then log into the instance on SSH (AWS has very clear and helpful tutorials on this that depend on whether you are logging on from Windows or a Linux operating system) and run the below commands.  The first one adds your rstudio user (that you will log onto from a web browser), makes a directory, lets you set the rstudio user password that you will use to log on, and then sets permissions so you can write to this directory.

All of the commands I discuss today you will input into the SSH terminal.  This means you are making changes to the remote computer (the Amazon EC2 instance, i.e., your new RStudio webserver), not your local computer.  Do not input the dollar sign - this represents the prompt that the terminal shows.

$sudo useradd rstudio
$sudo mkdir /home/rstudio
$sudo passwd rstudio
$sudo chmod -R 0777 /home/rstudio

Then update your instance.
$sudo apt-get update
$sudo apt-get upgrade

Here I use nano instead of vi to edit a new sources.list file (you have to put the .d or it won't be saved).  Other instructions I've seen use vi but I prefer nano as a simpler for the uninitiated like myself.
$sudo nano /etc/apt/sources.list.d/sources.list

Once you're in nano, add this line to the sources.list file.  You can replace it with your favorite CRAN mirror and whatever version of ubuntu you have.
$deb https://cloud.r-project.org/bin/linux/ubuntu xenial/

Next, add the key to your system.
$sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E084DAB9

Then update again...
$sudo apt-get update
...and install the latest version of R (next code line).  If you don't do the sources.list and key steps from previous lines, the r-base version will be older than current.
$sudo apt-get install r-base

Now that R is installed, install RStudio Server using the three lines below.  Go to the RStudio website for an updated version name for the .deb file (the code below is current as of 11 April 2017 when I first drafted this post for my own reference; I recommend going to find the most up-to-date filename). 


$sudo apt-get install gdebi-core

$wget https://download2.rstudio.org/rstudio-server-1.0.143-amd64.deb
$sudo gdebi rstudio-server-1.0.143-amd64.deb


Then you should be able to go to the IP address for your server (check in the EC2 console in AWS to get the IP address) with :8787 after it, and log in using the username and password you created at the beginning.








Part of the reason I wanted to use an AWS server is that I had a huge dataset that didn't fit on my laptop. Now that RStudio can be logged in, attach an Elastic Block Storage (EBS) volume to allow storing your files.  You can think of it like an external hard drive for your Amazon web server.

These instructions are adapted from the AWS tutorial and assume you are using using an instance and EBS volume that was created with the instance and is currently empty.
$lsblk
$sudo file -s /dev/xvdb
Answer was "data" which means is empty, no file system.

$sudo mkfs -t ext4 /dev/xvdb
$sudo mkdir /data
$sudo mount /dev/xvdb /data

$sudo chmod -R 0777 /data
$sudo chmod -R 0777 /data/*
These two lines add write permission for the folder and files.

I rebooted my instance and was terrified to not find the data drive.  However, it was because I have to mount the drive (the mount step above) each time.  You can change the fstab file to make it mount permanently.  To do this, search for the UUID of your EBS volume after it has been mounted.
$sudo blkid


You should get an answer back something like this:
/dev/xvdb: UUID="ab82e239-b284-4527-922f-b82b6b9ebc8c" TYPE="ext4"

$sudo cp /etc/fstab /etc/fstab.orig
$sudo nano /etc/fstab

Updated to note: Update the fstab file to include the UUID.  (I have forgotten exactly where, but this askubuntu.com answer says how.)


The EBS volume should now be mounted permanently.

To do mount a volume created from scratch (not at the time of the instance creation),
follow these steps and mount the volume as previously.   If the volume size needs increasing later on (i.e., you didn't predict the size of storage you needed), follow these instructions.  Then, if you are using a Linux system like Ubuntu, these.

You should now be able to shut down or reboot your RStudio server and still have the EBS volume still mounted.

Tuesday, September 20, 2016

Basic version control with Git and GitHub in RStudio in both Windows and Ubuntu

I don't remember why, but a few months ago I decided I finally had to try out this "version control" thing.  I love it SO MUCH.  Github and git can be a bit confusing initially, especially as I had the added layers of making it work with RStudio and on two different operating systems, but now that I've got it going it's great.

I started and installed git with this tutorial for starting with RStudio and git/github on Windows.  To understand how push and pull work (as this confused me), I read through several pages.  I started with this graphic of the workflow.  That one ignores RStudio and is just about git and github.  This essay has great illustrations and more details (code to use in the shell/terminal in RStudio).  Finally this one is github/git only (no RStudio) but I still found it helpful to read about push/pull/branching in yet another way.

Next problem was that when I opened up my project on Ubuntu, git said all lines in files were modified when I had not actually changed all lines.  This turned out to be an issue between line endings in Windows and linux type systems, and this would hide any actual changes if I had just made a few, so just committing every time was not a good option.  I decided to go with adding a gitattributes file in each repository (so all users will get the same line endings regardless of who I share with).  I added a gitattributes file (I combined general settings and the R settings available here) into the main project directory.  For a directory that I had already used a lot (so lots of files with the wrong line endings) I followed these steps for the per-repository settings, including opening a shell in RStudio to input their code for refreshing my repository.  (I backed up on a separate hard drive first in case I totally messed something up.)  At first this didn't work, because I have a dual-boot situation, not using the files in two separate computers, according to this top answer.  I ran the two lines of code in the top answer's update and that fixed it.
$ git config core.eol lf
$ git config core.autocrlf input

I now copy the custom attributes file into any new R repository I have, run those two lines, and haven't had any problems going between operating systems now.  Keep in mind this is where I have two different operating systems accessing the SAME FILES on the SAME drive/partition.  If I understand correctly the gitattributes file should work fine without the extra lines if you have different computers, but I have not yet tested this.

Finally, when I tried pushing in RStudio to github, I kept getting two errors:
error: unable to read askpass response from 'rpostback-askpass'
fatal: could not read Username for 'https://github.com': No such device or address

As I had already done the git config steps to add my github username and github email address, I looked up the error and found that I needed to create a private/public key pair because RStudio has issues authenticating apparently.  I followed the top answer's links, which resulted in my changing the url in the .config file and then generating and linking an SSH key.  I did this on both Ubuntu and Windows following the same instructions, resulting in two new key pairs (one for Ubuntu, one for Windows).

2016/11/04 edit: I got the askpass response error again in a new repository, but on the same computer that already had the SSH keys.  In this case I only changed the url in the .config file and then it worked swimmingly.  I've also had consistent success with line endings using the custom .gitattributes file followed by the two git config commands above.

Tuesday, July 19, 2016

Dual-boot Ubuntu 16.04 with Windows 7, then upgrading to Windows 10

I have a small Lenovo (ThinkPad X100e) running 32-bit Windows 7 Home edition.  I wantd to add dual-boot, then upgrade to Windows 10 to test that it won't erase my Ubuntu partition.

I first tried just running a bootable Ubuntu 16.04 LTS (long term stable) USB, and it got me into Ubuntu install, but when I got to the partitioning step the computer said okay, then shut down, and it never seemed to install.  I suspected I might need to partition first.  I pre-emptively went ahead on shrinking the Windows partition before repartitioning, following these steps as in my previous post just adjusting steps by looking in Windows 7 places for the settings.   System protection was already off and I skipped CHKDSK because Windows ran it on its own after my failed original Ubuntu automatic repartitioning attempts.  My computer also insisted on rebooting between steps 4 and 5.  Disk cleanup (step 5) took less than 20 minutes. Disk shrinking was maybe less than an hour.

I also realized during the Windows shrinking that I was trying to install 64-bit Ubuntu (the main file that downloads) onto a 32-bit computer.  I downloaded 32-bit from a mirror (there didn't seem to be an easy link on the main Ubuntu site, had to look around for it in their site) and made a new bootable USB.  I tried again.  At the partitioning step, I got a scary looking message about whether I wanted to continue with automatic partitioning (it said it will change and format some things).  I answered continue, and then I went on with set up.  That worked and I now have Ubuntu 16.04 LTS dual booting with Windows 7.

This went a lot faster than with my last dual-boot setup.  I think this was because I had Windows 7, an older laptop, and a bit more experience, and probably mostly because I cared less about whether I ruined my Windows set up. This older computer also didn't have weird boot settings that the newer one did (secure boot), nor did it have Windows 8 hibernation and fast shutdown/startup to worry about.  I also did not want to set up a shared data partition on this laptop so that did not take up any time.  So I did less prep, and it still turned out okay.  Your results may vary.

Now, the Windows 10 upgrade over the dual-boot system.  I ended up not having enough space on my Windows partition because I had some duplicate users and all their data.  I uninstalled a few large programs that I didn't use any more and then removed the two duplicate users and their data (be careful with this!  I was very sure I did not need those user profiles).  After following the various on-screen prompts, I eventually got a message that I had to log into my administrator account.  I did so, waited for the download again, and then the Windows 10 upgrade just... failed, every time, even though I was booting back into Windows 7 and not Ubuntu.  With the error code, I found that I should be rebooting into the system recovery partition.  I did that and sure enough, it worked!  The install crashed once because my laptop overheated, but that's my laptop's problem.  I set it on an air vent in the house and the AC kept it cool enough to restore Windows 7 (Windows did this on its own).  I then started the Windows 10 upgrade again and it finished the install.  I missed a few reboots and it booted into Ubuntu, but in those instances I just rebooted and watched to select the Windows system recovery partition and it resumed where it had left off.  Windows 10 did not erase my programs or apps, so I am pleased with how this went and might even try it on my main working computer now.

Tuesday, February 16, 2016

Adventures in compiling bgc for Bayesian estimation of genomic clines

Now that I have Ubuntu, installed the required libraries, and downloaded the program source code, I can install bgc.  It took me a lot of following error messages and looking for files, so please go to the end to see my final commands to get it compiled.  Even then, do not use my commands exactly.  This post is more to show you how the compilation process went and where things went wrong.  (Everywhere, that's where; mainly due to my inexperience.)

After reading the instruction manual for bgc, I ran this in the terminal:

/usr/local/src/bgcdist$ h5c++ -Wall -O2 -L/usr/include/gsl/lib -I/usr/local/gsl-1.15/include -o bgc

I got an error message:
The program 'h5c++' is currently not installed. You can install it by typing:
sudo apt-get install hdf5-helpers

So I did.

Note that I changed the directory for where to find GSL (highlighted) because I couldn't find it in usr/local.   Eventually I gave up looking for it and uninstalled GSL, then downloaded it to install from source where I specified the directory using ./configure --prefix=/usr/local .  (Spoiler alert: I mistyped this as "user/local" when I downloaded from source and this caused most of my problems later on.  I believe I should have used the Ubuntu software center to resintall it and make sure I had all the GSL libraries I needed because when I reinstalled GSL at the very end, it worked fine from the software center.)

**********************************************************************

 Done. The new package has been installed and saved to

 /usr/local/src/gsl-1.16/gsl_1.16-1_amd64.deb

 You can remove it from your system anytime using:

      dpkg -r gsl

**********************************************************************

It still went into src.  Hmm.

h5c++ -Wall -O2 -o bgc bgc_main.C bgc_func_readdata.C bgc_func_initialize.C bgc_func_mcmc.C bgc_func_write.C bgc_func_linkage.C bgc_func_ngs.C bgc_func_hdf5.C mvrandist.c -lgsl -lgslcblas

Be careful pasting from the manual, as in my terminal the underscores disappeared and then it couldn't find the files.

This gave me different errors, where it couldn't find GSL and compilation terminated.

h5c++ -Wall -O2 -L/usr/local/src/gsl-1.16 -I/usr/local/src/gsl-1.16 -o bgc bgc_main.C bgc_func_readdata.C bgc_func_initialize.C bgc_func_mcmc.C bgc_func_write.C bgc_func_linkage.C bgc_func_ngs.C bgc_func_hdf5.C mvrandist.c -lgsl -lgslcbla

This changed the missing files from those from gsl to one called hdf5.h.

h5c++ -Wall -O2 -L/usr/local/src/gsl-1.16 -I/usr/local/src/gsl-1.16 -prefix=/usr/local/src/hdf5-1.8.15-patch1/hdf5 -o bgc bgc_main.C bgc_func_readdata.C bgc_func_initialize.C bgc_func_mcmc.C bgc_func_write.C bgc_func_linkage.C bgc_func_ngs.C bgc_func_hdf5.C mvrandist.c -lgsl -lgslcbla

Nope.

Uninstalled hdf5.  Then I found a recommendation to install an hdf5 cpp.  Nope, still didn't work.  (The observant or more experienced reader may note that I keep changing that last green-highlighted portion of the commands to have an s at the end or not.  You will see below that this was of course a problem too.)

**********************************************************************
Finally, I was told that I had the prefixes wrongly specified (prefix just means it should be L or I, not actually saying prefix) and I had accidentally installed GSL into "user" instead of "usr" (the standard folder name).  So this code below works because I needed to replace prefix with -I/, installed hdf5-dev and hdf5-serial-dev to get some of the files when they weren't found, and pointed the compiler to the wayward GSL files in the weird directory.  I also sometimes forgot the s at the end of the green-highlighted command in previous attempts.
h5c++ -Wall -O2 -L/user/local/lib -L/usr/local/src/hdf5-1.8.15-patch1/hdf5/lib/ -I/usr/local/src/gsl-1.16 -I/usr/local/src/hdf5-1.8.15-patch1/hdf5/include/ -o bgc bgc_main.C bgc_func_readdata.C bgc_func_initialize.C bgc_func_mcmc.C bgc_func_write.C bgc_func_linkage.C bgc_func_ngs.C bgc_func_hdf5.C mvrandist.c -lgsl -lgslcblas

As with most things, essentially the installation process is following the error messages.  If the compiler can't find a file, make sure the compile commands point to the correct directories (search for where the file is located), or go install the package/library or a related thing (like the -dev versions of hdf5) if it can't find it because it doesn't exist yet.  Finally, when I went to run the compiled bgc, it turned out that the bgc program still couldn't find GSL in the misnamed "user" folder anyway.  I uninstalled GSL (using the Ubuntu software center), reinstalled it, and bgc started then.

UPDATE 2016/07/14: This is much easier if you don't fill your commands with typos and install the required packages in the correct places.  I upgraded to Ubuntu 16.04 LTS and it apparently removed GSL, so bgc no longer ran.  I reinstalled gsl and the gsl development versions from the command line this time using 'sudo apt-get install gsl-bin libgsl-dev'.  That presumably put them in the right place this time.  I then navigated to the bgcdist folder where the files were stored, and ran the exact compiling command from the user manual/documentation.  I was dreading a multi-hour fiasco again and it just worked.  I think the moral of the story here is that this is a lot easier if you have installed packages a few times in Ubuntu by the time you attempt this, but it is doable even if you are brand new.

Tuesday, November 03, 2015

Installing libraries on a linux operating system

Now that my computer can dual-boot into Ubuntu and Windows, I am going to start getting things set up for my original need for a Linux-type operating system: a program for estimation of genomic clines called bgc.  Installing the GNU Scientific Library was first.  I searched for it in the software center, and I was surprised to have 15+ options in the search results.  I eventually chose "GNU Scientific Library (GSL) -- library package".  It noted in "more info" that "To compile your own programs you also need to install libgsl0-dev", which I figure I do since bgc requires compiling.  I installed that one too.  Easy enough!

HDF5 at first seemed like it would be similarly easy, but all the binaries ready for installing were for either Windows or CentOS Linux, which I assume would be different.  So I have to compile it.  I followed "Compiling the easy way" from the Ubuntu website.

Step 1.  I wasn't sure if I was supposed to remove the $ before $USER.  Turns out I was.  I got an error when I tried $claire for my user name.  "chown: missing operand after ‘/usr/local/src’"  It worked fine when I just put claire though.  The hdf5 instructions say I need 'gcc' to compile it.  This Ubuntu help says build-essential contains gcc, and the "Compiling the easy way" did have me install it in this step.

Step 2. Obtain the package!  I got a .tar with Unix line endings (since the other options were Mac or Windows line endings) and .tar.gz seemed more complicated.  I moved it to the /user/local/src folder (which is under "Home") and right-clicked, then "Extract here".  I looked in the folder and there seemed to be some configure files, so I'll go ahead and try the next step

Step 3. The link to auto-apt confused me, so i went with the manual version, installing apt-file and its update ("sudo apt-get install apt-file" then "sudo apt-file update" which did not take as long as the instructions threatened on my reasonably fast connection, maybe five minutes at most).  I went into my directory (/usr/local/src) in the terminal as instructed, and ran ./configure and it gave me a different error message.  I navigated one level lower (to /usr/local/src/hdf5-1.8.15-patch1) and then it worked!  It did not end with any dependency errors, but it also did not obviously with config.status: creating Makefile.  I scrolled back up and found it, though, along with lots of other creating of filenames in various directories, and "no obvious errors" as the Ubuntu page said, so on to Step 4.

Step 4. It says to give the command "make".  I did.  Many things began happening, including warnings about overflows and floating points and such.  However, it kept going, so I let it be.  The hdf5 instructions said to "make install" in their step 4.3.1 so hopefully that didn't mess it up.  It took maybe five minutes.  As I read the Ubuntu instructions further "sudo checkinstall" replaces "make install".  I did the sudo checkinstall and the terminal asked if i wanted to create a default set of package docs.  Only one option ("y") so I said yes.  Then it wanted me to write a description for the package and end it with an empty line or EOF.  I wrote hdf5 and then pressed enter.  But enter just gave me a new line prefixed with >>.  So, end of file (EOF) is ctrl+D in linux?  But a blank line might work too?  I tried the blank line first.  That worked (pressing enter twice to create the blank line).  Next up it gave me a list of values for building the package (maintainer, summary, name, version, etc).  I couldn't think of any changes so I pressed enter to continue.  Then I messed up and tried to copy the message and ctrl+c did something, not sure what.  So I ran "sudo checkinstall" again and it seemed happy to return to the same message.  I pressed "y" when it asked me this:

Some of the files created by the installation are inside the build
directory: /usr/local/src/hdf5-1.8.15-patch1

You probably don't want them to be included in the package,
especially if they are inside your home directory.
Do you want me to list them?  [n]: y

This got me to a weird screen with (END) at the bottom.  Help me, google!  Pressing Q and then enter got me back to the main screen where it asked:

Should I exclude them from the package? (Saying yes is a good idea)  [y]: y

The install failed.

dpkg-deb: error: parsing file '/var/tmp/tmp.d7tq23dvxW/package/DEBIAN/control' near line 7 package 'hdf5-1.8.15':
 error in 'Version' field string 'patch1-1': version number does not start with digit

So I tried again.

I keep forgetting and pressing ctrl+c.
*** SIGINT received ***

Restoring overwritten files from backup...OK

Cleaning up...OK

Bye.

According to wikipedia, if I understand correctly, this just interrupts the current process.  So, it should be okay.

Anyway, the new install with version number changed to 1.8.15-patch1 installed fine!

******************************************************************
 Done. The new package has been installed and saved to

 /usr/local/src/hdf5-1.8.15-patch1/hdf5-1.8.15_1.8.15-patch1-1_amd64.deb

 You can remove it from your system anytime using:

      dpkg -r hdf5-1.8.15
*******************************************************************

I'm still not really sure if that's where I wanted it installed, but this stackexchange answer seems to indicate it is an appropriate place and I think section 4.6 in the hdf5 instructions agrees.

Step 4.5 in the hdf5 instructions suggests testing the library, so I ran "make check" and waited for it to go through its paces, which took about three minutes.  It didn't return any errors so I appear to have installed it!   Soon I will compile bgc and see if that works; presumably if the hdf5 install didn't go right in non-obvious way, I will find out then.

Thursday, July 16, 2015

Moving default folders such as Pictures and Documents, etc. to the new partition

So I have set up my computer to dual boot into Ubuntu and Windows 8.1.  Then I partitioned my hard drive so I could have a shared data partition between Ubuntu and Windows.  Now, I want to change the default folders on both operating systems (like My Documents and My Pictures on Windows) to be on this new partition so I can use files from both places easily.  It was pretty easy and took about 15 minutes in Windows 8.1 despite my having delayed doing this for several days because surely it'd be hard. It appears to be essentially the same in Windows 7 if you have that.  I had three user accounts that I all directed to the same folders.  Otherwise it would have just been a few minutes.  I didn't redirect the desktop as I think this allows me to have different things saved on each one, and I only save temporary files on the desktop.  There was one conflict where I had the same file in each download folder, and Windows asked me what to do about it (replace, add, etc.) so I think if you try this after you have a lot of files it would still work.  I did this when my computer was essentially empty.


Okay, how to do this in Ubuntu?  It appears Windows always mounts the drive so it's visible, but in Ubuntu it doesn't and you have to configure it manually.  Here is a file showing all the commands and responses I got.

Next, how do I change the folders?  That first link I provided wanted me to make some sort of links, but this changing of a configuration file seems more permanent and unlikely to confuse programs like LibreOffice.  I couldn't find the  .config folder though and it was hidden.  Ctrl+H did the trick. I changed the file from $home/Downloads to media/Data/Downloads first to test it.  It didn't show up at first, but this older tutorial says I need to either log off and on again, or kill and restart Nautilus first.  My computer needed rebooting for some updates anyway, so I tried that first.  It worked!

I wondered if Ubuntu would politely accommodate the files from both the original default folder and the new folder like Windows did, so I put two documents in the default: one that had a duplicate and one that did not.  Then I went back to the configuration file and changed everything except the desktop.  Templates and Public did not have folders in Windows, so I added those to the data partition in case they are important for Ubuntu (I don't know yet).  This time I tried the killall nautilus in the terminal and it worked (much faster than rebooting or logging on and off).  Ubuntu did not move the files over, which makes sense since it wasn't particularly automated.  So if you already have a bunch of files, you'll need to move them manually.

I next noticed that there are two sets of links to documents, downloads, music, pictures, etc. in the files browser.  The top set (about the Data, Windows8_OS, and Computer partitions) go to the newly set folders.  The bottom set goes to the old /home ones.  I deleted the folders from /home, but then those lower links just gave an error for a missing directory.  I discovered you can right click on them and remove them.  No more confusion or errors.  I then tried saving something from LibreOffice to see where it goes as default.  It goes to /home/Claire which would have been annoying anyway I think.  I opened LibreOffice Writer and went to Options>LibreOffice>Paths and edited where "My Documents" is.  I tried installing another program afterwards (DigiKam for photo management) and it automatically went to my new Pictures folder.  Success!

I only have one Ubuntu user account right now so I just did this once.  I assume it'll work okay if I create another account, but so far I'm just using one account.

Thursday, July 09, 2015

Setting up partitioning on my dualboot laptop

Now that I have my shiny new laptop successfully dual booting, I want to access the same files from both operating systems.  I see on the side menu thing (start menu?  task bar?) a "Windows8_OS" icon.  When I click this, it "mounts" the partition with Windows 8.1 so I can nose around in the files.  I had two screenshots from my dual boot adventures previously, so I went to those files and copied one and edited it.  Now I will reboot and go into Windows and see if it worked.  Yes!

I want a separate data partition though and inexplicably Windows 8.1 had 400+ GB in spite of using only about 35 GB currently.  I went to Adminstrative Tools>Disk Cleanup.  I selected all the files it gave me and told it to clean up system files as well (the button with the adminstrator shield on it).   Disk cleanup continued.  It took around 5-10 minutes and then brought up the window again with more selections for cleanup.  When I said okay, it asked if I wanted to permanently delete these files.  Yes, I do want to delete them.  Thanks.  It took at least 20 minutes.  Then I defragmented again.  This didn't get rid of the extra space.

Some googling let me know that Windows apparently stores some critical files at the middle/end of its original partition.  I followed these instructions to move the files into a smaller region.  It worked without a hitch.  I left about 70 GB for Windows 8.1.  Unfortunately, since I did my "unallocations" at two different times (once to make space for Ubuntu and now to solve the problem of why Windows wanted 400 GB), they are not combined.  The unallocated portions were separate.  It appeared the easiest way to combine them would be with the linux-based disk management GParted. 

I rebooted into Ubuntu and installed (using the application manager) and then opened up GParted.  It looks like I need to move the Ubuntu partitions around.  I did "swapoff" for the linux-swap partition, then moved it as described on the GParted site.  I just did one first to make sure it worked.  I rebooted twice into Windows and then once into Ubuntu to confirm everything was happy (the site suggests just doing Windows twice but I figured it was important to see if Ubuntu was happy since this was the linux swap partition I just moved).

Apparently I then needed a LiveCD version of GParted (can be done with USB too but CD seemed easier and it fit on the old CDs I have).  It was a bit over 200 MB so it took a while to download on my connection.  I burned this bootable CD on the lowest speed with "Verify disk after burning" checked.  I then reinserted the CD and shut down my laptop and turned it on again.  It didn't boot from the CD so I went to system settings, it took me through the Lenovo screen again, where I pressed F12 to choose the boot device.  I picked the third one, which had CD0 and DVDRAM in the name so I figured that was the CD.

I left it to sit a bit too long on default once GParted live had loaded and it started doing things.  Then the keymap screen came up as described. For the next few questions it asked me, I picked all defaults as suggested by the GParted help and then was at step 6.  I moved the remaining two linux partitions (/ and /home).  While I was there I right-clicked on the linux-swap file system and labeled it "Linuxswap".  After those changes were applied, I took the now-continuous and contiguous unallocated space and created a new partition which I labeled Data.

Once this was all done I rebooted into both operating systems to confirm I could see the files.  I ran into a bit of trouble with Windows not being able to read the Ubuntu screenshot, because it contained a colon.  I renamed the file back in Ubuntu and could see it fine in Windows then.

Finally, I needed to reset the changes I made from the initial instructions on reducing the size of the Windows partition.  The memory dump change wouldn't go without changing the paging file settings first.  It was still giving that error after I changed the paging file, so I did the other things (except for hibernation, which I have tried to turn off everywhere anyways).

I could have saved myself all this trouble by shrinking the Windows partition more appropriately BEFORE I installed Ubuntu.  Then I'd only have had to create the new partition from the one piece of unallocated space instead of moving things around.  Oh well, I learned how to use GParted!  Next up I'll figure out how to redirect all the default directories (My Documents, My Pictures, etc.) to the new partition and how to do the equivalent in Ubuntu.

Tuesday, June 23, 2015

Switching gears from virtual machine Ubuntu over to dual booting

I still haven't gotten bgc to work, mainly because I haven't made it that far into Ubuntu/Xubuntu/linux.  Running the virtual machine on my old laptop was becoming aggravating because of how slow it was, so I decided to just wait until I got a new computer.  It's a Windows 8.1 Lenovo machine, so before I load it up with all my files and settings I'm going to attempt to get it to dual-boot the pre-installed Windows 8.1 and the very latest version of Ubuntu (15.04).  The current recommended version of Ubuntu is 14.04.2, but apparently that may sometimes conflict with Windows 8.1 still.  I downloaded 15.04, accordingly.

Back up Windows 8.1

Part of the reason I waited until getting a new laptop was that I didn't want to ruin my main working computer if the dual boot install fails.  I typed "Create recovery media" into the search and followed Window's instructions.  Part of this involved my having to go out of the house buy a 32 GB USB drive.  Sigh.

Creating the Ubuntu boot drive

To create a bootable USB (using only a 4 GB USB drive, by the way), I followed ubuntu's directions, including downloading the bootable USB drive creator program pendrivelinux.  I ran the program on my Windows 7 desktop and just followed the instructions.  I checked the format usb drive option.  Once I clicked create, a warning window with the list of changes popped up.



I'm not sure if 7-Zip is required for this (I already had it installed), but the pendrivelinux program brought up a 7-Zip window that began extracting the Ubuntu .iso file.  It's not mentioned anywhere so I assume it works without it, but if not 7-Zip is easy to download and install.

In the guide to installing Ubuntu with Windows 8.1 it mentioned that WUBI (Windows-based Ubuntu Installer) no longer works.  I had no idea what this was.  When my USB stick was done, it had a WUBI file on it, so I was concerned.  I think, from reading this and another article, that WUBI now has only limited functionality and formerly would only run if I try to run the bootable USB from Windows already started.  So it's still there, and assorted askubuntu posts exist about it, but it seems unlikely to jump out and get me.  Also, I left the USB stick in and left for several hours.  When I woke the computer up, Windows Explorer locked up.  I'm not sure if it was confused about the bootable USB, so I shut it down and removed the USB before turning it on again.

It turned out later in installation that my first bootable USB had two errors, so I remade it with UNetbootin.  Not sure if it was the program that did it or luck of the draw.

Partitioning the computer's hard drive

Alright, this is one of the parts that scared me.  First, Ubuntu suggests several procedures to prepare.  Right clicking on C:/ within "This PC" (the new "My Computer") doesn't get tools; "Tools" are a tab you can find once you right-click C and click "properties".  First I optimized/defragmented the drive.  It took maybe 20 minutes or so since it is brand new and I've only been messing with it for a few days.  Then there is error checking.  Mine came up with a message saying no errors have been found (I guess it checks often?) but that I could scan if I wanted.  Scanning only took about as long as it took me to write these few sentences.  It doesn't have the same options as shown on the Ubuntu site (for scan and repair), so I think their instructions are for an older version (most seem to be for Windows 7 and earlier, though they occasionally discuss Windows 8.

Okay, partitioning!  I thought the Windows Disk Management sounded easiest.  Their instructions are also a little out of date there.  I went to "Control Panel">"System and Security">"Administrative Tools">"Computer Management" (the instructions say "Disk Management", so it's a bit different).  In the left hand panel you can go to "Storage">"Disk Management".  It said I didn't have access to this on [COMPUTERNAME].  Hmm, maybe access from the admin account.  I logged out of my user account and into admin.  No protests this time.
Here's what it looked like.



So, now what?  I followed these steps and allowed 30 GB for my Ubuntu partition.  Twenty GB was recommended by Ubuntu but I added a bit more for installing other programs (suggested by the partitioning guide link).  Very quickly after pressing "Shrink", 29.30 GB became unallocated.  I restarted twice as one of those guides pointed out it needs to reconsider its space after changing the allocation.  I had a brief moment of panic as I tried to under my usual user password before realizing I was logging into admin and really, how would repartitioning lose my password while rebooting normally.  Anyway.  Then after reading more I found I should use Ubuntu to create the shared partition later, so I shrunk the Windows volume again (to the default allowed number) and rebooted twice.  It was unclear to me why I couldn't shrink the Windows volume beyond about 450 GB when only about 30 GB are currently being used.  The Disk Management told me to use the defrag application log.  Wasn't sure what to do there, so instead went to defragment again (under "Defragment and Optimize Drives").  That didn't change anything so that's a problem for a different day, if it is even a problem.  Edited to add: I should have shrunk down the partition at this step following this procedure, because it ended up adding another hour or three of work to move two unallocated partitions together.

Making sure hybrid shutdown/fast start is disabled

I noticed this when reading about partitioning.  Apparently Windows 8.1's automatic "shut down" is really a weird hibernation if "fast startup" is enabled (which is the default).  If the files are still in use by Windows 8.1's snapshot that is created, anything you mess with in Ubuntu will get corrupted and disappear.  It was fairly easy to turn this off, both at the power button settings and power plans.  Essentially this takes you through all the power options in Control Panel > Hardware and Sound > Power Options.  Make sure hibernating is never allowed under any of the advanced settings.  I found that it would hibernate if the battery was critically low as well, so I set it to shut down as well.

Installing Ubuntu

I think I'm finally ready now.  There are various guides that talk about problems with Secure Boot, UEFI, and other things I'm not really sure what they do.  However, this guide (which seems to do well on the askubuntu site) suggests that many issues are for older installs of Ubuntu.  This is a shiny new Lenovo as well, and it comes pre-installed with Ubuntu in some regions, so I decided I should just go ahead and try it now.  I shut down my machine and put in the bootable USB.  Here goes nothing!

The Lenovo splash screen comes up first.  To interrupt startup, press Enter.  I waited to see what would happen.  Oh.  Nothing.  Back to Windows login.  I restarted.  Nope.  Restarted again and pressed Enter at the prompt.  Uh.  Somehow that didn't work.  Probably should have pressed it longer.  Shut down again.  Hmm.

This makes me think I somehow still have fast start up enabled.  I press shift while shutting down.  Nope.  This is not where I expected to run into trouble.  I then tried F1, which is not what the Lenovo boot screen tells me to do.  I disabled Quick Boot under the Startup tab (the other option, which is now selected, is "Diagnostics").  I couldn't find an Intel Smart Response option.  So I shut down and started again.  Still doesn't boot from the USB.  I went to F12 during startup this time.  I selected the USB HDD option (it also listed the name of my USB, SanDisk Cruzer or whatever it's called).  I then got a GNU GRUB menu.

I selected check disk for defects first.  Now a prettier Ubuntu screen sits there checking a list of files.  Hmm.  Errors were found in two files.  I decided to remake the USB drive with the other recommended program.   No errors were found.  Reboot again, the selected "Install Ubuntu" from the GNU Grub menu.  (I recall a few sites saying it wouldn't boot UEFI, which is the new thing as opposed to Legacy/BIOS mode but mine seems to have turned out okay; I checked at the end).

Followed the assorted instructions, connected to wifi, and had it download updates while installing and install the third-party MP3 software.

The screen for "How to install Ubuntu..." alongside, erase Windows, or something else.  From googling, it was unclear to me if "Alongside" would work since I had already shrunk my Windows partition.  Selecting "Something else" brought up a very complicated table of what exists on my computer already.  Google time.  I followed these instructions (did not do the optional ones) to make three new partitions (swap, /, and /home) out of the unallocated large space (about 450 GB).  I left quite a bit of unallocated space because I didn't see an option to create a NTFS file system and the internet tells me gparted will let me do that once I have Ubuntu installed.  Once I press "Install Now" Ubuntu asks if I want to write these changes to disk.  Go back is default, but it looks okay so I say continue.

Things seem to go on.  It asks where I am, what keyboard to use, and for a username, computer name, and password.  I made sure the computer name was the same as what Windows calls it, but no idea if that matters.  Now it installs!  I'm doomed!  Time to go check on my bored helper.
Nobody ever does anything fun with her.


Optional while you wait: trim dog's toenails, sweep floor, take out trash, organize field work schedule for next day, cut and sample blueberry muffin cake.  I actually only made it through clip dog toenails, sweep part of the floor, and take out the trash before it was done and requested a restart.

It brought me to the GNU GRUB menu again.  I guess I still have it set to boot off the USB.  I just selected the top option, which was Ubuntu.  I logged in, looked around a bit, and shut down.  I removed the USB.  Now I get the Lenovo start screen.  It takes me to the GNU GRUB again.  Let's see if I can find Windows.  Windows Boot Manager is the third option.  I select it and get a scary error, which disappears quickly.  It can't find some file.  After a moment it goes back to the GNU GRUB.  I tell it to go to system settings and it goes through the Lenovo splash screen.  I press F12.  In the boot menu now, ubuntu is first followed by Windows Boot Manager and assorted other options.  PCI LAN is the selected option.  I select Windows Boot Manager.  The computer thinks... and it works!  I'm back in Windows 8.1.  I go have a look in Disk Management and things are wild now.



I shut down from Windows.  Upon startup, without pressing anything, it takes me to the BIOS.  I didn't do anything as I couldn't figure out what to do.  So I read some more, and then remembered a lot of sites said to disable secure boot.  So back to the BIOS.  Disabled secure boot.  Then the ubuntu GRUB menu was up again.  This time pressing Windows Boot Manager did not give an error!  One line said it was booting unsecurely, and then I am at the Windows login screen.  SCORE.  Oddly, it has changed the time and claims it is six hours later than it is.  I changed the time back.  I switched users to test all three out.  So far okay.  Shutting it down again.  "Booting in insecure mode".  I get the GRUB again, and click Ubuntu.  It runs some file checks.  No idea why.  I restart from Ubuntu instead of shutting down to see if that's how I can get the GRUB menu again.  Yup.  I waited too long though so it just automatically selects Ubuntu.  The screen does a really weird flicker when I am shutting down or restarting, shifting things from side to side rapidly.  This time on restart I pick Windows Boot Manager, and sure enough, there's the candy-colored stripes that now show on Windows.  I think I did it!  The time is correct in both operating systems now.

I also wanted to double-check that I did a UEFI install (and not the legacy BIOS) because both operating systems are supposed to have the same booting.  I clicked on the Files icon in the menu bar (I guess that's what it's called), then "Computer", and then navigated to sys/firmware/efi as described here.  The folder exists (with stuff in it, no less), so I seem to have done that correctly.

What now?
Good question.  Mostly, eat dinner.  This whole dual-booting procedure took me about four or five hours (troubleshooting included), but longer if you count several days of reading up on the procedures.  Next, I should probably read up on things one does in Ubuntu.  Software updates seem a good first step, although I think at least some should have installed during setup because I selected that option.  I just typed "update" into the search box and ran the first icon (a swirly A) which was Ubuntu's "Software Updater".  It found some updates for me.  Thanks, updater!  I looked at settings and it let me know that it would check for updates daily, including security fixes.  The second icon "Software and Updates" actually also took me to the settings menu from the Software Updater.

I guess the next things I should do are find out what type of user account I should have (I seem to be an administrator) and if they mean the same things as in Windows, create a shared partition for all my data and files, understand the security (anti-virus and firewall) a bit more, and then figure out how to install the scientific packages I need.

Thursday, February 26, 2015

Setting up a virtual machine to run a linux operating system

I need linux so I can start learning how to use bgc, a program for analyzing genomic clines.  As I don't have any spare computers around to install linux on (and it seemed easier than dual-booting one of my main working computers), I decided to try a virtual machine.

First, download Oracle's free VirtualBox and your operating system of choice.  From the many flavors of linux, I started with Ubuntu as it seemed least intimidating and likely to do be sufficient for my purpose of running the one program.

Install VirtualBox first.  Once you've set up your first machine (I let it do all the default settings), copy the Ubuntu .iso file into your VM's folder.  Mine was stored at C:/Users/Username/VirtualBox VMs/yourvirtualmachinesname/ and I placed the .iso file in that folder.

Run your VM.  It'll ask you from what optical drive you want to boot.  Set the CD/DVD optical drive to the .iso file.  If you get a fatal boot error because you didn't do this the first time, just set the drive, then restart, and it should boot as if you had an operating system disk in a real computer.  It took a while to get to the install screen.  I let it run in the background and worked on other stuff.  Same for the Install Ubuntu wizard.  Periodically check and answer its questions.  It took a while (started 1pm, finished around 4pm), just like a real operating system install.

I found Ubuntu ran pretty slow in the VM on my aging tiny laptop, and XUbuntu was suggested to me as a less graphics-intensive alternative.  That's what I'm using now (just create a new VM in VirtualBox and follow the same steps) and that install also took less time (maybe an hour or two with me ignoring it as I did other tasks).  Stay tuned as I learn how to install some prerequisites for bgc (GNU Scientific Library and HDF5).