How to add a new hard disk to linux system.

การเพิ่ม hard disk เข้าไปในระบบปฏิบัติการ ลินุกซ์ นั้นไม่ยากเย็นแสนเข็ญเหมือนบางคนคิด แต่เป็นอะไรที่ง่ายและไม่ยุ่งยากซับซ้อนมากมายนัก(แต่ถ้าเทียบกับ microsoft windowns ก็ยากกว่านิดหน่อย) สิ่งที่เราจะต้องรู้ืและเข้าใจก็มีพวกการแบ่ง partition การสร้าง file system และการ mount โดยคำสั่งที่จะใช้ในการเพิ่ม hard disk ใหม่เข้าสู่ระบบมีดังต่อไปนี้

  1. fdisk เป็นคำสั่งที่เอาไว้ใช้จัดการเรื่อง partition ของ Hard drive
  2. mkfs.ext3 คำสั่งในการสร้าง file system ext3
  3. e2lable คำสั่งสำหรับไว้ทำ label ของ partition
  4. mount คำสั่งสำหรับการนำ partition ที่สร้างเสร็จแล้วมาใช้งาน

หลังจากที่ได้ทราบคำสั่งที่จะนำไปใช้เบื้องต้นแล้วเราลองมาดูวิธีการเลยดีกว่าว่าทำอย่างไรบ้าง

  1. หลังจากเพิ่ม hard disk แล้วรันคำสั่ง fdisk -l เพื่อดูว่ามี hard disk ที่เราเพิ่มเข้ามาแล้วหรือยัง ตัวอย่าง ด้านล่าง มีการแอด Hard disk ใหม่ที่มีชื่อว่า hdb เนื่องจากยังไม่มี partition table เลย(เป็นวิธีการดูอย่างง่ายๆ 1 วิธีจากหลายๆวิธี)
    [root@ezylinux ~]# fdisk -l
    Disk /dev/hda: 64 heads, 63 sectors, 621 cylinders
    Units = cylinders of 4032 * 512 bytes
    
       Device Boot    Start       End    Blocks   Id  System
    /dev/hda1   *         1       184    370912+  83  Linux
    /dev/hda2           185       368    370944   83  Linux
    /dev/hda3           369       552    370944   83  Linux
    /dev/hda4           553       621    139104   82  Linux swap
    
    Disk /dev/hdb: 64 heads, 63 sectors, 621 cylinders
    Units = cylinders of 4032 * 512 bytes
    Device Boot Start End Blocks Id System
    
  2. รันคำสั่ง
    [root@ezylinux ~]# fdisk /dev/hdb

    จากนั้นจะเข้าหน้าจอในการจัดการ hard disk ให้กด n เพื่อ create partition ต่อมากด p และใส่เลข 1 จากนั้นโปรแกรมจะให้เลือกว่าจะเริ่มต้น partition ที่ cylinder ไหน โดยทั่วไปให้กด enter ต่อมาจะถามว่าให้จบที่ cylinder ไหน แต่ว่าเราไม่ต้องตกใจไปว่าเราจะต้องนับ cylinder เลยหรือ เพราะว่าโปรแกรมนี้สามารถที่จะให้เราใส่ค่าเป็นหน่วยที่เราเข้าใจได้ อย่างเช่น MB เป็นต้น ในตัวอย่างนี้จะใส่ค่า +128MB (ต้องใส่เครื่องหมาย + ด้วยทุกครั้ง) จากนั้นลองกด p ดูเพื่อดูว่า partition ที่เราสร้างขึ้นมามีหรือยัง จะได้ผลลัพธ์ดังข้างล่าง

       Device Boot    Start       End    Blocks   Id  System
    /dev/hdb1             1       196    395104   83  Linux

    จากนั้นให้กด w เพื่อทำการ save เมื่อออกมาหน้าจอ terminal แล้วลองพิมพ์คำสั่ง

    [root@ezylinux ~]# fdisk -l /dev/hdb
    Disk /dev/hdb: 64 heads, 63 sectors, 621 cylinders
    Units = cylinders of 4032 * 512 bytes
    
       Device Boot    Start       End    Blocks   Id  System
    /dev/hdb1   *         1       196    395104+  83  Linux
    

    จากตัวอย่างจะเห็นว่ามี partition /dev/hdb1 ที่เราสร้างขึ้นโผล่มาแล้ว :)

  3. รันคำสั่ง
    [root@ezylinux ~]# mkfs.ext3 /dev/hdb1

    เพื่อสร้าง file system แบบ ext3

  4. ขั้นตอนนี้จะทำหรือไม่ทำก็ได้เพราะว่าไม่ค่อยมีความสำคัญมากนัก
    ทำการสร้าง Label ของ partition นี้ โดยใช้คำสั่ง
    [root@ezylinux ~]# e2label /dev/hdb1 /test1
  5. ทำการสร้าง directory ขึ้นมาชื่อหนึ่งด้วยคำสั่ง
    [root@ezylinux ~]# mkdir /test1
  6. ทำการ mount hdb1 ที่เราได้สร้างไว้ด้วยคำสั่ง
    [root@ezylinux ~]# mount -t ext3 /dev/hdb1 /test1

    แต่ถ้าต้องการให้ auto mount ทุกครั้งที่ restart ก็ให้ใช้คำสั่ง

    [root@ezylinux ~]# echo "LABEL=/test1 /test1 ext3 defaults 1 2" >>/etc/fstab
  7. จากนั้นลองใช้คำสั่ง
    [root@ezylinux ~]# df -h

    เพื่อตรวจสอบว่ามี partition ที่เราได้ทำการ mount อยู่หรือไม่

เป็นไงบ้างครับไม่ยากอย่างที่คิดใช่ไหมครับ :)

Related posts:

  1. Format NTFS partition on external hard drive from CentOS / RHEL linux หลังจากที่ได้เขียนวิธีการ mount NTFS filesystem บน CentOS / RHEL...
  2. How to add a swap partition to my system เมือต้องการเพิ่ม SWAP Partition ขึ้นมาใหม่จำเป็นจะต้องมีพาร์ทิชั่นว่างและต้อง set partition type เป็น...
  3. How to read hard drive device files name ในระบบปฏิบัติการ Linux ได้มีการจัดเก็บข้อมูลของ device ต่างๆเป็นไฟล์ไว้ที่ directory /dev/ ซึ่งชื่อของ...
  4. Diskdump report error messages when restart the diskdump service เมื่อเราได้ทำการแก้ไขหรือ configure diskdump แล้ว restart diskdump service ได้มี...
  5. Change I/O Disk Scheduler without Reboot I/O Scheduler สำหรับ Hard disk หรือพวก block device...

You can leave a response, or trackback from your own site.

One Response to “How to add a new hard disk to linux system.”

  1. inkman says:

    สุดยอด! ขอบคุณมากครับ

Leave a Reply