Skip to content

Disk Manage

Fri 04 Oct 2024  
🎉 Hi: ... 🎉

ข้อควรรู้ !!!

/dev/s[x][x] จะมีตัวอักษรและตัวเลขที่ไม่เหมือนกัน ขึ้นอยู่กับการติดตั้งและกำหนดชื่อ sda1 sdb2 ของแต่ละเซิร์ฟเวอร์

New disk

คำสั่งแสดงรายการ disk

bash
fdisk -l
Disk /dev/sdb: 10 GiB, 10737418240 bytes, 20971520 sectors

คำสั่งจัดการ disk

bash
fdisk /dev/sdb

Command (m for help): n

Select (default p): [ENTER]

Partition number (1-4, default 1): [ENTER]

First sector (2048-20971519, default 2048): [ENTER]

Last sector... : [ENTER]

Created a new partition 1 of type 'Linux' and of size 10 GiB.

Command (m for help): w

คำสั่งแสดงรายการ disk

bash
fdisk -l
Disk /dev/sdb: 10 GiB, 10737418240 bytes, 20971520 sectors
...
Device Boot Start End Sectors Size Id Type
/dev/sdb1 2048 20971519 20969472 10G 83 Linux

คำสั่งกำหนด ext4 system type

bash
mkfs.ext4 -F `/dev/sdb1`

สร้างแฟ้มที่ต้องการจะ mount

bash
mkdir /opt/database

คำสั่ง mount disk

bash
mount /dev/sdb1 /opt/database

เพิ่มคำสั่งที่ไฟล์ /etc/fstab

bash
vi /etc/fstab
bash
/dev/sdb1 /opt/database ext4 defaults,nofail,discard 0 0

Extend partition

  • ขั้นตอนการขยาย disk ให้มีพื้นที่มากขึ้นจาก 10GB เป็น 20GB จะต้องเพิ่มขนาด disk ใน nutanix ก่อนเป็นลำดับแรก

    ตรวจสอบพื้นที่ disk ด้วยคำสั่ง

    bash
    $ df -hT
    
    # Filesystem     Type      Size  Used Avail Use% Mounted on
    # ...
    # /dev/sdb1      ext4      9.8G   24K  9.3G   1% /opt/database

    ให้ umount /PARTITION|PATH ก่อนการ extend

    bash
    umount /opt/database

    คำสั่งจัดการ disk

    bash
    fdisk /dev/sdb

    Command (m for help): p

    Command (m for help): p
    Disk /dev/sdb: 20 GiB, 21474836480 bytes, 41943040 sectors
    Disk model: VDISK
    Units: sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 4096 bytes
    I/O size (minimum/optimal): 4096 bytes / 1048576 bytes
    Disklabel type: dos
    Disk identifier:

    Command (m for help): d

    Selected partition 1
    Partition 1 has been delet

    Command (m for help): n

    Partition type
     p   primary (0 primary, 0 extended, 4 free)
     e   extended (container for logical partitions)

    Select (default p): [ENTER]

    Partition number (1-4, default 1): [ENTER]

    First sector (2048-94371839, default 2048): [ENTER]

    Last sector... : [ENTER]

    Do you want to remove the signature? [Y]es/[N]o: N

    Command (m for help): w

    Reboot

    bash
    reboot

    Resize disk

    bash
    resize2fs /dev/sdb1

    หลังจากขยายพื้นที่ disk ตรวจสอบ disk ด้วยคำสั่ง

    bash
    $ df -hT
    
    # Filesystem     Type      Size  Used Avail Use% Mounted on
    # ...
    # /dev/sdb1      ext4       20G   24K   19G   1% /opt/database

Built with: VitePress.