首页 > 系统相关 >虚拟机linux扩容

虚拟机linux扩容

时间:2023-10-13 12:55:06浏览次数:49  
标签:扩容 虚拟机 linux dev sda3 ubuntu snap tmpfs loop

虚拟机ubuntu 扩容

ubuntu2004

原文:https://blog.csdn.net/changqing_xu/article/details/129286088

1.使用fdisk命令对硬盘进行分区操作。

fdisk /dev/sda

这里我先输入p,查看扇区,记录下起始扇区,后面重新分区时,要保持一致。

root@0-125:~# fdisk /dev/sda

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

Command (m for help): p   #查看扇区,记录sda3起始扇区号

Disk /dev/sda: 80 GiB, 85899345920 bytes, 167772160 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: gpt
Disk identifier: 7F13220A-DDDB-44AD-BC0D-E3F369DDE708

Device       Start      End  Sectors  Size Type
/dev/sda1     2048     4095     2048    1M BIOS boot
/dev/sda2     4096  3149823  3145728  1.5G Linux filesystem
/dev/sda3  3149824 83884031 80734208 38.5G Linux filesystem    #扇区起始号为3149824

Command (m for help): d   #删除分区
Partition number (1-3, default 3): 3   #删除3号分区

Partition 3 has been deleted.

Command (m for help): n   #新建分区
Partition number (3-128, default 3): 3   #分区号为3,与之前的保持一致
First sector (3149824-167772126, default 3149824): 3149824    #扇区起始号,与之前的保持一致
Last sector, +/-sectors or +/-size{K,M,G,T,P} (3149824-167772126, default 167772126):   #结束扇区,这里直接回车默认使用所有

Created a new partition 3 of type 'Linux filesystem' and of size 78.5 GiB.
Partition #3 contains a LVM2_member signature.

Do you want to remove the signature? [Y]es/[N]o: n    #这里一定要选n,不然原来存在的lvm卷就会被干掉

Command (m for help): w    #最后输入w,保存退出

The partition table has been altered.
Syncing disks.

然后执行lsblk查看/dev/sda3的空间已经由原来的38.5G增加至78.5G

root@0-125:~# lsblk
NAME                      MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
loop0                       7:0    0 63.3M  1 loop /snap/core20/1778
loop1                       7:1    0 63.3M  1 loop /snap/core20/1822
loop2                       7:2    0 67.2M  1 loop /snap/lxd/21835
loop3                       7:3    0 49.8M  1 loop /snap/snapd/17950
loop4                       7:4    0 91.9M  1 loop /snap/lxd/24061
loop5                       7:5    0 49.9M  1 loop /snap/snapd/18357
sda                         8:0    0   80G  0 disk
├─sda1                      8:1    0    1M  0 part
├─sda2                      8:2    0  1.5G  0 part /boot
└─sda3                      8:3    0 78.5G  0 part
  └─ubuntu--vg-ubuntu--lv 253:0    0 38.5G  0 lvm  /
sr0                        11:0    1 1024M  0 rom

4、此时虽然增加了/dev/sda3的可用空间,但是lvm物理卷空间是没有增加的

lvm> vgdisplay
  --- Volume group ---
  VG Name               ubuntu-vg
  System ID
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  3
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                1
  Open LV               1
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               <38.50 GiB
  PE Size               4.00 MiB
  Total PE              9855
  Alloc PE / Size       9855 / <38.50 GiB
  Free  PE / Size       0 / 0              #可用空间为0
  VG UUID               que55V-3g38-XqKx-yKdZ-QjQZ-Sy8S-JyQ6bn

接着折腾lvm物理卷,使用pvresize命令对物理卷大小进行调整

lvm> vgs     #查看空间
  VG        #PV #LV #SN Attr   VSize   VFree
  ubuntu-vg   1   1   0 wz--n- <38.50g    0
  
lvm> pvresize -t /dev/sda3     #先测试一下
  TEST MODE: Metadata will NOT be updated and volumes will not be (de)activated.
  Physical volume "/dev/sda3" changed
  1 physical volume(s) resized or updated / 0 physical volume(s) not resized
  
lvm> pvresize  /dev/sda3     #测试成功去掉 -t 执行
  Physical volume "/dev/sda3" changed
  1 physical volume(s) resized or updated / 0 physical volume(s) not resized
  
lvm> pvs         #再次查看空间大小已经更改
  PV         VG        Fmt  Attr PSize   PFree
  /dev/sda3  ubuntu-vg lvm2 a--  <78.50g 40.00g

稳妥起见,退出检查可用空间是否增加

root@0-125:~# vgdisplay ubuntu-vg
  --- Volume group ---
  VG Name               ubuntu-vg
  System ID
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  4
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                1
  Open LV               1
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               <78.50 GiB
  PE Size               4.00 MiB
  Total PE              20095
  Alloc PE / Size       9855 / <38.50 GiB
  Free  PE / Size       10240 / 40.00 GiB       #这里可用空间已经增加
  VG UUID               que55V-3g38-XqKx-yKdZ-QjQZ-Sy8S-JyQ6bn

这里还需要将可用的物理卷空间扩容至逻辑卷

root@0-125:~# lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lv      #将可用空间全部给逻辑卷
  Size of logical volume ubuntu-vg/ubuntu-lv changed from <38.50 GiB (9855 extents) to <78.50 GiB (20095 extents).
  Logical volume ubuntu-vg/ubuntu-lv successfully resized.

root@0-125:~# resize2fs /dev/ubuntu-vg/ubuntu-lv    #重新调整一下大小
resize2fs 1.45.5 (07-Jan-2020)
Filesystem at /dev/ubuntu-vg/ubuntu-lv is mounted on /; on-line resizing required
old_desc_blocks = 5, new_desc_blocks = 10
The filesystem on /dev/ubuntu-vg/ubuntu-lv is now 20577280 (4k) blocks long.

最后看看根目录空间是否已经增加

root@0-125:~# lsblk
NAME                      MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
loop0                       7:0    0 63.3M  1 loop /snap/core20/1778
loop1                       7:1    0 63.3M  1 loop /snap/core20/1822
loop2                       7:2    0 67.2M  1 loop /snap/lxd/21835
loop3                       7:3    0 49.8M  1 loop /snap/snapd/17950
loop4                       7:4    0 91.9M  1 loop /snap/lxd/24061
loop5                       7:5    0 49.9M  1 loop /snap/snapd/18357
sda                         8:0    0   80G  0 disk
├─sda1                      8:1    0    1M  0 part
├─sda2                      8:2    0  1.5G  0 part /boot
└─sda3                      8:3    0 78.5G  0 part
  └─ubuntu--vg-ubuntu--lv 253:0    0 78.5G  0 lvm  /
sr0                        11:0    1 1024M  0 rom
root@0-125:~# df -Th
Filesystem                        Type      Size  Used Avail Use% Mounted on
udev                              devtmpfs  7.8G     0  7.8G   0% /dev
tmpfs                             tmpfs     1.6G  1.3M  1.6G   1% /run
/dev/mapper/ubuntu--vg-ubuntu--lv ext4       78G  8.6G   66G  12% /
tmpfs                             tmpfs     7.9G     0  7.9G   0% /dev/shm
tmpfs                             tmpfs     5.0M     0  5.0M   0% /run/lock
tmpfs                             tmpfs     7.9G     0  7.9G   0% /sys/fs/cgroup
/dev/loop1                        squashfs   64M   64M     0 100% /snap/core20/1822
/dev/loop2                        squashfs   68M   68M     0 100% /snap/lxd/21835
/dev/loop0                        squashfs   64M   64M     0 100% /snap/core20/1778
/dev/sda2                         ext4      1.5G  303M  1.1G  22% /boot
/dev/loop3                        squashfs   50M   50M     0 100% /snap/snapd/17950
/dev/loop4                        squashfs   92M   92M     0 100% /snap/lxd/24061
/dev/loop5                        squashfs   50M   50M     0 100% /snap/snapd/18357
tmpfs                             tmpfs     1.6G     0  1.6G   0% /run/user/0

结束。

标签:扩容,虚拟机,linux,dev,sda3,ubuntu,snap,tmpfs,loop
From: https://www.cnblogs.com/zjxcyr/p/17761836.html

相关文章

  • Linux 日志文件查找命令
    Linux日志文件查找技巧一、tail命令简介下面列出一些常用的参数:-f:实时监控文件内容变化;-n:指定输出文件末尾的行数,默认为10行;-q:不显示文件名;-s:指定输出每行间隔的时间(秒数);-c:指定输出末尾的字节数;-v:显示详细的输出信息。使用示例查看文件file.txt......
  • Linux系统下配置Nginx使部分URL使用多套自定义的PHP-FPM配置
    Nginx修改演示:vim/usr/local/nginx/conf/vhost/example.comserver{ listen80; server_name192.168.1.180; location/{ root/Code/project/public; indexindex.phpindex.html; include/usr/local/nginx/conf/rewrite/laravel.conf;location~\.......
  • Linux下配置安装PHP环境
    参考别人的做法,遇到问题上网查,下面就是安装步骤.一、安装Apache2.2.221、到官网下载  https://www.52mwyd.com/2、解压   tar -zxvfhttpd-2.2.22.tar.gz3、建立目标文件夹(注意以下所有操作都时在root用户下执行的)   mkdir/usr/local/apache2   也就是说等下......
  • CentOS 7 配置网络(虚拟机)
    确认虚拟机NAT网段可以从图中看出,VMnet8网络的IP段是192.168.11.0,掩码255.255.255.0,网关192.168.11.2。编辑网络配置文件网络配置文件地址:/etc/sysconfig/network-scripts/编辑ifcfg-ens33文件:vim/etc/sysconfig/network-scripts/ifcfg-ens33重新启动网络服务命令:syste......
  • Linux安装cuda和cudnn教程
    https://blog.csdn.net/qq_34848334/article/details/131015697?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522169708238516800192266848%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fall.%2522%257D&request_id=169708238516800192266848&a......
  • Linux系统中tomcat设置开机自启动
    1.添加tomcat服务文件cd/etc/init.d vimtomcat在tomcat中添加如下配置#!/bin/bash#chkconfig:23451090#description:StartsandStopstheTomcatdaemon.#/etc/init.d/tomcatd#Tomcatauto-start#Sourcefunctionlibrary.#./etc/init......
  • 虚拟机如何打开hive数据库
    1、启动hodoop2.、启动hive的服务:metastorecd/export/server/apache-hive-3.1.2-bin/bin./hive--servicemetastore后台启动nohup./hive--servicemetastore&3、启动hive的服务:hiveserver2服务./hive--servicehiveserver2nohup./hive--servicehivese......
  • Linux平台下更换GCC版本号
    (1)使用sudoapt-getinstallgcc-xxx下载某个版本gcc,直至在终端输入(以gcc-12为例)gcc-12-v的时候能够输出对应的信息sudoapt-getinstallgcc-12(2)进入ubuntu系统的/usr/bin/文件夹中,此文件夹中存放链接文件(如链接文件gcc)此链接文件能够使得终端在输入gcc-v的时候输出对应......
  • Linux系统CUDA安装及踩坑记录
    https://zhuanlan.zhihu.com/p/501473091  我的Linux系统背景:系统和驱动都已安装。系统是centos8。查看自己操作系统的版本信息:cat/etc/issue或者是 cat/etc/lsb-release用nvidia-smi可以看到显卡驱动和可支持的最高cuda版本,我的是11.4。驱动版本是470.57.02。......
  • Linux笔记:增量备份程序rsync快速入门
    目的rsync是一款开源的文件增量备份程序,通常用于linux下文件的增量备份。这个程序可以将一个目录的文件备份到另一个目录中,并且在每次备份时还可以对文件进行比较,只复制更新有过改动的文件。rsync官网:https://rsync.samba.org/github项目:https://github.com/WayneD/rsync 快......