Partition

“磁碟外不能有分區!”對於從截斷圖像創建的 vdi

  • October 15, 2015

我曾經dd創建僅包含分配空間的磁碟的部分/截斷圖像,然後將其轉換為 VirtualBox 的 vdi 文件。我已成功使用 vdi 映像執行安裝在磁碟上的 Linux (Ubuntu)。

現在我不想執行 GParted 來刪除位於 Linux 分區之前的分區(這樣我就可以創建一個更小的映像)。但是 GParted 不起作用。它將整個磁碟顯示為未分配。我該如何解決?

附加資訊:

sudo parted /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

sudo 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

也許最簡單的解決方案是增加圖像的大小以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。如果仍然報錯,您可以嘗試將映像的大小增加到原始磁碟大小,前提是您有足夠的空間。

引用自:https://unix.stackexchange.com/questions/233608