Monday 16 September 2013

automount drivers on gentoo using i3wm

it is very annoying when simple wm doesn't provide any auto mount module, one has to find a way to mount usb drivers and mobile harddisks. it is even harder when there is a ntfs partitions.

In this page, we basically solve two problems:
1. How to let gentoo recognize ntfs partition?
2. How to auto mount usb and mobile hard disks?
For the first question, there are two steps:

step 1:
let kernel support fuse:
enable File Systems->Fuse (file system in userpsace), make it as module



step 2:
install ntfs3g
# emerge -a ntfs3g


For the second question, edit the following in /etc/fstab
/dev/sda1   /boot     ext4    noauto,noatime     1 2
/dev/sda2   /         ext4    noatime            0 1
/dev/sda7   none      swap    sw                 0 0
/dev/sda6   /home     ext4    defaults        0       2

# for sandisk usb driver noauto means it will not be mounted automatically, which is to avoid error if it is not mounted 
/dev/sdc1 /mnt/sandisk auto noauto,users,noatime,umask=0 0 0

# for mobile hard disk 
UUID="333c9d2f-1c2a-482e-83f7-616fa45a478a" /mnt/MobiC ext4 auto,rw,users,exec,nofail 0 0
UUID="D0CC0864CC0846E6"   /mnt/MobiD  ntfs-3g rw,suid,dev,exec,async,auto,users,nofail  0 0 

# for scientific linux
/dev/sda8 /home/chenming/SL ext4 rw,users,exec 0 0
# for Lubuntu
/dev/sda10 /home/chenming/Lubuntu ext4 rw,users,exec 0 0
# for slackware
/dev/sda5 /home/chenming/Slackware ext4 rw,users,exec 0 0
# the local ntfs driver
/dev/sda9 /home/chenming/ntfs      ntfs-3g defaults   0 0

sda2, sda7, sda6 are all for systems, sda8,sda10,sda5,sda9 are local disks. notice the difference between ntfs and ext4.
the two uuid ones are the mobile harddisk. note that both has been added noauto options, it is set to avoid mount on boot. when mobile hard disk is not present, booting the system with automount on will cause error. also by this way one can "partially" auto mount by click icons at nautilus.
the disadivantage for this method is that it can not automount ntfs driver, so at the moment after the device is inserted one has to run the following by root:
# mount  UUID="D0CC0864CC0846E6"
hope we can find better way to make the whole process automatically.
more info:
auto,nofail-- it means it will be automatically mount on boot. however, if it is not present on boot, error will not appear.
useful tools here:
command blkid is very good to find out all of the uuids:
mybox linux # blkid
/dev/sda1: UUID="1ed58cd8-d54c-4191-86b5-2b967298d3c2" TYPE="ext4" 
/dev/sda2: UUID="671f9d17-5de7-4fe7-a6bf-f1096f4efe29" TYPE="ext4" 
/dev/sda5: UUID="c8216a5e-3d03-491e-94a0-c19c25bdeee7" TYPE="ext4" 
/dev/sda6: UUID="90b2869f-0d85-43ea-af05-b2833ded28ff" TYPE="ext4" 
/dev/sda7: UUID="f660c6ea-ac34-4d1f-8945-e800adae05aa" TYPE="swap" 
/dev/sda8: UUID="1e45a116-4e39-4a0f-8c67-48fe0c3c2ec0" TYPE="ext4" PTTYPE="dos" 
/dev/sda9: UUID="075E30C271C193B7" TYPE="ntfs" 
/dev/sda10: UUID="692659d8-84d1-4de4-b530-5d97d302e353" TYPE="ext4" 
/dev/sr0: UUID="2012-02-03-16-05-05-00" LABEL=""SL 6.2 x86_64 DVD"" TYPE="iso9660"

gentoo: install ethernet card driver

after installing gentoo, i found it automatically recognize my ethernet card, but the driver is not properly installed (the module is loaded in default)
mybox Desktop # lspci -k
02:00.0 Network controller: Realtek Semiconductor Co., Ltd. RTL8188CE 802.11b/g/n WiFi Adapter (rev 01)
        Subsystem: Realtek Semiconductor Co., Ltd. Device 8182
        Kernel driver in use: rtl8192ce
        Kernel modules: rtl8192ce
06:00.0 Ethernet controller: Qualcomm Atheros AR8152 v2.0 Fast Ethernet (rev c1)
        Subsystem: Toshiba America Info Systems Device ff1e
note there is no modules list on the AR8152.
apparently the kernel should provide the driver for Ethernet card, so I should not try to look for drivers. from ubuntu, i found the module is called atl1c. then I tried to find it in the kernel menuconfig:
# cd /etc/usr/linux
# make menuconfig

then i found it at Device Drivers -> Network device support -> Ethernet driver support -> Atheros device (simplely choose all of them)
now remake the kernel module , install and load the module:
# make modules_install
# modeprobe atl1c

enjoy!

change mac address for ubuntu and gentoo

first one has to check the situation of network:
# ifconfig
this gives:
mybox Desktop # ifconfig
enp6s0: flags=4163  mtu 1500
        inet 10.33.21.70  netmask 255.255.252.0  broadcast 10.33.23.255
        inet6 fe80::222:19ff:fe2e:603f  prefixlen 64  scopeid 0x20
        ether 00:22:19:2e:60:3f  txqueuelen 1000  (Ethernet)
        RX packets 13223  bytes 6462275 (6.1 MiB)
        RX errors 0  dropped 18  overruns 0  frame 0
        TX packets 6147  bytes 1062544 (1.0 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 1  collisions 0

lo: flags=73  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10
        loop  txqueuelen 0  (Local Loopback)
        RX packets 600  bytes 48840 (47.6 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 600  bytes 48840 (47.6 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

wlp2s0: flags=4099  mtu 1500
        inet6 fe80::e2ca:94ff:fedb:57ac  prefixlen 64  scopeid 0x20
        ether e0:ca:94:db:57:ac  txqueuelen 1000  (Ethernet)
        RX packets 457  bytes 532967 (520.4 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 257  bytes 42551 (41.5 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
note that here enp6s0 is wired card and wlp2s0 is wireless, which is different from eth0 and wlan0 in some distributions (e.g., slackware ubuntu debian lubuntu, scientific linux) also note that the name of the mac is called ether rather than HWaddr
therefore, one can do:
ifconfig enp6s0 down
ifconfig enp6s0 hw ether  00:22:19:2E:60:3F
ifconfig enp6s0 up

now you have the new mac address working on your enternet. for other distributions, one may need to change enp6s0 into eth0, and ether into HWaddr. enjoy!

gentoo kernel 3.10.7: How to install camera on toshiba laptop

the really sad part of installing camera driver in linux is that one can not find anything from commands lsmod, lspci (this requires usbtencil). So the way for me to find out what module is required by camera is to run:
lsmod
on a system that drivers are installed. Alternatively, one can use windows and run devmgmt.msc to find out the models.
from the output, the module shows:
videobuf2_vmalloc       2864  1 uvcvideo
videobuf2_core         26953  1 uvcvideo
videodev              105533  2 uvcvideo,videobuf2_core
media                  10308  2 uvcvideo,videodev
so we try to find uvcvideo module in kenel config.
However, different from info given by forums, the new menuconfig can not find anything about uvc video. therefore, I decided to find out from .config file
#
# Media drivers
#
CONFIG_MEDIA_USB_SUPPORT=y

#
# Webcam devices
#
CONFIG_USB_VIDEO_CLASS=m
CONFIG_USB_VIDEO_CLASS_INPUT_EVDEV=y
CONFIG_USB_GSPCA=m
This is equivalent to menuconfig Device Drivers->Multimedia support->Cameras/video grabbers support&V4L platform device
then I am able to get the camera by running:
# modprobe uvcvideo
and further run by boot:
# echo "modules=\"uvcvideo\"">>/etc/conf.d/modules
The above mentioned method works very well for my toshiba laptop, but there is some problem on my logitech C160, as this device contains microphones as well. so we need to add that in. first menuconfig:
# make menuconfig
Device Drivers ->
  sound car support ->
    Advanced linux sound architecture ->
      USB sound devices
      [M]  USB Audio/Midi driver
then one needs to do
# make 
# make modules_install
# modprobe snd_usb_audio
# echo "modules=\"snd_usb_audio\"">>/etc/conf.d/modules
now you can select microphone in skype or check the presence of the card by
# cat /proc/asound/cards
some more information: if one can not find the vendor of the product, one can first find out the device id. for example
# lsusb 
Bus 001 Device 004: ID 046d:0824 Logitech, Inc. 
the information "046d:0824" contains vendor and model of the device, if you search on website, it is logitech webcam c160

Sunday 15 September 2013

auto backup local file in folder using crontab and rsync

it is really fast working at local hard disk. but the disadvantage is that it is not backuped. so a better way would be working at local hard disk that are automatically backed up as schedule.
two problems here.
1. how to make a schedule
2. how to sync with two folders.

slolution to problem 1:

using command

$ crontab

two useful parameters:

$ crontab -e

after executing this, a text editor pops out, which is the place one lodge a schedule, the format is like this (one can use # to comment out unnecessary schedules )


Code:
* * * * * /path/to/the/bash/script

the first star means minutes, it can be 0 to 59 or *. if it is star (*), it means every minute
the second star means hour, it can be 0 to 23 or *. if it is star (*), it means every hour
the third star means day of the month, it can be 0 to 31 or start*. if it is star (*), it means every day
the fourth star means month of the year, it can be 1 to 12. if it is star (*), it means every month
the fifth star means day of the week. if it is star (*), it means every day.

my final script after executing crontab -e is:
0 18 * * * /home/chenming/Hdrive/backup6.4

which means run backup6.4 at 18:00 of each day.

one needs to make sure that backup6.4 is a executable file (chmod +x backup6.4)

some other useful commands:

$ crontab -l

list schedules 

I usually use the following one to test:

schedule:
* * * * * /home/chenming/Hdrive/backup6.4

commands:
#!/bin/bash
echo $(date)>>/home/chenming/test

which writes date and time in one file per minute.




solution to problem 2:

use command rsync. put the following line in /home/chenming/Hdrive/backup6.4

rsync -a --progress --human-readable --states --update /path/to/folder/needs/to/be/synced --delete /path/to/folder/backup/file/stores/
here --progress shows the results (not useful as a schedule, though)
       --stats vobose mode
       --update skip files that are newer on the receiver (this is not useful if one doesn't change anything in receiver)
       --delete delete  extraneous files from dest dirs

Notes for systemd user:

you need to make sure that the service dcron is enabled:
 systemctl status dcron
systemctl is-enabled dcron
To enable it, you can do:
systemctl enable dcron

Tuesday 10 September 2013

give privilege to normal user to use nm-applet in gentoo

after installed networkmanager, i found as a normal user, one can not make any modifications and connections with prompt "insufficient privileges"

oh... it can not be done at the moment. i get my hand very dirty..

New update on this thread:
one can startx by root, set everything well on networkmanager. then logout and back in again as normal user. as a normal user, one can connect and disconnect availabe hotspots, but can not add new ones.

Friday 6 September 2013

convert large mov file from iphone to avi (libx264) for storage

use exiftool to inspect EXIF info of the jpe and mov file
exif


----------------original:::------------------------------------------
ExifTool Version Number         : 8.60
File Name                       : IMG_0014.MOV
Directory                       : .
File Size                       : 19 MB
File Modification Date/Time     : 2013:07:19 12:03:22-10:00
File Permissions                : rw-r--r--
File Type                       : MOV
MIME Type                       : video/quicktime
Major Brand                     : Apple QuickTime (.MOV/QT)
Minor Version                   : 0.0.0
Compatible Brands               : qt
Movie Data Size                 : 19979709
Movie Header Version            : 0
Modify Date                     : 2013:07:19 22:03:21
Time Scale                      : 600
Duration                        : 7.27 s
Preferred Rate                  : 1
Preferred Volume                : 100.00%
Preview Time                    : 0 s
Preview Duration                : 0 s
Poster Time                     : 0 s
Selection Time                  : 0 s
Selection Duration              : 0 s
Current Time                    : 0 s
Next Track ID                   : 3
Track Header Version            : 0
Track Create Date               : 2013:07:19 22:03:13
Track Modify Date               : 2013:07:19 22:03:21
Track ID                        : 1
Track Duration                  : 7.27 s
Track Layer                     : 0
Track Volume                    : 0.00%
Image Width                     : 1920
Image Height                    : 1080
Graphics Mode                   : ditherCopy
Op Color                        : 32768 32768 32768
Compressor ID                   : avc1
Source Image Width              : 1920
Source Image Height             : 1080
X Resolution                    : 72
Y Resolution                    : 72
Compressor Name                 : H.264
Bit Depth                       : 24
Video Frame Rate                : 27.011
Camera Identifier               : Back
Frame Readout Time              : 28512 microseconds
Matrix Structure                : 1 0 0 0 1 0 0 0 1
Media Header Version            : 0
Media Create Date               : 2013:07:19 22:03:13
Media Modify Date               : 2013:07:19 22:03:21
Media Time Scale                : 44100
Media Duration                  : 7.31 s
Media Language Code             : und
Balance                         : 0
Handler Class                   : Data Handler
Handler Vendor ID               : Apple
Handler Description             : Core Media Data Handler
Audio Channels                  : 1
Audio Bits Per Sample           : 16
Audio Sample Rate               : 44100
Audio Format                    : chan
Model                           : iPhone 4S
Software Version                : 6.1.3
Create Date                     : 2013:07:20 08:03:13+10:00
Make                            : Apple
Handler Type                    : Metadata Tags
Make (und-AU)                   : Apple
Creation Date (und-AU)          : 2013:07:20 08:03:13+10:00
Software (und-AU)               : 6.1.3
Model (und-AU)                  : iPhone 4S
Avg Bitrate                     : 22 Mbps
Image Size                      : 1920x1080
Rotation                        : 90

-------------------------------------------------------------------------

ffmpeg -i IMG_0014.MOV -vcodec libx264 -acodec copy IMG.avi

ExifTool Version Number         : 8.60
File Name                       : IMG.avi
Directory                       : .
File Size                       : 7.3 MB
File Modification Date/Time     : 2013:09:06 22:12:03-10:00
File Permissions                : rw-r--r--
File Type                       : AVI
MIME Type                       : video/x-msvideo
Frame Rate                      : 24
Max Data Rate                   : 7.748 kB/s
Frame Count                     : 176
Stream Count                    : 2
Stream Type                     : Video
Video Codec                     : H264
Video Frame Rate                : 24
Video Frame Count               : 176
Quality                         : Default
Sample Size                     : Variable
Image Width                     : 1920
Image Height                    : 1080
Planes                          : 1
Bit Depth                       : 24
Compression                     : H264
Image Length                    : 6220800
Pixels Per Meter X              : 0
Pixels Per Meter Y              : 0
Num Colors                      : Use BitDepth
Num Important Colors            : All
Audio Codec                     : .
Audio Sample Rate               : 43.07
Audio Sample Count              : 315
Encoding                        : AAC
Num Channels                    : 1
Sample Rate                     : 44100
Avg Bytes Per Sec               : 7934
Bits Per Sample                 : 16
Date Created                    : 2013:07:20T08:03:13+1000
Software                        : Lavf54.29.104
Duration                        : 7.33 s
Image Size                      : 1920x1080


------------------------------------------------------------------------
ffmpeg -i IMG_0014.MOV -vcodec libx264 -acodec copy -metadata "tag=value" IMG_tag_value-.avi
ExifTool Version Number         : 8.60
File Name                       : IMG_tag_value.avi
Directory                       : .
File Size                       : 7.3 MB
File Modification Date/Time     : 2013:09:06 22:17:20-10:00
File Permissions                : rw-r--r--
File Type                       : AVI
MIME Type                       : video/x-msvideo
Frame Rate                      : 24
Max Data Rate                   : 7.748 kB/s
Frame Count                     : 176
Stream Count                    : 2
Stream Type                     : Video
Video Codec                     : H264
Video Frame Rate                : 24
Video Frame Count               : 176
Quality                         : Default
Sample Size                     : Variable
Image Width                     : 1920
Image Height                    : 1080
Planes                          : 1
Bit Depth                       : 24
Compression                     : H264
Image Length                    : 6220800
Pixels Per Meter X              : 0
Pixels Per Meter Y              : 0
Num Colors                      : Use BitDepth
Num Important Colors            : All
Audio Codec                     : .
Audio Sample Rate               : 43.07
Audio Sample Count              : 315
Encoding                        : AAC
Num Channels                    : 1
Sample Rate                     : 44100
Avg Bytes Per Sec               : 7934
Bits Per Sample                 : 16
Date Created                    : 2013:07:20T08:03:13+1000
Software                        : Lavf54.29.104
Duration                        : 7.33 s
Image Size                      : 1920x1080


this is not what i want
------------------------------------------------------------------------
ffmpeg -i IMG_0014.MOV -vcodec libx264 -acodec copy -map_metadata 0  IMG_map_matadata_0.avi

ExifTool Version Number         : 8.60
File Name                       : IMG_map_matadata_0.avi
Directory                       : .
File Size                       : 7.3 MB
File Modification Date/Time     : 2013:09:06 22:22:04-10:00
File Permissions                : rw-r--r--
File Type                       : AVI
MIME Type                       : video/x-msvideo
Frame Rate                      : 24
Max Data Rate                   : 7.748 kB/s
Frame Count                     : 176
Stream Count                    : 2
Stream Type                     : Video
Video Codec                     : H264
Video Frame Rate                : 24
Video Frame Count               : 176
Quality                         : Default
Sample Size                     : Variable
Image Width                     : 1920
Image Height                    : 1080
Planes                          : 1
Bit Depth                       : 24
Compression                     : H264
Image Length                    : 6220800
Pixels Per Meter X              : 0
Pixels Per Meter Y              : 0
Num Colors                      : Use BitDepth
Num Important Colors            : All
Audio Codec                     : .
Audio Sample Rate               : 43.07
Audio Sample Count              : 315
Encoding                        : AAC
Num Channels                    : 1
Sample Rate                     : 44100
Avg Bytes Per Sec               : 7934
Bits Per Sample                 : 16
Date Created                    : 2013:07:20T08:03:13+1000
Software                        : Lavf54.29.104
Duration                        : 7.33 s
Image Size                      : 1920x1080

--------------------------------------------------------------------
ffmpeg -i IMG_0014.MOV -vcodec libx264 -acodec copy  IMG_no.avi

ExifTool Version Number         : 8.60
File Name                       : IMG_no.avi
Directory                       : .
File Size                       : 7.3 MB
File Modification Date/Time     : 2013:09:06 22:46:20-10:00
File Permissions                : rw-r--r--
File Type                       : AVI
MIME Type                       : video/x-msvideo
Frame Rate                      : 24
Max Data Rate                   : 7.748 kB/s
Frame Count                     : 176
Stream Count                    : 2
Stream Type                     : Video
Video Codec                     : H264
Video Frame Rate                : 24
Video Frame Count               : 176
Quality                         : Default
Sample Size                     : Variable
Image Width                     : 1920
Image Height                    : 1080
Planes                          : 1
Bit Depth                       : 24
Compression                     : H264
Image Length                    : 6220800
Pixels Per Meter X              : 0
Pixels Per Meter Y              : 0
Num Colors                      : Use BitDepth
Num Important Colors            : All
Audio Codec                     : .
Audio Sample Rate               : 43.07
Audio Sample Count              : 315
Encoding                        : AAC
Num Channels                    : 1
Sample Rate                     : 44100
Avg Bytes Per Sec               : 7934
Bits Per Sample                 : 16
Date Created                    : 2013:07:20T08:03:13+1000
Software                        : Lavf54.29.104
Duration                        : 7.33 s
Image Size                      : 1920x1080

Wednesday 4 September 2013

Use i3wm in Linux ( with dual screen and virtualbox)

Tiling window manager seems to be a good trend. the reason is: you don't have to go to a particular workspace and maximize the window

add
exec --no-startup-id nm-applet
in ~/.i3/config , so that network manager will be displayed in the tray.
two problems here:
1 the taskbar is not displayed properly
2 sometimes the autoscroll in chromium is not working.

-------------let virtualbox working perfectly with i3 with dual screen--------------

1. go to virtualbox->file->preference->input-> untick auto capture keyboard. (If unticked, the windows system will have the previlege to use win key, resulting in the failure of switching between workspaces)
2. put two screen of virtualbox separately on two monitors, each monitor is on different workspace (for example, monitor 1 has workspace 5, that display one virtualbox screen, monitor 2 has workspace 6, which display another virtualbox screen)
3. disable seamless mode, maximum mode.
4. configure ~/.i3config
add
bindsym $mod+z workspace 7;workspace 8
bindsym $mod+x workspace 3;workspace 4
bindsym $mod+c workspace 5;workspace 6
bindsym $mod+shift+z workspace 1;workspace 2

# for merge into new window
bindsym $mod+M focus left;split v;layout stacking;focus right;move left
bindsym $mod+comma focus right;split v;layout stacking;focus left;move right
WARNING: do not add any space to the digits, otherwise the workspace name will be 2[space] rather than 2. semicolon means to separate commands.
5. $mod+shift+c to reload
6. run
# VBoxManage setextradata global GUI/Customizations noMenuBar,noStatusBar


to disable the menubar and status bar in virtualbox windows

now every time we press $mod+c, we come into windows world, when we press $mod+z, we go back to i3 world.  
7. sloving keybinding problem: now the master key in i3wm is windows logo key, which conflicts with some shortcut within windows. (e.g., win+e=explorer, win+left arrow=place window by half screen, win+l=lock pc) for the window move, one can still keep using win key + numbers at number keyboard when numlock is disabled. To make full use of win logo key in guest machine, one has to map the win key to some idle keys (e.g., application key next to right control). it is not easy to change the regstration, we decided to use a software called Sharpkeys (becareful when using it 1. FROM on the left means the key that will be pressed, To on the right means the original function that one needs to be mapped out 2. if messed up, it is better clean all out , log in&out, then reconfiguire, because the modifided key doesn't hold the default function, which will be confusing)
Alternative solution to 7:

the basic idea is that the left windows logo key is used for i3wm, while the right one are still used on the right. However, I had some problem by make the keybinding changed on default.
the problem was if i put the following in ~/.Xmodmap
remove Mod4 = Super_R
add Mod3 = Super_R

and put
exec i3 --force-xinerama
if [ -s ~/.Xmodmap ]; then
    xmodmap ~/.Xmodmap
fi

in ~/.xinitrc, it doesn't change the key bindings at all (the reason I didn't delete this part is to remind myself of the wrong way). the way to work around it is to add the following to ~/.xinitrc

xmodmap ~/.Xmodmap &&
exec i3 --force-xinerama
if one does not put --force-xinerama, the two screens will be considered as one workspace, which may be good for some people. the we assign the left logo key as i3 mod, right one used for windows.

[chenming@T5500 ~]$ xmodmap
xmodmap:  up to 3 keys per modifier, (keycodes in parentheses):

shift       Shift_L (0x32),  Shift_R (0x3e)
lock        Caps_Lock (0x42)
control     Control_L (0x25),  Control_R (0x69)
mod1        Alt_L (0x40),  Alt_R (0x6c),  Meta_L (0xcd)
mod2        Num_Lock (0x4d)
mod3        Super_R (0x86)
mod4        Super_L (0x85),  Super_L (0xce),  Hyper_L (0xcf)
mod5        ISO_Level3_Shift (0x5c),  Mode_switch (0xcb)

8. Problems on changing host machine:
when guest is set as 64bit, after copy the file to another host, it says

VT-x/AMD-V hardware acceleration has been enabled, but is not operational. 
Certain guests (e.g. OS/2 and QNX) require this feature.

Please ensure that you have enabled VT-x/AMD-V properly in the BIOS of your
host computer.

this problem can be solved by enabling Intel Virtualization Technology in bios (but remember, may be only this one, nothing else. this happens for my dell 960 pc.

this method is quite good to integrate the performance of dual screen. as i3wm has to enable xinerama, which treats two monitor as separate worspaces. using the above mentioned way could "integrate" two screen together.

Tips: use $mod+d to run a command in a new window, so you don't have to launch an application from a terminal always.
   It is better not use shift or alt key when changing into windows workspace. It is found that the shift key can be "sticked" after switch so that single clicking the icon in the taskbar becomes not focusing the window, but open another new one.

#-----------------------------------------
make ati drivers work
in /usr/src/linux/.conf

# CONFIG_DRM_LOAD_EDID_FIRMWARE is not set
CONFIG_DRM_TTM=m         # this is newly added

#
# I2C encoder or helper chips
#
# CONFIG_DRM_I2C_CH7006 is not set
# CONFIG_DRM_I2C_SIL164 is not set
# CONFIG_DRM_I2C_NXP_TDA998X is not set
# CONFIG_DRM_TDFX is not set
# CONFIG_DRM_R128 is not set
CONFIG_DRM_RADEON=m         # this is newly added
# CONFIG_DRM_RADEON_UMS is not set
# CONFIG_DRM_NOUVEAU is not set


this is equivalent to
Processor type and features --->
<*> MTRR (Memory Type Range Register) support
Device drivers --->
   Graphics support --->
   <M> /dev/agpgart (AGP Support) --->
      (The agpgart option is not present on 64-bit kernels; just choose your chipset support.)
      <M> Intel 440LX/BX/GX, I8xx and E7x05 support
      (Enable your chipset instead of the above.)
   <M> Direct Rendering Manager (XFree86 4.1.0 and higher DRI support) --->
      <M> (Select your graphics card from the list)

at manual setup
#---------------------------------
can not find rxvt.
install rxvt



-----------------------change i3 as default manager-----------------
put
exec i3

in

~/.xinitrc

actually .xinitrc is the configureation file to specify which wm or de one wants to 

# -----------------add module on boot---
echo 'modules="dbus"' >>/etc/conf.d/modules
#---------------------------------------------


 ------- use mod+printscreen to cropscreen and save ----------------- 
Put the following lines in ~/.i3/config

bindsym  --release $mod+p exec --no-startup-id ~/Dropbox/scripts/scrot_s_2
bindsym  --release $mod+Print exec scrot -s -e 'mv $f ~/Pictures '

the content in ~/Dropbox/scripts/scrot_s_2 are

#!/bin/bash
scrot -s '%Y-%m-%d--%s_$wx$h_scrot.png' -e 'mv $f ~/Pictures'

--------------Make USB 2.0 work on client Windows--------------
1. install Virtualbox Guest Additions in the windows client
2. install Virtualbox extention pack from windows host. this can be done by executing

# emerge -av virtualbox-extpack-oracle
However, it is found that sometimes the installed atom can not be identified by Virtualbox system, as one can not see anything from File->preference->extentions. The way to solve this problem is to download the extention file from website and import the package from extention tab. Then the system will notice one extention has been installed.

--------------allow two virtual machine communicate-------------
There are three methods
Method 1:
(a) Run the following command
VBoxManage dhcpserver add --netname intnet --ip 10.0.1.1 --netmask 255.255.255.0 --lowerip 10.0.1.2 --upperip 10.0.1.200 --enable
(b) change the network adaptor into internal network, and make sure the name of the network is intnet.
(c) if one wants to have public access, e.g., internet, another adapter can be added with NAT network
The disadvantage of this method is the host computer can not access virtual machine at all.

Method 2
(a) choose


1.  make sure to reinstall nvidia and virtualbox after kernel update

my configureation in ~/.xinitrc is as follows
xmodmap ~/.Xmodmap &&
exec i3  --force-xinerama

eval "$(dbus-launch --sh-syntax --exit-with-session)"
export XMODIFIERS="@im=fcitx"
export QT_IM_MODULE=<module>
export GTK_IM_MODULE=<module>

every time I have to run xrdb ~/.Xresources to get the configuration of xterm right. However, sometimes it is needed to use win+shift+r to reload the i3wm as new terminal can not be generated by win+enter. Usually for the second time, everything would be fine.

Every time once new kernel is update, one needs to rebuild nvidia and virtualbox driver, respectively, after the new kernel gets booted.


For the nvidia driver one should do:
emerge -av --quiet-build=y nvidia-drivers

To check the status of the nvidia driver, one can do the following as root.
#journalctl -b |grep "nvidia"
#find /lib/modules -type f -name "nvidia.ko" -print
#eselect kernel list
see http://forums.gentoo.org/viewtopic-p-7591752.html#7591752 for details

If the above things were not done, one may not be able to go to x server using startx.

For the virtualbox, one should run
emerge -1 @module-rebuild
for m in vbox{drv,netadp,netflt}; do modprobe $m; done

Later after version 4.3.18, virtualbox has changed its lisence into PUEL. To further update this, one needs to do
ACCEPT_LICENSE="PUEL" emerge -av virtualbox-bin



-----------------map window key in guest to menukey-----------------
i3wm takes window key as the control key. this is a bit problematic for the guest windows as it is usual to use window key to map the windows.
This problem can be get around by map the win function in guest to other unused key, for example menukey. by using AutoHotkey app. only one liner in the configuration file is able to accomplish this:

Appskey::LWin

Remember to reload the configuration after putting in the mapping.


-----------------dual task bar in the guest windows-----------------
It is very normal to work in linux host in one screen, while windows guest in the other.
However, it is found that it is quite annoying when the guest windows doesn't have the window you want to see, to maximize the winodw, one has to go to the guest screen with task bars to nomalize it.
This issue can be convinently solved by installing dual monitor task bar, an open source application.
after the install, the window displayed in the specific screen will be listed in the bars.
n.  make trackpad less sensitive
following http://askubuntu.com/questions/483707/14-04-touchpad-is-too-sensitive
xinput set-prop "ETPS/2 Elantech Touchpad" "Synaptics Finger" 50 90 255
xinput set-prop "ETPS/2 Elantech Touchpad" "Synaptics Noise Cancellation" 20 20





Tuesday 3 September 2013

notes on installing gentoo with linux kernel 3.10 on toshiba laptop

When you learn Red Hat, you learn Red Hat, when you learn debian, you learn debian, when you learn Slackware/gentoo, you learn Linux

This is one of the reasons I decided to swap into slackware and gentoo.

different from mainstream linux which provides intall guides and be able to boot, gentoo has to be installed by chrooting from a working distro. now there are three stages to start from. however, it is suggested to be started from the stage three, as one didn't miss too much for the first two stages, together with the fact that it is very time consuming for the first two stages. I decided to start from the stage 3.

I used 


as installation guidance. it is very straightforward

here I just made some notes on the things that are be aware of during the installation:

1. it is suggested from the manual that one use minimal cd to install which provides all the required tools for compiling. However, I realized that using this approach can not connect to wifi still. therefore, I decided to use systemrescue cd and ubuntu. it turns out that both are almost the same, if one follows the instruction neatly.

2. it is also suggested from the manual that one separate /boot with /. i did that for my install. however, from the web, i do found that it is not necessary to do so if one don't want to. I will not install that in the next run.

3. commands

mount /dev/sda2 /mnt/gentoo
cd /mnt/gentoo/
mount -t proc proc /mnt/gentoo/proc   # required

it is still not clear why this is needed.


mount -o rbind /dev /mnt/gentoo/dev
mount -o rbind /sys /mnt/gentoo/sys   # needed

this two are very important --rbind sets /mnt/gentoo/dev to /dev recursively, so that the /dev at guest gentoo is equivalent to the host /dev. this is very important at the very beginning, because thereare not too much device working in the gentoo installation. also it is important because the linking file can point to the target properly

cp -L /etc/resolv.conf /mnt/gentoo/etc/
copy dns info

chroot /mnt/gentoo /bin/bash

remember once we rescue a crashed system (like scientificlinx) we use another medium to boot the pc and gain the root priviliage of the broken system and to work further.

source /etc/profile
export PS1="(gentoo) $PS1"

then we just follow the instruction to finish the installation. 

but the trouble part is how to install wifi driver in gentoo linux? mine is rtl8188. I tried to make driver downloaded from both rtl website and backports. but they all failed to install. (something like autoconf.h file do not exist any more. for backports, it is installed properly, but still may not be able to work) 
  later on I understood that after kernel 3. 8192 driver has been integrated into the kenel as modual. therefore, one has enable

CONFIG_RTLWIFI=m
CONFIG_RTL8192CE=m

at /usr/src/linux/.config file.

and recompile and install.

after that one still need

emerge linux-firmware 

to automatically find the driver

also one needs

ln /etc/init.d/net.lo /etc/init.d/net.wlp2s0
(wlp2s0 is the wifi name, which is not wlan0 as usual)

then one can use command 
/etc/init.d/net.wlp2s0 start
/etc/init.d/net.wlp2s0 restart

some useful commands for wifi
ifconfig wlp2s0 up
ethtool -i wlp2s0
iw wlp2s0 scan 
iwlist scan

other commands used during install
emerge htop
emerge net-wireless/wireless-tools
emerge app-editors/vim
emerge sys-apps/pciutils   # get ispci
emerge linux-firmware

emerge sync  #  apt-get update
emerge -DNu  world 
update-env
update-etc

so far the network is working, the next stage is just try to enrich the system and make it like a normal system.

another thing that needs to be aware is that once using wext driver in wpa_supplicant there are some problem, the wifi will not be connected. therefore, one has to use -Dnl8011 instead.

loss during install 1. two day working time 2. my windows 7 is mistakenly deleted during a install

#----------------------------------
make wicd work

# /etc/rc.d/dbus restart
# /etc/rc.d/wicd restart
# wicd-gtk


#--------------------------
wpa_supplicant -c /home/chenmingl/Desktop/wpa_supplicant.conf -i wlp2s0 -Dnl80211


make ati drivers work
in /usr/src/linux/.conf

# CONFIG_DRM_LOAD_EDID_FIRMWARE is not set
CONFIG_DRM_TTM=m         # this is newly added

#
# I2C encoder or helper chips
#
# CONFIG_DRM_I2C_CH7006 is not set
# CONFIG_DRM_I2C_SIL164 is not set
# CONFIG_DRM_I2C_NXP_TDA998X is not set
# CONFIG_DRM_TDFX is not set
# CONFIG_DRM_R128 is not set
CONFIG_DRM_RADEON=m         # this is newly added
# CONFIG_DRM_RADEON_UMS is not set
# CONFIG_DRM_NOUVEAU is not set


this is equivalent to
Processor type and features --->
<*> MTRR (Memory Type Range Register) support
Device drivers --->
   Graphics support --->
   <M> /dev/agpgart (AGP Support) --->
      (The agpgart option is not present on 64-bit kernels; just choose your chipset support.)
      <M> Intel 440LX/BX/GX, I8xx and E7x05 support
      (Enable your chipset instead of the above.)
   <M> Direct Rendering Manager (XFree86 4.1.0 and higher DRI support) --->
      <M> (Select your graphics card from the list)

at manual setup
#---------------------------------

if one wants to use wpa_managager, one has to stop dbus which supports networkmanager and wicd

/etc/init.d/dbus stop

#---make network manager work--------------------------------
# NetworkManager
# startx
#but the priviliage problem still exists, that is why i decided to go to gnome to try my luck

# the problem for wicd is if I run
# wicd
# wicd-gtk or wicd-client
the system didn't actually find network for it

there is a trick to work around this problem, which is to startx by root, set the wireless settings, then go back logon as normal user.


The problem for wpa_supplient is that it always connects and disconnects. which is very annoying

#------------------can not emerge  gnome-extra/gnome-user-docs----
this happens when I tries to emerge gnome
# MAKEOPTS=-j1 emerge -1 gnome-user-docs
#


#--------------------no GUI on VLC and virtualbox---------------
one has to ad qt4 in /etc/portage/make.conf file sothat it will be enabled.
#--------------------install chinese input in gentoo------------
now ibus does not have ebuild on ibus-table-wubi so we have to use another input method
Fcitx is a very good alternative for chinese input purpose.
but one has to be careful before installing that, one has to uninstall ibus completelly.
otherwise there will be problem in using ctrl+space to change input method.
#-------------------no sound problem after installing gentoo-----------------
once i came across a problem on sound card in gentoo.
I have installed the sound card properly in linux kernel,
and from lsmod, we can find the sound card module are properly loaded on boot
however, from pulsemixer I can not find any sound device.
it turns out to be a problem of the group. I need to add my user name to audio by
# usermod -a -G audio chenming

Saturday 24 August 2013

make videos by linux + PowerDirector

Recently I need to do a video project for my daughter's birthday. the project involves two chapters: the first chapter is to slide her photos with 0.2 seconds interval, each photos has approximately the same head size and eye position is close. The second chapter is to combine all of the interesting videos of her.


The first one is going to be massive if one uses gimp or photoshop to do that. therefore, I decided to use scripts to handle these problem. After digging, I found opencv in python and matlab has the function of finding faces from files. So I decided to use opencv as a start. I found a code (updated from http://stackoverflow.com/questions/13211745/detect-face-then-autocrop-pictures) I did further change so that each output file has put the face right in the middle with same size (translations and scaling)

here is the working scripts :


'''
Sources:
http://opencv.willowgarage.com/documentation/python/cookbook.html
http://www.lucaamore.com/?p=638
'''

#Python 2.7.2
#Opencv 2.4.2
#PIL 1.1.7

import cv #Opencv
import Image #Image from PIL
import glob
import os


# x correction
adj=0.05
# the width of output image
picx = 1024.1
# the height of output image
picy = 768.1
# the x ratio of picture in the whole output image
xpra=0.4
# the x ratio where picture starts
xra = (1-xpra-adj)/2
# the y ratio where picture starts
yra = (picy-xpra*picx)/picy/2



def DetectFace(image, faceCascade, returnImage=False):
    # This function takes a grey scale cv image and finds
    # the patterns defined in the haarcascade function
    # modified from: http://www.lucaamore.com/?p=638

    #variables    
    min_size = (200,200)
    haar_scale = 1.1
    min_neighbors = 3
    haar_flags = 0



    
    # Equalize the histogram
    cv.EqualizeHist(image, image)

    # Detect the faces
    faces = cv.HaarDetectObjects(
            image, faceCascade, cv.CreateMemStorage(0),
            haar_scale, min_neighbors, haar_flags, min_size
        )

    # If faces are found
    if faces and returnImage:
        for ((x, y, w, h), n) in faces:
            # Convert bounding box to two CvPoints
            pt1 = (int(x), int(y))
            pt2 = (int(x + w), int(y + h))
            cv.Rectangle(image, pt1, pt2, cv.RGB(255, 0, 0), 5, 8, 0)
    if returnImage:
        return image
    else:
        return faces

def pil2cvGrey(pil_im):
    # Convert a PIL image to a greyscale cv image
    # from: http://pythonpath.wordpress.com/2012/05/08/pil-to-opencv-image/
    pil_im = pil_im.convert('L')
    cv_im = cv.CreateImageHeader(pil_im.size, cv.IPL_DEPTH_8U, 1)
    cv.SetData(cv_im, pil_im.tostring(), pil_im.size[0]  )
    return cv_im

def cv2pil(cv_im):
    # Convert the cv image to a PIL image
    return Image.fromstring("L", cv.GetSize(cv_im), cv_im.tostring())

def imgCrop(image, cropBox, boxScale=1):
    # Crop a PIL image with the provided box [x(left), y(upper),
    # w(width), h(height)]

    # Calculate scale factors
    xDelta=max(cropBox[2]*(boxScale-1),0)
    yDelta=max(cropBox[3]*(boxScale-1),0)

    # Convert cv box to PIL box [left, upper, right, lower]
    PIL_box=[cropBox[0]-xDelta,
             cropBox[1]-yDelta,
             cropBox[0]+cropBox[2]+xDelta,
             cropBox[1]+cropBox[3]+yDelta]

    return image.crop(PIL_box)

def faceCrop(imagePattern,boxScale=1):
    # Select one of the haarcascade files:
    #   haarcascade_frontalface_alt.xml  <-- Best one?
    #   haarcascade_frontalface_alt2.xml
    #   haarcascade_frontalface_alt_tree.xml
    #   haarcascade_frontalface_default.xml
    #   haarcascade_profileface.xml
    faceCascade = cv.Load(
        '/usr/local/share/OpenCV/haarcascades/haarcascade_frontalface_alt.xml')
    #  faceCascade = cv.Load('haarcascade_frontalface_alt.xml')

    imgList=glob.glob(imagePattern)
    if len(imgList)<=0:
        print 'No Images Found'
        return

    for img in imgList:
        pil_im=Image.open(img)
        cv_im=pil2cvGrey(pil_im)
        faces=DetectFace(cv_im,faceCascade)
        if faces:
            n=1
            for face in faces:
               #  scale factor new/old
               scf=(picx*xpra)/face[0][3]
               #  new =old*scf
               rsx=int(pil_im.size[0]*scf)
               rsy=int(pil_im.size[1]*scf)
               resizedImage=pil_im.resize(
                   (rsx,rsy)
                   ,Image.ANTIALIAS)
               croppedImage=imgCrop(
                   resizedImage,
                   (int(face[0][0]*scf-xra*picx),int(face[0][1]*scf-yra*picy),int(picx),int(picy)),
#                   (int(face[0][0]*scf),int(face[0][1]*scf),int(picx),int(picy)),
#                   (int(face[0][0]*scf),int(face[0][1]*scf),int(face[0][2]*scf),int(face[0][3]*scf)),
                   boxScale=boxScale)  
               croppedImage2=imgCrop(pil_im, face[0],boxScale=boxScale)
               fname,ext=os.path.splitext(img)
               #resizedImage.save(fname+'_resized'+str(n)+ext)
               croppedImage.save(fname+'_r_c'+str(n)+ext)               
               croppedImage2.save(fname+'_cropori'+str(n)+ext)
               n+=1
        else:
            print 'No faces found:', img



            
def test(imageFilePath):
    pil_im=Image.open(imageFilePath)
    cv_im=pil2cvGrey(pil_im)
    # Select one of the haarcascade files:
    #   haarcascade_frontalface_alt.xml  <-- Best one?
    #   haarcascade_frontalface_alt2.xml
    #   haarcascade_frontalface_alt_tree.xml
    #   haarcascade_frontalface_default.xml
    #   haarcascade_profileface.xml
    faceCascade = cv.Load('haarcascade_frontalface_alt.xml')
    face_im=DetectFace(cv_im,faceCascade, returnImage=True)
    img=cv2pil(face_im)
    img.show()
    img.save('test.png')


# Test the algorithm on an image
#test('testPics/faces.jpg')

# Crop all jpegs in a folder. Note: the code uses glob which
# follows unix shell rules.
# Use the boxScale to scale the cropping area. 1=opencv box,
#    2=2x the width and height
#faceCrop('/home/debianchenming/Downloads/1/*.JPG',boxScale=1)
faceCrop('/media/D0CC0864CC0846E6/Portrait/secondtime/12-12-09/*.JPG',boxScale=1)