Linux: Centos Kernel panic – not syncing: VFS: Unable to mount root fs on unknown-block(0,0)

สั่ง reboot แล้วเครื่องเงียบหายไป  พอไปดูที่ console พบข้อความแจ้ง Kernel panic – not syncing: VFS: Unable to mount root fs on unknown-block(0,0)

วิธีแก้ขั้นต้นก็ต้องหาทางบูทเครื่องให้ได้ก่อน โดยเลือก kernel เวอร์ชันเก่า ๆ ในระหว่างขั้นตอนการบูทเครื่อง

เมื่อลองค้นดูในอินเทอร์เน็ตก็มีหลายคนบอกว่าเป็นปัญหาที่ไฟล์ initramfs ใน /boot ที่มีปัญหาระหว่างการ upgrade kernel

วิธีแก้ที่ผมลองทำแล้วสำเร็จเลยคือสั่ง

# yum reinstall kernel

ตัวอย่างผลลัพธ์

Loaded plugins: fastestmirror, replace
Skipping the running kernel: kernel-3.10.0-514.26.2.el7.x86_64
Loading mirror speeds from cached hostfile
* base: mirror2.totbb.net
* epel: mirror2.totbb.net
* extras: mirror2.totbb.net
* ius: mirrors.tongji.edu.cn
* updates: mirror2.totbb.net
Resolving Dependencies
--> Running transaction check
---> Package kernel.x86_64 0:3.10.0-693.2.2.el7 will be installed
---> Package kernel.x86_64 0:3.10.0-693.5.2.el7 will be installed
---> Package kernel.x86_64 0:3.10.0-693.11.1.el7 will be installed
---> Package kernel.x86_64 0:3.10.0-693.11.6.el7 will be installed
---> Package kernel.x86_64 0:3.10.0-693.17.1.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===========================================================================================================================
Package Arch Version Repository Size
===========================================================================================================================
Reinstalling:
kernel x86_64 3.10.0-693.2.2.el7 updates 43 M
kernel x86_64 3.10.0-693.5.2.el7 updates 43 M
kernel x86_64 3.10.0-693.11.1.el7 updates 43 M
kernel x86_64 3.10.0-693.11.6.el7 updates 43 M
kernel x86_64 3.10.0-693.17.1.el7 updates 43 M

Transaction Summary
===========================================================================================================================
Reinstall 5 Packages

Total size: 215 M
Total download size: 172 M
Installed size: 297 M
Is this ok [y/d/N]: y
Downloading packages:
Delta RPMs disabled because /usr/bin/applydeltarpm not installed.
(1/4): kernel-3.10.0-693.5.2.el7.x86_64.rpm | 43 MB 00:00:01
(2/4): kernel-3.10.0-693.2.2.el7.x86_64.rpm | 43 MB 00:00:01
(3/4): kernel-3.10.0-693.11.1.el7.x86_64.rpm | 43 MB 00:00:01
(4/4): kernel-3.10.0-693.11.6.el7.x86_64.rpm | 43 MB 00:00:01
---------------------------------------------------------------------------------------------------------------------------
Total 63 MB/s | 172 MB 00:00:02
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : kernel-3.10.0-693.2.2.el7.x86_64 1/5
Installing : kernel-3.10.0-693.11.6.el7.x86_64 2/5
Installing : kernel-3.10.0-693.11.1.el7.x86_64 3/5
Installing : kernel-3.10.0-693.17.1.el7.x86_64 4/5
Installing : kernel-3.10.0-693.5.2.el7.x86_64 5/5

Verifying : kernel-3.10.0-693.5.2.el7.x86_64 1/5
Verifying : kernel-3.10.0-693.17.1.el7.x86_64 2/5
Verifying : kernel-3.10.0-693.11.1.el7.x86_64 3/5
Verifying : kernel-3.10.0-693.11.6.el7.x86_64 4/5
Verifying : kernel-3.10.0-693.2.2.el7.x86_64 5/5

Installed:
kernel.x86_64 0:3.10.0-693.2.2.el7 kernel.x86_64 0:3.10.0-693.5.2.el7 kernel.x86_64 0:3.10.0-693.11.1.el7
kernel.x86_64 0:3.10.0-693.11.6.el7 kernel.x86_64 0:3.10.0-693.17.1.el7

Complete!

หายใจลึก ๆ แล้ว สั่ง reboot  ถ้าบูทสำเร็จก็ยินดีด้วย 🙂

แต่ถ้าไม่สำเร็จ ลองทำตามขั้นตอนต่อไปนี้

1.  Boot into a live same version of Centos. Choose the recovery options.
2. Go through all of the default prompts, then drop down to shell.
3. Type: chroot /mnt/sysimage
4. Type: cd /boot
5. Type: ls -l initramfs*
6. Look at the version numbers and determine the last version that was installed.  Eg. initramfs-2.6.32-358.el6.x86_64.img
7. Type: dracut -f /boot/initramfs-2.6.32-358.el6.x86_64.img 2.6.32-358.el6.x86_64

This will rebuild the initramfs.  On reboot your system should come back up.

Source: http://www.techpository.com/linux-centos-6redhat-kernel-panic-not-syncing-vfs-unable-to-mount-root-fs-on-unknown-block00/

วิธีการตั้งค่าให้ Postfix เป็น mail server สำรอง

เราสามารถตั้งค่า Postfix  ให้เป็น mail server สำรอง เพื่อรับอีเมลแทนในกรณีที่ mail server  หลักเกิดปัญหา และเมื่อ mail server หลักสามารถใช้งานได้  mail server สำรองก็จะส่งอีเมลไปที่ mail server  หลัก

สมมติว่าเรามี mail server  หลักชื่อ mail.diary.in.th แล้วเราต้องการเพิ่ม mail server สำรองชื่อ mail2.diary.in.th เพื่อให้รับอีเมลชั่วคราวในระหว่างที่ mail.diary.in.th มีปัญหา

ขั้นแรกต้องเพิ่มค่า MX record ที่ zone file ให้มีค่า mail2.diary.in.th เป็น mail server ที่มีค่า priority มากกว่า mail.diary.in.th

diary.in.th    86400 IN MX 10 mail.diary.in.th.
diary.in.th    86400 IN MX 20 mail2.diary.in.th.

ก่อนบันทึกไฟล์ต้องเพิ่มค่า serial แล้วทำการ reload zone file

ขั้นตอนต่อไปต้องแก้ไขไฟล์ /etc/postfix/main.cf ที่เครื่อง mail server สำรอง (mail2.diary.in.th)

แก้ไขค่า smtpd_recipient_restrictions ให้มีค่า permit_mynetworks และ reject_unauth_destination  เช่น

smtpd_recipient_restrictions = permit_sasl_authenticated, permit_mynetworks, reject_unauth_destination

แก้ไขค่า relay_domains โดยเพิ่มชื่อโดเมนของเรา เช่น

relay_domains = $mydestination, diary.in.th

แก้ไขค่า relay_recipient_maps ให้เป็นค่าว่าง ๆ เช่น

relay_recipient_maps =

การแก้ไขให้เป็นค่าว่าง ๆ ก็เพื่อความสะดวก ที่เราไม่ต้องเพิ่มอีเมลทุกอีเมลแต่ละอีเมลด้วยตัวเอง  แต่หากต้องการเพิ่มอีเมลแต่ละอีเมลก็สามารถทำได้ เช่น

relay_recipient_maps = hash:/etc/postfix/relay_recipients

โดยในไฟล์ relay_recipients มีรายชื่ออีเมลเช่น

user1@diary.in.th    OK
user2@diary.in.th    OK

หลังจากนั้นใช้คำสั่ง

postmap /etc/postfix/relay_recipients

สิ่งที่ต้องระวังคือค่าเหล่านี้ต้องไม่มีชื่อโดเมน diary.in.th อยู่ด้วย

mydestination
virtual_alias_domains
virtual_mailbox_domains

หลังจากแก้ไขค่าต่าง ๆ แล้วให้ restart posfix โดยใช้คำสั่ง

# systemctl restart postfix

เราสามารถปรับแต่งค่าเพิ่มเติมเพื่อให้ mail server สำรองเก็บอีเมลไว้นานขึ้น โดยตั้งค่า maximal_queue_lifetime ให้นานขึ้น (ค่า default คือ 5 วัน)

maximal_queue_lifetime = 10d

อ่านข้อมูลเพิ่มเติมเกี่ยวกับ maximal_queue_lifetime ได้ที่ http://www.postfix.org/TUNING_README.html#hammer

อ้างอิงและข้อมูลเพิ่มเติมอื่น ๆ :
https://www.howtoforge.com/postfix_backup_mx
https://samhobbs.co.uk/2016/01/mx-backup-postfix-email-server
https://www.cyberciti.biz/faq/postfix-backup-mx-server-anti-spam/

CI Notice: Only variable references should be returned by reference

Screen Shot 2557-11-18 at 20.27.23

ให้แก้ไขไฟล์ Common.phop ในไดเรกทอรี system/core/ บรรทัดที่ 257 จาก

return $_config[0] =& $config;

ให้เป็น

$_config[0] =& $config;
return $_config[0];

อ้างอิง: https://ellislab.com/forums/viewthread/244510/#1066558

Remove Duplicates from the “Open With” Right-Click Menu in Mac OS X

Fix the Open WIth menu and remove duplicate app entries

The “Open With” menu appears when any file in the Mac Finder is right-clicked (or control-clicked), and it is intended to provide a list of alternate apps that selected file can be opened with other than what is currently set as the default application.”

http://osxdaily.com/2013/01/22/fix-open-with-menu-mac-os-x/

Downloading an Entire Web Site with wget

If you ever need to download an entire Web site, perhaps for off-line viewing, wget can do the
job—for example:

$ wget \
     --recursive \
     --no-clobber \
     --page-requisites \
     --html-extension \
     --convert-links \
     --restrict-file-names=windows \
     --domains website.org \
     --no-parent \
     www.website.org/tutorials/html/

This command downloads the Web site www.website.org/tutorials/html/.

The options are:

  • –recursive: download the entire Web site.
  • –domains website.org: don’t follow links outside website.org.
  • –no-parent: don’t follow links outside the directory tutorials/html/.
  • –page-requisites: get all the elements that compose the page (images, CSS and so on).
  • –html-extension: save files with the .html extension.
  • –convert-links: convert links so that they work locally, off-line.
  • –restrict-file-names=windows: modify filenames so that they will work in Windows as well.
  • –no-clobber: don’t overwrite any existing files (used in case the download is interrupted and
    resumed).Source: http://www.linuxjournal.com/content/downloading-entire-web-site-wget 

วิธีการติดตั้ง PHP 5.4 ให้กับ Mac OS X Lion

สามารถดูได้จากที่นี่ http://php-osx.liip.ch/

ติดตั้ง brew ได้จาก http://mxcl.github.com/homebrew/

และสามารถอ่านวิธีการอื่นๆ เพิ่มเติมได้ที่นี่ http://jason.pureconcepts.net/2012/10/install-apache-php-mysql-mac-os-x/

วิธีติดตั้ง Smarty 3.1.7 กับ CodeIgniter 2.1.0

ผมหาทางติดตั้ง  Smarty 3.1.7 เพื่อให้ใช้งานได้กับ CodeIgniter 2.1.0  ได้  โดยมีขั้นดังนี้

  1. ดาวน์โหลดและติดตั้ง CodeIgniter ตามปกติ
  2. การติดตั้ง Smarty จะดำเนินการโดยใช้ Ci-Smarty  ที่พัฒนาขึ้นโดยคุณ Dwayne Charrington   ให้ดาวน์โหลดและติดตั้งลงใน CodeIgniter ในข้อ 1.  แล้วให้ทำการทดสอบว่าสามารถใช้งาน Smarty ได้จริง
  3. เนื่องจากในขณะที่เขียนบทความนี้ Smarty ที่ิติดตั้งใน Ci-Smarty เป็นเวอร์ชัน 3.1.1 เราจึงต้องมีการแก้ไขปรับแก้ไฟล์  โดยโครงสร้างไฟล์ของ Ci-Smarty มีดังภาพข้างล่างนี้
  4. เราต้องปรับแก้ 3 ส่วน ตามที่ลูกศรชี้ไว้
  • ส่วนที่ 1 แก้ไขไฟล์ smarty.php ในไดเรกทอรี config  โดยให้แก้ตัวแปร $config[‘cache_status’] ให้มีค่าเป็น TRUE จากเดิมที่เป็น 1 เนื่องจากในไฟล์ libraries/Smarty.php ตรวจสอบค่า $config[‘cache_status’] ว่าเป็น TRUE หรือไม่
    $config['cache_status'] = TRUE;

    และให้เพิ่ม 2 บรรทัดต่อไปนี้ที่ท้ายไฟล์  เพื่อจะได้เป็นการบังคับให้ให้มีการ compile template ทุกครั้งในระหว่างที่เรากำลังพัฒนาโปรแกรม   และเมื่อจะนำไปใช้งานจริงก็ควรกำหนดค่าให้เป็น FALSE ทั้ง 2 ตัวแปร

    $config['compile_check'] = TRUE; 
    $config['force_compile'] = TRUE;
  • ส่วนที่ 2 แก้ไขไฟล์ Smarty.net ในไดเรอกทอรี libraries  โดยให้เพิ่ม 2 คำสั่งต่อไปนี้ใต้บรรทัดที่มี $this->template_ext เพื่อนำค่าจากการแก้ไขส่วนที่ 1 มาใช้งาน
    $this->compile_check = config_item('compile_check');
    $this->force_compile = config_item('force_compile');

    หลังจากนั้นให้ทำการ comment ในคำสั่งส่วนที่จะทำการเพิ่ม helper ต่างๆ ​ โดยใส่เครื่องหมาย /* และ */ ครอบเอาไว้  สาเหตุที่ต้อง comment ไว้ก็เพราะเมื่อเรา upgrade Smarty เป็น 3.1.7 แล้ว คำสั่งในส่วนนี้จะทำให้เกิด error  (หากอยากทราบว่าเป็นอย่างไรก็ปล่อยไว้ได้)

    /*
     // Add all helpers to plugins_dir
     $helpers = glob(APPPATH . 'helpers/', GLOB_ONLYDIR | GLOB_MARK);
    foreach ($helpers as $helper)
     {
     $this->plugins_dir[] = $helper;
     }
     */
  • ส่วนที่ 3 ให้ทำการดาวน์โหลด Smarty 3.1.7  แล้วแตกไฟล์และคัดลอกเอาไฟล์และไดเรกทอรีภายใต้ libs มาทับของเดิมใน third_party/Smarty/ ทั้งหมด

ขอขอบคุณ คุณ Dwayne Charrington ที่ได้พัฒนา Ci-Smarty ไว้ครับ  ขั้นตอนข้างบนนี้จะไม่จำเป็นเมื่อ Ci-Smarty มีการ update ครับ  และผมไม่รับประกันความเสี่ยงที่เกิดขึ้น รวมทั้งปัญหาที่ตามมาใดๆ ทั้งสิ้นครับ!

Happy Coding Year! 😀

วิธีทำให้ mod_rewrite ทำงานบน Mac OS X Lion

หากใช้งาน Apache ที่มากับ Mac OS X แล้วเกิดปัญหา mod_rewrite ไม่ทำงาน  ให้แก้ไขที่ไฟล์ /etc/apache2/users/username.conf  (แทนที่ username ด้วย username จริงๆ ที่ใช้งานในระบบ)  ให้แก้ไข ที่ AllowOverride None ให้เป็น AllowOverride All ดังตัวอย่างข้างล่าง

<Directory "/Users/username/Sites/">
     Options Indexes MultiViews
     AllowOverride All
     Order allow,deny
     Allow from All
</Directory>

อีกวิธีการหนึ่งสามารถดูได้ที่นี่ http://akrabat.com/php/setting-up-php-mysql-on-os-x-10-7-lion/

เปลี่ยนชื่อ blog ใน wordpress

ผมเปลี่ยนชื่อจาก http://www.diary.in.th/my เป็น http://my.diary.in.th

ขั้นตอนการดำเนินการก็ไม่ยาก  เพราะอยู่ใน account เดียวกันแค่สร้าง subdomain เพิ่ม และก็อปปี้ข้อมูลจากไดเรกทอรีเดิมไปที่ใหม่

WordPress ก็ได้ทำเว็บไซต์เกี่ยวกับเรื่องนี้ไว้ด้วย  สามารถทำตามได้เลย

หลังจากย้ายข้อมูลเสร็จก็ใช้ Apache mod rewrite  จัดการให้ลิ้งก์เดิมถูกส่งต่อไปลิ้งใหม่  เช่น http://www.diary.in.th/archives/572 จะถูกส่งต่อไปที่ http://my.diary.in.th/archives/572 โดยอัตโนมัติ

ผมเขียนคำสั่งต่อไปนี้ในไฟล์ .htaccess

RewriteEngine On
Redirect 301 /my http://my.diary.in.th
Redirect 301 /archives http://my.diary.in.th/archives