在虚拟机中调整磁盘 LUN 大小不会反映在 OS Linux SuSe 中

在虚拟机中调整磁盘 LUN 大小不会反映在 OS Linux SuSe 中

我原本有 20GB 的磁盘设备 sda,我想将其扩展到 30GB。我在 VirtualBox 6.1 中扩展了它,但在操作系统 (SLES 15.2) 中没有反映出新的大小,即使重新启动并重新扫描后也是如此。仍然显示 20GB

# fdisk -l
Disk /dev/sda: 20 GiB, 21474836480 bytes, 41943040 sectors
Disk model: VBOX HARDDISK
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: 570B8A70-1684-4A82-B17C-510613CB8D49

Device     Start      End  Sectors Size Type
/dev/sda1   2048    18431    16384   8M BIOS boot
/dev/sda2  18432 41943006 41924575  20G Linux LVM



# lsblk
NAME                   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda                      8:0    0   20G  0 disk
├─sda1                   8:1    0    8M  0 part
└─sda2                   8:2    0   20G  0 part
  ├─system-swap        254:0    0  6.1G  0 lvm  [SWAP]
  ├─system-root        254:1    0    4G  0 lvm  /
  ├─system-opt         254:2    0    2G  0 lvm  /opt
  ├─system-var         254:3    0    2G  0 lvm  /var
  ├─system-vartmp      254:4    0    2G  0 lvm  /var/tmp


  ├─system-home        254:5    0    2G  0 lvm  /home
  └─system-tmp         254:6    0    2G  0 lvm  /tmp

VirtualBox 脚本:

答案1

将备份 GPT 移动到磁盘的新末端:

[tom@ideapad ~]$ sudo gdisk -l /dev/loop0
GPT fdisk (gdisk) version 1.0.8

Partition table scan:
  MBR: protective
  BSD: not present
  APM: not present
  GPT: present

Found valid GPT with protective MBR; using GPT.
Disk /dev/loop0: 4194304 sectors, 2.0 GiB
Sector size (logical/physical): 512/512 bytes
Disk identifier (GUID): 25833AA4-9BE0-43A8-9922-04DD10A607A3
Partition table holds up to 128 entries
Main partition table begins at sector 2 and ends at sector 33
First usable sector is 34, last usable sector is 4194270
Partitions will be aligned on 2048-sector boundaries
Total free space is 2014 sectors (1007.0 KiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048         4194270   2.0 GiB     8300  Linux filesystem
[tom@ideapad ~]$ sudo losetup -D
[tom@ideapad ~]$ truncate -s 4G /tmp/test 
[tom@ideapad ~]$ sudo losetup -P -f /tmp/test 
[tom@ideapad ~]$ sudo gdisk -l /dev/loop0
GPT fdisk (gdisk) version 1.0.8

Partition table scan:
  MBR: protective
  BSD: not present
  APM: not present
  GPT: present

Found valid GPT with protective MBR; using GPT.
Disk /dev/loop0: 8388608 sectors, 4.0 GiB
Sector size (logical/physical): 512/512 bytes
Disk identifier (GUID): 25833AA4-9BE0-43A8-9922-04DD10A607A3
Partition table holds up to 128 entries
Main partition table begins at sector 2 and ends at sector 33
First usable sector is 34, last usable sector is 4194270
Partitions will be aligned on 2048-sector boundaries
Total free space is 2014 sectors (1007.0 KiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048         4194270   2.0 GiB     8300  Linux filesystem
[tom@ideapad ~]$ sudo sgdisk -e /dev/loop0
The operation has completed successfully.
[tom@ideapad ~]$ sudo gdisk -l /dev/loop0
GPT fdisk (gdisk) version 1.0.8

Partition table scan:
  MBR: protective
  BSD: not present
  APM: not present
  GPT: present

Found valid GPT with protective MBR; using GPT.
Disk /dev/loop0: 8388608 sectors, 4.0 GiB
Sector size (logical/physical): 512/512 bytes
Disk identifier (GUID): 25833AA4-9BE0-43A8-9922-04DD10A607A3
Partition table holds up to 128 entries
Main partition table begins at sector 2 and ends at sector 33
First usable sector is 34, last usable sector is 8388574
Partitions will be aligned on 2048-sector boundaries
Total free space is 4196318 sectors (2.0 GiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048         4194270   2.0 GiB     8300  Linux filesystem
[tom@ideapad ~]$ 

相关内容