osx

Creating a bootable USB drive on Mac OSX

Below are the steps needed to create a bootable USB device:

1.Download/create the ISO file you want to load in the USB

Once you have the ISO then it is time to convert to an image file:

[sourcecode]
hdiutil convert -format UDRW -o ~/path/to/target.img ~/path/to/ubuntu.iso
[/sourcecode]

Breaking down the command:
hdiutil description:

hdiutil uses the DiskImages framework to manipulate disk images. Common verbs include attach, detach,
verify, create, convert, compact, and burn.

The -fomat argument specifies the format of the image you want to create, by default UDZO is used.
UDZO stands for “UDIF zlib-compressed” image and UDIF is an acronym for Universal Disk Image
More info about UDIF
However, instead of UDZO we’ll use the format UDRW (UDIF read/write image)
More info on disk image formats

The argument -o defines where the image will be savedScreen Shot 2013-01-21 at 10.19.07 AM

2. Copy the image to the USB device

Before copying the image, find where the usb device is located by running:

[sourcecode]
diskutil list
[/sourcecode]

diskutil description:

diskutil manipulates the structure of local disks. It provides information about, and allows the
administration of, the partitioning schemes, layouts, and formats of disks. This includes hard disks,
solid state disks, optical discs, CoreStorage volumes, and AppleRAID sets. It generally manipulates
whole volumes instead of individual files and directories.

Once you find where the device is located run:

[sourcecode]
diskutil unmountDisk /dev/diskN (N is the number of the device)
[/sourcecode]

Now that the image is created and the usb device is in place it is time to copy the image to the usb:

[sourcecode]
sudo dd if=/path/to/image.img of=/dev/diskN bs=1m
[/sourcecode]

The dd command will copy everything from the standard input to standard output

The if argument is to specify the input
The of the output
And the bs the block size of the data that will be copied, in this case it’s set to 1M, or 1024 bytes
Screen Shot 2013-01-21 at 11.35.02 AM

Once the dd command is finished, a popup window might show up:
Screen Shot 2013-01-21 at 11.34.51 AM

Just to make sure check if the usb was ejected:

[sourcecode]
diskutil list
[/sourcecode]

Find where the device is located and if it is still there:

[sourcecode]
diskutil eject /dev/diskN
[/sourcecode]

That’s all, you should have a bootable USB device by now :)

Links:
Install Ubuntu using USB drive
hdiutil man page
diskutil man page
dd man page
dd command info
Disk Images

Building GNU Scientific Library(GSL) from source

In the DPS915 workshop 2 we started working with the GNU Scientific Library(GSL) to perform some matrix operations.

GSL is an implementation of Basic Linear Algebra Subprograms(BLAS)

By default, the GSL libraries don’t come pre install on OSX, so if you want to use them you gotta install it yourself

Download

You can download the latest stable release from here.
At this time, the latest stable one is version 1.15
gsl-1.15.tar.gz

Install

Unzip the files and navigate to the folder.
The steps to install:

Check if all the dev dependencies are installed

./configure

Build the libraries.

time make -j12 > /dev/null

  • time will output how much the build process took
  • -j lets you specify how many cores to use during the build
  • > /dev/null redircts the output to make the build faster

Finally, it is time to install the libraries

sudo make install

The header files are installed in:

/user/loca/includes/gsl

And some libraries in:

/user/local/lib

Test it

To check if the gsl libs are working you can try to run a sample program:

 
 // matMult.cpp

 #include  
 #include  
 #include  
 #include  
 extern "C" {  
 #include   
 }  
 using namespace std;  
 #define WIDTH 5

 int main(int argc, char** argv) {  
 if (argc != 2)  
 cerr << "** invalid number of arguments**" << endl;  
 else {  
 int n = atof(argv[1]);  
 float* a = new float[n * n];  
 float* b = new float[n * n];  
 float* c = new float[n * n];  
 int k = 0;  
 srand(time(nullptr));  
 double f = 1.0 / RAND_MAX;  
 for (int i = 0; i < n; i++)  
 for (int j = 0; j < n; j++)  
 a[k++] = rand() * f;  
 k = 0;  
 for (int i = 0; i < n; i++)  
 for (int j = 0; j < n; j++)  
 b[k++] = rand() * f;

 // compute matrix product  
 cblas_sgemm(CblasRowMajor, CblasNoTrans, CblasNoTrans,  
 n, n, n, 1.0, a, n, b, n, 0.0, c, n);

 // output result  
 k = 0;  
 cout << setprecision(6) << fixed;  
 for (int i = 0; i < n; i++) {  
 cout << setw(5) << i+1 << ‘:';  
 for (int j = 0; j < n; j++) {  
 cout << setw(10) << c[k++] << ‘ ‘;  
 if (j % WIDTH == WIDTH – 1)  
 cout << endl << setw(5) << i+1 << ‘:';  
 }  
 cout << endl;  
 }  
 cout << endl;  
 delete [] a;  
 delete [] b;  
 delete [] c;  
 }  
 }  

To compile:

g++ -std=c++0x -Wall matMult.cpp -o matMult -lgslcblas

-std=c++0x enables c++0x support

To run the program:

./matMult 2

The first argument is the size of the matrix you want to generate

If you see a 2 by 2 matrix then it means it worked :)

*The code sample was taken from https://scs.senecac.on.ca/~gpu610/pages/content/lines.html