Rocky Linux 9虚拟机磁盘扩容

💡 主要过程跟CentOS扩容差不多,但也有些小地方要注意差异。

1.查看扩容前的磁盘容量,以及分区情况

fdisk -l
df -h

2.对扩容的磁盘分区

(1)磁盘分区命令,新增分区

输入n新增分区,默认为主分区,默认值直接敲回车就好

fdisk /dev/sda
n

(2)设置分区格式,在fdisk命令下输入 t ,回车默认值,然后输入 8e

8e是代表适用LVM分区类型

(3)最后写入分区表,在Fdisk命令位置输入:w

此时fdisk 再查看一下,发现多了一个分区,分区格式为LVM

fdisk -l

3、格式化磁盘,并分区

partprobe
mkfs.ext4 /dev/sda3

4、进入LVM合并磁盘

进入lvm,初始化 /dev/sda3,将新分区添加进系统默认的Volume group,Rocky Linux的默认Volume group为 rl

lvm
pvcreate /dev/sda3
vgextend rl /dev/sda3

查看一下当前的Volume卷详情

vgdisplay -v

将系统盘/dev/mapper/rl-root与sda3的2559空余容量合并

lvextend -l +2559 /dev/mapper/rl-root

quit

5.最后让系统识别就行了

xfs_growfs /dev/mapper/rl-root

6.结束,再用fdisk -l命令,以及df -h命令查看一下效果:

fdisk -l
df -h

最后附上操作log:

[root@localhost ~]# fdisk -l
Disk /dev/sda: 30 GiB, 32212254720 bytes, 62914560 sectors
Disk model: Virtual disk    
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: 0xeaed9efd

Device     Boot   Start      End  Sectors Size Id Type
/dev/sda1  *       2048  2099199  2097152   1G 83 Linux
/dev/sda2       2099200 41943039 39843840  19G 8e Linux LVM


Disk /dev/mapper/rl-root: 17 GiB, 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/rl-swap: 2 GiB, 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/sda

Welcome to fdisk (util-linux 2.37.4).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

This disk is currently in use - repartitioning is probably a bad idea.
It's recommended to umount all file systems, and swapoff all swap
partitions on this disk.


Command (m for help): n
Partition type
   p   primary (2 primary, 0 extended, 2 free)
   e   extended (container for logical partitions)
Select (default p): 

Using default response p.
Partition number (3,4, default 3): 
First sector (41943040-62914559, default 41943040): 
Last sector, +/-sectors or +/-size{K,M,G,T,P} (41943040-62914559, default 62914559): 

Created a new partition 3 of type 'Linux' and of size 10 GiB.

Command (m for help): t
Partition number (1-3, default 3): 
Hex code or alias (type L to list all): 8e

Changed type of partition 'Linux' to 'Linux LVM'.

Command (m for help): w
The partition table has been altered.
Syncing disks.

[root@localhost ~]# fdisk -l
Disk /dev/sda: 30 GiB, 32212254720 bytes, 62914560 sectors
Disk model: Virtual disk    
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: 0xeaed9efd

Device     Boot    Start      End  Sectors Size Id Type
/dev/sda1  *        2048  2099199  2097152   1G 83 Linux
/dev/sda2        2099200 41943039 39843840  19G 8e Linux LVM
/dev/sda3       41943040 62914559 20971520  10G 8e Linux LVM


Disk /dev/mapper/rl-root: 17 GiB, 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/rl-swap: 2 GiB, 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 ~]# partprobe
Warning: Unable to open /dev/sr0 read-write (Read-only file system).  /dev/sr0 has been opened read-only.
[root@localhost ~]# mkfs.ext4 /dev/sda3
mke2fs 1.46.5 (30-Dec-2021)
Creating filesystem with 2621440 4k blocks and 655360 inodes
Filesystem UUID: c673720a-efd1-4770-993c-93ae44ceb0c0
Superblock backups stored on blocks: 
	32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632

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

[root@localhost ~]# lvm
lvm> pvcreate /dev/sda3
WARNING: ext4 signature detected on /dev/sda3 at offset 1080. Wipe it? [y/n]: y
  Wiping ext4 signature on /dev/sda3.
  Physical volume "/dev/sda3" successfully created.
lvm> vgextend rl /dev/sda3
  Volume group "rl" successfully extended
lvm> vgdisplay -v
  --- Volume group ---
  VG Name               rl
  System ID             
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  4
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               28.99 GiB
  PE Size               4.00 MiB
  Total PE              7422
  Alloc PE / Size       4863 / <19.00 GiB
  Free  PE / Size       2559 / <10.00 GiB
  VG UUID               cYoE62-sQ6X-lVf0-XAu7-z2gK-Ro3g-NrlOAx
   
  --- Logical volume ---
  LV Path                /dev/rl/swap
  LV Name                swap
  VG Name                rl
  LV UUID                irNT0l-i7Gp-EZhv-SxZE-Yqs9-ed8w-bP1BjR
  LV Write Access        read/write
  LV Creation host, time localhost.localdomain, 2024-07-09 11:18:48 +0800
  LV Status              available
  # open                 2
  LV Size                2.00 GiB
  Current LE             512
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1
   
  --- Logical volume ---
  LV Path                /dev/rl/root
  LV Name                root
  VG Name                rl
  LV UUID                Hwb7Vm-DW0i-YAdX-gqHs-ThT5-Z9Ku-AMkCPx
  LV Write Access        read/write
  LV Creation host, time localhost.localdomain, 2024-07-09 11:18:48 +0800
  LV Status              available
  # open                 1
  LV Size                <17.00 GiB
  Current LE             4351
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0
   
  --- Physical volumes ---
  PV Name               /dev/sda2     
  PV UUID               Dtz0ky-SqCn-t1d4-3DEf-VBM9-SdvC-C2l24g
  PV Status             allocatable
  Total PE / Free PE    4863 / 0
   
  PV Name               /dev/sda3     
  PV UUID               SFTVTo-oxx7-dafx-XzFC-yH2c-Vtfh-yhmX9B
  PV Status             allocatable
  Total PE / Free PE    2559 / 2559
   
lvm> lvextend -l +2559 /dev/mapper/rl-root
  Size of logical volume rl/root changed from <17.00 GiB (4351 extents) to 26.99 GiB (6910 extents).
  Logical volume rl/root successfully resized.
lvm> quit
  Exiting.
[root@localhost ~]# xfs_growfs /dev/mapper/rl-root
meta-data=/dev/mapper/rl-root    isize=512    agcount=4, agsize=1113856 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=1, sparse=1, rmapbt=0
         =                       reflink=1    bigtime=1 inobtcount=1 nrext64=0
data     =                       bsize=4096   blocks=4455424, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0, ftype=1
log      =internal log           bsize=4096   blocks=16384, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 4455424 to 7075840
[root@localhost ~]# 
[root@localhost ~]# fdisk -l
Disk /dev/sda: 30 GiB, 32212254720 bytes, 62914560 sectors
Disk model: Virtual disk    
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: 0xeaed9efd

Device     Boot    Start      End  Sectors Size Id Type
/dev/sda1  *        2048  2099199  2097152   1G 83 Linux
/dev/sda2        2099200 41943039 39843840  19G 8e Linux LVM
/dev/sda3       41943040 62914559 20971520  10G 8e Linux LVM


Disk /dev/mapper/rl-root: 26.99 GiB, 28982640640 bytes, 56606720 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/rl-swap: 2 GiB, 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 ~]# df -h
Filesystem           Size  Used Avail Use% Mounted on
devtmpfs             4.0M     0  4.0M   0% /dev
tmpfs                1.8G     0  1.8G   0% /dev/shm
tmpfs                732M  8.7M  724M   2% /run
/dev/mapper/rl-root   27G  1.4G   26G   5% /
/dev/sda1            960M  225M  736M  24% /boot
tmpfs                366M     0  366M   0% /run/user/0
[root@localhost ~]#

Rocky Linux 9操作系统下安装Rocky Linux 9虚拟机,可以按照以下步骤进行操作: 1. 首先,需要安装KVM虚拟化软件,可以使用以下命令进行安装: ``` sudo dnf install -y qemu-kvm libvirt virt-install bridge-utils ``` 2. 确保KVM服务已经启动,可以使用以下命令进行检查: ``` systemctl status libvirtd ``` 如果服务已经启动,则会显示“active (running)”字样。 3. 创建一个虚拟机磁盘镜像文件,可以使用以下命令创建: ``` qemu-img create -f qcow2 /var/lib/libvirt/images/rocky9.qcow2 20G ``` 其中,“20G”表示虚拟机磁盘镜像文件的大小。 4. 下载Rocky Linux 9安装ISO文件,并将其存储到本地计算机或者服务器上。 5. 使用virt-install命令创建虚拟机,可以使用以下命令进行创建: ``` sudo virt-install --name rocky9 --ram 2048 --vcpus 2 --disk path=/var/lib/libvirt/images/rocky9.qcow2,size=20 --os-type linux --os-variant rhel8.0 --cdrom /path/to/rocky9.iso --network bridge=virbr0 --graphics none --console pty,target_type=serial ``` 其中,“rocky9”表示虚拟机的名称,“2048”表示虚拟机的内存大小,“2”表示虚拟机的CPU个数,“/var/lib/libvirt/images/rocky9.qcow2”表示虚拟机磁盘镜像文件的路径,“20”表示虚拟机磁盘镜像文件的大小,“/path/to/rocky9.iso”表示Rocky Linux 9安装ISO文件的路径,“virbr0”表示虚拟机使用的网络桥接设备。 6. 等待Rocky Linux 9安装程序启动,按照提示进行安装即可。 以上就是在Rocky Linux 9操作系统下安装Rocky Linux 9虚拟机的步骤。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值