Linux虚拟机增加硬盘和挂载
环境:
主机:Windows10
VMware Workstation 12 pro
虚拟机操作系统:CentOS Linux release 7.2.1511 (Core)
一、虚拟机增加硬盘
需要在虚拟机关闭的状态下操作。
1、选中虚拟机,右键“管理”
2、选中SCSI硬盘
3、创建虚拟硬盘,用默认选项
4、设置硬盘大小
5、虚拟硬盘文件路径
6、点击完成后创建硬盘完成。
二、Linux下挂载硬盘
1、检查硬盘分区使用“fdisk -l”的命令,可以看到新的20G的分区在/dev/sdb
[root@localhost ~]# fdisk -l
Disk **/dev/sdb**: 21.5 GB, 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、创建新分区
用命令 分区命令:#fdisk /dev/sdb
m:列出分区菜单
n:创建新分区
[root@localhost ~]# 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.
[root@localhost ~]# 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 0xd3e8746b.
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
g create a new empty GPT partition table
G create an IRIX (SGI) partition table
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
四次输入:
- 选择主分区,输入p
- 分区号,可以回车选择默认分区号
- 第一扇区选择,直接回车
- 最后扇区选择,直接回车
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
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} (2048-41943039, default 41943039):
执行结果,输入“w"保存退出:
Using default value 41943039
Partition 1 of type Linux and of size 20 GiB is set
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
3、分区格式化
(1)检查分区结果:
[root@localhost ~]# fdisk -l
Disk /dev/sdb: 21.5 GB, 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
Disk label type: dos
Disk identifier: 0xd3e8746b
Device Boot Start End Blocks Id System
/dev/sdb1 2048 41943039 20970496 83 Linux
(2)对新建的分区进行格式化:格式化成ext3的文件系统即可
命令:mkfs -t ext3 /dev/sdb1
[root@localhost ~]# 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
1310720 inodes, 5242624 blocks
262131 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
160 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
Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
显示所有分区都“done” 。
4、挂载格式化后的分区
(1)手工挂载
设置一个根目录,挂载,检查效果如下:
[root@localhost /]# mkdir /mysql
[root@localhost mysql]# mount /dev/sdb1 /mysql
[root@localhost mysql]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 28G 27G 756M 98% /
devtmpfs 1.4G 0 1.4G 0% /dev
tmpfs 1.4G 84K 1.4G 1% /dev/shm
tmpfs 1.4G 9.1M 1.4G 1% /run
tmpfs 1.4G 0 1.4G 0% /sys/fs/cgroup
/dev/sda1 297M 144M 154M 49% /boot
tmpfs 284M 16K 284M 1% /run/user/42
tmpfs 284M 0 284M 0% /run/user/0
/dev/sdb1 20G 45M 19G 1% /mysql
可以看到mysql目录挂载在/dev/sdb1 下,挂载成功!
块设备挂载情况:
[root@localhost mysql]# lsblk -f
NAME FSTYPE LABEL UUID MOUNTPOINT
sda
├─sda1 xfs b1cba7c0-27fe-4f36-9b4f-5cdca8b70cf7 /boot
├─sda2 swap 47380043-ef2a-4c9e-ad8b-fccd35a8311e [SWAP]
└─sda3 xfs f14b5262-1518-4aed-b4f7-f236fe32272d /
sdb
└─sdb1 ext3 17b76026-beca-4134-ad44-72d69f9ab80c /mysql
sr0
(2)设置自动挂载
为了保证重启后自动挂载目录。
在/etc/fstab 文件系统列表中增加:
/dev/sdb1 /mysql ext3 defaults 0 1
[root@localhost mysql]# cat /etc/fstab
# /etc/fstab
# Created by anaconda on Wed Sep 20 03:51:18 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=f14b5262-1518-4aed-b4f7-f236fe32272d / xfs defaults 0 0
UUID=b1cba7c0-27fe-4f36-9b4f-5cdca8b70cf7 /boot xfs defaults 0 0
UUID=47380043-ef2a-4c9e-ad8b-fccd35a8311e swap swap defaults 0 0
/dev/sdb1 /mysql ext3 defaults 0 1
fstab文件6列参数简要说明如下:
- file systems : 要挂载的分区或存储设备.
- dir : file systems的挂载位置。
- type : 要挂载设备或是分区的文件系统类型,支持许多种不同的文件系统:ext2, ext3, ext4, reiserfs, xfs, jfs, smbfs, iso9660, vfat, ntfs, swap 及 auto。 设置成auto类型,mount 命令可能会使用的文件系统类型,对 CDROM 和 DVD 等移动设备是非常有用的。
- options : 挂载时使用的参数,注意有些mount 参数是特定文件系统才有 defaults 使用文件系统的默认挂载参数,例如
ext4 的默认参数为:rw, suid, dev, exec, auto, nouser, async 。 - dump: dump 工具通过它决定何时作备份. dump 会检查其内容,并用数字来决定是否对这个文件系统进行备份。 允许的数字是 0
和 1 。0 表示忽略, 1 则进行备份。大部分的用户是没有安装 dump 的 ,对他们而言 dump 应设为 0。 - pass: fsck 读取 pass 的数值来决定需要检查的文件系统的检查顺序。允许的数字是0, 1, 和2。 根目录应当获得最高的优先权 1, 其它所有需要被检查的设备设置为 2. 0 表示设备不会被 fsck 所检查。
以上就是虚拟机增加硬盘并挂载的全部操作。