Linux 虚拟化

您所在的位置:网站首页 linux增加磁盘容量 Linux 虚拟化

Linux 虚拟化

2023-03-14 23:18| 来源: 网络整理| 查看: 265

0、背景

整理一下 Linux 虚拟化相关技术~

(1)本系列文章

格瑞图:Linux 虚拟化-0001-安装 KVM

格瑞图:Linux 虚拟化-0002-创建虚拟机

格瑞图:Linux 虚拟化-0003-容器化部署 opennebula

格瑞图:Linux 虚拟化-0004-克隆虚拟机

格瑞图:Linux 虚拟化-0005-调整虚机内存

格瑞图:Linux 虚拟化-0006-调整虚机磁盘

格瑞图:Linux 虚拟化-0007-KVM 虚机跨宿主迁移

1、步骤(1)创建磁盘文件[root@home ~]# qemu-img create -f qcow2 /data/sde1/kvm/nau128.100g.qcow2 100G Formatting '/data/sde1/kvm/nau128.100g.qcow2', fmt=qcow2 size=107374182400 encryption=off cluster_size=65536 lazy_refcounts=off [root@home kvm]# du -sh nau128.100g.qcow2 196K nau128.100g.qcow2 [root@home kvm]#

qemu-img 报告大小 size 为 107374182400

du 报告带下为 196K

(2)检查虚机磁盘名称[root@nau128 ~]# fdisk -l Disk /dev/sda: 20 GiB, 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 Disklabel type: dos Disk identifier: 0x3b290167 Device Boot Start End Sectors Size Id Type /dev/sda1 * 2048 2099199 2097152 1G 83 Linux /dev/sda2 2099200 37748735 35649536 17G 83 Linux /dev/sda3 37748736 41943039 4194304 2G 82 Linux swap / Solaris [root@nau128 ~]#

从图中磁盘名称 /dev/sda 命名得知磁盘名为 /dev/sdx

其中 x 为 a~z 字母排序

(3)添加磁盘到虚机[root@home kvm]# virsh attach-disk nau128 /data/sde1/kvm/nau128.100g.qcow2 sdb --cache none Disk attached successfully [root@home kvm]# ssh nau128 Last login: Sun May 22 12:02:20 2022 from 192.168.1.100 [root@nau128 ~]# fdisk -l Disk /dev/sda: 20 GiB, 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 Disklabel type: dos Disk identifier: 0x3b290167 Device Boot Start End Sectors Size Id Type /dev/sda1 * 2048 2099199 2097152 1G 83 Linux /dev/sda2 2099200 37748735 35649536 17G 83 Linux /dev/sda3 37748736 41943039 4194304 2G 82 Linux swap / Solaris Disk /dev/sdb: 194 KiB, 198656 bytes, 388 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@nau128 ~]#

磁盘显示 194KiB 是不是有问题呢?

先格式化挂载试试

(4)格式化磁盘[root@nau128 ~]# fdisk /dev/sdb Welcome to fdisk (util-linux 2.32.1). 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. Created a new DOS disklabel with disk identifier 0xae06f852. Command (m for help): o Created a new DOS disklabel with disk identifier 0x427e5c5d. Command (m for help): n Partition type p primary (0 primary, 0 extended, 4 free) e extended (container for logical partitions) Select (default p): Using default response p. Partition number (1-4, default 1): First sector (1-387, default 1): Last sector, +sectors or +size{K,M,G,T,P} (1-387, default 387): Created a new partition 1 of type 'Linux' and of size 193.5 KiB. Command (m for help): w The partition table has been altered. Calling ioctl() to re-read partition table. Syncing disks. [root@nau128 ~]#

查看磁盘

[root@nau128 ~]# fdisk -l Disk /dev/sda: 20 GiB, 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 Disklabel type: dos Disk identifier: 0x3b290167 Device Boot Start End Sectors Size Id Type /dev/sda1 * 2048 2099199 2097152 1G 83 Linux /dev/sda2 2099200 37748735 35649536 17G 83 Linux /dev/sda3 37748736 41943039 4194304 2G 82 Linux swap / Solaris Disk /dev/sdb: 194 KiB, 198656 bytes, 388 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 Disklabel type: dos Disk identifier: 0x427e5c5d Device Boot Start End Sectors Size Id Type /dev/sdb1 1 387 387 193.5K 83 Linux [root@nau128 ~]#

(5)重启查看一下

[root@nau128 ~]# fdisk -l Disk /dev/sda: 194 KiB, 198656 bytes, 388 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 Disklabel type: dos Disk identifier: 0x427e5c5d Device Boot Start End Sectors Size Id Type /dev/sda1 1 387 387 193.5K 83 Linux Disk /dev/sdb: 20 GiB, 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 Disklabel type: dos Disk identifier: 0x3b290167 Device Boot Start End Sectors Size Id Type /dev/sdb1 * 2048 2099199 2097152 1G 83 Linux /dev/sdb2 2099200 37748735 35649536 17G 83 Linux /dev/sdb3 37748736 41943039 4194304 2G 82 Linux swap / Solaris [root@nau128 ~]#

竟然把两块磁盘的顺序换了一下

[root@nau128 ~]# mkdir /data [root@nau128 ~]# mkfs.ext4 /dev/sda1 mke2fs 1.45.6 (20-Mar-2020) Filesystem too small for a journal Creating filesystem with 192 1k blocks and 24 inodes Allocating group tables: done Writing inode tables: done Writing superblocks and filesystem accounting information: done [root@nau128 ~]#[root@nau128 ~]# vi /etc/fstab [root@nau128 ~]# tail -n 1 /etc/fstab /dev/sda1 /data ext4 defaults 0 0 [root@nau128 ~]#(5)拷贝数据测试(base) gree2 :: 00.prevsh/data » scp java.8.image root@nau128:/data java.8.image 98% 619MB 22.7MB/s 00:00 ETA scp: /data/java.8.image: No space left on device java.8.image 100% 629MB 22.8MB/s 00:27 (base) gree2 :: 00.prevsh/data »(6)真是进坑了~

从一开始就错了

[root@home kvm]# ls -lh nau128.100g.qcow2 -rw-r--r--. 1 qemu qemu 194K May 22 12:26 nau128.100g.qcow2 [root@home kvm]# qemu-img info nau128.100g.qcow2 image: nau128.100g.qcow2 file format: raw virtual size: 194K (198656 bytes) disk size: 196K [root@home kvm]#[root@home kvm]# qemu-img create -f qcow2 -o size=100G /data/sde1/kvm/nau128.100g.qcow2 Formatting '/data/sde1/kvm/nau128.100g.qcow2', fmt=qcow2 size=107374182400 encryption=off cluster_size=65536 lazy_refcounts=off [root@home kvm]# qemu-img info nau128.100g.qcow2 image: nau128.100g.qcow2 file format: qcow2 virtual size: 100G (107374182400 bytes) disk size: 196K cluster_size: 65536 Format specific information: compat: 1.1 lazy refcounts: false [root@home kvm]#(7)重来

先使用图形界面搞定添加磁盘

[root@nau128 ~]# fdisk -l Disk /dev/sda: 20 GiB, 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 Disklabel type: dos Disk identifier: 0x3b290167 Device Boot Start End Sectors Size Id Type /dev/sda1 * 2048 2099199 2097152 1G 83 Linux /dev/sda2 2099200 37748735 35649536 17G 83 Linux /dev/sda3 37748736 41943039 4194304 2G 82 Linux swap / Solaris Disk /dev/sdb: 100 GiB, 107374182400 bytes, 209715200 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@nau128 ~]# fdisk /dev/sdb Welcome to fdisk (util-linux 2.32.1). 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. Created a new DOS disklabel with disk identifier 0xd460e0da. Command (m for help): o Created a new DOS disklabel with disk identifier 0xea6b99f5. Command (m for help): n Partition type p primary (0 primary, 0 extended, 4 free) e extended (container for logical partitions) Select (default p): Using default response p. Partition number (1-4, default 1): First sector (2048-209715199, default 2048): Last sector, +sectors or +size{K,M,G,T,P} (2048-209715199, default 209715199): Created a new partition 1 of type 'Linux' and of size 100 GiB. Command (m for help): w The partition table has been altered. Calling ioctl() to re-read partition table. Syncing disks. [root@nau128 ~]# fdisk -l Disk /dev/sda: 20 GiB, 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 Disklabel type: dos Disk identifier: 0x3b290167 Device Boot Start End Sectors Size Id Type /dev/sda1 * 2048 2099199 2097152 1G 83 Linux /dev/sda2 2099200 37748735 35649536 17G 83 Linux /dev/sda3 37748736 41943039 4194304 2G 82 Linux swap / Solaris Disk /dev/sdb: 100 GiB, 107374182400 bytes, 209715200 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 Disklabel type: dos Disk identifier: 0xea6b99f5 Device Boot Start End Sectors Size Id Type /dev/sdb1 2048 209715199 209713152 100G 83 Linux [root@nau128 ~]# vi /etc/fstab [root@nau128 ~]# mkfs.ext4 /dev/sdb1 mke2fs 1.45.6 (20-Mar-2020) Discarding device blocks: done Creating filesystem with 26214144 4k blocks and 6553600 inodes Filesystem UUID: cb8e0a85-198f-41b4-9dc9-800e69c504ff Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 4096000, 7962624, 11239424, 20480000, 23887872 Allocating group tables: done Writing inode tables: done Creating journal (131072 blocks): done Writing superblocks and filesystem accounting information: done [root@nau128 ~]# mount /dev/sdb1 /data [root@nau128 ~]# 2、后记

这个坑还没有过去,使用 virsh attach-disk 添加的磁盘,空间就是有问题~

先忙正事儿~



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3