k(la)buntu Configuration

ประสบการณ์ลองถูกลองผิดมาเยอะ พบว่า อย่าไป remastersys สร้าง backup distro ใ่หม่เรยครับ

ผมชอบลง ubuntu สดๆ แล้ว run script ของผม ตามที่ผมต้องการมากกว่า ไม่เกิน 10 นาที ก็ recover มาเป็น style ที่ผมชอบแระ

ฉบับ 9.04 Jaunty Jackalope

แบ่ง Partitions

Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/sda1             14421344   3560896  10127888  27% /                 (35 GB)
/dev/sda2             38496500    248452  36292536   1% /home             (25 GB)
/dev/sda3            183405488    191800 173897196   1% /data             (191 GB)

Mount Partition

อ้างอิงจาก Mount Linux Partitions

  1. พิมพ์คำสั่งตามนี้ เพื่อหาว่า Device ไหนที่ต้องการจะ mount เช่น /dev/sda3
    $ sudo fdisk -l
    Disk /dev/sda: 250.0 GB, 250059350016 bytes
    255 heads, 63 sectors/track, 30401 cylinders
    Units = cylinders of 16065 * 512 = 8225280 bytes
    Disk identifier: 0x9ac49ac4
     
       Device Boot      Start         End      Blocks   Id  System
    /dev/sda1   *           1        1824    14651248+  83  Linux
    /dev/sda2            1825        6693    39110242+  83  Linux
    /dev/sda3            6694       29890   186329902+  83  Linux
    /dev/sda4           29891       30401     4104607+   5  Extended
    /dev/sda5           29891       30401     4104576   82  Linux swap / Solaris
  2. สร้าง mount point
    $ sudo mkdir /data
  3. หา UUID ของ Device ที่ต้องการจะ mount
    $ sudo blkid -o full -s UUID
  4. Backup ไฟล์ /etc/fstab แล้วเปิดไฟล์ขึ้นมาแก้ไข
    $ sudo cp /etc/fstab /etc/fstab.save
    $ sudo vi /etc/fstab
    เพิ่มข้อมูลตามนี้
    # /data was on /dev/sda3
    UUID=a0b3c386-1291-4d6f-89a1-c476c75b4fc5	/data	ext4	defaults	0        0
    
  5. ตามด้วยคำสั่ง
    $ sudo mount -a
    $ sudo chown -R klainfo:klainfo /data
    $ sudo chmod 775 -R /data

เป็นอันเสร็จสิ้นกระบวนการ

ลงโปรแกรมเบื้องต้น ตามนี้

อย่าลืมเปลี่ยนเป็น Mirror Kasetsart นะครับ

sudo mv /etc/apt/sources.list /etc/apt/sources.list.old
sudo wget http://mirror1.ku.ac.th/apt-ubuntu/10.10/sources.list -O /etc/apt/sources.list
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install vim-full mono-mcs mono-devel p7zip-full p7zip-rar checkgmail filezilla

ติดตั้ง DynDNS

เริ่มจาก ลงโปรแกรมพื้นฐานก่อน

$ sudo apt-get install ddclient ssh-server
ตามด้วย domainname username password และ “web” interface

ลอง restart service อีกครั้ง

$ sudo /etc/init.d/ddclient restart
ทดสอบ
$ ssh klainfo.mine.nu
ถ้าต้องการแก้ไขในภายหลัง
$ sudo vi /etc/ddclient.conf
$ sudo /etc/init.d/ddclient restart

Multimedia

$ sudo apt-get install gstreamer0.10-ffmpeg gstreamer0.10-plugins-ugly \
gstreamer0.10-plugins-ugly-multiverse gstreamer0.10-plugins-bad \
gstreamer0.10-plugins-bad-multiverse flashplugin-installer

Install Chromium

  1. add repository
    deb http://ppa.launchpad.net/chromium-daily/ppa/ubuntu karmic main
    
  2. update key
    gpg --keyserver keyserver.ubuntu.com --recv 5A9BF3BB4E5E17B5
    gpg --export --armor 5A9BF3BB4E5E17B5 | sudo apt-key add -
    sudo apt-get update
    sudo apt-get install chromium-browser
    

Install Acrobat Reader

$ sudo wget http://www.medibuntu.org/sources.list.d/hardy.list -O /etc/apt/sources.list.d/medibuntu.list
$ sudo apt-get update && sudo apt-get install medibuntu-keyring && sudo apt-get update
$ sudo apt-get install acroread

Ubuntu for Thinkpad(X61)

Driver for window
Complete source

#!/bin/bash
 
# TrackPoint Configuration
sudo dpkg -i thinkpad/configure-trackpoint_0.7-1_i386.deb
 
# Disable Bluetooth on StartUp
sudo chmod 666 /proc/acpi/ibm/bluetooth
sudo echo "disable" > /proc/acpi/ibm/bluetooth
 
# Enable Middle Button Scrolling
sudo cp $PWD/thinkpad/middlescrolling/mouse-wheel.fdi /etc/hal/fdi/policy/mouse-wheel.fdi
sudo apt-get install --yes -f wacom-tools
sudo cp $PWD/thinkpad/middlescrolling/custom-wacom.fdi /etc/hal/fdi/policy/custom-wacom.fdi
sudo cp $PWD/thinkpad/middlescrolling/wacom /etc/init.d/wacom
sudo chmod +x /etc/init.d/wacom
sudo ln -s /etc/init.d/wacom /etc/rc5.d/S27wacom
sudo ln -s /etc/init.d/wacom /etc/rc4.d/S27wacom
sudo ln -s /etc/init.d/wacom /etc/rc3.d/S27wacom
sudo ln -s /etc/init.d/wacom /etc/rc2.d/S27wacom
 
sudo cp $PWD/thinkpad/middlescrolling/10-wacom.fdi /usr/share/hal/fdi/policy/20thirdparty/10-wacom.fdi
 
echo "Please, Reboot"
echo "usage: $ sudo shutdown -r now"
 
# install fingerprint
#!/bin/bash
sudo apt-key adv --recv-keys --keyserver keyserver.ubuntu.com F2A12FABE936A7BBDC4EA33351DB180D1323E149
 
sudo echo "deb http://ppa.launchpad.net/jon-oberheide/ppa/ubuntu jaunty main
deb-src http://ppa.launchpad.net/jon-oberheide/ppa/ubuntu jaunty main" >> /etc/apt/sources.list
 
sudo apt-get update
sudo apt-get install --yes thinkfinger-tools libpam-thinkfinger
echo "Initiated as root"
sudo tf-tool --acquire 
sudo tf-tool --verify 
echo "Enable thinkfinger"
sudo /usr/lib/pam-thinkfinger/pam-thinkfinger-enable
echo "Add user (klainfo)"
tf-tool --acquire klainfo
 
echo "Change Login Window
  - Tab Local -> select 'Themed with face browser and Selected Only' 
  - relogin"
 
# setup fingerprint
#!/bin/bash
 
USERNAME=$1
 
if [ x$USERNAME = x ]; then
	echo "usage: ./fingerauth username"
	exit 0
fi
 
tf-tool --add-user $USERNAME
#gpasswd -a $USERNAME fingerprint
chown $USERNAME:root /etc/pam_thinkfinger/$USERNAME.bir
chmod 400 /etc/pam_thinkfinger/$USERNAME.bir

Disable Bluetooth on Startup

  1. edit /etc/rc.local and add before 'exit 0':
    chmod 666 /proc/acpi/ibm/bluetooth 
    echo "disable" > /proc/acpi/ibm/bluetooth

Setup the Middle Button Scrolling

  1. Create a new file called /etc/hal/fdi/policy/mouse-wheel.fdi typing:
    sudo gedit /etc/hal/fdi/policy/mouse-wheel.fdi
  2. And fill it with this code:
    <?xml version="1.0" encoding="UTF-8"?> 
    <match key="info.product" string="TPPS/2 IBM TrackPoint">
        <merge key="input.x11_options.EmulateWheel" type="string">true</merge>
        <merge key="input.x11_options.EmulateWheelButton" type="string">2</merge>
        <merge key="input.x11_options.XAxisMapping" type="string">6 7</merge>
        <merge key="input.x11_options.YAxisMapping" type="string">4 5</merge>
        <merge key="input.x11_options.ZAxsisMapping" type="string">4 5</merge>
        <merge key="input.x11_options.Emulate3Buttons" type="string">true</merge>
    </match>
  3. Reboot

http://thesopebocks.com/2009/05/07/the-new-xorg-and-your-tablet-pc/

Setup_Fingerprint_Reader

ยังไม่เจอวิธีที่ประสบความสำเร็จเลย

Change keymap

Mapping F1 as Esc

  1. lookup the keycode F1 and Esc
    $ xev
    or
    $ xmodmap -pke | less
  2. change it
    $ xmodmap -e 'keycode 67 = Escape'

Ubuntu Server

Set Static IP Address

  1. ค้นหา ip address สังเกตุคำว่า “inet addr:158.108.213.126”
    $ ifconfig eth0
    eth0      Link encap:Ethernet  HWaddr 00:08:a1:91:08:a4  
              inet addr:158.108.213.126  Bcast:158.108.213.127  Mask:255.255.255.128
              inet6 addr: fe80::208:a1ff:fe91:8a4/64 Scope:Link
              UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
              RX packets:130315 errors:0 dropped:0 overruns:0 frame:0
              TX packets:71707 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:1000 
              RX bytes:40944583 (40.9 MB)  TX bytes:10263714 (10.2 MB)
              Interrupt:17 Base address:0x9000
  2. ค้นหา subnet mask และ gateway
    $ route -n
    Kernel IP routing table
    Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
    158.108.213.0   0.0.0.0         255.255.255.128 U     0      0        0 eth0
    169.254.0.0     0.0.0.0         255.255.0.0     U     1000   0        0 eth0
    0.0.0.0         158.108.213.1   0.0.0.0         UG    100    0        0 eth0
  3. เปิดไฟล์ /etc/network/interfaces
    auto lo
    iface lo inet loopback
    iface eth0 inet static
    address 158.108.213.126
    netmask 255.255.255.128
    gateway 158.108.213.1
    auto eth0
    

Change Welcome Message after SSH_login

  1. edit welcome message
    $ sudo vi /etc/motd
  2. edit config file with root

    /etc/ssh/sshd_config

    PrintLastLog no
    
  3. restart ssh service
    $ sudo /etc/init.d/ssh restart

Change hostname

  1. lookup the hostname
    $ hostname
  2. edit

    /etc/hosts

    127.0.0.1       localhost
    127.0.1.1       newhostname
    
    # The following lines are desirable for IPv6 capable hosts
    ::1     localhost ip6-localhost ip6-loopback
    fe00::0 ip6-localnet
    ff00::0 ip6-mcastprefix
    ff02::1 ip6-allnodes
    ff02::2 ip6-allrouters
    ff02::3 ip6-allhosts
    Change “127.0.1.1 klainfo-desktop” to “127.0.1.1 newhostname”
  3. restart network
    $ sudo /etc/init.d/networking restart

เปิดบริการ mod_rewrite และ .htaccess

  1. enabled mod_rewrite ก่อน
    $ sudo a2enmod rewrite
  2. เปิดไฟล์ 000-default เปลี่ยนจาก “AllowOverride None” เป็น “AllowOverride All” เพื่อให้ .htaccess ทำงาน
    $ sudo vi /etc/apache2/sites-enabled/000-default
  3. Restart Apache จิ๊ดนุง
    $ sudo /etc/init.d/apache2 restart
  4. เปลี่ยนจาก “AllowOverride None” เป็น “AllowOverride All” เพื่อให้ .htaccess ทำงาน จะได้ Code หน้าตาประมาณนี้
    <VirtualHost *:80>
            ServerAdmin webmaster@localhost
    	ServerName localhost
    	DocumentRoot /var/www
    	<Directory /var/www/>
    		Options Indexes FollowSymLinks MultiViews
    		AllowOverride All
    		Order allow,deny
    		allow from all
    	</Directory>
    </VirtualHost>
    
  5. Restart Apache อีกครั้ง
    $ sudo /etc/init.d/apache2 restart
  6. ทดสอบที่ index.php
    <?php echo phpinfo(); ?>

อ้างอิง AllowOverride หมายถึง อนุญาติให้ใช้ไฟล์ .htaccess [http://httpd.apache.org/docs/2.0/mod/core.html#allowoverride]

Enabling access http://localhost/~username

  1. $ a2enmod userdir
  2. edit /etc/apache2/apache2.conf and add the following lines :
    <IfModule mod_userdir.c>
        UserDir public_html
    </IfModule>
    
    <Directory /home/*/public_html>
        AllowOverride FileInfo AuthConfig Limit
        Options Indexes SymLinksIfOwnerMatch IncludesNoExec
    </Directory>
    
  3. execute the following commands
    $ cd /etc/apache2/mods-enabled
    $ sudo ln -s /etc/apache2/mods-available/userdir.conf userdir.conf
    $ sudo ln -s /etc/apache2/mods-available/userdir.load userdir.load
  4. restart apache
    $ sudo /etc/init.d/apache2 restart

User and Group Management

Ref http://www.yolinux.com/TUTORIALS/LinuxTutorialManagingGroups.html มี 2 วิธี

  1. วิธีแรก
    $ sudo useradd -md /home/klainfo  klainfo -s /bin/bash -G staff
    $ sudo passwd klainfo
  2. วิธีที่สองแบบอัตโนมัติ
    $ sudo adduser klainfo
  3. set owner และ group id
    $ sudo chown pamon:staff -R /home/pamon

/etc/passwd

Format

user-name:x:user-number:group-number:comment section:/home-directory:default-shell
เช่น
klainfo:x:1000:1000:klainfo,707,029343577,029343577:/home/klainfo:/bin/bash
Default-shell ควรเป็น /bin/bash

/etc/group

Format

group-name:x:group-number:user1,user2
เช่น
staff:x:1000:klainfo,pamon

Subversion via http

  1. ติดตั้ง
    $ sudo apt-get install subversion libapache2-svn apache2
  2. ตรวจดูว่า apache ได้ enable โมดูล dav_svn ไว้ให้แล้วหรือยัง(โดย default จะ enable ไว้แล้ว)
    $ a2enmod dav_svn
    Considering dependency dav for dav_svn:
    Module dav already enabled
    Module dav_svn already enabled
  3. แก้ config ของ svn ที่ทำงานบน apache

    /etc/apache2/mods-enabled/dav_svn.conf

     
    # เรียกใ้ช้งานผ่าน http://domainname.com/svn/reponame
    <Location /svn> # sub ที่เรียกผ่าน host
      DAV svn
      # ให้เลือกเอาอย่างใดอย่างหนึ่งว่าจะให้เป็น svn parent path หรือ svn path ไปเลย
      # svn parent path สามารถใช้งานได้หลายๆ repository 
      # svn path เป็นการระบุให้สามารถใช้งานได้เพียง repository เดียว
      #SVNPath /home/svn
      SVNParentPath /data/svn
      
      # หากต้องการใช้ตรวจสอบผู้ใช้งาน
      AuthType Basic
      AuthName "Subversion Repository"
      AuthUserFile /etc/apache2/dav_svn.passwd
    
      # หากต้องการ ควบคุมการเข้าถึงของ user
      AuthzSVNAccessFile /etc/apache2/dav_svn.authz
    
      Require valid-user
    </Location>
    
  4. สร้างไฟล์เพื่อเก็บ user และ password ถ้าเคยสร้างไว้แล้วไม่ต้องมี c(create)
    $ htpasswd -cm /etc/apache2/dav_svn.passwd ชื่อuser
  5. สร้างไฟล์เพื่อกำหนด permission ในการเข้าถึงแต่ละ repository

    /etc/apache2/dav_svn.authz

    [groups]
    master=eiei, eueu
    
    [/]
    @master=rw
    
    [test1:/]
    eaea=rw
    
    [test2:/]
    * = r
    
    [test3:/eueu]
    eueu=rw
    
    หมายเหตุ:
    eiei eueu eaea คือ ชื่อ user
    master คือ ชื่อ group
    test1 test2 test3 คือ ชื่อของ repository
    [/] คือ ตั้งแต่ ParentPath
    [test3:/eueu] คือ directory ชื่อ eueu ที่อยู่ใน repository test3 
    
  6. สร้าง repository และกำหนดเจ้าของให้เป็น www-data
    $ mkdir /data/svn
    $ svnadmin create /data/svn/test1
    $ chown -R www-data: /data/svn/test1
  7. restart apache2
    $ sudo /etc/init.d/apache2 restart
  8. เรียกใช้งานที่เครื่อง Client ตามนี้ เช่น
    $ svn co http://grid.klainfo.com/svn/111

Additional

Convert TIS-620 to UTF-8

for file in `ls *.html` 
do
    iconv -f tis-620 -t utf-8 $file > ../test/$file
    sed '15i <meta http-equiv="Content-Type" content="text/html; charset=utf-8">' $file
done

แก้ปัญหาสระลอยใน Firefox

Batch resize images with the ImageMagick mogrify command

ต้องการรู้ว่าลีนุกซ์อะไร เวอร์ชันไหน

lsb_release -a

ต้องการรู้ว่า Encoding ของไฟล์คืออะไร

file -i <filename>

 
ubuntu.txt · Last modified: 2010/10/06 15:22 by klainfo · [Old revisions]
Recent changes RSS feed Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki