如何调整磁盘映像设备的大小?

如何调整磁盘映像设备的大小?

我正在尝试减小备份驱动器映像的大小。原始磁盘有以下分区:

Model: ST916082 1A (scsi)
Disk /dev/sde: 160GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number  Start   End     Size    Type      File system  Flags
 1      32.3kB  65.7GB  65.7GB  primary   ntfs         boot
 2      65.7GB  160GB   94.4GB  extended               lba
 5      65.7GB  160GB   94.4GB  logical   ntfs

映像是使用以下命令从逻辑分区创建的

> sudo ddrescue /dev/sde5 datapartition logfile

Press Ctrl-C to interrupt
Initial status (read from logfile)
rescued:         0 B,  errsize:       0 B,  errors:       0
Current status
rescued:    94368 MB,  errsize:       0 B,  current rate:   23068 kB/s
   ipos:    94368 MB,   errors:       0,    average rate:   28839 kB/s
   opos:    94368 MB,     time from last successful read:       0 s
Finished

ntfsresize -i -f datapartition说:

ntfsresize v2012.1.15AR.5 (libntfs-3g)
Device name        : datapartition
NTFS volume version: 3.1
Cluster size       : 4096 bytes
Current volume size: 26999992832 bytes (27000 MB)
Current device size: 94368605184 bytes (94369 MB)
Checking filesystem consistency ...
100.00 percent completed
Accounting clusters ...
Space in use       : 26107 MB (96.7%)
Collecting resizing constraints ...
You might resize at 26106810368 bytes or 26107 MB (freeing 893 MB).
Please make a test run using both the -n and -s options before real resizing!

所以看起来我已经调整了文件系统的大小以适应数据,但没有调整设备的大小? (这是 2 年前的事了,我忘了。)我需要使用 fdisk 调整设备大小,对吧?但 fdisk 无法识别该分区:

> fdisk -lu datapartition 

Disk datapartition: 94.4 GB, 94368605184 bytes
255 heads, 63 sectors/track, 11472 cylinders, total 184313682 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: 0x69205244

This doesn't look like a partition table
Probably you selected the wrong device.

        Device Boot      Start         End      Blocks   Id  System
datapartition1   ?   218129509  1920119918   850995205   72  Unknown
datapartition2   ?   729050177  1273024900   271987362   74  Unknown
datapartition3   ?   168653938   168653938           0   65  Novell Netware 386
datapartition4      2692939776  2692991410       25817+   0  Empty

Partition table entries are not in disk order

cfdisk 也不:

> cfdisk datapartition 

FATAL ERROR: Bad primary partition 1: Partition begins after end-of-disk
                      Press any key to exit cfdisk

不过,我可以安装分区并从中复制文件。如何调整设备大小?

答案1

如果只是分区的转储,则没有分区表。分区就是文件,只需要缩小文件即可:

truncate -s 27000832000 datapartition

(为了安全起见,27000832000 是 26999992832 四舍五入到下一个 MiB,您是否希望将其压缩为某种qcow2格式或任何其他可安装的压缩格式)

答案2

你可能想给予gparted看看。当我们想要调整不同类型的分区大小时,我们通常使用这个实时发行版。

gparted 的示例屏幕截图

                              gparted 的 ss #1

                              gparted 的 ss #2

看一眼本教程了解更多详情。

相关内容