Showing posts with label linux. Show all posts
Showing posts with label linux. Show all posts

Wednesday, March 30, 2016

check bad sector on linux


ก่อนอื่นต้องเช็ค Disk drive บนเครื่องก่อน มีอะไรบ้าง สำหรับเครื่องที่ใช้รูปแบบดิสก์เป็น LVM ใช้คำสั่งตรวจเช็คดังนี้ check-disk-lvm-on-centos

แล้วใช้คำสั่งต่อไปนี้ ตรวจสอบฮาร์ดดิสก์

badblocks -v /dev/sda2 > bad-block


หลังจากรันคำสั่งเสร็จ ก็รายงานผลออกมาดังภาพด้านล่าง


badblocks -svn /dev/sdd
to have the hard disk controller replace bad blocks by spare blocks.

fsck /dev/sdd  > fix all drive
fsck /dev/sdd1  > fix special drivebadbl
repair disk

e2fsck -cfpv /dev/sda1
The parameters have the following meanings: “c” searches for bad blocks and adds them to the list, “f” forces a check on the file system, “p” repairs anything that can be safely repaired and “v” is verbose mode so you can see the command progress.

Ref: fix haddisk bad sector

Thursday, January 30, 2014

Converting to a virtual machine image

ต้องการ Convert Linux Server(Mail) run os Debain ไปยัง Vmware แต่ติดปัญหาว่ามัน Convert ไม่ได้ จึงต้องใช้วิธีการ Convert ให้เป็น Image file(IMG) ก่อน จากนั้น convert img -to .vmdk (Vmware)
วิธีการ
1. ในเครื่อง Linux หา h/d สักลูกไปจั้มต่อด้านหลัง แล้ว mount h/d external ขึ้นมา เพื่อเก็บไฟล์ Image หรือ Map network drive ไปยังเครื่อง Share File server ดังนี้ แก้ไข /etc/fstab

//192.168.x.xx/Sharefile  /media/disk  cifs    username=center1,password=mst001,iocharset=utf8,codepage=unicode,unicode       0      0

เสร็จแล้วสร้าง Folder ที่ /media/disk แล้ว Run mount -a จะ Map driver ขึ้นมา

2. Convert Image file ด้วยคำสั่ง

dd if=/dev/sda of=/media/EXTERNAL_DRIVE/sda.img bs=1024

3. ติดตั้ง Software qemu-img เพื่อ Convert File Image
ผมใช้ Ubuntu Convert

qemu-img convert -f raw sda.img -O vmdk sda.vmdk.

4. นำไฟล์ Vmdk ที่ได้ Add disk เข้าไปใน Vmware
เข้าไปสร้าง Vmware ไว้ก่อนแต่ไม่ต้องมีต้อง H/D เพราะจะแอดเพิ่มเข้าไปที่หลัง

5. ทดสอบการใช้งาน
ในเคสนี้เจอว่า มันไม่สามารถรัน Mysql ได้ เกิด Err.

'Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (111)'

วิธีการแก้ปัญหา
แก้ไข file /etc/mysql/my.cnf เพิ่มบรรทัดนี้เข้าไป แล้ว Restart 1 ครั้ง

[mysqld]
innodb_force_recovery = 1

อ้างอิง
Convert Image and Vmware
แก้ไข Err. mysql
Add/Remove Mysql