1. คุณต้องรู้ว่า directory driver เป็นอะไร
2. ใช้คำสั้ง umount ด้วยสิทธิที่ ใกล้เคียง root "sudo umount /dev/xxx" ในที่นี้ ใช้ sda1
3. ใช้คำสั้ง เพื่อทำการ format "sudo mkfs.vfat -n 'tapi' -I /dev/sdb1
แสดงบทความที่มีป้ายกำกับ TIP UBUNTU แสดงบทความทั้งหมด
แสดงบทความที่มีป้ายกำกับ TIP UBUNTU แสดงบทความทั้งหมด
วันพุธที่ 15 มิถุนายน พ.ศ. 2554
วันจันทร์ที่ 2 พฤษภาคม พ.ศ. 2554
shell script backup
First you need to connect your external hard drive and then mount it. Assuming you’ve done so already, here’s the backup script.
#! /bin/bash
echo Backup Started `date` >> ~/backuplog
mkdir /mnt/usbdrive/backups/`date +%Y%m%d`
tar -czf /mnt/usbdrive/backups/`date +%Y%m%d`/data.tar.gz /data
echo Backup Completed `date` >> ~/backuplog
The first line tells the script that is is using the BASH shell, which is located in /bin/bash on the file server. This is the standard location on nearly any UNIX machine.
The second line tells the script to write a line to a log file (located in our users home directory by specifying the tilde ~ ) with the days date. This log file can be referenced to ensure that the backup is completed each day.
The third line will create the folder on our mounted usbdrive, in the backups folder with the days date in the format YYYYMMDD (example: 20060915).
The fourth line actually creates the backup. On our file server we have created the folder /data where we store everything. We have multiple directories within the data folder for clients, internal documentation, resources, etc… and everything in that folder is compressed into an archive file using the tar command. The file is given the name data.tar.gz.
Finally, the fifth line writes a line to the backuplog telling us that the backup was completed and at what time.
NOTE: You must save this file somewhere on your computer, we recommend in the bin folder of your home directory, and you must give it execute permissions. If you want all users to be able to run the script, you need to use the chmod a+x command, if you want to keep it to yourself, then use the chmod u+x command. S, with it being saved in our home folder’s bin directory we type at the shell terminal:
chmod u+x /home/username/bin/backup
To run the script, simply type: backup from the terminal. Because we placed it in our bin directory (which is in our user’s execute path by default) the system looks there to execute the file. The entire process takes between one and two hours, and using a cronjob we have set this up to run automatically at noon everyday.
00 12 * * 1-5 /home/username/bin/backup
This CRON statement tells the operating system to run the backup command, which is located in the bin directory of the user’s home folder, at 12:00 noon, monday to friday. (We TRY to take weekends off so there isn’t a need for backups).
Now we have a simple script in place that will create a compressed archive of all our sensitive information on a daily basis and store it on our external hard drive.
////////////////////////////////////////////////////////////////////////////////////////
Backup script for Linux using tar and find
Every Linux distribution provides a range of utilities that you can use to make backups of your files. Here is the how I get the job done with crontab and a shell script using tar and find
Goal
I wanted to secure all the data-files on my system on a regular basis. Regular for me implies on an automated basis. I've tried doing a manual backup every week or so but that caused too much hassle, so effectively I stopped making backups....
Further, I wanted to have an up-to-date backup of the most essential configuration settings on my system. This would help me in case I accidentally lost some datafiles or setting on my system. In case of losing everything I would need to reinstall my Linux distribution (plus extra installed software) and restore data files and settings. I decided that a full backup of the whole system wouldn't be worth the effort (and resources!).
Choice of hardware
Say "backup" and most Unix people think "tapedrive". However, nowadays harddrives come that cheap that I chose to add an extra harddrive to my AMD 400 machine. This cheap option has the advantage that a harddrive can be mounted automatically, no need for manually inserting tapes. A disadvantage is that the backup resides in the same physical unit as the very data it is supposed to secure. However, since I do have a CD-writer om my local network I still have the option to copy a backup to a CD once in a while.
My main HD is 6Mb. The backup HD has 10Mb.
Script
After adding the drive to my machine I wrote a little shell script (for bash) that basically does the following:
* it mounts my backupdrive
* it checks the date
* every sunday it makes a full backup of some datafiles and some configuration settings, older incremental backups are removed. other days it backups files that have been accessed the last day
* it dumps all the contents of a mysql database to the backup drive and zips the file
* it unmounts the backup drive
This script (I've stored it in /root/scripts) is called every night at 3:01 AM by cron. The crontab file looks like:
1 3 * * * /root/scripts/daily_backup
Add this line using contab -e when root.
Code
Here's the actual code:
#!/bin/bash
#
# creates backups of essential files
#
DATA="/home /root /usr/local/httpd"
CONFIG="/etc /var/lib /var/named"
LIST="/tmp/backlist_$$.txt"
#
mount /mnt/backup
set $(date)
#
if test "$1" = "Sun" ; then
# weekly a full backup of all data and config. settings:
#
tar cfz "/mnt/backup/data/data_full_$6-$2-$3.tgz" $DATA
rm -f /mnt/backup/data/data_diff*
#
tar cfz "/mnt/backup/config/config_full_$6-$2-$3.tgz" $CONFIG
rm -f /mnt/backup/config/config_diff*
else
# incremental backup:
#
find $DATA -depth -type f \( -ctime -1 -o -mtime -1 \) -print > $LIST
tar cfzT "/mnt/backup/data/data_diff_$6-$2-$3.tgz" "$LIST"
rm -f "$LIST"
#
find $CONFIG -depth -type f \( -ctime -1 -o -mtime -1 \) -print > $LIST
tar cfzT "/mnt/backup/config/config_diff_$6-$2-$3.tgz" "$LIST"
rm -f "$LIST"
fi
#
# create sql dump of databases:
mysqldump -u root --password=mypass --opt mydb > "/mnt/backup/database/mydb_$6-$2-$3.sql"
gzip "/mnt/backup/database/mydb_$6-$2-$3.sql"
#
umount /mnt/backup
Discussion
data files:
All my data files are in /root, /home or /usr/local/httpd.
settings:
I chose to backup all the setting in /etc (where most essential settings are stored), /var/named (nameserver settings) and /var/lib (not sure about the importance of this one...). I might need to add more to the list but I still far from being a Unix-guru ;-). All suggestions are welcome!
tar versus cpio
The first version of this script used cpio to create backups iso tar. However, I found the cpio format not very handy for restoring single files so I chang ed it to tar. A disadvantage of using tar is that you can't (as far as I know) simply pipe the output of a find to it.
Using a construct like tar cvfz archive.tgz `find /home -ctime -1 -depth -print` caused errors for files that contained a space " " character. This problem was solved by wring the output of find to a file first (and using tar with the -T option).
#! /bin/bash
echo Backup Started `date` >> ~/backuplog
mkdir /mnt/usbdrive/backups/`date +%Y%m%d`
tar -czf /mnt/usbdrive/backups/`date +%Y%m%d`/data.tar.gz /data
echo Backup Completed `date` >> ~/backuplog
The first line tells the script that is is using the BASH shell, which is located in /bin/bash on the file server. This is the standard location on nearly any UNIX machine.
The second line tells the script to write a line to a log file (located in our users home directory by specifying the tilde ~ ) with the days date. This log file can be referenced to ensure that the backup is completed each day.
The third line will create the folder on our mounted usbdrive, in the backups folder with the days date in the format YYYYMMDD (example: 20060915).
The fourth line actually creates the backup. On our file server we have created the folder /data where we store everything. We have multiple directories within the data folder for clients, internal documentation, resources, etc… and everything in that folder is compressed into an archive file using the tar command. The file is given the name data.tar.gz.
Finally, the fifth line writes a line to the backuplog telling us that the backup was completed and at what time.
NOTE: You must save this file somewhere on your computer, we recommend in the bin folder of your home directory, and you must give it execute permissions. If you want all users to be able to run the script, you need to use the chmod a+x command, if you want to keep it to yourself, then use the chmod u+x command. S, with it being saved in our home folder’s bin directory we type at the shell terminal:
chmod u+x /home/username/bin/backup
To run the script, simply type: backup from the terminal. Because we placed it in our bin directory (which is in our user’s execute path by default) the system looks there to execute the file. The entire process takes between one and two hours, and using a cronjob we have set this up to run automatically at noon everyday.
00 12 * * 1-5 /home/username/bin/backup
This CRON statement tells the operating system to run the backup command, which is located in the bin directory of the user’s home folder, at 12:00 noon, monday to friday. (We TRY to take weekends off so there isn’t a need for backups).
Now we have a simple script in place that will create a compressed archive of all our sensitive information on a daily basis and store it on our external hard drive.
////////////////////////////////////////////////////////////////////////////////////////
Backup script for Linux using tar and find
Every Linux distribution provides a range of utilities that you can use to make backups of your files. Here is the how I get the job done with crontab and a shell script using tar and find
Goal
I wanted to secure all the data-files on my system on a regular basis. Regular for me implies on an automated basis. I've tried doing a manual backup every week or so but that caused too much hassle, so effectively I stopped making backups....
Further, I wanted to have an up-to-date backup of the most essential configuration settings on my system. This would help me in case I accidentally lost some datafiles or setting on my system. In case of losing everything I would need to reinstall my Linux distribution (plus extra installed software) and restore data files and settings. I decided that a full backup of the whole system wouldn't be worth the effort (and resources!).
Choice of hardware
Say "backup" and most Unix people think "tapedrive". However, nowadays harddrives come that cheap that I chose to add an extra harddrive to my AMD 400 machine. This cheap option has the advantage that a harddrive can be mounted automatically, no need for manually inserting tapes. A disadvantage is that the backup resides in the same physical unit as the very data it is supposed to secure. However, since I do have a CD-writer om my local network I still have the option to copy a backup to a CD once in a while.
My main HD is 6Mb. The backup HD has 10Mb.
Script
After adding the drive to my machine I wrote a little shell script (for bash) that basically does the following:
* it mounts my backupdrive
* it checks the date
* every sunday it makes a full backup of some datafiles and some configuration settings, older incremental backups are removed. other days it backups files that have been accessed the last day
* it dumps all the contents of a mysql database to the backup drive and zips the file
* it unmounts the backup drive
This script (I've stored it in /root/scripts) is called every night at 3:01 AM by cron. The crontab file looks like:
1 3 * * * /root/scripts/daily_backup
Add this line using contab -e when root.
Code
Here's the actual code:
#!/bin/bash
#
# creates backups of essential files
#
DATA="/home /root /usr/local/httpd"
CONFIG="/etc /var/lib /var/named"
LIST="/tmp/backlist_$$.txt"
#
mount /mnt/backup
set $(date)
#
if test "$1" = "Sun" ; then
# weekly a full backup of all data and config. settings:
#
tar cfz "/mnt/backup/data/data_full_$6-$2-$3.tgz" $DATA
rm -f /mnt/backup/data/data_diff*
#
tar cfz "/mnt/backup/config/config_full_$6-$2-$3.tgz" $CONFIG
rm -f /mnt/backup/config/config_diff*
else
# incremental backup:
#
find $DATA -depth -type f \( -ctime -1 -o -mtime -1 \) -print > $LIST
tar cfzT "/mnt/backup/data/data_diff_$6-$2-$3.tgz" "$LIST"
rm -f "$LIST"
#
find $CONFIG -depth -type f \( -ctime -1 -o -mtime -1 \) -print > $LIST
tar cfzT "/mnt/backup/config/config_diff_$6-$2-$3.tgz" "$LIST"
rm -f "$LIST"
fi
#
# create sql dump of databases:
mysqldump -u root --password=mypass --opt mydb > "/mnt/backup/database/mydb_$6-$2-$3.sql"
gzip "/mnt/backup/database/mydb_$6-$2-$3.sql"
#
umount /mnt/backup
Discussion
data files:
All my data files are in /root, /home or /usr/local/httpd.
settings:
I chose to backup all the setting in /etc (where most essential settings are stored), /var/named (nameserver settings) and /var/lib (not sure about the importance of this one...). I might need to add more to the list but I still far from being a Unix-guru ;-). All suggestions are welcome!
tar versus cpio
The first version of this script used cpio to create backups iso tar. However, I found the cpio format not very handy for restoring single files so I chang ed it to tar. A disadvantage of using tar is that you can't (as far as I know) simply pipe the output of a find to it.
Using a construct like tar cvfz archive.tgz `find /home -ctime -1 -depth -print` caused errors for files that contained a space " " character. This problem was solved by wring the output of find to a file first (and using tar with the -T option).
Backup และ Restore ฐานข้อมูลผ่าน command
การ Backup และ Restore ฐานข้อมูลผ่าน command lineในการสำรองข้อมูล (Backup) หรือการคืนค่าข้อมูล (Restore) หลายท่านน่าจะเคยทำผ่าน web application เช่น phpMyAdmin มาบ้างแล้ว แต่ด้วยข้อจำกัดของ HTTP นั้นจะมีปัญหาสำหรับฐานข้อมูลที่มีขนาดใหญ่ ดังนั้นการใช้คำสั่งผ่าน command line นั้นจึงมีประสิทธิภาพมากที่สุด
การสำรองข้อมูลใน MySQL นั้นทางผู้พัฒนาเองได้ให้เครื่องมือช่วยมาด้วยชื่อว่า mysqldump สามารถทำการสำรองข้อมูลตามต้องการได้ โดยการใช้งานสั่งได้โดยทำงานผ่าน command line โดยมีรูปแบบ
BASH
mysqldump -u [username] -p[password] [database] > [filename]
ตัวอย่างการใช้งานเช่น
BASH
mysqldump -u root -pMyPass test > backup.sql
เป็นลักษณะการสั่งให้สำรองฐานข้อมูลลงในไฟล์ ในระบบปฎิบัติการ Unix/Linux นั้นเราสามารถใช้คำสั่งบีบอัดร่วมได้เช่น
BASH
mysqldump -u root -pMyPass test | gzip > backup.sql.gz
หรือ
BASH
mysqldump -u root -pMyPass test | bzip2 > backup.sql.bz2
และยังเรายังสามารถสำรองฐานข้อมูลทั้งหมดด้วย
BASH
mysqldump -u root -pMyPass --all-databases | gzip > backup.sql.gz
และยังมีค่าอื่นเพื่อระบุรูปแบบได้ตามต้องการ เช่น
--add-drop-table เพื่อสั่งให้ drop ตารางที่มีอยู่ก่อน
--no-data เพื่อสั่งให้สำรองเฉพาะโครงสร้างของตาราง
--add-locks เพื่อสั่งให้มีการล็อคตารางและคลายล็อคตาราง
ส่วนการคืนค่าข้อมูลก็สามารถทำได้ด้วยการใช้คำสั่ง mysql มีรูปแบบการใช้งาน
BASH
mysql -u [username] -p[password] [database] < backup.sql
ตัวอย่างการใช้งานเช่น
BASH
mysql -u root -pMyPass test < backup.sql
ส่วนถ้าเป็นไฟล์บีบอัดเช่น
BASH
gunzip < backup.sql.gz | mysql -u root -pMyPass test
หรือ
BASH
bzip2 < backup.sql.bz2 | mysql -u root -pMyPass test
หวังว่าจะมีประโยชน์สำหรับทุกท่าน
การสำรองข้อมูลใน MySQL นั้นทางผู้พัฒนาเองได้ให้เครื่องมือช่วยมาด้วยชื่อว่า mysqldump สามารถทำการสำรองข้อมูลตามต้องการได้ โดยการใช้งานสั่งได้โดยทำงานผ่าน command line โดยมีรูปแบบ
BASH
mysqldump -u [username] -p[password] [database] > [filename]
ตัวอย่างการใช้งานเช่น
BASH
mysqldump -u root -pMyPass test > backup.sql
เป็นลักษณะการสั่งให้สำรองฐานข้อมูลลงในไฟล์ ในระบบปฎิบัติการ Unix/Linux นั้นเราสามารถใช้คำสั่งบีบอัดร่วมได้เช่น
BASH
mysqldump -u root -pMyPass test | gzip > backup.sql.gz
หรือ
BASH
mysqldump -u root -pMyPass test | bzip2 > backup.sql.bz2
และยังเรายังสามารถสำรองฐานข้อมูลทั้งหมดด้วย
BASH
mysqldump -u root -pMyPass --all-databases | gzip > backup.sql.gz
และยังมีค่าอื่นเพื่อระบุรูปแบบได้ตามต้องการ เช่น
--add-drop-table เพื่อสั่งให้ drop ตารางที่มีอยู่ก่อน
--no-data เพื่อสั่งให้สำรองเฉพาะโครงสร้างของตาราง
--add-locks เพื่อสั่งให้มีการล็อคตารางและคลายล็อคตาราง
ส่วนการคืนค่าข้อมูลก็สามารถทำได้ด้วยการใช้คำสั่ง mysql มีรูปแบบการใช้งาน
BASH
mysql -u [username] -p[password] [database] < backup.sql
ตัวอย่างการใช้งานเช่น
BASH
mysql -u root -pMyPass test < backup.sql
ส่วนถ้าเป็นไฟล์บีบอัดเช่น
BASH
gunzip < backup.sql.gz | mysql -u root -pMyPass test
หรือ
BASH
bzip2 < backup.sql.bz2 | mysql -u root -pMyPass test
หวังว่าจะมีประโยชน์สำหรับทุกท่าน
วันอังคารที่ 26 เมษายน พ.ศ. 2554
การใช้งาน crontab
หลายๆคนน่าจะมีบ้างที่มีความจำเป็นที่จะต้องตั้งเวลาให้เครื่องของเราทำงาน บางอย่างให้โดยอัตโนมัติ ในเวลาที่เราต้องการ เช่น ทุกๆวันเวลาเที่ยงคืนเราต้องการให้มีการสั่งรัน script เพื่อ backup ข้อมูล ไอ้ครั้นจะมานั่งรอเวลาให้ถึงเที่ยงคืนแล้วก็มานั่งสั่งรัน script ด้วยตัวเองมันก็ออกจะเกินไปหน่อย ถ้าจะให้ดีพอถึงเวลาเที่ยงคืน ระบบมันก็ควรจะ backup ให้เองโดยอัตโนมัติเลยดิฟะ ซึ่งถ้าอยากจะให้เป็นเช่นนั้นก็ไม่ยากเพราะ linux มีเครื่องมือที่จะช่วยแก้ปัญหาในเรื่องนี้มาให้ อยู่แล้วในตัวไม่ต้องลงอะไรเพิ่ม นั่นก็คือ crontab น่ะเองครับ
วิธีการใช้งาน crontab ครับ
step 1: เข้า terminal แล้วก็พิมพ์ crontab -e เพื่อสร้าง crontab ที่จะใช้งาน โดยครั้งแรกที่เรียก crontab ขึ้นมาจะเห็นเป็นไฟล์เปล่าๆ มีแค่ comment บอกรูปแบบการเขียน crontab คร่าวๆดังนี้
# m h dom mon dow command
*** อธิบายเพิ่มเติมครับ ***
---------------------------------------------------------------------------------------
Field มีค่า รายละเอียด
---------------------------------------------------------------------------------------
m(minute) 0-59 เวลาเป็นนาที จะสั่งให้คำสั่งที่กำหนดทำงานทันทีเมื่อถึง
h(hour) 0-23 เวลาเป็นชั่วโมง จะสั่งให้คำสั่งที่กำหนดทำงานทันทีเมื่อถึง
dom(day of month) 1-31 เวลาเป็นวัน จะสั่งให้คำสั่งที่กำหนดทำงานทันทีเมื่อถึง
mon(month) 1-12 เวลาเป็นเดือน จะสั่งให้คำสั่งที่กำหนดทำงานทันทีเมื่อถึง
dow(day of week) 0-6 วันของแต่ละสัปดาห์ มีค่าดังนี้(อาทิตย์=0,จันทร์=1,...,เสาร์=6)
command คำสั่ง เราสามารถกำหนดคำสั่งหรือ script ที่ต้องการรันลงไปได้
---------------------------------------------------------------------------------------
step 2: เขียนคำสั่งลงไป เช่น
# m h dom mon dow command
0 0 * * * /home/rooney/backup.sh
เป็น การสั่งให้รัน backup script เวลา 24.00 น. ของทุกวัน โดยเครื่องหมาย * หมายถึงเอาทั้งหมด อย่างกรณีข้างต้น เครื่องหมาย * ตรง dom หมายถึงทำทุกๆวันของเดือน
หรือ
# m h dom mon dow command
55 6 * * 1,5 rm -rf /tmp/*
เป็นการสั่งให้ remove file ใน folder tmp ทิ้งในเวลา 6.55 น. ของทุกๆวันจันทร์และศุกร์ ในทุกๆเดือน
step 3: หลังจากสร้าง crontab เสร็จก็ save ซะครับ แต่ถ้าอยากจะแก้ไขก็ให้พิมพ์ crontab -e อีกครั้งเพื่อเรียก file ขึ้นมาแก้ หรือถ้าต้องการจะเรียกดูว่าเราได้มีการสร้าง crontab อะไรไปแล้วบ้างให้พิมพ์ crontab -l เพื่อให้ระบบมันลิสต์crontab ทั้งหมดที่ได้สร้างไว้โดย user คนนี้ขึ้นมาให้ดู แต่ถ้าเกิดอยากจะลบ crontab ของ user นี้ทิ้งก็ให้พิมพ์ crontab -r เพื่อ remove ครับ
ถ้ายังไม่ได้ให้ใช้ user root นะครับ น่าจะได้
ข้อมูลจาก :: http://www.ubuntuclub.com/html/index.php?option=com_content&task=view&id=466
วิธีการใช้งาน crontab ครับ
step 1: เข้า terminal แล้วก็พิมพ์ crontab -e เพื่อสร้าง crontab ที่จะใช้งาน โดยครั้งแรกที่เรียก crontab ขึ้นมาจะเห็นเป็นไฟล์เปล่าๆ มีแค่ comment บอกรูปแบบการเขียน crontab คร่าวๆดังนี้
# m h dom mon dow command
*** อธิบายเพิ่มเติมครับ ***
---------------------------------------------------------------------------------------
Field มีค่า รายละเอียด
---------------------------------------------------------------------------------------
m(minute) 0-59 เวลาเป็นนาที จะสั่งให้คำสั่งที่กำหนดทำงานทันทีเมื่อถึง
h(hour) 0-23 เวลาเป็นชั่วโมง จะสั่งให้คำสั่งที่กำหนดทำงานทันทีเมื่อถึง
dom(day of month) 1-31 เวลาเป็นวัน จะสั่งให้คำสั่งที่กำหนดทำงานทันทีเมื่อถึง
mon(month) 1-12 เวลาเป็นเดือน จะสั่งให้คำสั่งที่กำหนดทำงานทันทีเมื่อถึง
dow(day of week) 0-6 วันของแต่ละสัปดาห์ มีค่าดังนี้(อาทิตย์=0,จันทร์=1,...,เสาร์=6)
command คำสั่ง เราสามารถกำหนดคำสั่งหรือ script ที่ต้องการรันลงไปได้
---------------------------------------------------------------------------------------
step 2: เขียนคำสั่งลงไป เช่น
# m h dom mon dow command
0 0 * * * /home/rooney/backup.sh
เป็น การสั่งให้รัน backup script เวลา 24.00 น. ของทุกวัน โดยเครื่องหมาย * หมายถึงเอาทั้งหมด อย่างกรณีข้างต้น เครื่องหมาย * ตรง dom หมายถึงทำทุกๆวันของเดือน
หรือ
# m h dom mon dow command
55 6 * * 1,5 rm -rf /tmp/*
เป็นการสั่งให้ remove file ใน folder tmp ทิ้งในเวลา 6.55 น. ของทุกๆวันจันทร์และศุกร์ ในทุกๆเดือน
step 3: หลังจากสร้าง crontab เสร็จก็ save ซะครับ แต่ถ้าอยากจะแก้ไขก็ให้พิมพ์ crontab -e อีกครั้งเพื่อเรียก file ขึ้นมาแก้ หรือถ้าต้องการจะเรียกดูว่าเราได้มีการสร้าง crontab อะไรไปแล้วบ้างให้พิมพ์ crontab -l เพื่อให้ระบบมันลิสต์crontab ทั้งหมดที่ได้สร้างไว้โดย user คนนี้ขึ้นมาให้ดู แต่ถ้าเกิดอยากจะลบ crontab ของ user นี้ทิ้งก็ให้พิมพ์ crontab -r เพื่อ remove ครับ
ถ้ายังไม่ได้ให้ใช้ user root นะครับ น่าจะได้
ข้อมูลจาก :: http://www.ubuntuclub.com/html/index.php?option=com_content&task=view&id=466
วันพฤหัสบดีที่ 7 เมษายน พ.ศ. 2554
Installing LAMP (Linux, Apache, MySQL, PHP)
Firstly open a terminal by clicking Applications -> Accessories -> Terminal. Do not be frightened of the terminal though, it is one of GNU+Linux's most powerful tools; in this case it makes working through the article easy, all the reader has to do is copy and paste from article to the terminal. Firstly select then click Edit -> Copy on the line below:
sudo apt-get install apache2 php5 php5-gd mysql-server php5-mysql apache2-dev php5-dev php-pear make vim-full python2.5
Then click Edit -> Paste in the terminal. Note: when the tutorial says Copy or Paste, Ctrl-c (for copy) and Ctrl-v (for paste) can be used as well. Just as in other operating systems, middle-click also works for copy/paste operations.
Press Enter and fill-in the administrator password. This will install the software required for later steps. Next open the /etc/php5/apache2/php.ini file by selecting, then clicking Edit -> Copy on the text below:
gksu gedit /etc/php5/apache2/php.ini &
Edit -> Paste this into the terminal and press Enter, opening a text editor. Do not do anything with this yet, return to the terminal, it will be required later.
Download and Install Xdebug
Select then Edit -> Copy the following:
sudo pecl install xdebug-beta
Then click Edit -> Paste to download and install Xdebug (the PHP debugger). This last command will spew lots of data into the terminal, in the last few lines is a note showing where Xdebug has been installed. It will look similar to:
Installing
'/var/tmp/pear-build-root/install-xdebug-2.0.0RC4//usr/lib/php5/20060613+lfs/xdebug.so'
Or:
Installing '/usr/lib/php5/20060613+lfs/xdebug.so'
Select the /usr/lib/php5/20060613+lfs/xdebug.so part in the terminal with the cursor, then click Edit -> Copy. This line may vary for different versions of XDebug, particularly the part which is a date, if in doubt select from /usr/lib/ up to (and including) xdebug.so.
Bring back the text editor opened earlier, search through the file (pressing Ctrl-f then entering ‘module settings’ works) and find the section marked:
;;;;;;;;;;;;;;;;;;;
; Module Settings ;
;;;;;;;;;;;;;;;;;;;
Click the empty line beneath it (or create one) and enter:
zend_extension=
Then click Edit -> Paste to paste the location of Xdebug into the file. The zend_extension line should look similar to:
zend_extension=/usr/lib/php5/20060613+lfs/xdebug.so
Having done this press Enter afterwards to create a new line (there are more settings to be pasted into the file).
Select the text below, and Edit -> Copy:
[debug]
; Remote settings
xdebug.remote_autostart=off
xdebug.remote_enable=on
xdebug.remote_handler=dbgp
xdebug.remote_mode=req
xdebug.remote_host=localhost
xdebug.remote_port=9000
; General
xdebug.auto_trace=off
xdebug.collect_includes=on
xdebug.collect_params=off
xdebug.collect_return=off
xdebug.default_enable=on
xdebug.extended_info=1
xdebug.manual_url=http://www.php.net
xdebug.show_local_vars=0
xdebug.show_mem_delta=0
xdebug.max_nesting_level=100
;xdebug.idekey=
; Trace options
xdebug.trace_format=0
xdebug.trace_output_dir=/tmp
xdebug.trace_options=0
xdebug.trace_output_name=crc32
; Profiling
xdebug.profiler_append=0
xdebug.profiler_enable=0
xdebug.profiler_enable_trigger=0
xdebug.profiler_output_dir=/tmp
xdebug.profiler_output_name=crc32
Return to the php.ini file in the text editor. Edit -> Paste beneath the zend_extension line, this should put the lines copied above into the php.ini file. Next click File -> Save, and close the text editor. Select then Edit -> Copy the following and Edit -> Paste into the terminal to restart Apache:
sudo /etc/init.d/apache2 restart
Configure Vim for PHP Debugging
Now a plugin for Vim which enables PHP debugging is required . Firstly Vim needs a directory for plugins: from the main menu click Places -> Home Folder, this should open a new file browser window. From this window, click View -> Show Hidden Files and check whether a directory named .vim exists (note the full stop at the start of the directory name), if not right-click, select Create Folder (and enter ‘.vim’) to create it.
Open a Web browser and go to this address:
http://www.vim.org/scripts/script.php?script_id=1929
Download this script—currently named debugger.zip—to the .vim directory (hidden files can be shown in the save as box by right-clicking in the file list and selecting Show Hidden Files). From the file browser opened earlier double-click the zip file, then in the window that appears right-click the plugin directory and click Extract. Click Extract to extract the plugin to the .vim directory (check the extract file selection box has defaulted to the .vim directory before extracting, if the files are not in that directory the plugin will not work). The PHP debugging script for Vim should now be installed.
To check the plugin is where it should be, navigate to the: .vim/plugin/ directory using the file browser. Inside this directory should be two files:
* debugger.py
* debugger.vim
PHP Debugger Testing
To test the debugger start Vim by pressing Alt-F2 on the keyboard, type gvim in the box provided, then press Enter. Note: there is a main menu entry for Vim, but it is hidden by default. Right-click on the main menu (top-left of the screen) and click Edit Menus to rectify this. Also required is a PHP script (on the local machine). Open the script in a Web browser but add ?XDEBUG_SESSION_START=1 on the end of the URL (as usual Edit -> Copy/Paste can be used to copy/paste from this article). For example, the URL might look similar to:
http://localhost/test.php?XDEBUG_SESSION_START=1
Press F5 in Vim, then quickly switch to the Web browser and press the Reload button. This must be done within five seconds or Vim will display an error. Don't worry if it does though, just press F5 again. When successfully debugging Vim should stop on the first line of PHP code in the file, it also shows help on how to step-over, step-into, and run etc. use that to learn the commands.
The screenshot below shows Vim debugging PHP. Note: if Vim does nothing when F5 is pressed, it has not been setup correctly, check that the plugin has been installed correctly
sudo apt-get install apache2 php5 php5-gd mysql-server php5-mysql apache2-dev php5-dev php-pear make vim-full python2.5
Then click Edit -> Paste in the terminal. Note: when the tutorial says Copy or Paste, Ctrl-c (for copy) and Ctrl-v (for paste) can be used as well. Just as in other operating systems, middle-click also works for copy/paste operations.
Press Enter and fill-in the administrator password. This will install the software required for later steps. Next open the /etc/php5/apache2/php.ini file by selecting, then clicking Edit -> Copy on the text below:
gksu gedit /etc/php5/apache2/php.ini &
Edit -> Paste this into the terminal and press Enter, opening a text editor. Do not do anything with this yet, return to the terminal, it will be required later.
Download and Install Xdebug
Select then Edit -> Copy the following:
sudo pecl install xdebug-beta
Then click Edit -> Paste to download and install Xdebug (the PHP debugger). This last command will spew lots of data into the terminal, in the last few lines is a note showing where Xdebug has been installed. It will look similar to:
Installing
'/var/tmp/pear-build-root/install-xdebug-2.0.0RC4//usr/lib/php5/20060613+lfs/xdebug.so'
Or:
Installing '/usr/lib/php5/20060613+lfs/xdebug.so'
Select the /usr/lib/php5/20060613+lfs/xdebug.so part in the terminal with the cursor, then click Edit -> Copy. This line may vary for different versions of XDebug, particularly the part which is a date, if in doubt select from /usr/lib/ up to (and including) xdebug.so.
Bring back the text editor opened earlier, search through the file (pressing Ctrl-f then entering ‘module settings’ works) and find the section marked:
;;;;;;;;;;;;;;;;;;;
; Module Settings ;
;;;;;;;;;;;;;;;;;;;
Click the empty line beneath it (or create one) and enter:
zend_extension=
Then click Edit -> Paste to paste the location of Xdebug into the file. The zend_extension line should look similar to:
zend_extension=/usr/lib/php5/20060613+lfs/xdebug.so
Having done this press Enter afterwards to create a new line (there are more settings to be pasted into the file).
Select the text below, and Edit -> Copy:
[debug]
; Remote settings
xdebug.remote_autostart=off
xdebug.remote_enable=on
xdebug.remote_handler=dbgp
xdebug.remote_mode=req
xdebug.remote_host=localhost
xdebug.remote_port=9000
; General
xdebug.auto_trace=off
xdebug.collect_includes=on
xdebug.collect_params=off
xdebug.collect_return=off
xdebug.default_enable=on
xdebug.extended_info=1
xdebug.manual_url=http://www.php.net
xdebug.show_local_vars=0
xdebug.show_mem_delta=0
xdebug.max_nesting_level=100
;xdebug.idekey=
; Trace options
xdebug.trace_format=0
xdebug.trace_output_dir=/tmp
xdebug.trace_options=0
xdebug.trace_output_name=crc32
; Profiling
xdebug.profiler_append=0
xdebug.profiler_enable=0
xdebug.profiler_enable_trigger=0
xdebug.profiler_output_dir=/tmp
xdebug.profiler_output_name=crc32
Return to the php.ini file in the text editor. Edit -> Paste beneath the zend_extension line, this should put the lines copied above into the php.ini file. Next click File -> Save, and close the text editor. Select then Edit -> Copy the following and Edit -> Paste into the terminal to restart Apache:
sudo /etc/init.d/apache2 restart
Configure Vim for PHP Debugging
Now a plugin for Vim which enables PHP debugging is required . Firstly Vim needs a directory for plugins: from the main menu click Places -> Home Folder, this should open a new file browser window. From this window, click View -> Show Hidden Files and check whether a directory named .vim exists (note the full stop at the start of the directory name), if not right-click, select Create Folder (and enter ‘.vim’) to create it.
Open a Web browser and go to this address:
http://www.vim.org/scripts/script.php?script_id=1929
Download this script—currently named debugger.zip—to the .vim directory (hidden files can be shown in the save as box by right-clicking in the file list and selecting Show Hidden Files). From the file browser opened earlier double-click the zip file, then in the window that appears right-click the plugin directory and click Extract. Click Extract to extract the plugin to the .vim directory (check the extract file selection box has defaulted to the .vim directory before extracting, if the files are not in that directory the plugin will not work). The PHP debugging script for Vim should now be installed.
To check the plugin is where it should be, navigate to the: .vim/plugin/ directory using the file browser. Inside this directory should be two files:
* debugger.py
* debugger.vim
PHP Debugger Testing
To test the debugger start Vim by pressing Alt-F2 on the keyboard, type gvim in the box provided, then press Enter. Note: there is a main menu entry for Vim, but it is hidden by default. Right-click on the main menu (top-left of the screen) and click Edit Menus to rectify this. Also required is a PHP script (on the local machine). Open the script in a Web browser but add ?XDEBUG_SESSION_START=1 on the end of the URL (as usual Edit -> Copy/Paste can be used to copy/paste from this article). For example, the URL might look similar to:
http://localhost/test.php?XDEBUG_SESSION_START=1
Press F5 in Vim, then quickly switch to the Web browser and press the Reload button. This must be done within five seconds or Vim will display an error. Don't worry if it does though, just press F5 again. When successfully debugging Vim should stop on the first line of PHP code in the file, it also shows help on how to step-over, step-into, and run etc. use that to learn the commands.
The screenshot below shows Vim debugging PHP. Note: if Vim does nothing when F5 is pressed, it has not been setup correctly, check that the plugin has been installed correctly
Installing Xdebug on Ubuntu 10.04
Install Xdebug
sudo apt-get install php5-xdebug
Update xdebug.ini
Now we need to update the xdebug.ini file. Use the following command to open the file with gedit:
sudo gedit /etc/php5/apache2/conf.d/xdebug.ini
Change the file so it looks like this:
; configuration for php xdebug module
zend_extension="/usr/lib/php5/20090626/xdebug.so"
xdebug.remote_enable=1
xdebug.remote_handler=dbgp
xdebug.remote_mode=req
xdebug.remote_host=127.0.0.1
xdebug.remote_port=9000
Restart Apache
All left to do now is restart Apache with the following command:
sudo /etc/init.d/apache2 restart
Now you can check if all is OK with phpinfo(). You should see the following text:
This program makes use of the Zend Scripting Language Engine:
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
with Xdebug v2.0.5, Copyright (c) 2002-2008, by Derick Rethans
with Suhosin v0.9.29, Copyright (c) 2007, by SektionEins GmbH
sudo apt-get install php5-xdebug
Update xdebug.ini
Now we need to update the xdebug.ini file. Use the following command to open the file with gedit:
sudo gedit /etc/php5/apache2/conf.d/xdebug.ini
Change the file so it looks like this:
; configuration for php xdebug module
zend_extension="/usr/lib/php5/20090626/xdebug.so"
xdebug.remote_enable=1
xdebug.remote_handler=dbgp
xdebug.remote_mode=req
xdebug.remote_host=127.0.0.1
xdebug.remote_port=9000
Restart Apache
All left to do now is restart Apache with the following command:
sudo /etc/init.d/apache2 restart
Now you can check if all is OK with phpinfo(). You should see the following text:
This program makes use of the Zend Scripting Language Engine:
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
with Xdebug v2.0.5, Copyright (c) 2002-2008, by Derick Rethans
with Suhosin v0.9.29, Copyright (c) 2007, by SektionEins GmbH
วันอังคารที่ 5 เมษายน พ.ศ. 2554
mount usb 2 on blacktack
1. Example
2. Detecting USB hard drive
After you plug in your USB device to your USB port, linux will add new block device into /dev/ directory. At this stage you are not able to use this device as the USB filesystem needs to be mouted before you are able to retrieve any data. To find out what name your block device file have you can run fdisk command:
# fdisk -l
You will get output similar to this:
Disk /dev/sdb: 60.0 GB, 60060155904 bytes
255 heads, 63 sectors/track, 7301 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x000b2b03
Device Boot Start End Blocks Id System
/dev/sdb1 1 7301 58645251 b W95 FAT32
3. Creating mount point
Create directory where you want to mount your device:
mkdir /mnt/sdb1
4. Edit /etc/fstab
To automate this process you can edit /etc/fstab file and add line similar to this:
/dev/sdb1 /mnt/sdb1 vfat defaults 0 0
Run mount command to mount all not yet mounted devices. Keep in mind that if you have more different USB devices in you system, device name can vary!!!
# mount -a
2. Detecting USB hard drive
After you plug in your USB device to your USB port, linux will add new block device into /dev/ directory. At this stage you are not able to use this device as the USB filesystem needs to be mouted before you are able to retrieve any data. To find out what name your block device file have you can run fdisk command:
# fdisk -l
You will get output similar to this:
Disk /dev/sdb: 60.0 GB, 60060155904 bytes
255 heads, 63 sectors/track, 7301 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x000b2b03
Device Boot Start End Blocks Id System
/dev/sdb1 1 7301 58645251 b W95 FAT32
3. Creating mount point
Create directory where you want to mount your device:
mkdir /mnt/sdb1
4. Edit /etc/fstab
To automate this process you can edit /etc/fstab file and add line similar to this:
/dev/sdb1 /mnt/sdb1 vfat defaults 0 0
Run mount command to mount all not yet mounted devices. Keep in mind that if you have more different USB devices in you system, device name can vary!!!
# mount -a
mount on ubuntu
This page explains how to use USB drives, like external hard disks and USB flash drives (aka USB sticks, thumb drives, pen drives, etc). The material here also applies to flash cards (like in your digital camera).
IconsPage/stop.png If you are looking for help with internal hard drives, see these links:
*
Fstab
*
MountingWindowsPartitions
IconsPage/IconTip.png USB storage devices have the enormous advantage that for the most part they use a standard set of protocols. Thus, instead of needing individual drivers, as does much computer hardware, a standard driver permits access to the devices, making them very portable and able to easily work on many platforms.
Automounting
Mounting
By default, storage devices that are plugged into the system mount automatically in the /media directory, open a file browser window for each volume and place an icon on your desktop. If you plug in a usb hard disk with many partitions, all of the partitions will automatically mount. This behaviour may not be what you want so you can configure it as shown below.
If the volumes have labels the icons will be named accordingly, otherwise they will be named "disk" and as more volumes are added, you can get "disk-1" and so on.
To change the volume label see RenameUSBDrive.
Configuring Automounting
To enable or disable automount open a terminal and type gconf-editor followed by the [Enter] key.
Browse to /apps/nautilus/preferences/media_automount.
The media_automount key controls whether to automatically mount media. If set to true, then Nautilus will automatically mount media such as user-visible hard disks and removable media on start-up and media insertion.
There is another key /apps/nautilus/preferences/media_automount_open. This controls whether to automatically open a folder for automounted media. This key can also be set in the Nautilus (file manager) window. From the Edit menu in Nautilus select Preferences and then select the Media tab.
If set to true, then Nautilus will automatically open a folder when media is automounted. This only applies to media where no known x-content/* type was detected; for media where a known x-content type is detected, the user configurable action will be taken instead. This can be configured as shown below.
Configuring Program Autostart
To control which programs automatically start when you plug in a device, go to System->Preferences->Removable Drives and Media.
Ubuntu 9.10 (Karmic Koala)
In Ubuntu 9.10 (Karmic Koala) Removable Drives and Media is no longer in the Preferences menu but you can still do this as follows.
This user configurable action for specific media types can be configured in the Nautilus (file manager) window. From the Edit menu in Nautilus select Preferences and then select the Media tab. There you can select what happens when media is inserted. For example we need to turnoff audio CD auto play. CD audio "can do nothing" or "ask what to do" or "open folder".
For more complex scenarios, see UsbDriveDoSomethingHowto.
Unmounting/Ejecting
Before you disconnect the device, don't forget to unmount it. This can be done by right clicking the desktop icon and selecting "Unmount" (or in some cases, "Eject"). In Ubuntu 9.10 (Karmic Koala), in the file manager window you can also click on an "eject" button against the name of the mounted volume.
Automounting (Ubuntu Server)
By default, disk drives do not automount in Ubuntu Server Edition. If you are looking for a lightweight solution that does not depend on HAL/DBUS, you can install "usbmount".
Manually Mounting
Using mount
Get the Information
IconsPage/IconGNOMETerminal.png Sometimes devices don't automount, in which case you should try to manually mount it. First, you must know what device we are dealing with and what filesystem it is formatted with. Most flash drives are FAT16 or FAT32 and most external hard disks are NTFS.
sudo fdisk -l
Find your device in the list, it is probably something like /dev/sdb1. For more information about filesystems, see LinuxFilesystemsExplained.
Create the Mount Point
Now we need to create a mount point for the device, let's say we want to call it "external". You can call it whatever you want, just please don't use spaces in the name or it gets a little more complicated - use an underscore to separate words (like "my_external"). Create the mount point:
sudo mkdir /media/external
Mount the Drive
IconsPage/example.png We can now mount the drive. Let's say the device is /dev/sdb1, the filesystem is FAT16 or FAT32 (like it is for most USB flash drives), and we want to mount it at /media/external (having already created the mount point):
sudo mount -t vfat /dev/sdb1 /media/external -o uid=1000,gid=100,utf8,dmask=027,fmask=137
The options following the "-o" allow your user to have ownership of the drive, and the masks allow for extra security for file system permissions. If you don't use those extra options you may not be able to read and write the drive with your regular username.
Otherwise if the device is formatted with NTFS, run:
sudo mount -t ntfs-3g /dev/sdb1 /media/external
IconsPage/IconNote.png You must have the ntfs-3g driver installed. See MountingWindowsPartitions for more information.
Unmounting the Drive
IconsPage/example.png When you are finished with the device, don't forget to unmount the drive before disconnecting it. Assuming /dev/sdb1 mounted at /media/external, you can either unmount using the device or the mount point:
sudo umount /dev/sdb1
or:
sudo umount /media/external
You cannot unmount from the desktop by right clicking the icon if the drive was manually mounted.
Using pmount
There is a program called pmount available in the repositories which allows unprivileged users to mount drives as if they were using sudo, even without an entry in /etc/fstab. This is perfect for computers that have users without RootSudo access, like public terminals or thin clients.
pmount can be used with the same syntax as mount (but without sudo), or quite simply as follows:
pmount [ label ]
Example:
*
pmount /dev/sdb1 flash_drive
This will mount the device /dev/sdb1 at /media/flash_drive
If you leave off the label option, it will mount by default at /media/device
To unmount the device, use pumount, like so:
pumount
Example:
*
pumount /dev/sdb1
For more help, you can see the man pages for pmount and pumount.
Unmounting Explained
IconsPage/IconHint2.png Before disconnecting devices, you must unmount them first. This is similar to "Safely Remove" in Windows in that the device won't unmount until data is finished being written to the device, or until other programs are finished using it. This applies to all types of storage devices, including flash drives, flash cards, external hard drives, ipods and other media players, and even remote storage like Samba or NFS shares.
Failure to unmount before disconnecting the device can result in loss of data and/or a corrupted file system. There are no exceptions to this rule. Be safe - unmount your drives before disconnecting them!
Other Useful Commands
To see a list of your USB devices (the vendor and device ID's), run:
lsusb
To see all attached storage devices and their partitions, run:
sudo fdisk -l
To see information about currently mounted systems, simply run:
mount
Troubleshooting
Presented here are some common problems users encounter.
Unclean LogFile
If you are mounting drives formatted with NTFS (like most external USB hard disks are), you must first have the ntfs-3g driver installed. This is done automatically in newer versions of Ubuntu. You should also install ntfs-config and enable the mounting, which is not done automatically. For ntfs-3g and ntfs-config, see MountingWindowsPartitions.
IconsPage/IconFAQ.png When a drive is not Safely Removed from a Windows machine (or a forced shutdown occurs from Windows), you may get an error like this when you plug in your drive:
$LogFile indicates unclean shutdown (0, 0)
Failed to mount '/dev/sda1': Operation not supported
Mount is denied because NTFS is marked to be in use. Choose one action:
Choice 1: If you have Windows then disconnect the external devices by
clicking on the 'Safely Remove Hardware' icon in the Windows
taskbar then shutdown Windows cleanly.
Choice 2: If you don't have Windows then you can use the 'force' option for
your own responsibility. For example type on the command line:
mount -t ntfs-3g /dev/sda1 /media/sda1/ -o force
The best option is Choice 1, but you can force the mount by running Choice 2 with sudo. Then to unmount the drive, you must do it manually from terminal (you can't right click the desktop icon):
sudo umount
After that the drive should automount normally again.
User Privileges
If your usb device doesn't appear on your desktop, you should check that your user has the correct privileges. Go to System->Administration->User and Groups, choose the user, click on "Properties", then go to the "User Privileges" tab. You should have the "Access external storage devices automatically" option checked.
Preferences
If your usb device doesn't appear on your desktop, you should check that the automount action is enabled in the preferences:
*
Navigate to "System" > "Preferences" > "Removable Drives and Media"
* Verify that all "Mount removable drives when..." are checked.
NOTE: This does not seem to apply to Hardy Heron.
USB 2 Issues
old kernels workaround
If you encounter problems using your USB device with USB 2 (i.e. 'high speed' mode), you can revert to the 'full speed' mode (slower) by unloading ehci_hcd. To do that, type in a terminal:
sudo rmmod ehci_hcd
before plugging in your device.
recent kernels workaround, from Karmic
see also AbsolutelyTech
ehci_hcd is now built into the kernel and cannot be load/unloaded using modprobe. To revert a connected device from (failing) high-speed to full-speed.
1) identify your device id using
lsusb
2) find to which bus it is connected. The bus id can be found as a folder in /sys/bus/pci/drivers/ehci_hcd. Below script explores buses and connected devices.
pushd /sys/bus/pci/drivers/ehci_hcd > /dev/null
for bus in 0000:??:??.? ; do
echo "ehci_hcd bus $bus"
pushd $bus/usb1 > /dev/null
for dev in ?-?; do
idVendor=`cat $dev/idVendor`
idProduct=`cat $dev/idProduct`
echo "ehci_hcd bus $bus: device $dev = $idVendor:$idProduct"
done
popd > /dev/null
done
popd > /dev/null
The information is also usually available in /var/log/kern.log 3) Unbind the bus (and all devices) from the ehci_hcd driver. replace in below code the bus id, which format is 0000:00:xx.x
sudo sh -c 'echo -n "0000:00:xx.x" > unbind'
Buffer I/O Errors
If you see errors related to Buffer I/O when attaching a USB Storage device, there are two ways to work around it. First, try using varying max_sectors settings, as such:
sudo sh -c "echo 120 > /sys/block/sda/queue/max_sectors_kb"
Try values of 120, 64 and 32.
If this does not resolve the issue, then you may need an unusual_dev entry for your device. It would look something like this:
UNUSUAL_DEV(0x03eb , 0x2002, 0x0100, 0x9999,
"Generic",
"MusicDrive",
US_SC_DEVICE, US_PR_DEVICE, NULL,
US_FL_IGNORE_RESIDUE),
The vendor and device ID's can be obtained from the output of "lsusb". The entry would be placed in drivers/usb/storage/unusual_devs.h. If you cannot compile your own kernel, please file a bug report, and we'll attempt to compile a test module for you.
Device become suddenly read only
If your device changes suddenly to read only mode, and you see this kind of error:
[17183798.908000] FAT: Filesystem panic (dev sda1)
[17183798.908000] fat_get_cluster: invalid cluster chain (i_pos 0)
[17183798.908000] File system has been set read-only
This might be the sign of an unclean device. You should check your device. Try TestingStorageMedia to do so. Or use "Disk Utility" (under System, Administration), find your device, unmount it, check the file system, then mount it again.
USB-Device is, or become suddenly read only without errors
If you see "Write Protect is off" and no errors in your logfiles, than you should set filesystem type specific mount options (FS_MOUNTOPTIONS) in /etc/usbmount/usbmount.conf. Wrong gid causes mounting read only.
General tip
When you encounter problems with USB devices, the first thing to do is to check the latest debug information generated from the kernel just after you plug in your device and/or just after you encounter the problem.
To do that, open a terminal and type :
dmesg
Check the latest messages, they should be related to your problem.
Seeking Further Help
The best place to get help with almost any Ubuntu problem is on the Ubuntu Forums. The Absolute Beginner Talk section is best for beginners.
IconsPage/stop.png If you are looking for help with internal hard drives, see these links:
*
Fstab
*
MountingWindowsPartitions
IconsPage/IconTip.png USB storage devices have the enormous advantage that for the most part they use a standard set of protocols. Thus, instead of needing individual drivers, as does much computer hardware, a standard driver permits access to the devices, making them very portable and able to easily work on many platforms.
Automounting
Mounting
By default, storage devices that are plugged into the system mount automatically in the /media directory, open a file browser window for each volume and place an icon on your desktop. If you plug in a usb hard disk with many partitions, all of the partitions will automatically mount. This behaviour may not be what you want so you can configure it as shown below.
If the volumes have labels the icons will be named accordingly, otherwise they will be named "disk" and as more volumes are added, you can get "disk-1" and so on.
To change the volume label see RenameUSBDrive.
Configuring Automounting
To enable or disable automount open a terminal and type gconf-editor followed by the [Enter] key.
Browse to /apps/nautilus/preferences/media_automount.
The media_automount key controls whether to automatically mount media. If set to true, then Nautilus will automatically mount media such as user-visible hard disks and removable media on start-up and media insertion.
There is another key /apps/nautilus/preferences/media_automount_open. This controls whether to automatically open a folder for automounted media. This key can also be set in the Nautilus (file manager) window. From the Edit menu in Nautilus select Preferences and then select the Media tab.
If set to true, then Nautilus will automatically open a folder when media is automounted. This only applies to media where no known x-content/* type was detected; for media where a known x-content type is detected, the user configurable action will be taken instead. This can be configured as shown below.
Configuring Program Autostart
To control which programs automatically start when you plug in a device, go to System->Preferences->Removable Drives and Media.
Ubuntu 9.10 (Karmic Koala)
In Ubuntu 9.10 (Karmic Koala) Removable Drives and Media is no longer in the Preferences menu but you can still do this as follows.
This user configurable action for specific media types can be configured in the Nautilus (file manager) window. From the Edit menu in Nautilus select Preferences and then select the Media tab. There you can select what happens when media is inserted. For example we need to turnoff audio CD auto play. CD audio "can do nothing" or "ask what to do" or "open folder".
For more complex scenarios, see UsbDriveDoSomethingHowto.
Unmounting/Ejecting
Before you disconnect the device, don't forget to unmount it. This can be done by right clicking the desktop icon and selecting "Unmount" (or in some cases, "Eject"). In Ubuntu 9.10 (Karmic Koala), in the file manager window you can also click on an "eject" button against the name of the mounted volume.
Automounting (Ubuntu Server)
By default, disk drives do not automount in Ubuntu Server Edition. If you are looking for a lightweight solution that does not depend on HAL/DBUS, you can install "usbmount".
Manually Mounting
Using mount
Get the Information
IconsPage/IconGNOMETerminal.png Sometimes devices don't automount, in which case you should try to manually mount it. First, you must know what device we are dealing with and what filesystem it is formatted with. Most flash drives are FAT16 or FAT32 and most external hard disks are NTFS.
sudo fdisk -l
Find your device in the list, it is probably something like /dev/sdb1. For more information about filesystems, see LinuxFilesystemsExplained.
Create the Mount Point
Now we need to create a mount point for the device, let's say we want to call it "external". You can call it whatever you want, just please don't use spaces in the name or it gets a little more complicated - use an underscore to separate words (like "my_external"). Create the mount point:
sudo mkdir /media/external
Mount the Drive
IconsPage/example.png We can now mount the drive. Let's say the device is /dev/sdb1, the filesystem is FAT16 or FAT32 (like it is for most USB flash drives), and we want to mount it at /media/external (having already created the mount point):
sudo mount -t vfat /dev/sdb1 /media/external -o uid=1000,gid=100,utf8,dmask=027,fmask=137
The options following the "-o" allow your user to have ownership of the drive, and the masks allow for extra security for file system permissions. If you don't use those extra options you may not be able to read and write the drive with your regular username.
Otherwise if the device is formatted with NTFS, run:
sudo mount -t ntfs-3g /dev/sdb1 /media/external
IconsPage/IconNote.png You must have the ntfs-3g driver installed. See MountingWindowsPartitions for more information.
Unmounting the Drive
IconsPage/example.png When you are finished with the device, don't forget to unmount the drive before disconnecting it. Assuming /dev/sdb1 mounted at /media/external, you can either unmount using the device or the mount point:
sudo umount /dev/sdb1
or:
sudo umount /media/external
You cannot unmount from the desktop by right clicking the icon if the drive was manually mounted.
Using pmount
There is a program called pmount available in the repositories which allows unprivileged users to mount drives as if they were using sudo, even without an entry in /etc/fstab. This is perfect for computers that have users without RootSudo access, like public terminals or thin clients.
pmount can be used with the same syntax as mount (but without sudo), or quite simply as follows:
pmount
Example:
*
pmount /dev/sdb1 flash_drive
This will mount the device /dev/sdb1 at /media/flash_drive
If you leave off the label option, it will mount by default at /media/device
To unmount the device, use pumount, like so:
pumount
Example:
*
pumount /dev/sdb1
For more help, you can see the man pages for pmount and pumount.
Unmounting Explained
IconsPage/IconHint2.png Before disconnecting devices, you must unmount them first. This is similar to "Safely Remove" in Windows in that the device won't unmount until data is finished being written to the device, or until other programs are finished using it. This applies to all types of storage devices, including flash drives, flash cards, external hard drives, ipods and other media players, and even remote storage like Samba or NFS shares.
Failure to unmount before disconnecting the device can result in loss of data and/or a corrupted file system. There are no exceptions to this rule. Be safe - unmount your drives before disconnecting them!
Other Useful Commands
To see a list of your USB devices (the vendor and device ID's), run:
lsusb
To see all attached storage devices and their partitions, run:
sudo fdisk -l
To see information about currently mounted systems, simply run:
mount
Troubleshooting
Presented here are some common problems users encounter.
Unclean LogFile
If you are mounting drives formatted with NTFS (like most external USB hard disks are), you must first have the ntfs-3g driver installed. This is done automatically in newer versions of Ubuntu. You should also install ntfs-config and enable the mounting, which is not done automatically. For ntfs-3g and ntfs-config, see MountingWindowsPartitions.
IconsPage/IconFAQ.png When a drive is not Safely Removed from a Windows machine (or a forced shutdown occurs from Windows), you may get an error like this when you plug in your drive:
$LogFile indicates unclean shutdown (0, 0)
Failed to mount '/dev/sda1': Operation not supported
Mount is denied because NTFS is marked to be in use. Choose one action:
Choice 1: If you have Windows then disconnect the external devices by
clicking on the 'Safely Remove Hardware' icon in the Windows
taskbar then shutdown Windows cleanly.
Choice 2: If you don't have Windows then you can use the 'force' option for
your own responsibility. For example type on the command line:
mount -t ntfs-3g /dev/sda1 /media/sda1/ -o force
The best option is Choice 1, but you can force the mount by running Choice 2 with sudo. Then to unmount the drive, you must do it manually from terminal (you can't right click the desktop icon):
sudo umount
After that the drive should automount normally again.
User Privileges
If your usb device doesn't appear on your desktop, you should check that your user has the correct privileges. Go to System->Administration->User and Groups, choose the user, click on "Properties", then go to the "User Privileges" tab. You should have the "Access external storage devices automatically" option checked.
Preferences
If your usb device doesn't appear on your desktop, you should check that the automount action is enabled in the preferences:
*
Navigate to "System" > "Preferences" > "Removable Drives and Media"
* Verify that all "Mount removable drives when..." are checked.
NOTE: This does not seem to apply to Hardy Heron.
USB 2 Issues
old kernels workaround
If you encounter problems using your USB device with USB 2 (i.e. 'high speed' mode), you can revert to the 'full speed' mode (slower) by unloading ehci_hcd. To do that, type in a terminal:
sudo rmmod ehci_hcd
before plugging in your device.
recent kernels workaround, from Karmic
see also AbsolutelyTech
ehci_hcd is now built into the kernel and cannot be load/unloaded using modprobe. To revert a connected device from (failing) high-speed to full-speed.
1) identify your device id using
lsusb
2) find to which bus it is connected. The bus id can be found as a folder in /sys/bus/pci/drivers/ehci_hcd. Below script explores buses and connected devices.
pushd /sys/bus/pci/drivers/ehci_hcd > /dev/null
for bus in 0000:??:??.? ; do
echo "ehci_hcd bus $bus"
pushd $bus/usb1 > /dev/null
for dev in ?-?; do
idVendor=`cat $dev/idVendor`
idProduct=`cat $dev/idProduct`
echo "ehci_hcd bus $bus: device $dev = $idVendor:$idProduct"
done
popd > /dev/null
done
popd > /dev/null
The information is also usually available in /var/log/kern.log 3) Unbind the bus (and all devices) from the ehci_hcd driver. replace in below code the bus id, which format is 0000:00:xx.x
sudo sh -c 'echo -n "0000:00:xx.x" > unbind'
Buffer I/O Errors
If you see errors related to Buffer I/O when attaching a USB Storage device, there are two ways to work around it. First, try using varying max_sectors settings, as such:
sudo sh -c "echo 120 > /sys/block/sda/queue/max_sectors_kb"
Try values of 120, 64 and 32.
If this does not resolve the issue, then you may need an unusual_dev entry for your device. It would look something like this:
UNUSUAL_DEV(0x03eb , 0x2002, 0x0100, 0x9999,
"Generic",
"MusicDrive",
US_SC_DEVICE, US_PR_DEVICE, NULL,
US_FL_IGNORE_RESIDUE),
The vendor and device ID's can be obtained from the output of "lsusb". The entry would be placed in drivers/usb/storage/unusual_devs.h. If you cannot compile your own kernel, please file a bug report, and we'll attempt to compile a test module for you.
Device become suddenly read only
If your device changes suddenly to read only mode, and you see this kind of error:
[17183798.908000] FAT: Filesystem panic (dev sda1)
[17183798.908000] fat_get_cluster: invalid cluster chain (i_pos 0)
[17183798.908000] File system has been set read-only
This might be the sign of an unclean device. You should check your device. Try TestingStorageMedia to do so. Or use "Disk Utility" (under System, Administration), find your device, unmount it, check the file system, then mount it again.
USB-Device is, or become suddenly read only without errors
If you see "Write Protect is off" and no errors in your logfiles, than you should set filesystem type specific mount options (FS_MOUNTOPTIONS) in /etc/usbmount/usbmount.conf. Wrong gid causes mounting read only.
General tip
When you encounter problems with USB devices, the first thing to do is to check the latest debug information generated from the kernel just after you plug in your device and/or just after you encounter the problem.
To do that, open a terminal and type :
dmesg
Check the latest messages, they should be related to your problem.
Seeking Further Help
The best place to get help with almost any Ubuntu problem is on the Ubuntu Forums. The Absolute Beginner Talk section is best for beginners.
วันพุธที่ 30 มีนาคม พ.ศ. 2554
RootSudo
Contents
1. Background Information
2. Advantages and Disadvantages
1. Benefits of using sudo
2. Downsides of using sudo
3. Usage
1. sudo
2. Graphical sudo
3. Drag & Drop sudo
4. Users
1. Allowing other users to run sudo
2. Logging in as another user
3. root account
1. Enabling the root account
2. Re-disabling your root account
5. Other Information
1. Misconceptions
2. Special notes on sudo and shells
6. Remove Password Prompt For sudo
7. Reset sudo timeout
8. Other Resources
Note: For help with configuring sudo privileges via its configuration file /etc/sudoers, please see Sudoers.
Background Information
In Linux (and Unix in general), there is a SuperUser named Root. The Windows equivalent of Root is Administrators group. The SuperUser can do anything and everything, and thus doing daily work as the SuperUser can be dangerous. You could type a command incorrectly and destroy the system. Ideally, you run as a user that has only the privileges needed for the task at hand. In some cases, this is necessarily Root, but most of the time it is a regular user.
By default, the Root account password is locked in Ubuntu. This means that you cannot login as Root directly or use the su command to become the Root user. However, since the Root account physically exists it is still possible to run programs with root-level privileges. This is where sudo comes in - it allows authorized users (normally "Administrative" users; for further information please refer to AddUsersHowto) to run certain programs as Root without having to know the root password.
This means that in the terminal you should use sudo for commands that require root privileges; simply prepend sudo to all the commands you would normally run as Root. For more extensive usage examples, please see below. Similarly, when you run GUI programs that require root privileges (e.g. the network configuration applet), use graphical sudo and you will also be prompted for a password (more below). Just remember, when sudo asks for a password, it needs YOUR USER password, and not the Root account password.
Advantages and Disadvantages
Benefits of using sudo
Some benefits of leaving Root logins disabled by default include the following:
* The Ubuntu installer has fewer questions to ask.
* Users don't have to remember an extra password (i.e. the root password), which they are likely to forget (or write down so anyone can crack into their account easily).
*
It avoids the "I can do anything" interactive login by default (e.g. the tendency by users to login as an "Administrator" user in Microsoft Windows systems), you will be prompted for a password before major changes can happen, which should make you think about the consequences of what you are doing.
*
sudo adds a log entry of the command(s) run (in /var/log/auth.log). If you mess up, you can always go back and see what commands were run. It is also nice for auditing.
*
Every cracker trying to brute-force their way into your box will know it has an account named Root and will try that first. What they don't know is what the usernames of your other users are. Since the Root account password is locked, this attack becomes essentially meaningless, since there is no password to crack or guess in the first place.
*
Allows easy transfer for admin rights, in a short term or long term period, by adding and removing users from groups, while not compromising the Root account.
* sudo can be setup with a much more fine-grained security policy.
* The Root account password does not need to be shared with everybody who needs to perform some type of administrative task(s) on the system (see the previous bullet).
* The authentication automatically expires after a short time (which can be set to as little as desired or 0); so if you walk away from the terminal after running commands as Root using sudo, you will not be leaving a Root terminal open indefinitely.
Downsides of using sudo
Although for desktops the benefits of using sudo are great, there are possible issues which need to be noted:
*
Redirecting the output of commands run with sudo requires a different approach. For instance consider sudo ls > /root/somefile will not work since it is the shell that tries to write to that file. You can use ls | sudo tee -a /root/somefile to append, or ls | sudo tee /root/somefile to overwrite contents. You could also pass the whole command to a shell process run under sudo to have the file written to with root permissions, such as sudo sh -c "ls > /root/somefile".
* In a lot of office environments the ONLY local user on a system is Root. All other users are imported using NSS techniques such as nss-ldap. To setup a workstation, or fix it, in the case of a network failure where nss-ldap is broken, Root is required. This tends to leave the system unusable unless cracked. An extra local user, or an enabled Root password is needed here. The local user account should have its $HOME on a local disk, _not_ on NFS (or any other networked filesystem), and a .profile/.bashrc that doesn't reference any files on NFS mounts. This is usually the case for Root, but if adding a non-Root rescue account, you will have to take these precautions manually.
o Alternatively, a sysadmin type account can be implemented as a local user on all systems, and granted proper sudo privileges. As explained in the benefits section above, commands can be easily tracked and audited.
Usage
* When using sudo, your password is stored by default for 15 minutes. After that time, you will need to enter your password again.
*
Your password will not be shown on the screen as you type it, not even as a row of stars (******). It is being entered with each keystroke!
sudo
To use sudo on the command line, preface the command with sudo, as below: Example #1
sudo chown bob:bob /home/bob/*
Example #2
sudo /etc/init.d/networking restart
To repeat the last command entered, except with sudo prepended to it, run:
sudo !!
Graphical sudo
You should never use normal sudo to start graphical applications as Root. You should use gksudo (kdesudo on Kubuntu) to run such programs. gksudo sets HOME=~root, and copies .Xauthority to a tmp directory. This prevents files in your home directory becoming owned by Root. (AFAICT, this is all that's special about the environment of the started process with gksudo vs. sudo).
Examples:
gksudo gedit /etc/fstab
or
kdesudo kate /etc/X11/xorg.conf
* To run the graphical configuration utilities, simply launch the application via the Administration menu.
*
gksudo and kdesudo simply link to the commands gksu and kdesu
Drag & Drop sudo
This is a trick from this thread on the Ubuntu Forums.
Create a launcher with the following command:
gksudo "gnome-open %u"
When you drag and drop any file on this launcher (it's useful to put it on the desktop or on a panel), it will be opened as Root with its own associated application. This is helpful especially when you're editing config files owned by Root, since they will be opened as read only by default with gedit, etc.
Users
Allowing other users to run sudo
To add a new user to sudo, open the Users and Groups tool from System->Administration menu. Then click on the user and then on properties. Choose the User Privileges tab. In the tab, find Administer the system and check that.
*
In Hardy Heron and newer, you must first Unlock, then you can select a user from the list and hit Properties. Choose the User Privileges tab and check Administer the system.
/!\ In the terminal this would be: sudo adduser admin, where you replace with the name of the user (without the <>).
Logging in as another user
Please don't use this to become Root, see further down in the page for more information about that.
sudo -i -u
For example to become the user amanda for tape management purposes.
sudo -i -u amanda
The password being asked for is your own, not amanda's.
root account
Enabling the root account
IconsPage/IconWarning3.png
Enabling the Root account is rarely necessary. Almost everything you need to do as administrator of an Ubuntu system can be done via sudo or gksudo. If you really need a persistent Root login, the best alternative is to simulate a Root login shell using the following command...
IconsPage/IconWarning3.png
sudo -i
To enable the Root account (i.e. set a password) use:
sudo passwd root
Use at your own risk!
IconsPage/dont.png
Logging in to X as root may cause very serious trouble. If you believe you need a root account to perform a certain action, please consult the official support channels first, to make sure there is not a better alternative.
IconsPage/dont.png
Re-disabling your root account
IconsPage/info.png
If for some reason you have enabled your root account and wish to disable it again, use the following command in terminal...
IconsPage/info.png
sudo usermod -p '!' root
Other Information
Misconceptions
*
Isn't sudo less secure than su?
o
The basic security model is the same, and therefore these two systems share their primary weaknesses. Any user who uses su or sudo must be considered to be a privileged user. If that user's account is compromised by an attacker, the attacker can also gain root privileges the next time the user does so. The user account is the weak link in this chain, and so must be protected with the same care as Root.
On a more esoteric level, sudo provides some features which encourage different work habits, which can positively impact the security of the system. sudo is commonly used to execute only a single command, while su is generally used to open a shell and execute multiple commands. The sudo approach reduces the likelihood of a root shell being left open indefinitely, and encourages the user to minimize their use of root privileges.
*
I won't be able to enter single-user mode!
o The sulogin program in Ubuntu is patched to handle the default case of a locked root password.
*
I can get a root shell from the console without entering a password!
o You have to enter your password.
Console users have access to the boot loader, and can gain administrative privileges in various ways during the boot process. For example, by specifying an alternate init(8) program. Linux systems are not typically configured to be secure at the console, and additional steps (for example, setting a root password, a boot loader password and a BIOS password) are necessary in order to make them so. Note that console users usually have physical access to the machine and so can manipulate it in other ways as well.
Special notes on sudo and shells
None of the methods below are suggested or supported by the designers of Ubuntu.
Please do not suggest this to others unless you personally are available 24/7 to support the user if they have issues as a result of running a shell as Root.
To start a root shell (i.e. a command window where you can run Root commands), starting Root's environment and login scripts, use:
sudo -i (similar to sudo su - , gives you roots environment configuration)
To start a root shell, but keep the current shell's environment, use:
sudo -s (similar to sudo su)
For a brief overview of some of the differences between su, su -, and sudo -{i,s} see : Ubuntu Forums Post with nice table .
For a detailed description of the differences see man su and man sudo .
Remove Password Prompt For sudo
IconsPage/IconDialog-Warning1.png
If you disable the sudo password for your account, you will seriously compromise the security of your computer. Anyone sitting at your unattended, logged in account will have complete Root access, and remote exploits become much easier for malicious crackers.
IconsPage/IconDialog-Warning1.png
*
This method is NOT suggested nor supported by the designers of Ubuntu.
* Please do not suggest this to others unless you personally are available 24/7 to support the user if they have issues as a result of running a shell as Root.
These instructions are to remove the prompt for a password when using the sudo command. The sudo command will still need to be used for Root access though.
Edit the sudoers file
Open a Terminal window. Type in sudo visudo. Add the following line to the END of the file (if not at the end it can be nullified by later entries):
ALL=NOPASSWD: ALL
Replace with your user name (without the <>). This is assuming that Ubuntu has created a group with the same name as your user name, which is typical. You can alternately use the group users or any other such group you are in. Just make sure you are in that group. This can be checked by going to System->Administration->Users and Groups
Example:
michael ALL=NOPASSWD: ALL
Type in ^x to exit. This should prompt for an option to save the file, type in Y to save.
Log out, log back in. This should now allow you to run the sudo command without being prompted for a password.
Reset sudo timeout
You can make sure sudo asks for password next time by running:
sudo -k
The default sudo timeout length can be changed by following this article: RootSudoTimeout.
1. Background Information
2. Advantages and Disadvantages
1. Benefits of using sudo
2. Downsides of using sudo
3. Usage
1. sudo
2. Graphical sudo
3. Drag & Drop sudo
4. Users
1. Allowing other users to run sudo
2. Logging in as another user
3. root account
1. Enabling the root account
2. Re-disabling your root account
5. Other Information
1. Misconceptions
2. Special notes on sudo and shells
6. Remove Password Prompt For sudo
7. Reset sudo timeout
8. Other Resources
Note: For help with configuring sudo privileges via its configuration file /etc/sudoers, please see Sudoers.
Background Information
In Linux (and Unix in general), there is a SuperUser named Root. The Windows equivalent of Root is Administrators group. The SuperUser can do anything and everything, and thus doing daily work as the SuperUser can be dangerous. You could type a command incorrectly and destroy the system. Ideally, you run as a user that has only the privileges needed for the task at hand. In some cases, this is necessarily Root, but most of the time it is a regular user.
By default, the Root account password is locked in Ubuntu. This means that you cannot login as Root directly or use the su command to become the Root user. However, since the Root account physically exists it is still possible to run programs with root-level privileges. This is where sudo comes in - it allows authorized users (normally "Administrative" users; for further information please refer to AddUsersHowto) to run certain programs as Root without having to know the root password.
This means that in the terminal you should use sudo for commands that require root privileges; simply prepend sudo to all the commands you would normally run as Root. For more extensive usage examples, please see below. Similarly, when you run GUI programs that require root privileges (e.g. the network configuration applet), use graphical sudo and you will also be prompted for a password (more below). Just remember, when sudo asks for a password, it needs YOUR USER password, and not the Root account password.
Advantages and Disadvantages
Benefits of using sudo
Some benefits of leaving Root logins disabled by default include the following:
* The Ubuntu installer has fewer questions to ask.
* Users don't have to remember an extra password (i.e. the root password), which they are likely to forget (or write down so anyone can crack into their account easily).
*
It avoids the "I can do anything" interactive login by default (e.g. the tendency by users to login as an "Administrator" user in Microsoft Windows systems), you will be prompted for a password before major changes can happen, which should make you think about the consequences of what you are doing.
*
sudo adds a log entry of the command(s) run (in /var/log/auth.log). If you mess up, you can always go back and see what commands were run. It is also nice for auditing.
*
Every cracker trying to brute-force their way into your box will know it has an account named Root and will try that first. What they don't know is what the usernames of your other users are. Since the Root account password is locked, this attack becomes essentially meaningless, since there is no password to crack or guess in the first place.
*
Allows easy transfer for admin rights, in a short term or long term period, by adding and removing users from groups, while not compromising the Root account.
* sudo can be setup with a much more fine-grained security policy.
* The Root account password does not need to be shared with everybody who needs to perform some type of administrative task(s) on the system (see the previous bullet).
* The authentication automatically expires after a short time (which can be set to as little as desired or 0); so if you walk away from the terminal after running commands as Root using sudo, you will not be leaving a Root terminal open indefinitely.
Downsides of using sudo
Although for desktops the benefits of using sudo are great, there are possible issues which need to be noted:
*
Redirecting the output of commands run with sudo requires a different approach. For instance consider sudo ls > /root/somefile will not work since it is the shell that tries to write to that file. You can use ls | sudo tee -a /root/somefile to append, or ls | sudo tee /root/somefile to overwrite contents. You could also pass the whole command to a shell process run under sudo to have the file written to with root permissions, such as sudo sh -c "ls > /root/somefile".
* In a lot of office environments the ONLY local user on a system is Root. All other users are imported using NSS techniques such as nss-ldap. To setup a workstation, or fix it, in the case of a network failure where nss-ldap is broken, Root is required. This tends to leave the system unusable unless cracked. An extra local user, or an enabled Root password is needed here. The local user account should have its $HOME on a local disk, _not_ on NFS (or any other networked filesystem), and a .profile/.bashrc that doesn't reference any files on NFS mounts. This is usually the case for Root, but if adding a non-Root rescue account, you will have to take these precautions manually.
o Alternatively, a sysadmin type account can be implemented as a local user on all systems, and granted proper sudo privileges. As explained in the benefits section above, commands can be easily tracked and audited.
Usage
* When using sudo, your password is stored by default for 15 minutes. After that time, you will need to enter your password again.
*
Your password will not be shown on the screen as you type it, not even as a row of stars (******). It is being entered with each keystroke!
sudo
To use sudo on the command line, preface the command with sudo, as below: Example #1
sudo chown bob:bob /home/bob/*
Example #2
sudo /etc/init.d/networking restart
To repeat the last command entered, except with sudo prepended to it, run:
sudo !!
Graphical sudo
You should never use normal sudo to start graphical applications as Root. You should use gksudo (kdesudo on Kubuntu) to run such programs. gksudo sets HOME=~root, and copies .Xauthority to a tmp directory. This prevents files in your home directory becoming owned by Root. (AFAICT, this is all that's special about the environment of the started process with gksudo vs. sudo).
Examples:
gksudo gedit /etc/fstab
or
kdesudo kate /etc/X11/xorg.conf
* To run the graphical configuration utilities, simply launch the application via the Administration menu.
*
gksudo and kdesudo simply link to the commands gksu and kdesu
Drag & Drop sudo
This is a trick from this thread on the Ubuntu Forums.
Create a launcher with the following command:
gksudo "gnome-open %u"
When you drag and drop any file on this launcher (it's useful to put it on the desktop or on a panel), it will be opened as Root with its own associated application. This is helpful especially when you're editing config files owned by Root, since they will be opened as read only by default with gedit, etc.
Users
Allowing other users to run sudo
To add a new user to sudo, open the Users and Groups tool from System->Administration menu. Then click on the user and then on properties. Choose the User Privileges tab. In the tab, find Administer the system and check that.
*
In Hardy Heron and newer, you must first Unlock, then you can select a user from the list and hit Properties. Choose the User Privileges tab and check Administer the system.
/!\ In the terminal this would be: sudo adduser
Logging in as another user
Please don't use this to become Root, see further down in the page for more information about that.
sudo -i -u
For example to become the user amanda for tape management purposes.
sudo -i -u amanda
The password being asked for is your own, not amanda's.
root account
Enabling the root account
IconsPage/IconWarning3.png
Enabling the Root account is rarely necessary. Almost everything you need to do as administrator of an Ubuntu system can be done via sudo or gksudo. If you really need a persistent Root login, the best alternative is to simulate a Root login shell using the following command...
IconsPage/IconWarning3.png
sudo -i
To enable the Root account (i.e. set a password) use:
sudo passwd root
Use at your own risk!
IconsPage/dont.png
Logging in to X as root may cause very serious trouble. If you believe you need a root account to perform a certain action, please consult the official support channels first, to make sure there is not a better alternative.
IconsPage/dont.png
Re-disabling your root account
IconsPage/info.png
If for some reason you have enabled your root account and wish to disable it again, use the following command in terminal...
IconsPage/info.png
sudo usermod -p '!' root
Other Information
Misconceptions
*
Isn't sudo less secure than su?
o
The basic security model is the same, and therefore these two systems share their primary weaknesses. Any user who uses su or sudo must be considered to be a privileged user. If that user's account is compromised by an attacker, the attacker can also gain root privileges the next time the user does so. The user account is the weak link in this chain, and so must be protected with the same care as Root.
On a more esoteric level, sudo provides some features which encourage different work habits, which can positively impact the security of the system. sudo is commonly used to execute only a single command, while su is generally used to open a shell and execute multiple commands. The sudo approach reduces the likelihood of a root shell being left open indefinitely, and encourages the user to minimize their use of root privileges.
*
I won't be able to enter single-user mode!
o The sulogin program in Ubuntu is patched to handle the default case of a locked root password.
*
I can get a root shell from the console without entering a password!
o You have to enter your password.
Console users have access to the boot loader, and can gain administrative privileges in various ways during the boot process. For example, by specifying an alternate init(8) program. Linux systems are not typically configured to be secure at the console, and additional steps (for example, setting a root password, a boot loader password and a BIOS password) are necessary in order to make them so. Note that console users usually have physical access to the machine and so can manipulate it in other ways as well.
Special notes on sudo and shells
None of the methods below are suggested or supported by the designers of Ubuntu.
Please do not suggest this to others unless you personally are available 24/7 to support the user if they have issues as a result of running a shell as Root.
To start a root shell (i.e. a command window where you can run Root commands), starting Root's environment and login scripts, use:
sudo -i (similar to sudo su - , gives you roots environment configuration)
To start a root shell, but keep the current shell's environment, use:
sudo -s (similar to sudo su)
For a brief overview of some of the differences between su, su -, and sudo -{i,s} see : Ubuntu Forums Post with nice table .
For a detailed description of the differences see man su and man sudo .
Remove Password Prompt For sudo
IconsPage/IconDialog-Warning1.png
If you disable the sudo password for your account, you will seriously compromise the security of your computer. Anyone sitting at your unattended, logged in account will have complete Root access, and remote exploits become much easier for malicious crackers.
IconsPage/IconDialog-Warning1.png
*
This method is NOT suggested nor supported by the designers of Ubuntu.
* Please do not suggest this to others unless you personally are available 24/7 to support the user if they have issues as a result of running a shell as Root.
These instructions are to remove the prompt for a password when using the sudo command. The sudo command will still need to be used for Root access though.
Edit the sudoers file
Open a Terminal window. Type in sudo visudo. Add the following line to the END of the file (if not at the end it can be nullified by later entries):
Replace
Example:
michael ALL=NOPASSWD: ALL
Type in ^x to exit. This should prompt for an option to save the file, type in Y to save.
Log out, log back in. This should now allow you to run the sudo command without being prompted for a password.
Reset sudo timeout
You can make sure sudo asks for password next time by running:
sudo -k
The default sudo timeout length can be changed by following this article: RootSudoTimeout.
วันอังคารที่ 22 มีนาคม พ.ศ. 2554
ใช้งาน vi editor เบื้องต้น
สำหรับ คนที่พัฒนาระบบงานบน Linux หรือ Unix และเป็นผู้ที่ไม่ชอบย้ายมือออกจากคีย์บอร์ดนั้น ขอแนะนำให้ใ้ช้ Vi Editor แล้วท่านจะไม่ผิดหวัง เนื่องจาก vi นั้นถูกออกแบบมาให้ใช้งาน โดยที่ไม่จำเป็นต้องเอามือออกจากคีย์บอร์ดเลย ไม่เพียงเท่านั้น 10 นิ้วของท่าน จะไม่หลุดออกแป้น a s d f space j k l : เลย แม้แต่ลูกศรขึ้นลง ก็ไม่ได้ใช้ ตัวเลข ก็ไม่ได้ใช้ อยากรู้แล้วใช้ไหมครับ ว่ามันทำงานอย่างไร
vi ประกอบด้วย 2 Mode คือ
1. Mode command ไว้สำหรับใช้คำสั่ง Mode นี้ เพียงกด Esc ก็จะเข้าสู่ Mode command อัตโนมัติ (คิดอะไรไม่ออก กด Esc ลูกเดียว)
2. Mode การพิมพ์ ไว้สำหรับเพิ่มข้อมูล เลื่อน Cursor ต่าง ๆ แต่เราต้องใช้ Command ก่อน เช่น หากต้องการเพิ่มอักษร ต้องสั่ง I (Insert) เสียก่อน และเมื่อพิมพ์จะเป็นการแทรกข้อความอัตโนมัติ
ผมขอแนะนำเทคนิคที่ใช้กันบ่อย ๆ นะครับ
รูปแสดงแผนผังการใช้งาน VI Editor แบบไม่ยกนิ้วกันเลยครับผม
การเลื่อนทิศทาง (Motivation)
สังเกตุนะครับ มือจะไม่ขยับไปใช้ ลูกศร ขึ้นลง เลย ทำให้ทำงานได้เร็วขึ้น
* h = เลื่อนไปทางซ้าย
* l = เลื่อนไปทางขวา
* j = เลื่อนลง
* k = เลื่อนขึ้น
* หาก พิมพ์ 8l = เลื่อนไปทางขวา 8 ตัวอักษร
* w , W = เลื่อนไปทางขวา 1 คำ เช่น this is test เมื่อกด w จะเลื่อน Cursor ไป 1 word Cursor จะไปยืนอยู่ที่ this is test เป็นต้น
* { = เลื่อนไปยังต้น Paragraph
* } = เลื่อนไปยังท้าย Paragraph
* :หมายเลขบรรทัด = เลื่อนไปยังบรรทัดที่ต้องการ เช่น :10 หมายถึงไปบรรทัดที่ 10 เป็นต้น
* $ = ไปตัวอักษรท้ายสุดของบรรทัด
* 0 = ไปตัวอักษรตัวแรกสุด ของบรรทัด
การกระทำการ (Operator)
* i = เพิ่มตัวอักษร (insert) ใช้งาน โดยพิมพ์ i แล้วพิมพ์ต่อได้เลย
* I = เพิ่มตัวอักษรต้นบรรทัด
* x = ลบตัวษรทีละ 1 ตัว
* 10x = ลบตัวอักษร 10 ตัว
* dw = ลบทั้งคำ
* dd = ลบทั้งบรรทัด
* yy = yank หมายถึง Copy ทั้งบรรทัด
* p = วาง (Paste) วางบรรทัดล่างจาก Cursor อยู่
* P = วาง (Paste) วางแทรกบรรทัดปัจจุบัน
การจัดการเกี่ยวกับไฟล์
* :w ชื่อไฟล์ = save ไฟล ์ด้วยชื่อที่กำหนด
* :wq = save ไฟล์ และออกจาก vi (Quit)
* :q! = ออกจาก vi โดยไม่ Save
* :set
o set nu = สั่งให้ vi แสดงหมายเลขบรรทัด
o set ic = สั่งให้เวลา Search ไม่ดูการค้น ตัวเล็ก ตัวใหญ่ ใด ๆ (Ignore Case)
o set nu ic สั่งให้ทำงานทั้ง 2 แบบ
ลอง Telnet แล้วไปของพิมพ์เล่น ๆ ดูนะครับ ทางด้านบนนั้น เป็นเพียงแค่ความสามารถเพียงนิดเดียวของ Vi ครับ หวังว่าหลายคนที่มองหา Editor ฟรี ๆ ความสามารถสูง ๆ ที่พร้อมใช้ังานอยู่ใน Server อยู่แล้วครับ
ขอบพระคุณที่สนใจอ่าน
vi ประกอบด้วย 2 Mode คือ
1. Mode command ไว้สำหรับใช้คำสั่ง Mode นี้ เพียงกด Esc ก็จะเข้าสู่ Mode command อัตโนมัติ (คิดอะไรไม่ออก กด Esc ลูกเดียว)
2. Mode การพิมพ์ ไว้สำหรับเพิ่มข้อมูล เลื่อน Cursor ต่าง ๆ แต่เราต้องใช้ Command ก่อน เช่น หากต้องการเพิ่มอักษร ต้องสั่ง I (Insert) เสียก่อน และเมื่อพิมพ์จะเป็นการแทรกข้อความอัตโนมัติ
ผมขอแนะนำเทคนิคที่ใช้กันบ่อย ๆ นะครับ
รูปแสดงแผนผังการใช้งาน VI Editor แบบไม่ยกนิ้วกันเลยครับผม
การเลื่อนทิศทาง (Motivation)
สังเกตุนะครับ มือจะไม่ขยับไปใช้ ลูกศร ขึ้นลง เลย ทำให้ทำงานได้เร็วขึ้น
* h = เลื่อนไปทางซ้าย
* l = เลื่อนไปทางขวา
* j = เลื่อนลง
* k = เลื่อนขึ้น
* หาก พิมพ์ 8l = เลื่อนไปทางขวา 8 ตัวอักษร
* w , W = เลื่อนไปทางขวา 1 คำ เช่น this is test เมื่อกด w จะเลื่อน Cursor ไป 1 word Cursor จะไปยืนอยู่ที่ this is test เป็นต้น
* { = เลื่อนไปยังต้น Paragraph
* } = เลื่อนไปยังท้าย Paragraph
* :หมายเลขบรรทัด = เลื่อนไปยังบรรทัดที่ต้องการ เช่น :10 หมายถึงไปบรรทัดที่ 10 เป็นต้น
* $ = ไปตัวอักษรท้ายสุดของบรรทัด
* 0 = ไปตัวอักษรตัวแรกสุด ของบรรทัด
การกระทำการ (Operator)
* i = เพิ่มตัวอักษร (insert) ใช้งาน โดยพิมพ์ i แล้วพิมพ์ต่อได้เลย
* I = เพิ่มตัวอักษรต้นบรรทัด
* x = ลบตัวษรทีละ 1 ตัว
* 10x = ลบตัวอักษร 10 ตัว
* dw = ลบทั้งคำ
* dd = ลบทั้งบรรทัด
* yy = yank หมายถึง Copy ทั้งบรรทัด
* p = วาง (Paste) วางบรรทัดล่างจาก Cursor อยู่
* P = วาง (Paste) วางแทรกบรรทัดปัจจุบัน
การจัดการเกี่ยวกับไฟล์
* :w ชื่อไฟล์ = save ไฟล ์ด้วยชื่อที่กำหนด
* :wq = save ไฟล์ และออกจาก vi (Quit)
* :q! = ออกจาก vi โดยไม่ Save
* :set
o set nu = สั่งให้ vi แสดงหมายเลขบรรทัด
o set ic = สั่งให้เวลา Search ไม่ดูการค้น ตัวเล็ก ตัวใหญ่ ใด ๆ (Ignore Case)
o set nu ic สั่งให้ทำงานทั้ง 2 แบบ
ลอง Telnet แล้วไปของพิมพ์เล่น ๆ ดูนะครับ ทางด้านบนนั้น เป็นเพียงแค่ความสามารถเพียงนิดเดียวของ Vi ครับ หวังว่าหลายคนที่มองหา Editor ฟรี ๆ ความสามารถสูง ๆ ที่พร้อมใช้ังานอยู่ใน Server อยู่แล้วครับ
ขอบพระคุณที่สนใจอ่าน
วันอาทิตย์ที่ 20 มีนาคม พ.ศ. 2554
apt-get
การติดตั้งแบบออนไลน์คือการดาวน์โหลด และติดตั้งแพ็กเก็จจากเซิร์ฟเวอร์ที่ให้บริการ หรือจาก CD แต่ไม่ได้เข้าถึงไฟล์ .deb โดยตรง เหมือน dpkg ส่วนประกอบสำคัญที่ทำให้เราสามารถติดตั้งโปรแกรมต่างๆ ได้นั่นก็คือไฟล์ที่ระบุ Server ปลายทางที่ให้บริการ นั่นก็คือไฟล์ /etc/apt/sources.list ซึ่งจะมีมาให้แล้วตอนที่เราติดตั้ง ubuntu ก่อนที่จะใช้งานหรือติดตั้งแพ็กเก็จใดควรจะเรียกใช้คำสั่ง apt-get update เพื่ออัพเดทฐานข้อมูลของแพ็กเก็จให้เป็นปัจจุบัน
ในการใช้งาน apt-get install เป็นการดาวน์โหลดไฟล์จากเซิร์ฟเวอร์ที่ให้บริการ หรือจาก CD ติดตั้ง ทั้งนี้ขึ้นอยู่กับไฟล์ /etc/apt/sources.list สำหรับการดาวน์โหลดไฟล์ .deb จะมีที่เก็บไฟล์อยู่ที่ /var/cache/apt/archives/ ซึ่งสามารถเก็บเอาไว้ติดตั้งด้วยคำสั่ง dpkg ได้ ถ้าแพ็กเก็จที่เราได้ติดตั้ง และลบออกไปแล้ว และต้องการที่จะติดตั้งใหม่อีกครั้งถ้ายังมีไฟล์อยู่ใน /var/cache/apt/archives/ ก็จะไม่ดาวน์โหลดใหม่
การใช้งานคำสั่ง apt-get
sudo apt-get update อัพเดทฐานข้อมูลของแพ็กเก็จทั้งหมด รันคำสั่งนี้เมื่อ เปลี่ยนแปลงไฟล์ /etc/apt/sources.list
sudo apt-cache search ค้นหาแพ็กเก็จที่ต้องการติดตั้ง
sudo apt-get install ดาวน์โหลด และติดตั้งแพ็กเก็จ
sudo apt-get remove ลบแพ็กเก็จที่ติดตั้งไปแล้ว
sudo apt-get -d install ดาวน์โหลดแพ็กเก็จเก็บไว้ใน /var/cache/apt/archives แต่ไม่ติดตั้ง
sudo apt-cache show แสดงข้อมูลรายละเอียดของแพ็กเก็จ
sudo apt-get upgrade เชคดูว่าแพ็กเก็จที่ติดตั้งไปทั้งหมดมีเพ็กเก็จใดมีการอัพเดทบ้าง ต่อจากนั้นก็จะถามว่าต้องการดาวน์โหลดและติดตั้งหรือไม่
sudo apt-get dist-upgrade อัพเกรดระบบทั้งหมด เช่นการเปลี่ยนเวอร์ชันจาก 7.10 เป็น 8.04
sudo apt-get autoclean ลบแพ็กเก็จที่ดาวน์โหลดมาไม่สมบูรณ์ หรือแพ็กเก็จที่ไม่ได้ใช้ติดตั้งแล้ว
sudo apt-get clean ลบทุกแพ็กเก็จที่ดาวน์โหลดมาเก็บอยู่ที่ /var/cache/apt/archives
sudo apt-get -f install กรณีที่มีความผิดพลาดเกิดขึ้นในขณะที่กำลังติดตั้งแพ็กเก็จ เช่น สั่งยกเลิก หรือ ไฟฟ้าดับ
แล้วใช้คำสั่ง apt-get install แล้วมีข้อความ error สามารถใช้คำสั่ง apt-get -f install ช่วยแก้ปัญหาได้
sudo apt-config -v แสดงเวอร์ชัน และรายละเอียดของ APT utilities
sudo apt-cache stats แสดงสถิติของแพ็กเก็จที่ติดตั้งไปแล้วทั้งหมด
sudo apt-cache depends ดูแพ็กเก็จที่ขึ้นต่อกันของแพ็กเก็จที่จะติดตั้ง
sudo apt-cache pkgnames แสดงแพ็กเก็จทั้งหมดที่ได้ติดตั้งไป
ในการใช้งาน apt-get install เป็นการดาวน์โหลดไฟล์จากเซิร์ฟเวอร์ที่ให้บริการ หรือจาก CD ติดตั้ง ทั้งนี้ขึ้นอยู่กับไฟล์ /etc/apt/sources.list สำหรับการดาวน์โหลดไฟล์ .deb จะมีที่เก็บไฟล์อยู่ที่ /var/cache/apt/archives/ ซึ่งสามารถเก็บเอาไว้ติดตั้งด้วยคำสั่ง dpkg ได้ ถ้าแพ็กเก็จที่เราได้ติดตั้ง และลบออกไปแล้ว และต้องการที่จะติดตั้งใหม่อีกครั้งถ้ายังมีไฟล์อยู่ใน /var/cache/apt/archives/ ก็จะไม่ดาวน์โหลดใหม่
การใช้งานคำสั่ง apt-get
sudo apt-get update อัพเดทฐานข้อมูลของแพ็กเก็จทั้งหมด รันคำสั่งนี้เมื่อ เปลี่ยนแปลงไฟล์ /etc/apt/sources.list
sudo apt-cache search
sudo apt-get install
sudo apt-get remove
sudo apt-get -d install
sudo apt-cache show
sudo apt-get upgrade เชคดูว่าแพ็กเก็จที่ติดตั้งไปทั้งหมดมีเพ็กเก็จใดมีการอัพเดทบ้าง ต่อจากนั้นก็จะถามว่าต้องการดาวน์โหลดและติดตั้งหรือไม่
sudo apt-get dist-upgrade อัพเกรดระบบทั้งหมด เช่นการเปลี่ยนเวอร์ชันจาก 7.10 เป็น 8.04
sudo apt-get autoclean ลบแพ็กเก็จที่ดาวน์โหลดมาไม่สมบูรณ์ หรือแพ็กเก็จที่ไม่ได้ใช้ติดตั้งแล้ว
sudo apt-get clean ลบทุกแพ็กเก็จที่ดาวน์โหลดมาเก็บอยู่ที่ /var/cache/apt/archives
sudo apt-get -f install กรณีที่มีความผิดพลาดเกิดขึ้นในขณะที่กำลังติดตั้งแพ็กเก็จ เช่น สั่งยกเลิก หรือ ไฟฟ้าดับ
แล้วใช้คำสั่ง apt-get install แล้วมีข้อความ error สามารถใช้คำสั่ง apt-get -f install ช่วยแก้ปัญหาได้
sudo apt-config -v แสดงเวอร์ชัน และรายละเอียดของ APT utilities
sudo apt-cache stats แสดงสถิติของแพ็กเก็จที่ติดตั้งไปแล้วทั้งหมด
sudo apt-cache depends ดูแพ็กเก็จที่ขึ้นต่อกันของแพ็กเก็จที่จะติดตั้ง
sudo apt-cache pkgnames แสดงแพ็กเก็จทั้งหมดที่ได้ติดตั้งไป
วันพฤหัสบดีที่ 10 มีนาคม พ.ศ. 2554
ลง opencv 1
วันนี้ทำการลง openCV ใหม่หลังจากลงอุบุนตุใหม่ ประกอบกับจำไม่ได้ว่า ครั้งก่อนลงไปแล้วไม่ได้จดวิธีลงไว้ ลงอีกครั้งเลยขอจดไว้ก่อน เผื่อคราวหน้า ลงอุบุนตุใหม่จะได้ไม่มานั่งงมอีก
อ้างอิงการลง openCV บน Ubuntu 9.04 จาก
http://webeng.cs.ait.ac.th/cvwiki/opencv:tutorial:install:ubuntu
(Thanks อ.แมท(Dr.Matthew@AIT)for very useful installation guide)
ซึ่งมีขั้นตอนดังนี้
1. ใช้ synaptic ติดตั้ง libgstreamer0.10-dev และ libdc1394-13-dev
2. ดาวน์โหลด opencv 1.1.0 ได้จาก openCV wiki
3. แตกไฟล์ opencv-1.1pre1.tar.gz โดยใช้คำสั่ง tar -xvfz opencv-1.1pre1.tar.gz
4. ในไดเรกทอรี่ของ opencv-1.1.0 พิมพ์คำสั่ง(ให้เหมือนอันนี้เลยนะ เครื่องหมาย=พิมพ์ให้ติดprefix)
./configure –prefix=${HOME}/opencv –without-xine –without-quicktime –with-gstreamer –with-1394libs –with-v4l
5. ในไดเรกทอรี่ของ opencv-1.1.0 พิมพ์คำสั่ง
make
6. เมื่อ make เสร็จ ก็พิมพ์
make install
เพื่อติดตั้ง opencv ได้เลยโดย opencv จะไปติดตั้งอยู่ที่ /home/jednipat/opencv ตามไดเรคทอรี่ที่ระบุไว้ตอนรัน ./configure
7. พิมพ์
export LD_LIBRARY_PATH=/home/jednipat/opencv/lib
เมื่อ make install เสร็จ ก็ลองมารัน example ที่ opnecv ให้มาโดยคอมไพล์ดังนี้
g++ -o outputname yourfilename.c -I /home/jednipat/opencv/include/opencv/ -lhighgui -L /home/jednipat/opencv/lib/
กรณีของผมคอมไพล์ผ่านแต่พอรันแล้ว เจอ error ดังนี้ (เนื่องจากผมลืมทำข้อ 7)
error while loading shared libraries: libhighgui.so.2: cannot open
shared object file: No such file or directory
เลยค้นวิธีแก้ได้มาจากบล็อกของ dsin (พี่พง) สาเหตุเป็นเพราะว่ายังไม่ได้ export LD_LIBRARY_PATH ซึ่งก็ทำได้ดังนี้
export LD_LIBRARY_PATH=/home/jednipat/opencv/lib
จากนั้นทำการเปิดไฟล์ .bashrc ขึ้นมาแล้วเพิ่มบรรทัดนี้เข้าไปในไฟล์ .bashrc แล้วก็ทำการ save (พิมพ์ gedit .bashrc ใน home directory เพื่อทำการแก้ไขไฟล์ .bashrc เพราะจะได้ไม่ต้องมานั่งพิมพ์ export ทุกครั้งไปที่จะใช้งาน )
ที่นี้คิดว่าน่าจะรันได้ตามปกติ ลองคอมไพล์และรัน example ดูอีกที คอมไพล์ผ่าน
แต่พอรันปุ๊ป เจอกับ
OpenCV ERROR: Unspecified error (The function is not implemented.
Rebuild the library with Windows, GTK+ 2.x or Carbon support)
in function cvNamedWindow, window.cpp(71)
Terminating the application…
Segmentation fault
อ๊ากก… ค้นไปค้นมาอีกก็ได้คำแนะนำจากเว็บนี้ < – - คลิก คอมเมนต์สุดท้ายบอกไว้ว่าสาเหตุมาจากตอนรัน ./configure และ make ไม่มี gtk+ lib dev ไม่มีเขาแนะนำให้ remove openCV ออกก่อน แล้วไปลง libgtk2.0-dev (เข้า synaptic package manager แล้ว search คำว่า libgtk2.0-dev ละก็ mark for installation - > apply )
เมื่อลง libgtk2.0-dev เสร็จให้ uninstall openCV ก่อนโดยพิมพ์ make uninstall
ในไดเรคทอรี่ opencv-1.1.0 จากนั้นเพื่อความชัวร์ควรจะ restart เครื่องก่อน
(ผมไม่รีสตาร์ทเครื่อง make ใหม่ก็เจอปัญหาเดิม เลยลอง รีสตาร์ทเครื่อง แล้วทำใหม่)
แล้วทำการ ./configure , make , make install อีกที
1> ./configure blablabla..
2> make
3> make install
4> export LD_LIBRARY_PATH=/home/jednipat/opencv/lib
จากนั้นไปยัง directory /home/jednipat/opencv-1.1.0/samples/c
แล้วลองคอมไพล์ไฟล์ใด ๆ ผมเลือกไฟล์ตัวอย่างการใช้งาน SURF descriptor
ชื่อไฟล์ว่า find_obj.cpp คอมไพล์ด้วยคำสั่งดังนี้
g++ find_obj.cpp -o test -I /home/jednipat/opencv/include/opencv/ -lhighgui
-L /home/jednipat/opencv/lib/
จากนั้นรัน ./test เพื่อดูผลลัพธ์ของโปรแกรม
เย้… สำเร็จ..
อ้างอิงการลง openCV บน Ubuntu 9.04 จาก
http://webeng.cs.ait.ac.th/cvwiki/opencv:tutorial:install:ubuntu
(Thanks อ.แมท(Dr.Matthew@AIT)for very useful installation guide)
ซึ่งมีขั้นตอนดังนี้
1. ใช้ synaptic ติดตั้ง libgstreamer0.10-dev และ libdc1394-13-dev
2. ดาวน์โหลด opencv 1.1.0 ได้จาก openCV wiki
3. แตกไฟล์ opencv-1.1pre1.tar.gz โดยใช้คำสั่ง tar -xvfz opencv-1.1pre1.tar.gz
4. ในไดเรกทอรี่ของ opencv-1.1.0 พิมพ์คำสั่ง(ให้เหมือนอันนี้เลยนะ เครื่องหมาย=พิมพ์ให้ติดprefix)
./configure –prefix=${HOME}/opencv –without-xine –without-quicktime –with-gstreamer –with-1394libs –with-v4l
5. ในไดเรกทอรี่ของ opencv-1.1.0 พิมพ์คำสั่ง
make
6. เมื่อ make เสร็จ ก็พิมพ์
make install
เพื่อติดตั้ง opencv ได้เลยโดย opencv จะไปติดตั้งอยู่ที่ /home/jednipat/opencv ตามไดเรคทอรี่ที่ระบุไว้ตอนรัน ./configure
7. พิมพ์
export LD_LIBRARY_PATH=/home/jednipat/opencv/lib
เมื่อ make install เสร็จ ก็ลองมารัน example ที่ opnecv ให้มาโดยคอมไพล์ดังนี้
g++ -o outputname yourfilename.c -I /home/jednipat/opencv/include/opencv/ -lhighgui -L /home/jednipat/opencv/lib/
กรณีของผมคอมไพล์ผ่านแต่พอรันแล้ว เจอ error ดังนี้ (เนื่องจากผมลืมทำข้อ 7)
error while loading shared libraries: libhighgui.so.2: cannot open
shared object file: No such file or directory
เลยค้นวิธีแก้ได้มาจากบล็อกของ dsin (พี่พง) สาเหตุเป็นเพราะว่ายังไม่ได้ export LD_LIBRARY_PATH ซึ่งก็ทำได้ดังนี้
export LD_LIBRARY_PATH=/home/jednipat/opencv/lib
จากนั้นทำการเปิดไฟล์ .bashrc ขึ้นมาแล้วเพิ่มบรรทัดนี้เข้าไปในไฟล์ .bashrc แล้วก็ทำการ save (พิมพ์ gedit .bashrc ใน home directory เพื่อทำการแก้ไขไฟล์ .bashrc เพราะจะได้ไม่ต้องมานั่งพิมพ์ export ทุกครั้งไปที่จะใช้งาน )
ที่นี้คิดว่าน่าจะรันได้ตามปกติ ลองคอมไพล์และรัน example ดูอีกที คอมไพล์ผ่าน
แต่พอรันปุ๊ป เจอกับ
OpenCV ERROR: Unspecified error (The function is not implemented.
Rebuild the library with Windows, GTK+ 2.x or Carbon support)
in function cvNamedWindow, window.cpp(71)
Terminating the application…
Segmentation fault
อ๊ากก… ค้นไปค้นมาอีกก็ได้คำแนะนำจากเว็บนี้ < – - คลิก คอมเมนต์สุดท้ายบอกไว้ว่าสาเหตุมาจากตอนรัน ./configure และ make ไม่มี gtk+ lib dev ไม่มีเขาแนะนำให้ remove openCV ออกก่อน แล้วไปลง libgtk2.0-dev (เข้า synaptic package manager แล้ว search คำว่า libgtk2.0-dev ละก็ mark for installation - > apply )
เมื่อลง libgtk2.0-dev เสร็จให้ uninstall openCV ก่อนโดยพิมพ์ make uninstall
ในไดเรคทอรี่ opencv-1.1.0 จากนั้นเพื่อความชัวร์ควรจะ restart เครื่องก่อน
(ผมไม่รีสตาร์ทเครื่อง make ใหม่ก็เจอปัญหาเดิม เลยลอง รีสตาร์ทเครื่อง แล้วทำใหม่)
แล้วทำการ ./configure , make , make install อีกที
1> ./configure blablabla..
2> make
3> make install
4> export LD_LIBRARY_PATH=/home/jednipat/opencv/lib
จากนั้นไปยัง directory /home/jednipat/opencv-1.1.0/samples/c
แล้วลองคอมไพล์ไฟล์ใด ๆ ผมเลือกไฟล์ตัวอย่างการใช้งาน SURF descriptor
ชื่อไฟล์ว่า find_obj.cpp คอมไพล์ด้วยคำสั่งดังนี้
g++ find_obj.cpp -o test -I /home/jednipat/opencv/include/opencv/ -lhighgui
-L /home/jednipat/opencv/lib/
จากนั้นรัน ./test เพื่อดูผลลัพธ์ของโปรแกรม
เย้… สำเร็จ..
วันพุธที่ 9 มีนาคม พ.ศ. 2554
เปลี่ยน THEMES
Theme สวยๆสำหรับ Ubuntu 10.10 และ 10.04
หลังเราได้อัพเดตหรือว่าติดตั้ง Ubuntu ใหม่แล้ว บางคนอาจจะไม่ค่อยถูกใจกับธีมเดิมๆที่มีมา ผมขอแนะนำชุดธีมเหล่านี้ครับ ซึ่งเป็นธีมที่มาจาก Besigi project ซึ่งเป็นบล็อกของ François Vogelweith สำหรับการติดตั้งจะใช้ command line นะครับ รับรองไม่ยาก โดยคุณสามารถเลือกจะติดตั้งบางธีมหรือจะติดตั้งทั้งหมดเลยก็ได้เช่นกัน
เรามาดูขั้นตอนในการติดตั้งเลยดีกว่า
ก่อนอื่นเปิด Terminal ขึ้นมากจากนั้นพิมพ์ตามนี้เลยครับ เพื่อเพิ่ม repository
sudo add-apt-repository ppa:bisigi/ppa/
ต่อจากนั้นให้พิมพ์ตามนี้เลยครับ (ก้อบวางก็ได้นะครับ เหอะๆ)
gpg --keyserver hkp://keyserver.ubuntu.com:11371 --recv-key 881574DE && gpg -a --export 881574DE | sudo apt-key add -
ต่อด้วย
sudo apt-get update
จากนั้นหากต้องการติดตั้งแบบทั้งชุดฟอลโล่ตามนี้ได้เลยครับ
sudo apt-get install bisigi-themes
หรือท่านใดต้องการติดตั้งบางธีมเท่านั้น
1-Showtime for Gnome
sudo apt-get install showtime-theme
2- Balanzan
sudo apt-get install balanzan-theme
3-Infinity
sudo apt-get install infinity-theme
4-Wild shine
sudo apt-get install wild-shine-theme
5-Exotic
sudo apt-get install exotic-theme
6- Tropical
sudo apt-get install tropical-theme
7-Bamboo Zen
sudo apt-get install bamboo-zen-theme
8- Ubuntu sunrise
sudo apt-get install ubuntu-sunrise-theme
9- Aqua Dreams
sudo apt-get install aquadreams-theme
10- Orange
sudo apt-get install orange-theme
11- Ellanna
sudo apt-get install ellanna-theme
12- Airlines
sudo aptitude install airlines-theme
13-Eco
sudo aptitude install eco-theme
หากต้องการลบก็สามารถทำได้เลย
sudo apt-get remove theme-name
หลังเราได้อัพเดตหรือว่าติดตั้ง Ubuntu ใหม่แล้ว บางคนอาจจะไม่ค่อยถูกใจกับธีมเดิมๆที่มีมา ผมขอแนะนำชุดธีมเหล่านี้ครับ ซึ่งเป็นธีมที่มาจาก Besigi project ซึ่งเป็นบล็อกของ François Vogelweith สำหรับการติดตั้งจะใช้ command line นะครับ รับรองไม่ยาก โดยคุณสามารถเลือกจะติดตั้งบางธีมหรือจะติดตั้งทั้งหมดเลยก็ได้เช่นกัน
เรามาดูขั้นตอนในการติดตั้งเลยดีกว่า
ก่อนอื่นเปิด Terminal ขึ้นมากจากนั้นพิมพ์ตามนี้เลยครับ เพื่อเพิ่ม repository
sudo add-apt-repository ppa:bisigi/ppa/
ต่อจากนั้นให้พิมพ์ตามนี้เลยครับ (ก้อบวางก็ได้นะครับ เหอะๆ)
gpg --keyserver hkp://keyserver.ubuntu.com:11371 --recv-key 881574DE && gpg -a --export 881574DE | sudo apt-key add -
ต่อด้วย
sudo apt-get update
จากนั้นหากต้องการติดตั้งแบบทั้งชุดฟอลโล่ตามนี้ได้เลยครับ
sudo apt-get install bisigi-themes
หรือท่านใดต้องการติดตั้งบางธีมเท่านั้น
1-Showtime for Gnome
sudo apt-get install showtime-theme
2- Balanzan
sudo apt-get install balanzan-theme
3-Infinity
sudo apt-get install infinity-theme
4-Wild shine
sudo apt-get install wild-shine-theme
5-Exotic
sudo apt-get install exotic-theme
6- Tropical
sudo apt-get install tropical-theme
7-Bamboo Zen
sudo apt-get install bamboo-zen-theme
8- Ubuntu sunrise
sudo apt-get install ubuntu-sunrise-theme
9- Aqua Dreams
sudo apt-get install aquadreams-theme
10- Orange
sudo apt-get install orange-theme
11- Ellanna
sudo apt-get install ellanna-theme
12- Airlines
sudo aptitude install airlines-theme
13-Eco
sudo aptitude install eco-theme
หากต้องการลบก็สามารถทำได้เลย
sudo apt-get remove theme-name
สมัครสมาชิก:
บทความ (Atom)