仮想マシンのディスク拡張

1.はじめに

開発を行うとき、使用中の仮想マシンが多く、そのような問題に遭遇することがよくあります。仮想マシンの作成時に作成されたディスク領域は比較的小さく、仮想マシンとともにインストールされるソフトウェアの占有スペースもますます増えています。大規模なため、仮想マシンのディスク領域がますます少なくなるか、十分ではなくなります。この時点で、仮想マシンのディスクサイズ拡張できます。簡単に言うと、仮想マシンに別のディスクを追加します。

2.仮想マシンの拡張手順

Linuxシステムfdiskコマンドを使用してディスク操作します。

2.1現在の仮想マシンのディスク使用量

# fdisk -l
Disk /dev/sda: 100 GiB, 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
Disklabel type: dos
Disk identifier: 0xb7a127db

Device     Boot     Start       End   Sectors  Size Id Type    第一块磁盘分为三个扇区
/dev/sda1  *         2048 207620095 207618048   99G 83 Linux
/dev/sda2       207622142 209713151   2091010 1021M  5 Extended
/dev/sda5       207622144 209713151   2091008 1021M 82 Linux swap / Solaris


Disk /dev/sdb: 300 GiB, 322122547200 bytes, 629145600 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
Disklabel type: dos
Disk identifier: 0x9b2ba102

Device     Boot Start       End   Sectors  Size Id Type		第二块磁盘只有一个扇区
/dev/sdb1        2048 629145599 629143552  300G 83 Linux
# 

上記の情報から、現在の仮想マシンには2つのディスク(1つは100G、もう1つは300G)が含まれており、各ディスクは異なる数のセクター(ユニット)に分割されていることがわかります。この情報は、VMwareの「仮想マシン設定」で確認できます。仮想マシンで表示されるのは、次の2つのディスクです。「ハードディスク」=「/ dev / sda」、「ハードディスク2」=「/ 「dev / sdb」です
ここに画像の説明を挿入
が、空きパーティションは使用できないため、まず物理マシンsystem上の仮想マシンに一定量のディスク領域を割り当てる必要がありますつまり、上の図にもう1つ「ディスク3」を追加して、仮想マシンに未使用のディスクが表示され、新しく割り当てられたディスクを操作します。

2.2仮想マシンにディスク容量を割り当てる

物理マシン(物理マシン、ホスト)のVMwareソフトウェアに新しいディスクを追加します。「次へ」までのすべての方法を
ここに画像の説明を挿入
作成できます。新しく作成したディスクの情報がページに表示されます(作成したディスクサイズは20Gです)。
ここに画像の説明を挿入

  • ディスクが作成されました。次のステップは仮想マシンで操作することです

2.3現在の仮想マシンのディスク使用量

上記の手順の後、Windows物理マシン上に新しいディスクが作成されます。ディスクを操作するには、まず最新のディスク割り当てと使用状況を確認する必要があります。

# fdisk -l
Disk /dev/sda: 100 GiB, 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
Disklabel type: dos
Disk identifier: 0xb7a127db

Device     Boot     Start       End   Sectors  Size Id Type
/dev/sda1  *         2048 207620095 207618048   99G 83 Linux
/dev/sda2       207622142 209713151   2091010 1021M  5 Extended
/dev/sda5       207622144 209713151   2091008 1021M 82 Linux swap / Solaris


Disk /dev/sdb: 300 GiB, 322122547200 bytes, 629145600 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
Disklabel type: dos
Disk identifier: 0x9b2ba102

Device     Boot Start       End   Sectors  Size Id Type
/dev/sdb1        2048 629145599 629143552  300G 83 Linux

Disk /dev/sdc: 20 GiB, 21474836480 bytes, 41943040 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
# 

2.1での表示結果と比較すると、サイズ20Gの追加のディスク** / dev / sdc **があり、このディスクは2.2で新しく割り当てられたディスクです。ただし、まだ使用できず、使用するにはフォローアップする必要があります。

  • フォローアップ操作はすべて新しく割り当てられたディスクです。私の名前は/ dev / sdcです。一部の仮想マシンには元のディスクが1つしかない場合があるため、新しく作成されたディスクは/ dev / sdbになる場合があります。ディスクの場合、/ dev / sddになります。つまり、これは単なるディスク名であり、仮想マシンのクエリ結果に基づいて、以降の操作のためのディスク名を決定します

2.3パーティションを作成する

ディスク/ dev / sdcはすでに存在していますが、まだ使用できません。fdiskコマンドを使用して、/ dev / sdcにパーティションを作成します。

多くの情報があるように見えますが、実際には、「m」、「p」、「n」、「p」、「1」、「w」の数文字だけを入力する必要があります。さらに、デフォルト値を持ついくつかのコマンドがあります。ヘルプ情報を表示する必要がない場合は、['n':パーティションの作成]、['w':ディスクに書き込み、プッシュアウト]を2文字入力するだけで、残りはEnterキーシステムを使用して、デフォルト値を使用してパーティションを作成する

# fdisk /dev/sdc
Welcome to fdisk (util-linux 2.27.1).
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.
Created a new DOS disklabel with disk identifier 0x5063a350.

Command (m for help): m     【m用来查看有哪些命令】
Help:
  DOS (MBR)
   a   toggle a bootable flag
   b   edit nested BSD disklabel
   c   toggle the dos compatibility flag
  Generic
   d   delete a partition
   F   list free unpartitioned space
   l   list known partition types
   n   add a new partition
   p   print the partition table
   t   change a partition type
   v   verify the partition table
   i   print information about a partition
  Misc
   m   print this menu
   u   change display/entry units
   x   extra functionality (experts only)
  Script
   I   load disk layout from sfdisk script file
   O   dump disk layout to sfdisk script file
  Save & Exit
   w   write table to disk and exit
   q   quit without saving changes
  Create a new label
   g   create a new empty GPT partition table
   G   create a new empty SGI (IRIX) partition table
   o   create a new empty DOS partition table
   s   create a new empty Sun partition table
   
Command (m for help): p    【查询当前磁盘分区情况】
Disk /dev/sdc: 20 GiB, 21474836480 bytes, 41943040 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
Disklabel type: dos
Disk identifier: 0x5063a350


Command (m for help): n    【创建一个新分区】
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): p      【分区类型默认主分区】
Partition number (1-4, default 1): 1   【分区编号】
First sector (2048-41943039, default 2048):   【分区大小】
Last sector, +sectors or +size{K,M,G,T,P} (2048-41943039, default 41943039): 

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

Command (m for help): w		【写入磁盘并推出】
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

# 已经退出fdisk命令

2.4パーティションが正常に作成されたかどうかを確認する

パーティション情報を表示するには、引き続きコマンドfdiskを使用します。

# fdisk -l
Disk /dev/sda: 100 GiB, 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
Disklabel type: dos
Disk identifier: 0xb7a127db

Device     Boot     Start       End   Sectors  Size Id Type
/dev/sda1  *         2048 207620095 207618048   99G 83 Linux
/dev/sda2       207622142 209713151   2091010 1021M  5 Extended
/dev/sda5       207622144 209713151   2091008 1021M 82 Linux swap / Solaris


Disk /dev/sdb: 300 GiB, 322122547200 bytes, 629145600 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
Disklabel type: dos
Disk identifier: 0x9b2ba102

Device     Boot Start       End   Sectors  Size Id Type
/dev/sdb1        2048 629145599 629143552  300G 83 Linux


Disk /dev/sdc: 20 GiB, 21474836480 bytes, 41943040 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
Disklabel type: dos
Disk identifier: 0x5063a350

Device     Boot Start      End  Sectors Size Id Type
/dev/sdc1        2048 41943039 41940992  20G 83 Linux

# 

情報の最後の行から、/ dev / sdc1が作成され、サイズがちょうど20Gであることがわかります。

2.5パーティションのフォーマット

ディスクパーティション** / dev / sdc1を作成した後、すぐにパーティションを使用することはできません。パーティションのファイルシステムフォーマットするには、mkfs 使用する必要があります/ dev / sdc1 **:個人的な使用はext4ファイルシステムです

# mkfs.ext4 /dev/sdc1 
mke2fs 1.42.13 (17-May-2015)
Creating filesystem with 5242624 4k blocks and 1310720 inodes
Filesystem UUID: 1cf52965-51df-451e-ae80-404cdf6a1568
Superblock backups stored on blocks: 
	32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
	4096000

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

#

2.6ファイルシステムのマウント

パーティションをフォーマットした後は使用できますが、使用する場合は、特定のファイル(「すべてがファイル」)の下にパーティションをマウントして、必要なファイルなどをこのディレクトリに配置できるようにする必要があります。ファイルは新しいディスクに置かれます。次のようにコマンドをハングします。

# mkdir /sunzd
# mount /dev/sdc1 /sunzd

上記のコマンドにより、ディスク/ dev / sdc1が/ sunzdディレクトリにマウントされます。通常の方法は、上記のhangコマンドをシステム初期化スクリプトに入れることです。これにより、仮想マシンが起動するたびに、指定したディレクトリのディスクで自動的にハングします。
これ以降、ディレクトリ** / sunzd **の操作は、ディスク** / dev / sdc1 **を操作することです。
マウントコマンドを** / etc / rc.local **スクリプトに入れます。

root@book-virtual-machine:/home/book# cat /etc/rc.local 
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
ifconfig ens33 192.168.1.54
mount /dev/sdc1 /home/sunzd/
exit 0

2.7パーティションのステータスの確認

dfコマンドを使用して、現在のディスクハングステータスを表示します。

root@book-virtual-machine:/home/book# df -l
Filesystem     1K-blocks      Used Available Use% Mounted on
udev             1977632         0   1977632   0% /dev
tmpfs             401628      6380    395248   2% /run
/dev/sda1      102049120   7139108  89703180   8% /
tmpfs            2008124       216   2007908   1% /dev/shm
tmpfs               5120         4      5116   1% /run/lock
tmpfs            2008124         0   2008124   0% /sys/fs/cgroup
/dev/sdb1      309505024    951480 292808572   1% /work
vmhgfs-fuse    131853484 113761468  18092016  87% /mnt/hgfs
tmpfs             401628        68    401560   1% /run/user/1000
/dev/sdc1       20510332     44992  19400432   1% /home/sunzd
# 
81件の元の記事が公開されました 高く評価されました 69 訪問者50,000以上

おすすめ

転載: blog.csdn.net/s2603898260/article/details/103837379