Tuesday, September 16, 2014

chroot to the linux distribution filesystem

For recovery purposes, mostly, you may need to boot with the live cd and perform some maintenance.

cd /mnt/arch # or where you are preparing the chroot dir
mount -t proc proc proc/
mount -t sysfs sys sys/
mount -o bind /dev dev/
 
 

Friday, July 18, 2014

ImportError: No module named pymeanshift

To install the pymeanshift module i did it easily like this:

1) Download the sources https://code.google.com/p/pymeanshift/downloads/list

(there is no binary at the time of writing this)


2) tar zxvf pymeanshift-0.2.1.tar.gz


root@walter-Lenovo-Z480:~/pymeanshift-0.2.1# ./setup.py install
running install
running build
running build_py
creating build
creating build/lib.linux-x86_64-2.7
copying pymeanshift.py -> build/lib.linux-x86_64-2.7
running build_ext
building '_pymeanshift' extension
creating build/temp.linux-x86_64-2.7
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/local/lib/python2.7/dist-packages/numpy/core/include -I/usr/include/python2.7 -c ms.cpp -o build/temp.linux-x86_64-2.7/ms.o
cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for Ada/C/ObjC but not for C++ [enabled by default]
ms.cpp: In member function ‘void MeanShift::generalLSearch(double*, double*)’:
ms.cpp:2171:26: warning: variable ‘lN’ set but not used [-Wunused-but-set-variable]
ms.cpp: In member function ‘void MeanShift::optGeneralLSearch(double*, double*)’:
ms.cpp:2327:37: warning: variable ‘lN’ set but not used [-Wunused-but-set-variable]
ms.cpp: In member function ‘void MeanShift::generalSearch(tree*, int, double*, double*)’:
ms.cpp:1818:5: warning: ‘diff’ may be used uninitialized in this function [-Wuninitialized]
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/local/lib/python2.7/dist-packages/numpy/core/include -I/usr/include/python2.7 -c msImageProcessor.cpp -o build/temp.linux-x86_64-2.7/msImageProcessor.o
cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for Ada/C/ObjC but not for C++ [enabled by default]
msImageProcessor.cpp: In member function ‘void msImageProcessor::TransitiveClosure()’:
msImageProcessor.cpp:2414:8: warning: variable ‘threshold’ set but not used [-Wunused-but-set-variable]
msImageProcessor.cpp:2563:6: warning: unused variable ‘oldRegionCount’ [-Wunused-variable]
msImageProcessor.cpp: In member function ‘void msImageProcessor::Prune(int)’:
msImageProcessor.cpp:2784:57: warning: variable ‘oldRegionCount’ set but not used [-Wunused-but-set-variable]
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/local/lib/python2.7/dist-packages/numpy/core/include -I/usr/include/python2.7 -c rlist.cpp -o build/temp.linux-x86_64-2.7/rlist.o
cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for Ada/C/ObjC but not for C++ [enabled by default]
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/local/lib/python2.7/dist-packages/numpy/core/include -I/usr/include/python2.7 -c RAList.cpp -o build/temp.linux-x86_64-2.7/RAList.o
cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for Ada/C/ObjC but not for C++ [enabled by default]
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/local/lib/python2.7/dist-packages/numpy/core/include -I/usr/include/python2.7 -c pymeanshift.cpp -o build/temp.linux-x86_64-2.7/pymeanshift.o
cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for Ada/C/ObjC but not for C++ [enabled by default]
In file included from /usr/local/lib/python2.7/dist-packages/numpy/core/include/numpy/ndarraytypes.h:1761:0,
                 from /usr/local/lib/python2.7/dist-packages/numpy/core/include/numpy/ndarrayobject.h:17,
                 from /usr/local/lib/python2.7/dist-packages/numpy/core/include/numpy/arrayobject.h:4,
                 from pymeanshift.cpp:21:
/usr/local/lib/python2.7/dist-packages/numpy/core/include/numpy/npy_1_7_deprecated_api.h:15:2: warning: #warning "Using deprecated NumPy API, disable it by " "#defining NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION" [-Wcpp]
g++ -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions -Wl,-z,relro build/temp.linux-x86_64-2.7/ms.o build/temp.linux-x86_64-2.7/msImageProcessor.o build/temp.linux-x86_64-2.7/rlist.o build/temp.linux-x86_64-2.7/RAList.o build/temp.linux-x86_64-2.7/pymeanshift.o -o build/lib.linux-x86_64-2.7/_pymeanshift.so
running install_lib
copying build/lib.linux-x86_64-2.7/_pymeanshift.so -> /usr/local/lib/python2.7/dist-packages
copying build/lib.linux-x86_64-2.7/pymeanshift.py -> /usr/local/lib/python2.7/dist-packages
byte-compiling /usr/local/lib/python2.7/dist-packages/pymeanshift.py to pymeanshift.pyc
running install_egg_info
Writing /usr/local/lib/python2.7/dist-packages/pymeanshift-0.2.1.egg-info

-----

Monday, December 30, 2013

Expanding a disk with ubuntu and virtualbox

I have no more free space in my virtualbox disk.  And i created the disk as "static" which is an obstacle when you want to expand the disk:


 walter@walter-Lenovo-Z480:~/VirtualBox VMs/intraweb$ VBoxManage modifyhd Linux1.vdi --resize 20000  
 0%...  
 Progress state: VBOX_E_NOT_SUPPORTED  
 VBoxManage: error: Resize hard disk operation for this format is not implemented yet!  

The disk says "Format variant: fixed"


 walter@walter-Lenovo-Z480:~/VirtualBox VMs/intraweb$ VBoxManage showhdinfo Linux1.vdi  
 UUID:      3492e240-1589-479f-a6d7-f58586a7a671  
 Parent UUID:  base  
 State:     created  
 Type:      normal (base)  
 Location:    /home/walter/VirtualBox VMs/intraweb/Linux1.vdi  
 Storage format: VDI  
 Format variant: fixed default  
 Capacity:    4853 MBytes  
 Size on disk:  4854 MBytes  
 In use by VMs: intraweb (UUID: 76173fac-f9b3-4cf9-9daf-06e363eecd6d)  

The first thing you have to do, just clone the disk.  Once cloned, it will be dynamic:

 walter@walter-Lenovo-Z480:~/VirtualBox VMs/intraweb$ VBoxManage clonehd Linux1.vdi Linux1d.vdi  
 0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%  
 Clone hard disk created in format 'VDI'. UUID: e8f06a57-805e-464f-8cbc-3e23d082a003  
 walter@walter-Lenovo-Z480:~/VirtualBox VMs/intraweb$ VBoxManage showhdinfo Linux1d.vdi  
 UUID:      e8f06a57-805e-464f-8cbc-3e23d082a003  
 Parent UUID:  base  
 State:     created  
 Type:      normal (base)  
 Location:    /home/walter/VirtualBox VMs/intraweb/Linux1d.vdi  
 Storage format: VDI  
 Format variant: dynamic default  
 Capacity:    4853 MBytes  
 Size on disk:  4475 MBytes  

Now, i changed the original disk with this new one in the Virtual Box GUI Management and everything was smooth.

Next, i just resized the disk to have 20 Gig instead of only 4 Gig
 walter@walter-Lenovo-Z480:~/VirtualBox VMs/intraweb$ VBoxManage modifyhd ~/VirtualBox\ VMs/intraweb/Linux1d.vdi --resize 20000  
 0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%  

Now i started the ubuntu desktop to use gparted and resize the guest operating system:

Choose to "Try Ubuntu"

Make sure to choose the right disk, i can not take any responsibility if something of this goes wrong:


I was not able to move the swap disk, so i removed it with fdisk.

fdisk /dev/sda
d 5
d 2
w
And then i started gparted again. Now i was able to resize the partition.  Then, i rebooted the virtual machine and opened gparted again.  Added the swap partition and rebooted.






Tuesday, November 05, 2013

How to compress a file in linux. In parts

To compress a file in parts i use RAR.  There are many ways to do it.

rar a -v250000k /rar_file_name.rar /directory_or_file/

Tuesday, June 12, 2012

Creating a RAMFS

With the previous method i found it slow for being a ram disk, i read that ramfs does no swapping, i want to test it:

mount -t ramfs -o size=50m ramfs /ramcache
 

This is a good resource:
http://www.thegeekstuff.com/2008/11/overview-of-ramfs-and-tmpfs-on-linux/ 

Linux RAM filesystem

I do datamining, and the first thing learned is that 80% of this wonderful science is datapreparation.  I am looking for cheap wais to manage large about of data, and today i want to try how a RAM disk in Linux performs to create a dataset for weka.

As root, i want a 10MB file (yes, even though it is far away from being big data, the data preparation was taking several minutes)

root@talento:~# mkfs -q /dev/ram1 10240
root@talento:~# mkdir -p /ramcache
root@talento:~# mount /dev/ram1 /ramcache
root@talento:~# df -H | grep ramcache
/dev/ram1               11M    95k   9.6M   1% /ramcache




Wednesday, June 06, 2012

How to normalize a variable

This is simple procedure, to normalize a variable and bring it from a scale to another, this is the procedure:



The minimum values of A and maximum values are obvious (i hope),
D and C are the new ranges.  Being D the maximum from the new range and C the minimum from the new range.

This is an example:


Tuesday, May 29, 2012

Perl Date manipulation as is

Today i had to program a little script, in perl, and had to manipulate some dates.  To convert the AM/PM part i used this previously written function (here).

But then i need to do some delta operation on the dates, for whom i new packages like Date::Calc.

The surprise was that i couldn't install new packages in the server, it is a remote server and the less problems one causes, the better... because the server is shared, there was no gcc, bla, bla..

I found this package:
use Date::Manip;

Which seems to be included with Perl.  I couldn't confirm it but it saved the day, here is an example:

my $ffin = &DateCalc("$startdate", "+8 days", \$err);
my ($y, $m, $d) = $ffin =~ m/([0-9]{4})([0-9]{2})([0-9]{2}).*/g;


More about it:
http://snowhare.com/utilities/perldoc2tree/example/Date/Manip.html