Parallels Desktop 给Linux增加磁盘大小

/ 默认分类 / 没有评论 / 63浏览

默认安装镜像只分配了64G ,安装之前还不能修改硬盘大小

修改虚拟机分配的大小

设置->硬盘

image-20241031140137631

列出块设备信息

[root@AlmaLinux ~]# lsblk
NAME                         MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS
sda                            8:0    0  200G  0 disk 
├─sda1                         8:1    0  600M  0 part /boot/efi
├─sda2                         8:2    0    1G  0 part /boot
└─sda3                         8:3    0 62.4G  0 part 
  ├─almalinux_almalinux-root 253:0    0 40.6G  0 lvm  /
  ├─almalinux_almalinux-swap 253:1    0    2G  0 lvm  [SWAP]
  └─almalinux_almalinux-home 253:2    0 19.8G  0 lvm  /home

查看磁盘的分区和未分配空间

[root@AlmaLinux ~]# sudo parted /dev/sda print free
型号:ATA AlmaLinux-0 SSD (scsi)
磁盘 /dev/sda:215GB
扇区大小 (逻辑/物理):512B/4096B
分区表:gpt
磁盘标志:

编号  起始点  结束点  大小    文件系统  名称                  标志
      17.4kB  1049kB  1031kB  可用空间
 1    1049kB  630MB   629MB   fat32     EFI System Partition  启动, esp
 2    630MB   1704MB  1074MB  xfs
 3    1704MB  68.7GB  67.0GB                                  lvm
      68.7GB  215GB   146GB   可用空间

创建物理卷 (PV)

创建新分区

sudo parted /dev/sda

在parted提示符下输入:

mkpart primary 68.7GB 215GB
print
quit

查看新分区

[root@AlmaLinux ~]# lsblk
NAME                         MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS
sda                            8:0    0  200G  0 disk 
├─sda1                         8:1    0  600M  0 part /boot/efi
├─sda2                         8:2    0    1G  0 part /boot
├─sda3                         8:3    0 62.4G  0 part 
│ ├─almalinux_almalinux-root 253:0    0 40.6G  0 lvm  /
│ ├─almalinux_almalinux-swap 253:1    0    2G  0 lvm  [SWAP]
│ └─almalinux_almalinux-home 253:2    0 19.8G  0 lvm  /home
└─sda4                         8:4    0  136G  0 part 
sr0                           11:0    1 1024M  0 rom

sda4 就是新分区的名字

格式化新分区为物理卷

[root@AlmaLinux ~]# pvcreate /dev/sda4
  Physical volume "/dev/sda4" successfully created.

扩展卷组以包含新的物理卷

查看当前的卷组

[root@AlmaLinux ~]# vgdisplay
  --- Volume group ---
  VG Name               almalinux_almalinux
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  6
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                3
  Open LV               3
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               62.41 GiB
  PE Size               4.00 MiB
  Total PE              15977
  Alloc PE / Size       15977 / 62.41 GiB
  Free  PE / Size       0 / 0   
  VG UUID               3b18iP-pPQ6-5iEe-91AQ-2edY-N6Py-FvzC2u

将新的物理卷添加到卷组

[root@AlmaLinux ~]# vgextend almalinux_almalinux /dev/sda4
  Volume group "almalinux_almalinux" successfully extended

最下面146GB就是我要扩容的空间大小

扩展根逻辑卷

查看现有逻辑卷

[root@AlmaLinux ~]# lvdisplay
  --- Logical volume ---
  LV Path                /dev/almalinux_almalinux/swap
  LV Name                swap
  VG Name                almalinux_almalinux
  LV UUID                m2JM1L-Mgmw-m7dP-4RRg-mZJ9-CbIX-LFA8fZ
  LV Write Access        read/write
  LV Creation host, time AlmaLinux, 2024-10-31 10:53:43 +0800
  LV Status              available
  # open                 2
  LV Size                1.99 GiB
  Current LE             510
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1
   
  --- Logical volume ---
  LV Path                /dev/almalinux_almalinux/home
  LV Name                home
  VG Name                almalinux_almalinux
  LV UUID                eA0RJ4-2s4J-tb1F-3ivQ-cCVd-CBxw-EdmwX4
  LV Write Access        read/write
  LV Creation host, time AlmaLinux, 2024-10-31 10:53:44 +0800
  LV Status              available
  # open                 1
  LV Size                19.82 GiB
  Current LE             5074
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:2
   
  --- Logical volume ---
  LV Path                /dev/almalinux_almalinux/root
  LV Name                root
  VG Name                almalinux_almalinux
  LV UUID                g1U1xP-j8dE-so1R-LFeA-EF40-D1O7-51XtQc
  LV Write Access        read/write
  LV Creation host, time AlmaLinux, 2024-10-31 10:53:44 +0800
  LV Status              available
  # open                 1
  LV Size                <40.60 GiB
  Current LE             10393
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0

扩展根逻辑卷

现在,你可以使用lvextend命令来扩展根逻辑卷almalinux_almalinux-root,以使用新添加的空间。

[root@AlmaLinux ~]# lvextend -l +100%FREE  /dev/almalinux_almalinux/root
  Size of logical volume almalinux_almalinux/root changed from <40.60 GiB (10393 extents) to 176.59 GiB (45208 extents).
  Logical volume almalinux_almalinux/root successfully resized.

调整文件系统大小

查看文件系统类型

[root@AlmaLinux ~]# df -T
文件系统                             类型         1K-块    已用      可用 已用% 挂载点
devtmpfs                             devtmpfs      4096       0      4096    0% /dev
tmpfs                                tmpfs      8006968       0   8006968    0% /dev/shm
tmpfs                                tmpfs      3202788    9676   3193112    1% /run
/dev/mapper/almalinux_almalinux-root xfs      109608960 6012672 103596288    6% /
/dev/mapper/almalinux_almalinux-home xfs       20717568  185280  20532288    1% /home
/dev/sda2                            xfs         983040  276528    706512   29% /boot
/dev/sda1                            vfat        613160    7196    605964    2% /boot/efi
tmpfs                                tmpfs      1601392     136   1601256    1% /run/user/1000
tmpfs                                tmpfs      1601392      36   1601356    1% /run/user/0

调整文件系统大小

扩展文件系统以使用新增加的空间。假设你使用的是 ext4 文件系统:

resize2fs /dev/almalinux_almalinux/root

如果使用其他文件系统,比如 xfs,可以用:

[root@AlmaLinux ~]# xfs_growfs /
meta-data=/dev/mapper/almalinux_almalinux-root isize=512    agcount=18, agsize=2660608 blks
         =                       sectsz=4096  attr=2, projid32bit=1
         =                       crc=1        finobt=1, sparse=1, rmapbt=0
         =                       reflink=1    bigtime=1 inobtcount=1 nrext64=0
data     =                       bsize=4096   blocks=46292992, 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=4096  sunit=1 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0

成功扩容

[root@AlmaLinux ~]# lsblk
NAME                         MAJ:MIN RM   SIZE RO TYPE MOUNTPOINTS
sda                            8:0    0   200G  0 disk 
├─sda1                         8:1    0   600M  0 part /boot/efi
├─sda2                         8:2    0     1G  0 part /boot
├─sda3                         8:3    0  62.4G  0 part 
│ ├─almalinux_almalinux-root 253:0    0 176.6G  0 lvm  /
│ ├─almalinux_almalinux-swap 253:1    0     2G  0 lvm  [SWAP]
│ └─almalinux_almalinux-home 253:2    0  19.8G  0 lvm  /home
└─sda4                         8:4    0   136G  0 part 
  └─almalinux_almalinux-root 253:0    0 176.6G  0 lvm  /