漫天飞雪

虚拟机添加硬盘

一、VMware workstation菜单栏👉虚拟机👉设置👉添加👉硬盘👉下一步

img

img

二、SCSI👉下一步:

img

三、创建新虚拟磁盘👉下一步

img

四、选择自己需要的硬盘大小👉立即分配磁盘取消勾选👉将虚拟磁盘存储为单个文件👉下一步

img

五、完成

img

六、重启虚拟机后,使用lsblk命令查看磁盘情况

[root@localhost ~]# lsblk
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda               8:0    0   20G  0 disk 
├─sda1            8:1    0    1G  0 part /boot
└─sda2            8:2    0   19G  0 part 
  ├─centos-root 253:0    0   17G  0 lvm  /
  └─centos-swap 253:1    0    2G  0 lvm  [SWAP]
sdb               8:16   0    5G  0 disk 
sr0              11:0    1 1024M  0 rom  

发现已经成功添加新硬盘sdb。

七、使用fdisk创建新分区

[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 0x03295b0a.

Command (m for help):

然后输入 p ,回车:

Command (m for help): p

Disk /dev/sdb: 5368 MB, 5368709120 bytes, 10485760 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: 0x03295b0a

   Device Boot      Start         End      Blocks   Id  System

Command (m for help): 

输入 n 回车:

Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): 

输入 p 回车, 1 回车,回车,回车:

Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-10485759, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-10485759, default 10485759): 
Using default value 10485759
Partition 1 of type Linux and of size 5 GiB is set

输入 p ,回车:

Command (m for help): p

Disk /dev/sdb: 5368 MB, 5368709120 bytes, 10485760 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: 0x03295b0a

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048    10485759     5241856   83  Linux

Command (m for help):

输入 w ,回车,保存退出。至此,磁盘分区完成。

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

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

八、使用mkfs.ext4命令进行格式化

先查看分区表

[root@localhost ~]# lsblk
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda               8:0    0   20G  0 disk 
├─sda1            8:1    0    1G  0 part /boot
└─sda2            8:2    0   19G  0 part 
  ├─centos-root 253:0    0   17G  0 lvm  /
  └─centos-swap 253:1    0    2G  0 lvm  [SWAP]
sdb               8:16   0    5G  0 disk 
└─sdb1            8:17   0    5G  0 part 
sr0              11:0    1 1024M  0 rom 

发现新分区是sdb1(我只分了一个主分区,所以是sdb1。)然后我们对sdb1进行格式化

[root@localhost ~]# mkfs.ext4 /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
327680 inodes, 1310464 blocks
65523 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=1342177280
40 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

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

至此格式化完成。

九、挂载分区

我以挂载到根分区的data目录为例:

新建/data目录

[root@localhost /]# mkdir data

挂载分区到/data目录

[root@localhost /]# mount /dev/sdb1 /data

查看磁盘使用情况

[root@localhost /]# df -hT
Filesystem              Type      Size  Used Avail Use% Mounted on
/dev/mapper/centos-root xfs        17G  1.3G   16G   8% /
devtmpfs                devtmpfs  1.9G     0  1.9G   0% /dev
tmpfs                   tmpfs     1.9G     0  1.9G   0% /dev/shm
tmpfs                   tmpfs     1.9G   12M  1.9G   1% /run
tmpfs                   tmpfs     1.9G     0  1.9G   0% /sys/fs/cgroup
/dev/sda1               xfs      1014M  148M  867M  15% /boot
tmpfs                   tmpfs     378M     0  378M   0% /run/user/0
/dev/sdb1               ext4      4.8G   20M  4.6G   1% /data

十、软raid0

yum -y install mdadm
mdadm -C /dev/md0 -a yes -l 0  -n 1 --force /dev/vdb
df -h
lsblk
mkfs.xfs /dev/md0
mkdir -p /data1
ll /data1
mount /dev/md0 /data1

cat /etc/fstab 
/dev/md0            /data1            xfs    defaults      0   0 
mount -a

十一、多快盘挂载在/data目录下

方法一: 
1)磁盘分区--此步非必须 
在将磁盘或者磁盘分区用作物理卷(PV)之前,需要对其进行初始化工作,即进行磁盘分区操作
# 新建/dev/sdb的磁盘标签类型为GPT
[root@ ~]# parted /dev/sdb mklabel gpt
# 将/dev/sdb整个空间分给同一个分区
[root@ ~]# parted /dev/sdb mkpart primary 0 100%
Warning: The resulting partition is not properly aligned for best performance.
Ignore/Cancel? I                                                          
Information: You may need to update /etc/fstab.
# 新建/dev/sdc的磁盘标签类型为GPT
[root@ ~]# parted /dev/sdc mklabel gpt
# 将/dev/sdc整个空间分给同一个分区
[root@ ~]# parted /dev/sdc mkpart primary 0 100%
Warning: The resulting partition is not properly aligned for best performance.
Ignore/Cancel? I                                                          
Information: You may need to update /etc/fstab.
# 新建/dev/sde的磁盘标签类型为GPT
[root@ ~]# parted /dev/sde mklabel gpt
# 将/dev/sdc整个空间分给同一个分区
[root@ ~]# parted /dev/sde mkpart primary 0 100%
Warning: The resulting partition is not properly aligned for best performance.
Ignore/Cancel? I                                                          
Information: You may need to update /etc/fstab.

方法二:
fdisk /dev/vdb  
m n p w

2)创建物理卷
创建物理卷的命令为pvcreate;利用该命令将希望添加到卷组的所有分区或磁盘创建为物理卷;
将分区/dev/sdb1、/dev/sdc1、/dev/sde1分区创建为物理卷:
[root@ ~]#  pvcreate /dev/sdb1
  Physical volume "/dev/sdb1" successfully created.
[root@ ~]#  pvcreate /dev/sdc1
  Physical volume "/dev/sdc1" successfully created.
[root@ ~]#  pvcreate /dev/sde1
  Physical volume "/dev/sde1" successfully created.

3)创建卷组
创建卷组的命令为vgcreate;用此命令将使用pvcreate建立的物理卷创建为一个完整的卷组;
将物理卷/dev/sdb1创建为一个名为vgftp的卷组:
[root@ ~]#  vgcreate vgftp /dev/sdb1
  Volume group "vgftp" successfully created

4)添加新的物理卷到卷组中
此步即为将3块磁盘空间合并的关键步骤;当系统中新增了磁盘或新建了物理卷,而要将其添加到已有卷组时,就可使用vgextend命令;
将物理卷/dev/sdc1添加到vgftp卷组中:
[root@ ~]#  vgextend vgftp /dev/sdc1
  Volume group "vgftp" successfully extended
[root@ ~]#  vgextend vgftp /dev/sde1
  Volume group "vgftp" successfully extended

5)查看卷组
查看卷组用vgs:
[root@ ~]#  vgs
  VG      #PV #LV #SN Attr   VSize   VFree
  vgftp   2   0   0 wz--n-  5.5t 5.5t
  vgroot    1   4   0 wz--n- 264.00g  4.00m
从vgs命令的回显结果来看,卷组vgftp成功添加,并且其总空间为两块物理磁盘的总大小(因换算单位不同,所以不是精确的6T)。

6)创建逻辑卷
创建逻辑卷的命令为lvcreate;用此命令将在使用vgcreate建立的卷组上创建逻辑卷;
在卷组vgftp上创建一个名为lvftp的逻辑卷,起大小为5.5T;
-n:指定逻辑卷名
-L:指定逻辑卷大小
方法一:
[root@ ~]#  lvcreate -L 5.5T -n lvftp vgftp
  Rounding up size to full physical extent 5.5 TiB
  Logical volume "lvftp" created.

方法二:
lvextend  -l 20%FREE  /dev/lvm_test/lv1

7)格式化逻辑卷
将创建的lvftp逻辑卷格式化为ext4  xfs
[root@ ~]#  mkfs -t ext4 /dev/vgftp/lvftp
meta-data=/dev/vgftp/lvftp   isize=512    agcount=33, agsize=268435328 blks
         =                       sectsz=4096  attr=2, projid32bit=1
         =                       crc=1        finobt=1, sparse=0, rmapbt=0, reflink=0
data     =                       bsize=4096   blocks=8777839616, imaxpct=5
         =                       sunit=64     swidth=64 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal log           bsize=4096   blocks=521728, version=2
         =                       sectsz=4096  sunit=1 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0

8)创建挂载目录并挂载
创建挂载目录/ftp_data
[root@ ~]#  mkdir /ftp_data
挂载
[root@ ~]#  mount /dev/vgftp/lvftp /ftp_data/
做开机自动挂载  
[root@ ~]#echo '/dev/mapper/vgftp-lvftp /ftp_data ext4     defaults 0 0' >>/etc/fstab

9)查看是否挂载成功
[root@ ~]#  df -h  

参考:https://www.cnblogs.com/quail2333/p/11173511.html

posted @ 2020-11-23 18:31  1naonao  阅读(791)  评论(0编辑  收藏  举报