CentOS 新增硬碟 - 新增 VMWare (ESX) 硬碟

  • 5312
  • 0

摘要:CentOS 新增硬碟 - 新增 VMWare (ESX) 硬碟

 

 當你的 CentOS 安裝在虛擬主機 vmware 環境下,如果想新增一顆硬碟該怎麼做呢?我們來聊聊處理的方法!!

首先,你必須先在 vmware 的環境裡,增加一顆磁碟給 CentOS (傳統就是在主機上多插一顆硬碟)
然後在到 CentOS 找到並將這顆磁碟給 mount 起來

----------

S1:想在 vmware 的環境裡增加一顆磁碟,你可以在 Guest OS 的名稱上點滑鼠右鍵,然後選「Edit Settings」進行環境設定

 

S2:在硬體頁籤裡「Add」磁碟 Hard Disk


 

S3:這個步驟可以讓你選新增一顆磁碟,或是去掛載 mount 已存在的磁碟

 

S4:設定磁碟大小及選擇 Data Provisioning 的方式

 

S5:對應的 device Node,這項不用改他,系統會依序的增加,所以直接下一步



S6:最後確認各項設定是否如你所想


 

設定「Finish」後重新啟動 Guest OS 讓他去抓到這個新硬體,然後開始進入『CentOS 怎麼新增硬碟』的步驟

步驟我用底下列點的方式呈現,至於完整的畫面,就請大家看更底下方框中的執行過程。

  1. dmesg | grep sdb     // 先察看開機過程有沒找到新的硬碟(因為是第2顆所以是 sdb)
  2. sudo blkid                   //察看目前掛載硬碟的UUID,blkid: command-line utility to locate/print block device attributes
  3. sudo fdisk -l                // 列出目前抓到的硬碟資訊
  4. sudo fdisk /dev/sdb   //開始對 sdb 硬碟做 fdisk 初始化
  5. sudo mkfs.ext4 -L data200G /dev/sdb1   //對sdb 硬碟做格式化
  6. sudo blkid                   // 再觀察剛剛加進來的 sdb 是否加入了
  7. sudo mkdir /home/www    //建立 mount point 目錄
  8. sudo vi /etc/fstab     //修改 fstab 檔案
  9. sudo mount -a           // 全部掛載 fstab 裡有記載的 partition
  10. df -h                            // 觀察磁碟空間 
 
 
[user1@CentOS64 ~]$ more /etc/fstab

# /etc/fstab
# Created by anaconda on Fri Apr 19 15:09:58 2013
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
UUID=e1b0ddc7-94c0-4600-86c0-0759c8ed3732 /                       ext4    defaults        1 1
UUID=723260b1-a847-4324-8756-374024dc0431 swap                    swap    defaults        0 0
tmpfs                   /dev/shm                tmpfs   defaults        0 0
devpts                  /dev/pts                devpts  gid=5,mode=620  0 0
sysfs                   /sys                    sysfs   defaults        0 0
proc                    /proc                   proc    defaults        0 0

[user1@CentOS64 ~]$ man blkid

[user1@CentOS64 ~]$ sudo blkid
/dev/sda2: UUID="e1b0ddc7-94c0-4600-86c0-0759c8ed3732" TYPE="ext4" 
/dev/sda1: UUID="723260b1-a847-4324-8756-374024dc0431" TYPE="swap" 

[user1@CentOS64 ~]$ dmesg | grep sdb
sd 2:0:1:0: [sdb] 419430400 512-byte logical blocks: (214 GB/200 GiB)
sd 2:0:1:0: [sdb] Write Protect is off
sd 2:0:1:0: [sdb] Mode Sense: 61 00 00 00
sd 2:0:1:0: [sdb] Cache data unavailable
sd 2:0:1:0: [sdb] Assuming drive cache: write through
sd 2:0:1:0: [sdb] Cache data unavailable
sd 2:0:1:0: [sdb] Assuming drive cache: write through
 sdb: unknown partition table
sd 2:0:1:0: [sdb] Cache data unavailable
sd 2:0:1:0: [sdb] Assuming drive cache: write through
sd 2:0:1:0: [sdb] Attached SCSI disk
 

[user1@CentOS64 ~]$ sudo fdisk -l
Disk /dev/sda: 55.8 GB, 55834574848 bytes
64 heads, 32 sectors/track, 53248 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000a8759

Device Boot      Start         End      Blocks   Id  System

/dev/sda1               2        2001     2048000   82  Linux swap / Solaris
Partition 1 does not end on cylinder boundary.
/dev/sda2   *        2002       53248    52476928   83  Linux
Partition 2 does not end on cylinder boundary.

Disk /dev/sdb: 214.7 GB, 214748364800 bytes
255 heads, 63 sectors/track, 26108 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

[user1@CentOS64 ~]$ sudo fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x06d9f3c4.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.
 

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite) 

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p

Partition number (1-4): 1
First cylinder (1-26108, default 1): 
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-26108, default 26108): Enter
Using default value 26108

Command (m for help): p

Disk /dev/sdb: 214.7 GB, 214748364800 bytes
255 heads, 63 sectors/track, 26108 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x06d9f3c4

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1       26108   209712478+  83  Linux

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

[user1@CentOS64 ~]$ cat /proc/partitions
major minor  #blocks  name
 

   8        0   54525952 sda
   8        1    2048000 sda1
   8        2   52476928 sda2
   8       16  209715200 sdb
   8       17  209712478 sdb1

[user1@CentOS64 ~]$ sudo mkfs.ext4 -L data200G /dev/sdb1
mke2fs 1.41.12 (17-May-2010)
Filesystem label=data200G
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
13107200 inodes, 52428119 blocks
2621405 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
1600 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks: 
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
4096000, 7962624, 11239424, 20480000, 23887872

Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
 

This filesystem will be automatically checked every 28 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

[user1@CentOS64 ~]$ sudo blkid
/dev/sda2: UUID="e1b0ddc7-94c0-4600-86c0-0759c8ed3732" TYPE="ext4" 
/dev/sda1: UUID="723260b1-a847-4324-8756-374024dc0431" TYPE="swap" 
/dev/sdb1: LABEL="data200G" UUID="89a79c32-7914-48ca-ba50-b2c67ae9dfb7" TYPE="ext4" 

[user1@CentOS64 ~]$ sudo mkdir /home/www/
[user1@CentOS64 ~]$ sudo vi /etc/fstab                  //註1*
[user1@CentOS64 ~]$ sudo mount -a
[user1@CentOS64 ~]$ df -h
檔案系統              Size  Used Avail Use% 掛載點
/dev/sda2              50G  3.7G   44G   8% /
tmpfs                   1.9G  228K  1.9G   1% /dev/shm
/dev/sdb1             197G  188M  187G   1% /home/www

 

 

//註1*   CentOS 掛載磁碟的 fstab 有三種寫法

#1 使用 UUID,這個 UUID 千萬別抄我的阿,要看你的 blkid 執行出來的結果
UUID="89a79c32-7914-48ca-ba50-b2c67ae9dfb7"     /home/www     ext4    defaults     1 2

 

#2 使用 Device Name
/dev/sdb1               /home/www               ext4    defaults        1 2

 

#3 使用 partition Label Name 也就是前面的 data200G,前面格式化若沒指定 -L 那就不要用這個方法囉!反正 Label 在 unix 裡也不太重要。
LABEL=data200G       /home/www               ext4    defaults        1 2

 

 ~End