VMware Workstation 添加磁盤 掛載目錄(centos)

參考文檔: Linux命令大全

需求:測試環境虛擬機某個目錄下空間不足,準備通過添加一塊磁盤,並將該目錄掛載到該磁盤

前面幾步在測試服務器上操作的,截圖困難,所以網上找了幾張設置圖

  • 關閉虛擬機(沒測試過不關閉的情況)
  • 虛擬機中添加一塊新的磁盤
    虛擬機中添加一塊新的磁盤.png

  • 選擇磁盤類型
    選擇磁盤類型.png

  • 創建新磁盤

創建新磁盤.png


  • 設置大小、拆分方式
    設置大小、拆分方式.png

  • 設定文件名(一般默認即可)
    設定文件名.png

  • 確定(一定要確定,不然不會保存的)
    確定.png

  • 重啓虛擬機

  • fdisk觀察硬盤實體使用情況
[root@node3 ~]# fdisk -l

Disk /dev/sda: 536.9 GB, 536870912000 bytes, 1048576000 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000bd826

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200  1048575999   523238400   8e  Linux LVM

//新加的磁盤(100G)
Disk /dev/sdb: 107.4 GB, 107374182400 bytes, 209715200 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/mapper/centos-root: 53.7 GB, 53687091200 bytes, 104857600 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/mapper/centos-swap: 2147 MB, 2147483648 bytes, 4194304 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/mapper/centos-home: 480.0 GB, 479954206720 bytes, 937410560 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

  • 選擇要進行操作的磁盤
[root@node3 ~]# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x2890866a.

  • 輸入m列出可以執行的命令:
command (m for help): m
Command action
   a   toggle a bootable flag
   b   edit bsd disklabel
   c   toggle the dos compatibility flag
   d   delete a partition //刪除現有分區
   l   list known partition types
   m   print this menu
   n   add a new partition //添加新的分區
   o   create a new empty DOS partition table
   p   print the partition table //查看分區情況
   q   quit without saving changes
   s   create a new empty Sun disklabel
   t   change a partition's system id
   u   change display/entry units
   v   verify the partition table
   w   write table to disk and exit
   x   extra functionality (experts only)

  • 輸入p列出磁盤目前的分區情況 (如果是新的磁盤 忽略步驟)
Command (m for help): p

Disk /dev/sdb: 3221 MB, 3221225472 bytes
255 heads, 63 sectors/track, 391 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1           1        8001   8e  Linux LVM
/dev/sdb2               2          26      200812+  83  Linux
  • 刪除現有分區
Command (m for help): d
Partition number (1-4): 1

Command (m for help): d
Selected partition 2

  • 確認分區已經刪除
Command (m for help): p

Disk /dev/sdb: 3221 MB, 3221225472 bytes
255 heads, 63 sectors/track, 391 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System

Command (m for help):

  • 建立新的磁盤分區(兩個主磁盤分區)
Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p    //建立主分區
Partition number (1-4): 1  //分區號
First cylinder (1-391, default 1):  //分區起始位置
Using default value 1
last cylinder or +size or +sizeM or +sizeK (1-391, default 391): 100  //分區結束位置,單位爲扇區(磁盤扇區默認是512Byte)

Command (m for help): n  //再建立一個分區
Command action
   e   extended
   p   primary partition (1-4)
p 
Partition number (1-4): 2  //分區號爲2
First cylinder (101-391, default 101):
Using default value 101
Last cylinder or +size or +sizeM or +sizeK (101-391, default 391): +200M  //分區結束位置,單位爲M

  • 建一個擴展分區
Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
e  //選擇擴展分區
Partition number (1-4): 3
First cylinder (126-391, default 126):
Using default value 126
Last cylinder or +size or +sizeM or +sizeK (126-391, default 391)://剩下的空間都用做擴展分區
Using default value 391

  • 查看擴展分區
Command (m for help): p

Disk /dev/sdb: 3221 MB, 3221225472 bytes
255 heads, 63 sectors/track, 391 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1         100      803218+  83  Linux
/dev/sdb2             101         125      200812+  83  Linux
/dev/sdb3             126         391     2136645    5  Extended

  • 擴展分區上建立邏輯分區
Command (m for help): n
Command action
   l   logical (5 or over)
   p   primary partition (1-4)
l //選擇邏輯分區
First cylinder (126-391, default 126):
Using default value 126
Last cylinder or +size or +sizeM or +sizeK (126-391, default 391): +400M    

Command (m for help): n
Command action
   l   logical (5 or over)
   p   primary partition (1-4)
l
First cylinder (176-391, default 176):
Using default value 176
Last cylinder or +size or +sizeM or +sizeK (176-391, default 391):
Using default value 391

  • 查看當前分區情況
Command (m for help): p

Disk /dev/sdb: 3221 MB, 3221225472 bytes
255 heads, 63 sectors/track, 391 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1         100      803218+  83  Linux
/dev/sdb2             101         125      200812+  83  Linux
/dev/sdb3             126         391     2136645    5  Extended
/dev/sdb5             126         175      401593+  83  Linux
/dev/sdb6             176         391     1734988+  83  Linux

Command (m for help):

從上面的結果我們可以看到,在硬盤sdb我們建立了2個主分區(sdb1,sdb2),1個擴展分區(sdb3),2個邏輯分區(sdb5,sdb6)

注意:主分區和擴展分區的磁盤號位1-4,也就是說最多有4個主分區或者擴展分區,邏輯分區開始的磁盤號爲5,因此在這個實驗中試沒有sdb4的。


  • 保存分區操作
Command (m for help): w
The partition table has been altered!

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

分區創建方式按照參考文檔的操作,但是我並沒有創建這麼多分區,100G全部創建了主分區即/dev/sdb1


  • fdisk 查看硬盤分區情況
[root@node3 ~]# fdisk -l

Disk /dev/sda: 536.9 GB, 536870912000 bytes, 1048576000 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000bd826

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200  1048575999   523238400   8e  Linux LVM

Disk /dev/sdb: 107.4 GB, 107374182400 bytes, 209715200 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x2890866a

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048   209715199   104856576   83  Linux  //新的分區(sbd1:100G)

Disk /dev/mapper/centos-root: 53.7 GB, 53687091200 bytes, 104857600 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/mapper/centos-swap: 2147 MB, 2147483648 bytes, 4194304 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/mapper/centos-home: 480.0 GB, 479954206720 bytes, 937410560 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

  • cat /proc/partitions 查看磁盤文件信息
[root@node3 ~]# cat /proc/partitions
major minor  #blocks  name

   8        0  524288000 sda
   8        1    1048576 sda1
   8        2  523238400 sda2
   8       16  104857600 sdb
   8       17  104856576 sdb1
  11        0    1048575 sr0
 253        0   52428800 dm-0
 253        1    2097152 dm-1
 253        2  468705280 dm-2

  • mkfs -t ext3 /dev/sdb1格式化分區
[root@node3 ~]# mkfs -t ext3 /dev/sdb1
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
6553600 inodes, 26214144 blocks
1310707 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
800 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

Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
  • mount /dev/sdb1 /guazai
#/usr/hdp/  目錄要先存在
[root@node3 ~]# mount /dev/sdb1 /usr/hdp/
  • 查看掛載情況
[root@node3 usr]# df -h
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/centos-root   50G   50G   20K 100% /
devtmpfs                 3.8G     0  3.8G   0% /dev
tmpfs                    3.9G     0  3.9G   0% /dev/shm
tmpfs                    3.9G   12M  3.8G   1% /run
tmpfs                    3.9G     0  3.9G   0% /sys/fs/cgroup
/dev/sda1               1014M  142M  873M  14% /boot
/dev/mapper/centos-home  447G 1018M  446G   1% /home
tmpfs                    781M     0  781M   0% /run/user/0
/dev/sdb1                 99G   60M   94G   1% /usr/hdp //掛載成功
  • 取消掛載
[root@node3 /]# umount /dev/sdb1
[root@node3 /]# df -k
Filesystem              1K-blocks     Used Available Use% Mounted on
/dev/mapper/centos-root  52403200 52403180        20 100% /
devtmpfs                  3983896        0   3983896   0% /dev
tmpfs                     3996168        0   3996168   0% /dev/shm
tmpfs                     3996168    11992   3984176   1% /run
tmpfs                     3996168        0   3996168   0% /sys/fs/cgroup
/dev/sda1                 1038336   145260    893076  14% /boot
/dev/mapper/centos-home 468476420  1041428 467434992   1% /home
tmpfs                      799236        0    799236   0% /run/user/0

取消掛載成功
還可以用umount /usr/hdp 取消掛載

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章