“磁盘外不能有分区!”对于从截断的映像创建的 vdi

“磁盘外不能有分区!”对于从截断的映像创建的 vdi

我曾经dd创建磁盘的部分/截断映像,其中仅包含分配的空间,然后将其转换为 VirtualBox 的 vdi 文件。我已成功使用 vdi 映像运行安装在磁盘上的 Linux (Ubuntu)。

现在我不想运行 GParted 来删除位于 Linux 分区之前的分区(以便我可以创建较小的映像)。但 GParted 不起作用。它显示整个磁盘未分配。我该如何修复它?

附加信息:

sudo pared /dev/sda 单位打印

Error: Can't have a partition outside the disk!                           

sudo fdisk -l -u /dev/sda

Disk /dev/sda: 97.7 GB, 97729379840 bytes
255 heads, 63 sectors/track, 11881 cylinders, total 190877695 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 identifier: 0x3c36156a

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2459647     1228800    7  HPFS/NTFS/exFAT
/dev/sda2         2459648   125339129    61439741    7  HPFS/NTFS/exFAT
/dev/sda3       125339646   190877695    32769025    5  Extended
/dev/sda5       125339648   190877695    32769024   83  Linux

sudo sfdisk -uS -l /dev/sda

Disk /dev/sda: 11881 cylinders, 255 heads, 63 sectors/track
Warning: extended partition does not start at a cylinder boundary.
DOS and Linux will interpret the contents differently.
Units = sectors of 512 bytes, counting from 0

   Device Boot    Start       End   #sectors  Id  System
/dev/sda1   *      2048   2459647    2457600   7  HPFS/NTFS/exFAT
/dev/sda2       2459648 125339129  122879482   7  HPFS/NTFS/exFAT
/dev/sda3     125339646 190877695   65538050   5  Extended
/dev/sda4             0         -          0   0  Empty
/dev/sda5     125339648 190877695   65538048  83  Linux

须藤 sfdisk -d /dev/sda

Warning: extended partition does not start at a cylinder boundary.
DOS and Linux will interpret the contents differently.
# partition table of /dev/sda
unit: sectors

/dev/sda1 : start=     2048, size=  2457600, Id= 7, bootable
/dev/sda2 : start=  2459648, size=122879482, Id= 7
/dev/sda3 : start=125339646, size= 65538050, Id= 5
/dev/sda4 : start=        0, size=        0, Id= 0
/dev/sda5 : start=125339648, size= 65538048, Id=83

答案1

也许最简单的解决方案是增加图像的大小以gparted再次快乐。这很可能是一种一次性问题,因此将图像大小增加几兆字节就足够了:

dd if=/dev/zero of=newimage.raw bs=1M count=102400
qemu-img convert -f vdi oldimage.vdi -O raw oldimage.raw
dd if=oldimage.raw of=newimage.raw count=190877695 conv=notrunc
qemu-img convert -f raw newimage.raw -O vdi newimage.vdi

或者简单地:

cp oldimage.vdi newimage.vdi
VBoxManage modifyhd /path/to/newimage.vdi --resize 102400

gparted然后您应该重试在 上运行newimage.vdi。如果仍然出现问题,您可以尝试将图像的大小增加到原始磁盘大小,前提是您有足够的空间。

相关内容