今天上午,因为练习需要,我想要装一个Oracle 12R2的数据库,软件也下载了,也上传到虚拟机了,解压的时候,发现解压失败,因为磁盘空间满了,没法解压了,但是这不能阻挡我想要装数据库的动力,所以我就想着在linux系统上添加额外的磁盘。其实这种问题,很多朋友都遇到过这样问题,自己的虚拟机用着用着,忽然发现没有空间了,但是还必须用,这怎么办呢,就必须在现有的linux系统上添加新的磁盘,所以我就总结一下,方便大家的使用。
在当前的我这个环境中,我必须首先把我当前的虚拟机关机,然后添加硬盘。我用的是VMware Workstation虚拟计算机软件。关机之后,设备--硬盘,左下方“添加”,进入添加硬件向导中,硬盘--默认第二个scsi接口类型--模式,独立永久--创建新虚拟机磁盘--磁盘大小,这个根据自己需要多大,就建立多大,我这里设置10G,在选择第三个将虚拟磁盘拆分多个文件--完成。再打开计算机,下面就具体进入怎么添加磁盘了
1、fdisk-l
这个命令会列出当前分区和配置。
[root@cql ~]# fdisk -l
Disk /dev/sda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 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: 0x000e3d27
Device Boot Start End Blocks Id System
/dev/sda1 1 914 7340032 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 914 1437 4194304 82 Linux swap / Solaris
/dev/sda3 * 1437 2611 9436160 83 Linux
Disk /dev/sdb: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 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
/dev/sdb就是我新添加的硬盘
2、分区
[root@cql ~]# 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 0x902f648a.
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): m ###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)
Command (m for help): n #####新建
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-1305, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-1305, default 1305): +10G
Value out of range.
Last cylinder, +cylinders or +size{K,M,G} (1-1305, default 1305): +9G
Command (m for help): w ######保存和退出
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
验证
[root@cql ~]# fdisk -lDisk /dev/sda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 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: 0x000e3d27
Device Boot Start End Blocks Id System
/dev/sda1 1 914 7340032 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 914 1437 4194304 82 Linux swap / Solaris
/dev/sda3 * 1437 2611 9436160 83 Linux
Disk /dev/sdb: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 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: 0x902f648a
Device Boot Start End Blocks Id System
/dev/sdb1 1 1176 9446188+ 83 Linux
3、格式化
首先确定我当前的文件系统都是什么类型的,这里可以看到都是ext3日志类型的
[root@cql ~]# df -hT
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda3 ext3 8.9G 4.0G 4.5G 48% /
tmpfs tmpfs 931M 72K 931M 1% /dev/shm
/dev/sda1 ext3 6.9G 3.4G 3.2G 52% /u01
格式化
[root@cql ~]# mkfs.ext3 /dev/sdb1
mke2fs 1.41.12 (17-May-2010)文件系统标签=
操作系统:Linux
块大小=4096 (log=2)
分块大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
591008 inodes, 2361547 blocks
118077 blocks (5.00%) reserved for the super user
第一个数据块=0
Maximum filesystem blocks=2420113408
73 block groups
32768 blocks per group, 32768 fragments per group
8096 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632
正在写入inode表: 完成
Creating journal (32768 blocks): 完成
Writing superblocks and filesystem accounting information: 完成
This filesystem will be automatically checked every 29 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
4、挂在分区
[root@cql ~]# mount /dev/sdb1 /u01
查看
[root@cql ~]# df -hFilesystem Size Used Avail Use% Mounted on
/dev/sda3 8.9G 4.0G 4.5G 48% /
tmpfs 931M 224K 931M 1% /dev/shm
/dev/sda1 8.9G 149M 8.3G 2% /u01
/dev/sr0 3.6G 3.6G 0 100% /media/RHEL_6.5 x86_64 Disc 1
/dev/sdb1 8.9G 149M 8.3G 2% /u01
5、加入开机自动
我是通过修改/etc/fstab文件,加入开机自动的,反正方法各种各样,都可以的,随自己的心情~
5.1首先查看分区的UUID
[root@cql ~]# sudo blkid
/dev/sda3: UUID="16046051-6a05-4e6b-b5d2-b64258f5e6d2" TYPE="ext3"
/dev/sda1: UUID="1573581f-e2d5-4f7c-a2de-da6e0eb94359" TYPE="ext3"
/dev/sda2: UUID="a0b44529-1476-4cd7-a009-51b879ba163a" TYPE="swap"
/dev/sdb1: UUID="f124b1f5-16df-4d68-bdc4-41aa08562111" TYPE="ext3"
5.2编辑
[root@cql ~]# vi /etc/fstab#
# /etc/fstab
# Created by anaconda on Sun Sep 17 22:40:58 2017
#
# 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=16046051-6a05-4e6b-b5d2-b64258f5e6d2 / ext3 defaults 1 1
UUID=1573581f-e2d5-4f7c-a2de-da6e0eb94359 /u01 ext3 defaults 1 2
UUID=a0b44529-1476-4cd7-a009-51b879ba163a 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
UUID=f124b1f5-16df-4d68-bdc4-41aa08562111 /u01 ext3 defaults 1 2
~
"/etc/fstab" 16L, 899C written
[root@cql ~]# cat /etc/fstab
#
# /etc/fstab
# Created by anaconda on Sun Sep 17 22:40:58 2017
#
# 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=16046051-6a05-4e6b-b5d2-b64258f5e6d2 / ext3 defaults 1 1
UUID=1573581f-e2d5-4f7c-a2de-da6e0eb94359 /u01 ext3 defaults 1 2
UUID=a0b44529-1476-4cd7-a009-51b879ba163a 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
UUID=f124b1f5-16df-4d68-bdc4-41aa08562111 /u01 ext3 defaults 1 2
5.3重启,确认结果~
[root@cql ~]# reboot
Broadcast message from root@cql
(/dev/pts/3) at 21:50 ...
The system is going down for reboot NOW!
[root@cql ~]# df -hT
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda3 ext3 8.9G 4.0G 4.5G 48% /
tmpfs tmpfs 931M 72K 931M 1% /dev/shm
/dev/sda1 ext3 8.9G 149M 8.3G 2% /u01
/dev/sdb1 ext3 8.9G 149M 8.3G 2% /u01
OK!