在Vmware Workstation的 Redhat linux系统硬盘扩容

Vmware Workstation Redhat Linux系统硬盘扩容
服务器可能会随着业务量的不断增长造成磁盘空间不足的情况,这时候就需要增加磁盘空间,这里介绍使用fdisk分区工具创建磁盘分区和挂载分区,介绍对原有的磁盘的剩余空间增加分区。采用创建主分区或扩展分区
1 打开虚拟机
在Vmware Workstation 我的计算机下的虚拟机双击,点击:“设备->硬盘”
在这里插入图片描述

2 将磁盘空间扩大到120GB
在右侧的“磁盘实用工具”下点击“扩展” 虚拟机,出现“扩展磁盘容量”对话框,输入要扩展到的容量,我从70GB扩展到120GB
在这里插入图片描述

3 启动VMware环境下的Linux操作系统,添加新分区,需要root账号身份。
(切换root帐号的linux命令为: su )
3.1 fdisk -l, 查看最大分区为/dev/sda3,说明新创建的分区将是sda4

[root@Master dhy]# fdisk -l
Disk /dev/sda: 128.8 GB, 128849018880 bytes
255 heads, 63 sectors/track, 15665 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: 0x0004fa36

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          39      307200   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              39         894     6864896   82  Linux swap / Solaris
Partition 2 does not end on cylinder boundary.
/dev/sda3             894        9138    66227200   83  Linux

3.2输入【fdisk /dev/sda】
(使用fdisk /dev/sda进入菜单项m是列出菜单,p是列出分区表,n是增加分区,w是保存并退出)
a :设置可引导标记
b :修改bsd的磁盘标签
c :设置DOS操作系统兼容标记
d :删除一个分区
l :显示已知的分区类型,其中82为Linux swap分区,83为Linux分区
m :显示帮助信息
n :增加一个新的分区
o :创建一个新的空白的DOS分区表
p :显示磁盘当前的分区表
q :退出fdisk程序,不保存任何修改
s :创建一个新的空白的Sun磁盘标签
t :改变一个分区的系统号码(比如把Linux Swap分区改为Linux分区)
u :改变显示记录单位
v :对磁盘分区表进行验证
w :保存修改结果并退出fdisk程序
x :特殊功能

3.2.1命令行提示下输入【m】
3.2.2输入命令【n】添加新分区。
3.2.3输入命令【p】创建主分区。
3.2.4输入【回车】,选择默认的First cylinder,这样不浪费空间
3.2.5输入【回车】,选择默认的Last cylinder,不浪费空间
3.2.6输入【w】,保持修改

若采用创建主分区如下:

[root@Master dhy]# fdisk /dev/sda

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
Selected partition 4
First cylinder (9138-15665, default 9138): 
Using default value 9138
Last cylinder, +cylinders or +size{K,M,G} (9138-15665, default 15665): 
Using default value 15665

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

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.

若采用扩展分区如下:

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
e
Selected partition 4
First cylinder (9138-15665, default 9138): 
Using default value 9138
Last cylinder, +cylinders or +size{K,M,G} (9138-15665, default 15665): 
Using default value 15665

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

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.

3.3 这时在/dev/目录下,才能看到了新的分区比如/dev/sda4
3.3.1 查看分区信息
若建立主分区:

[root@Master ~]# fdisk -l

Disk /dev/sda: 128.8 GB, 128849018880 bytes
255 heads, 63 sectors/track, 15665 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: 0x0004fa36

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          39      307200   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              39         894     6864896   82  Linux swap / Solaris
Partition 2 does not end on cylinder boundary.
/dev/sda3             894        9138    66227200   83  Linux
/dev/sda4            9138       15665    52428792+  83  Linux

若建立扩展分区:

[root@Master ~]# fdisk -l

Disk /dev/sda: 128.8 GB, 128849018880 bytes
255 heads, 63 sectors/track, 15665 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: 0x0004fa36

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          39      307200   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              39         894     6864896   82  Linux swap / Solaris
Partition 2 does not end on cylinder boundary.
/dev/sda3             894        9138    66227200   83  Linux
/dev/sda4            9138       15665    52428792+   5  Extended

可以看到当前已创建了sdb4扩展分区,柱面从 9138到15665,即将剩下的所有空间创建为扩展分区。
可以发现sda4的文件系统类型是扩展分区,扩展分区是无法使用的,必须在扩展分区的基础上创建逻辑分区

fdisk /dev/sda 命令下输入 n 创建逻辑分区, 因为这里只剩下刚才创建的逻辑分区需要创建,所以不需要选择输入开始和结束柱面即可。
输入w保存。
3.3.2 对扩展分区需创建逻辑分区

[root@Master ~]# fdisk /dev/sda

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
First cylinder (9138-15665, default 9138): 
Using default value 9138
Last cylinder, +cylinders or +size{K,M,G} (9138-15665, default 15665): 
Using default value 15665

Command (m for help): p

Disk /dev/sda: 128.8 GB, 128849018880 bytes
255 heads, 63 sectors/track, 15665 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: 0x0004fa36

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          39      307200   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              39         894     6864896   82  Linux swap / Solaris
Partition 2 does not end on cylinder boundary.
/dev/sda3             894        9138    66227200   83  Linux
/dev/sda4            9138       15665    52428792+   5  Extended
/dev/sda5            9138       15665    52428761   83  Linux

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

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
[root@Master ~]# 

3.4 输入【reboot】 重启linux,必须reboot,否则/dev/sda4无法格式化。
3.5 格式化逻辑分区
【mkfs -t ext4 /dev/sda5】
格式化为ext4,

[root@Master ~]# mkfs.ext2 /dev/sda4
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
3276800 inodes, 13107198 blocks
655359 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
400 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

Writing inode tables: done                            
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 24 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
[root@Master ~]# 

mkfs -t ext4 /dev/sda5

3.6 在根目录下创建disk5目录
3.7 【mount /dev/sda4 /disk4/】将分区mount到/disk5/上

[root@Master ~]# mkdir /disk5
[root@Master ~]# mount /dev/sda5/ /disk5/

3.8 在vim修改/etc/fstab文件,加入
【/dev/sda5 /disk5 ext2 defaults 0 0】一行,并保存,实现开机自动mount。

至此,新增加的磁盘空间容量,即可在disk4上体现,并且重新开机自动mount该分区,追加磁盘空间的工作完毕。

[root@Master ~]# df -l
Filesystem     1K-blocks     Used Available Use% Mounted on
/dev/sda3       65055532 23711584  38032588  39% /
tmpfs             953140      224    952916   1% /dev/shm
/dev/sda1         289293    39766    234167  15% /boot
/dev/sr0         3787224  3787224         0 100% /media/RHEL-6.8 Server.x86_64
/dev/sda5       51475028    53064  48800528   1% /disk5
[root@Master ~]# 

如果当前磁盘无容可括,可以用增加磁盘的方法,在VMware主界面,选择 【VMware】下拉菜单,选择【Settings】,用【Add】方式增加一块磁盘,后面的操作类似,不再重复。

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值