手动添加一个80G的硬盘,单独做kvm的存储池
为什么要做一个单独的存储池呢,因为我们正常来说系统盘一般来说20G左右就够了,里面放的是系统的数据,第一:其大小无法满足kvm后期日益增大的需求;第二、实行数据与系统数据的分离,确保数据备份和数据的安全
第一、对添加的80G硬盘分区初始化。
[root@localhost ~]# fdisk -l #查看80G的盘是否正常添加
Disk /dev/sdb: 85.9 GB, 85899345920 bytes, 167772160 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 /dev/sda: 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: 0x0009ee77
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 41943039 19921920 8e Linux LVM
Disk /dev/mapper/centos-root: 18.2 GB, 18249416704 bytes, 35643392 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 /dev/mapper/centos-swap: 2147 MB, 2147483648 bytes, 4194304 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
[root@localhost ~]# fdisk /dev/sdb #对新添加的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 0xce9685c7.
Command (m for help): p #打印当前的区,发现没有是正常的,毕竟是一块新盘
Disk /dev/sdb: 85.9 GB, 85899345920 bytes, 167772160 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: 0xce9685c7
Device Boot Start End Blocks Id System
Command (m for help): n #创建新的分区
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p #这个p对应的是上一条命令的 p primary (0 primary, 0 extended, 4 free)。
Partition number (1-4, default 1): #默认,直接回车
First sector (2048-167772159, default 2048): #默认,直接回车
Using default value 2048 #默认,直接回车
Last sector, +sectors or +size{K,M,G} (2048-167772159, default 167772159): #默认,直接回车
Using default value 167772159
Partition 1 of type Linux and of size 80 GiB is set
Command (m for help): p #再次打印分好的区当前的
Disk /dev/sdb: 85.9 GB, 85899345920 bytes, 167772160 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: 0xce9685c7
Device Boot Start End Blocks Id System
/dev/sdb1 2048 167772159 83885056 83 Linux
Command (m for help): t #设置新分的区的格式
Selected partition 1
Hex code (type L to list all codes): l #显示所有类型
0 Empty 24 NEC DOS 81 Minix / old Lin bf Solaris
1 FAT12 27 Hidden NTFS Win 82 Linux swap / So c1 DRDOS/sec (FAT-
2 XENIX root 39 Plan 9 83 Linux c4 DRDOS/sec (FAT-
3 XENIX usr 3c PartitionMagic 84 OS/2 hidden C: c6 DRDOS/sec (FAT-
4 FAT16 <32M 40 Venix 80286 85 Linux extended c7 Syrinx
5 Extended 41 PPC PReP Boot 86 NTFS volume set da Non-FS data
6 FAT16 42 SFS 87 NTFS volume set db CP/M / CTOS / .
7 HPFS/NTFS/exFAT 4d QNX4.x 88 Linux plaintext de Dell Utility
8 AIX 4e QNX4.x 2nd part 8e Linux LVM df BootIt
9 AIX bootable 4f QNX4.x 3rd part 93 Amoeba e1 DOS access
a OS/2 Boot Manag 50 OnTrack DM 94 Amoeba BBT e3 DOS R/O
b W95 FAT32 51 OnTrack DM6 Aux 9f BSD/OS e4 SpeedStor
c W95 FAT32 (LBA) 52 CP/M a0 IBM Thinkpad hi eb BeOS fs
e W95 FAT16 (LBA) 53 OnTrack DM6 Aux a5 FreeBSD ee GPT
f W95 Ext'd (LBA) 54 OnTrackDM6 a6 OpenBSD ef EFI (FAT-12/16/
10 OPUS 55 EZ-Drive a7 NeXTSTEP f0 Linux/PA-RISC b
11 Hidden FAT12 56 Golden Bow a8 Darwin UFS f1 SpeedStor
12 Compaq diagnost 5c Priam Edisk a9 NetBSD f4 SpeedStor
14 Hidden FAT16 <3 61 SpeedStor ab Darwin boot f2 DOS secondary
16 Hidden FAT16 63 GNU HURD or Sys af HFS / HFS+ fb VMware VMFS
17 Hidden HPFS/NTF 64 Novell Netware b7 BSDI fs fc VMware VMKCORE
18 AST SmartSleep 65 Novell Netware b8 BSDI swap fd Linux raid auto
1b Hidden W95 FAT3 70 DiskSecure Mult bb Boot Wizard hid fe LANstep
1c Hidden W95 FAT3 75 PC/IX be Solaris boot ff BBT
1e Hidden W95 FAT1 80 Old Minix
Hex code (type L to list all codes): 8e #选择8e,Linux LVM格式
Changed type of partition 'Linux' to 'Linux LVM'
Command (m for help): w #保存操作并退出
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@localhost ~]# fdisk -l #在看下sdb盘,出现了sdb1
Disk /dev/sdb: 85.9 GB, 85899345920 bytes, 167772160 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: 0xce9685c7
Device Boot Start End Blocks Id System
/dev/sdb1 2048 167772159 83885056 8e Linux LVM
Disk /dev/sda: 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: 0x0009ee77
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 41943039 19921920 8e Linux LVM
Disk /dev/mapper/centos-root: 18.2 GB, 18249416704 bytes, 35643392 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 /dev/mapper/centos-swap: 2147 MB, 2147483648 bytes, 4194304 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
第二、创建lvm逻辑卷。方便后续生产扩缩容。
[root@localhost ~]# pvcreate /dev/sdb1 #创建pv卷
Physical volume "/dev/sdb1" successfully created.
[root@localhost ~]# pvscan #查看pv卷创建情况
PV /dev/sda2 VG centos lvm2 [<19.00 GiB / 0 free]
PV /dev/sdb1 lvm2 [<80.00 GiB]
Total: 2 [<99.00 GiB] / in use: 1 [<19.00 GiB] / in no VG: 1 [<80.00 GiB]
[root@localhost ~]# vgcreate vmvg /dev/sdb1 #创建vg,叫vmvg
Volume group "vmvg" successfully created
[root@localhost ~]# vgscan #查看vg情况
Reading volume groups from cache.
Found volume group "centos" using metadata type lvm2
Found volume group "vmvg" using metadata type lvm2
[root@localhost ~]# vgdisplay vmvg #查看vmvg的详细情况
--- Volume group ---
VG Name vmvg
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 1
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 0
Open LV 0
Max PV 0
Cur PV 1
Act PV 1
VG Size <80.00 GiB
PE Size 4.00 MiB
Total PE 20479
Alloc PE / Size 0 / 0
Free PE / Size 20479 / <80.00 GiB #这里可以看到有20479的大小是空闲的
VG UUID URWvil-qOge-vLGe-vAOK-fbck-ZepH-SffmJG
[root@localhost ~]# lvcreate -n lvvm1 -l 20479 vmvg #创建lv逻辑卷,把vmvg的20479全给他
Logical volume "lvvm1" created.
[root@localhost ~]# vgdisplay vmvg #再次查看vmvg的情况
--- Volume group ---
VG Name vmvg
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 2
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 1
Open LV 0
Max PV 0
Cur PV 1
Act PV 1
VG Size <80.00 GiB
PE Size 4.00 MiB
Total PE 20479
Alloc PE / Size 20479 / <80.00 GiB
Free PE / Size 0 / 0 #发现他已经为空,如果后续还要空间的话,可以从pv里面添加
VG UUID URWvil-qOge-vLGe-vAOK-fbck-ZepH-SffmJG
[root@localhost ~]# lvscan #查看lv逻辑卷情况
ACTIVE '/dev/centos/swap' [2.00 GiB] inherit
ACTIVE '/dev/centos/root' [<17.00 GiB] inherit
ACTIVE '/dev/vmvg/lvvm1' [<80.00 GiB] inherit
[root@localhost ~]# mkfs.ext4 /dev/vmvg/lvvm1 #格式化lvvm1逻辑卷
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
5242880 inodes, 20970496 blocks
1048524 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2168455168
640 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, 20480000
Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
[root@localhost ~]# mkdir /vm #创建目录,用来挂载逻辑卷
[root@localhost ~]# vim /etc/fstab #添加到fstab文件中,方便开机自动挂载
#
# /etc/fstab
# Created by anaconda on Sun Jan 31 14:11:42 2021
#
# 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
#
/dev/mapper/centos-root / xfs defaults 0 0
UUID=a3019dd5-fd57-4ef7-9dc3-d174d0c3322e /boot xfs defaults 0 0
/dev/mapper/centos-swap swap swap defaults 0 0
/dev/vmvg/lvvm1 /vm ext4 defaults 0 0 #手动添加这行,建议先备份,这个文件比较敏感
[root@localhost ~]# mount /vm #进行挂载
[root@localhost ~]# mount #查看挂载情况
sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime)
proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
devtmpfs on /dev type devtmpfs (rw,nosuid,size=920376k,nr_inodes=230094,mode=755)
securityfs on /sys/kernel/security type securityfs (rw,nosuid,nodev,noexec,relatime)
tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev)
devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000)
tmpfs on /run type tmpfs (rw,nosuid,nodev,mode=755)
tmpfs on /sys/fs/cgroup type tmpfs (ro,nosuid,nodev,noexec,mode=755)
cgroup on /sys/fs/cgroup/systemd type cgroup (rw,nosuid,nodev,noexec,relatime,xattr,release_agent=/usr/lib/systemd/systemd-cgroups-agent,name=systemd)
pstore on /sys/fs/pstore type pstore (rw,nosuid,nodev,noexec,relatime)
cgroup on /sys/fs/cgroup/devices type cgroup (rw,nosuid,nodev,noexec,relatime,devices)
cgroup on /sys/fs/cgroup/perf_event type cgroup (rw,nosuid,nodev,noexec,relatime,perf_event)
cgroup on /sys/fs/cgroup/hugetlb type cgroup (rw,nosuid,nodev,noexec,relatime,hugetlb)
cgroup on /sys/fs/cgroup/cpu,cpuacct type cgroup (rw,nosuid,nodev,noexec,relatime,cpuacct,cpu)
cgroup on /sys/fs/cgroup/cpuset type cgroup (rw,nosuid,nodev,noexec,relatime,cpuset)
cgroup on /sys/fs/cgroup/freezer type cgroup (rw,nosuid,nodev,noexec,relatime,freezer)
cgroup on /sys/fs/cgroup/net_cls,net_prio type cgroup (rw,nosuid,nodev,noexec,relatime,net_prio,net_cls)
cgroup on /sys/fs/cgroup/memory type cgroup (rw,nosuid,nodev,noexec,relatime,memory)
cgroup on /sys/fs/cgroup/blkio type cgroup (rw,nosuid,nodev,noexec,relatime,blkio)
cgroup on /sys/fs/cgroup/pids type cgroup (rw,nosuid,nodev,noexec,relatime,pids)
configfs on /sys/kernel/config type configfs (rw,relatime)
/dev/mapper/centos-root on / type xfs (rw,relatime,attr2,inode64,noquota)
systemd-1 on /proc/sys/fs/binfmt_misc type autofs (rw,relatime,fd=35,pgrp=1,timeout=0,minproto=5,maxproto=5,direct,pipe_ino=14745)
debugfs on /sys/kernel/debug type debugfs (rw,relatime)
mqueue on /dev/mqueue type mqueue (rw,relatime)
hugetlbfs on /dev/hugepages type hugetlbfs (rw,relatime)
/dev/sda1 on /boot type xfs (rw,relatime,attr2,inode64,noquota)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw,relatime)
tmpfs on /run/user/0 type tmpfs (rw,nosuid,nodev,relatime,size=186532k,mode=700)
fusectl on /sys/fs/fuse/connections type fusectl (rw,relatime)
/dev/sr0 on /run/media/root/CentOS 7 x86_64 type iso9660 (ro,nosuid,nodev,relatime,uid=0,gid=0,iocharset=utf8,mode=0400,dmode=0500,uhelper=udisks2)
/dev/mapper/vmvg-lvvm1 on /vm type ext4 (rw,relatime,data=ordered) #可以看到已经挂载成功。
第三、上传iso文件到kvm服务器里面,kvm虚拟机创建的时候需要这些iso文件,大家自己酌情添加
这里还是之前用的那个centos7.5的镜像,获取方式请看前面的文章。下面再提供一个win10的镜像,地址如下
链接:https://pan.baidu.com/s/1CRMGBBoENl0EOatExyTIUA
提取码:9cim
复制这段内容后打开百度网盘手机App,操作更方便哦
[root@localhost ~]# mkdir /iso #创建一个专门放镜像文件的目录
[root@localhost ~]# cd /iso/
[root@localhost iso]# yum -y install lrzsz #安装lrzsz,可以通过rz命令,直接将文件拖进服务器里面
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.huaweicloud.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
Resolving Dependencies
--> Running transaction check
---> Package lrzsz.x86_64 0:0.12.20-36.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
=================================================================================================================================================
Package Arch Version Repository Size
=================================================================================================================================================
Installing:
lrzsz x86_64 0.12.20-36.el7 base 78 k
Transaction Summary
=================================================================================================================================================
Install 1 Package
Total download size: 78 k
Installed size: 181 k
Downloading packages:
lrzsz-0.12.20-36.el7.x86_64.rpm | 78 kB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : lrzsz-0.12.20-36.el7.x86_64 1/1
Verifying : lrzsz-0.12.20-36.el7.x86_64 1/1
Installed:
lrzsz.x86_64 0:0.12.20-36.el7
Complete!
[root@localhost iso]# rz -E #出现这个代表着传输完成,不是手动输入的命令
rz waiting to receive.
关于如何将超过4G的镜像文件通过lrzsz服务拖进虚拟机里面,这个大家可以用360的压缩分卷功能,分成两部分,最大不超过4G,然后一个一个的拖进去。当然也可以通过ftp,scp,或者samba服务
超过4G的文件,unzip是不能解压的,unzip最大解压为2G.可以百度下7za这个解压服务,源码安装超级简单。分卷压缩的文件解压一个另一个也就会自动解压的。两个就会合并成一个文件的。
第四、对iso文件进行解压。
[root@localhost ~]# cd /iso/
[root@localhost iso]# ls
CentOS-7-x86_64-DVD-1804.zip.001 CentOS-7-x86_64-DVD-1804.zip.002 cn_windows_10_enterprise_x64_dvd_6846957.iso
[root@localhost iso]# 7za x CentOS-7-x86_64-DVD-1804.zip.001 -r -o./ #利用7za解压缩,unzip不能解压大于2G的
7-Zip (a) [64] 16.02 : Copyright (c) 1999-2016 Igor Pavlov : 2016-05-21
p7zip Version 16.02 (locale=en_US.UTF-8,Utf16=on,HugeFiles=on,64 bits,4 CPUs x64)
Scanning the drive for archives:
1 file, 4194304000 bytes (4000 MiB)
Extracting archive: CentOS-7-x86_64-DVD-1804.zip.001
--
Path = CentOS-7-x86_64-DVD-1804.zip.001
Type = Split
Physical Size = 4194304000
Volumes = 2
Total Physical Size = 4292956205
----
Path = CentOS-7-x86_64-DVD-1804.zip
Size = 4292956205
--
Path = CentOS-7-x86_64-DVD-1804.zip
Type = zip
Physical Size = 4292956205
Everything is Ok
Size: 4470079488
Compressed: 4292956205
[root@localhost iso]# ls
CentOS-7-x86_64-DVD-1804.iso CentOS-7-x86_64-DVD-1804.zip.001 CentOS-7-x86_64-DVD-1804.zip.002 cn_windows_10_enterprise_x64_dvd_6846957.iso
[root@localhost iso]# ll
total 12622348
-rw-r--r-- 1 root root 4470079488 Jun 24 2019 CentOS-7-x86_64-DVD-1804.iso
-rw-r--r-- 1 root root 4194304000 Jan 30 23:16 CentOS-7-x86_64-DVD-1804.zip.001
-rw-r--r-- 1 root root 98652205 Jan 30 23:16 CentOS-7-x86_64-DVD-1804.zip.002
-rw-r--r-- 1 root root 4162242560 Aug 3 2015 cn_windows_10_enterprise_x64_dvd_6846957.iso
7za参数含义:
- x 代表解压缩文件,并且是按原始目录树解压(还有个参数 e 也是解压缩文件,但其会将所有文件都解压到根下,而不是自己原有的文件夹下)
test.zip 是当前目录下的压缩文件,这里用做测试文件 - -r 表示递归解压缩所有的子文件夹
- -o 是指定解压到的目录,-o后是没有空格的,直接接目录(-o./ 为当前目录)
----------------------------------一切努力只为抽一包好烟-------------------------------------------------------
下一章:kvm实战之创建linux和windows虚拟机(七)