sudo mount -o loop image_file.mdf
Thursday, November 11, 2010
Mounting .mdf and .iso images
I tried this on a .mdf file, but it is supposed to work for .iso as well.
sudo mount -o loop image_file.mdf /mounting/directory
sudo mount -o loop image_file.mdf
Monday, October 4, 2010
Remotely turn on and off display
It is possible to turn on and off your display remotely using ssh. To turn off the monitor, login on the remote machine with ssh and enter:
$ export DISPLAY=":0"
$ xset dpms force off
To turn it back on use the xset command again:
$ xset dpms force on
Sunday, October 3, 2010
Play movie with mplayer via SSH
Playing a movie over ssh is very easy. Ssh into the machine you want to play the movie and enter:
export DISPLAY=":0"
mplayer ---
Saturday, October 2, 2010
Mount and NFS Server and Client
This tutorial shows how I mounted an NFS file system in my home network with two computers.
SERVER
1) Install nfs-kernel-server package:
$ sudo apt-get install nfs-kernel-server
2) Create the export file system where the the NFS file system will be mounted to. In my case, the Storage directory:
$ sudo mkdir -p /export/Storage
3) I want to mount my external hard drive at /media/LACIE. To do that we enter:
$ sudo mount --bind /media/LACIE /export/Storage
4) If everything works out fine you should be able to access your files through the directory /exports/Storage. To make sure this will work at startup add the following line to the /etc/fstab file:
$ /media/LACIE /export/Storage none 0 0
5) In file /etc/default/nfs-kernel-server set:
NEED_SVCGSSD=no
6) In file /etc/default/nfs-common set:
NEED_IDMAPD=yes
NEED_GSSD=no
7) To export the directory to the machine with IP 10.42.43.3 we add in the /etc/exports file:
/export 10.42.43.3(rw,fsid=0,insecure,no_subtree_check,async)
/export/Storage 10.42.43.3(rw,nohide,insecure,no_subtree_check,async)
8) Now restart the service:
$ sudo service nfs-kernel-server restart
CLIENT
1) Install packages:
$ sudo apt-get install nfs-common
2) Mount the file system on the desired directory. In the command line below the IP 10.42.43.1 is the address of the server.
sudo mount -vt nfs4 -o proto=tcp,port=2049 10.42.43.1:/Storage /home/gbezerra/Storage
3) Finally, to make sure it works on boot add the following line to /etc/fstab:
10.42.43.1:/Storage /home/gbezerra/Storage nfs4 _netdev,auto 0 0
The reference I used was:
Wednesday, September 15, 2010
Vim stuff
TAB completion
set wildmode=longest,list
set wildmenu
Text width
Vim does not break text into lines automatically. This is good for programming, but not so much for documents. To make vim break the text into lines set the textwidth property:
set textwidth=70
When you do that, vim will apply the property to the current text. If you want to set the property for the entire document go to the top, enter gq, and then go to the bottom:
gg
gq
G
The gq command applies the format to a text segment marked by 'movement'.
Working with tabs
Edit file in a new tab:
:tabe
Next and previous tab:
gt
gT
Bookmarks:
Mark position
: m {a-z}
Return to marked position
: ' {a-z}
Return to previous position
: ' '
Editing remote files:
tabe scp://hostname//path/to/file
or
vim scp://hostname//path/to/file
Patching
Patching code is really easy. Let's look at some examples. Consider the patch file parsec-ocreat.patch, which has the following beginning lines:
diff -N -u -r parsec-2.1-orig/pkgs/kernels/dedup/src/decoder.c parsec-2.1/pkgs/k
ernels/dedup/src/decoder.c
--- parsec-2.1-orig/pkgs/kernels/dedup/src/decoder.c 2009-01-27 17:09:55.0000
00000 -0800
+++ parsec-2.1/pkgs/kernels/dedup/src/decoder.c 2009-09-01 00:51:12.000000000 -0
700
The first file --- parsec-2.1-orig/pkgs/kernels/dedup/src/decoder.c represents the original file which will be patched. The second file +++ parsec-2.1/pkgs/kernels/dedup/src/decoder.c is the one with the correct modifications. We won't care about the second file, only the first one. To patch the original file we need to match the location given in the "---" line of the patch file with its actual location in our directory tree. In this case I don't have the directory parsec-2.1.orig, but I do have parsec-2.1. To make them match I do the following.
$ cd parsec-2.1
$ patch -p1 <parsec-ocreat.patch
The p# parameter defines the number of slashes you have to remove from the path to make the two files match. In this case, because the first directory doesn't match I used p1. Put another way:
-p1 "parsec-2.1-orig/pkgs/kernels/dedup/src/decoder.c" = pkgs/kernels/dedup/src/decoder.c
If you're afraid of patching the wrong file or are unsure of how patch works, do a dry run first:
$ patch --dry-run -p1 <parsec-ocreat.patch
If you receive successful messages you can now patch your file. Let's look at another example, the file blackscholes.c.patch which begins as:
--- blackscholes.c 2009-07-28 00:58:12.000000000 +0100
+++ blackscholes.new.c 2010-05-04 12:14:07.416033100 +0100
This time the path is not given, so I need to move my prompt all the way where the blackscholes.c file is. Now the name of the original file will match the name given in the "---" line of the patch file. As a result, no slashes need to be removed:
$ patch -p0 <blackscholes.c.patch
Reversing a patch is also possible. Just run patch with the -R option:
$ patch -R -p0 <blackscholes.c.patch
This will restore the previous original file.
That's all. Good luck!
Tuesday, September 14, 2010
SSH stuff
SSH key
This is how you can set an ssh key so that password will not be required.
From the client enter:
$ ssh-keygen -t dsa
This will generate the public key, which is saved in the file ~/.ssh/id_dsa.pub, and the private key, saved in ~/.ssh/id_dsa. Now we copy the public key in the server by entering:
$ ssh-copy-id username@remotehost
If you use a non-standard port a little trick is necessary. We put the host address in quotation marks as
$ ssh-copy-id '-p 2222 username@remotehost'
That should work just fine! A good reference is https://help.ubuntu.com/9.04/serverguide/C/openssh-server.html and http://mikegerwitz.com/2009/10/07/ssh-copy-id-and-sshd-port/
Screen
This is how you use screen so that you can keep jobs running at a remote host even when the connection drops or you logout. First install screen on the server:
$ sudo apt-get install screen
When you log in via ssh you can initiate a screen session by typing $ screen. Now you can play around with screen using the following commands:
Ctrl+a c : creates a new terminal tab within the screen session
Ctrl+a p : goes to the previous terminal tab
Ctrl+a n : goes to the next terminal tab
Ctrl+a d : detaches the current screen so that you can come back to it later
exit : exits a terminal tab within screen or exits the screen if there is only one tab open
Within a screen you can create several terminals to interact with the host system. This is done with the command Ctrl+ c. You can also multiple screen running in the same system.
To list all screens running in the system use:
$ screen -ls
The output will be something like this:
There are screens on:
13528.pts-1.brazil (09/14/2010 09:22:08 PM) (Attached)
13496.pts-1.brazil (09/14/2010 09:09:02 PM) (Detached)
2 Sockets in /var/run/screen/S-gbezerra.
To reconnect to the detached screen type screen -r :
$ screen -r 13496.pts-1.brazil
When a screen is detached you can logout and it will still be running. The same occurs if the connection drops. Just log back in, list the active screens and reconnect to the screen you want.
You can also name the screen you create, so that it is easier to reconnect to it.
$ screen -S george
To reconnect enter:
$ screen -r george
Finally if you're running a screen in a given terminal/client and want to capture that screen at another terminal/client, but the screen has not been detatched, enter:
$ screen -rd george
this will detatch the screen and pull it into your current terminal.
A good reference for screen is http://www.howtoforge.com/linux_screen
Saturday, September 11, 2010
Compiling the Kernel
This are the steps I followed to compile the linux kernel 2.6.35.4 on Ubuntu 10.04.
1) Download. The first step is to download the kernel at http://www.kernel.org/ and then unpack it in some location.
2) Prerequisites. Now we make sure all the necessary packets are installed:
$ sudo apt-get install fakeroot kernel-wedge build-essential makedumpfile kernel-package
$ sudo apt-get install libncurses5 libncurses5-dev
3) Configuration. Building the kernel is all about configuration. Configuring the kernel for your machine is fun but takes a lot of time and might be dangerous if you don't know what you're doing. We will take a shortcut here and use the Ubuntu configuration file for the current kernel. Go to the source directory and follow the steps bellow:
$ cd linux-2.6.35.4
$ cp /boot/config-2.6.32-24-generic .config
$ make menuconfig
In the configuration menu you can see all the options for your kernel. I only changed the processor from generic to "Core 2/newer Xeon" and the preemption model to make my computer more responsive. Fell free to explore other options. The help feature can be very useful to learn more about your computer.
4) Initramfs and initrd. Now we need a couple more tweaks before we start. First we will borrow some scripts that will help us create the initramfs file system.
$ sudo cp /usr/share/doc/kernel-package/examples/etc/kernel/postinst.d/initramfs /etc/kernel/postinst.d/initramfs
$ sudo cp /usr/share/doc/kernel-package/examples/etc/kernel/postrm.d/initramfs /etc/kernel/postrm.d/initramfs
Next we need to make sure that the initrd image is also created. To do so follow the steps below:
First create your overlay directory:
$ cp -r /usr/share/kernel-package $HOME
Now download the source code for your current kernel version:
$ sudo apt-get source linux-image-2.6.32-24-generic
This will unpack the source in $HOME/linux-2.6.32. Now copy the control scripts into your new overlay:
$ cp linux-2.6.32/debian/control-scripts/{postinst,postrm,preinst,prerm} kernel-package/pkg/image/
$ cp linux-2.6.32/debian/control-scripts/headers-postinst kernel-package/pkg/headers/
5) Parallelizing. Compiling the kernel might take a long time, like 2 hours. So if you have multiple processors in your machine you should take advantage of them to speedup the process. To do so, setup the concurrency level variable to the number of processors you have plus 1. In my case I have a core i3, with 2 processors but also with hyperthreading, so my computer sees 4 processors.
$ export CONCURRENCY_LEVEL=5
6) Compilation. Now everything should be ready for the grand compilation. Type the commands below to start compiling:
$ make-kpkg clean
$ fakeroot make-kpkg --initrd --overlay-dir=$HOME/kernel-package --append-to-version=-gbezerra kernel-image kernel-headers
Change the "gbezerra" string to whatever you want to be appended to your kernel name.
7) Installation. After 30min, depending on how many processors you have, you should have your kernel compiled and some .deb packages ready to be installed. Go to one directory above and proceed as follows.
$ cd..
$ sudo dpkg -i linux-image-2.6.35.4-gb_2010.09.10_amd64.deb
$ sudo dpkg -i linux-headers-2.6.35.4-gb_2010.09.10_amd64.deb
After that your kernel should be installed. Just to make sure, go to the /boot directory and see that all the new kernel files are there. You're ready to reboot your machine and try it out.
$ sudo reboot
Good luck!
For a helpful reference go to https://help.ubuntu.com/community/Kernel/Compile
Thursday, September 9, 2010
Updating database
In order for the 'locate' command to work we need to update the database by simply typing 'updatedb'
Adding user to sudoers
Simple stuff I don't wanna forget:
sudo adduser username admin
Or go to /etc/sudoers and add:
user ALL=(ALL) ALL
Or go to /etc/sudoers and add:
user ALL=(ALL) ALL
Tuesday, August 24, 2010
Installing GEMS step-by-step
System is Ubuntu 9.04 64-bits. The compiler version used is the recommended gcc 3.4.1.
mkdir ~/GEMS
Copy all the downloaded GEMS files into the GEMS directory. Now edit the .bashrc file and add the following:
GEMS=$HOME/GEMS
export SIMICS_INSTALL=/opt/virtutech/simics-3.0.31
export SIMICS_EXTRA_LIB=./modules
export PYTHONPATH=./modules
Restart the computer.
Now create a simics workspace:
cd $SIMICS_INSTALL/bin
./workspace-setup $GEMS/simics_workspace
Edit GEMS/scripts/makesymlinks.h to include the correct $SIMICS_INSTALL path:
echo "Making symlink for import directory.."
ln -s /opt/virtutech/simics-3.0.31/import import
Run makesymlinks from the simics workspace:
cd ~/GEMS/simics_workspace
../scripts/makesymlinks.h
Link your simics workspace to $GEMS/simics:
cd $GEMS
ln -s simics_workspace simics
Edit GEMS makefiles:
1) $GEMS/common/Makefile.common
A) Modify the CC for your chosen compiler to 3.4.1, only for amd64-linux, and the path to gcc
B) Set value to HOST_TYPE directly: HOST_TYPE=amd64-linux
C) After line ifeq ($(SIMICS_VERSION),3.0) modify lines:
SIMICS_ROOT := $(GEMS_ROOT)/simics
SIMICS_INCLUDE_ROOT := $(SIMICS_INSTALL)/src/include
2) $GEMS/ruby/module/Makefile
A) Modify the CC_version and the path to gcc
B) Set value to HOST_TYPE directly: HOST_TYPE=amd64-linux
3) $GEMS/opal/module/Makefile
A) Modify the CC_version and the path to gcc
B) Set value to HOST_TYPE directly: HOST_TYPE=amd64-linux
4) $GEMS/tourmaline/module/Makefile
A) Modify the CC_version and the path to gcc
B) Set value to HOST_TYPE directly: HOST_TYPE=amd64-linux
Now it's time to compile ruby:
cd $GEMS/ruby
make PROTOCOL=MOSI_SMP_bcast DESTINATION=MOSI_SMP_bcast
Next compile opal:
cd $GEMS/opal
make module DESTINATION=MOSI_SMP_bcast
Building gcc-3.4.1 on Ubuntu 9.04 64-bits
Download gcc:
mkdir srcgcc
mkdir objgcc
Extract the source files into the source directory, then go to the object directory to configure your build:
cd objgcc
make distclean; CFLAGS=-m64; CC=gcc; ../srcgcc/gcc-3.4.1/configure --prefix=/opt/gcc-3.4.1/ --disable-multilib --enable-languages=c,c++
In the above command the target directory is /opt/gcc-3.4.1. If you run into permission issues, make sure you own the target directory:
sudo chown gbezerra /opt/gcc-3.4.1
Now compile gcc:
make bootstrap
Finally install it:
sudo make install
Subscribe to:
Posts (Atom)