การเพิ่ม 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 วิธีจากหลายๆวิธี)
    [shell]
    [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
    [/shell]

  2. รันคำสั่ง
    [shell][root@ezylinux ~]# fdisk /dev/hdb[/shell]

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

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

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

    [shell][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
    [/shell]

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

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

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

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

    [shell][root@ezylinux ~]# echo "LABEL=/test1 /test1 ext3 defaults 1 2" >>/etc/fstab[/shell]

  7. จากนั้นลองใช้คำสั่ง
    [shell][root@ezylinux ~]# df -h[/shell]

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

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

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

Comments are closed.