Search

Friday, January 21, 2011

Common Linux Problems and Answers

Common Linux problems and answers, written as write's experience
enviroment  : Fedora 14 minimum installation. GNOME desktop environment.



Partition Automount
auto mounting non-system partition, eq : windows NTFS partition.
Can be achieved by :
  • /etc/fstab. The disadvatage is regardless of how infrequently a user accesses the NFS mounted file system, the system must dedicate resources to keep the mounted file system in place. This is not a problem with one or two mounts, but when the system is maintaining mounts to many systems at one time, overall system performance can be affected
  • kernel based automount utility, consists of two components :
    • a kernel module that implements a file system
    • a user space daemon that performs all of the other functions
sources :
http://docs.fedoraproject.org/en-US/Fedora/14/html/Storage_Administration_Guide/s1-nfs-client-config-autofs.html

Automount Internal Partitions Without Root Authorization
I have 2 windows partitions  (NTFS ) in my laptop's hardisk. Those partitions by default are automounted, they always appear in my GNOME's explorer. The problem is that accessing each partitions is requiring root (super user) password each time machine reboot. Steps below is to keep both partitions remain active each time Linux system restart.
  • use console, login as super user 
    • su
  • change directory to /usr/share/polkit-1/actions and copy (as backup in case anything goes wrong) file org.freedesktop.udisks.policy
    • cd /usr/share/polkit-1/actions
    • cp -p org.freedesktop.udisks.policy org.freedesktop.udisks.policy.default
  • Find xml block that define internal partition, started with lines below
    • <action id="org.freedesktop.udisks.filesystem-mount-system-internal">
    • <description>Mount  a system-internal device</description>
  • Edit file org.freedesktop.udisks.policy to keep internal partition active. Change activation state from auth_admin_keep to yes.
    • <allow_active>auth_admin_keep</allow_active>
    • <allow_active>yes</allow_active>
Logout to test the effect. Now our system internal device will be mounted without necessity to supply system with root password. However to activate, related mounted device must be selected first (eq : by selecting in Dolphin explorer). To auto-list (activate) internal device follow next instructions.

List Open Files on a System Internal Device

  • Login in as super user (root)
  • Open file   /usr/share/polkit-1/actions/org.freedesktop.udisks.policy
  • Find xml block that define list open files, started with lines below
  • <action id="org.freedesktop.udisks.filesystem-lsof-system-internal">
  • Edit line
<allow_active>auth_admin_keep</allow_active> 
to
<allow_active>yes</allow_active>


Kill Background Task  via Console
Find out the process ID (PID)
# ps -f
Kill application 
# kill <process_id>

Search and Replace Text by Pattern in Files / Directories
Using find and sed via linux command console.
Search by pattern (regex) for string 'testing' replace with 'pass' while maintain 'ing' in all '*.php' files in current directory :

# find -name '*.php' -exec sed -i 's/test\(ing\)/pass\1/' {}  \;
Replacing all string '<? ' with '<?php ' in all php files within a current  directory. There are 2 types of '<?' to be removed. '<?' that followed by space '\s' and followed by end of line '$'. Must be careful not to replace string that already '<?php'.
At first I tried to use pipeline as OR Regex statement, which didn't worked :
# find -name '*.php' -exec sed -i 's/<?\(\s|$\)/<?php/' {} \;
Workaround for this is to use 2 separate commands for each '<?' type :
# find -name '*.php' -exec sed -i 's/<?\(\s\)/<?php/' {} \; 
# find -name '*.php' -exec sed -i 's/<?\($\)/<?php/' {} \;
Commands above succeed to replace opening PHP tags '<?', followed by space and end of line,
 to '<?php' then followed by space or end of line.

source : http://www.grymoire.com/Unix/Sed.html

Create batch command in sh file
Create a text file with sh extension, lets say test.sh. Make sure that file is executable, check the permission setting.
Edit test.sh, put : #! /bin/sh.
That's it !
Now you can add all the console command you want to add in that text file.


Restore GNOME (top) panel
In Gnome, panel is bar/place to put application launcher and immediate information in desktop. By default there are 2 panels, top panel and bottom panel.

  1. Run gnome-terminal : Press Alt + F2 and type    gnome-terminal   in dialog box. This will run console terminal in /home/user directory.
  2. type in   gconftool-2 --shutdown
  3. type in   rm -rf ~/.gconf/apps/panel
  4. type in   pkill gnome-panel
  5. (top) panel will immediately show up.

source : http://albertsiow.wordpress.com/2008/06/26/restore-panel-bartop-in-ubuntu-gnome/


Cool Linux Sources ( for beginners )
http://lowfatlinux.com

No comments:

Post a Comment