ディスクイメージファイルのパーティションサイズを変更した後、ディスクイメージファイルのパーティションテーブルをどのように更新しますか?

ディスクイメージファイルのパーティションサイズを変更した後、ディスクイメージファイルのパーティションテーブルをどのように更新しますか?

ディスク上のディスクイメージ(Raspbianイメージ)のサイズを変更しようとしています。

問題は、サイズ変更された画像(SDカードに書き込んだ後)からRaspberryPiを起動しようとすると、次のような結果が出ることです。

カーネルパニック - 非同期:VFS:未知のブロックにルートfsをマウントできません。

(申し訳ありません。正確なエラーを特定できませんでした。関連している場合は更新できます。)

考えるこれは、パーティションテーブルを更新しないためです。背景は次のとおりです。

初期イメージパーティション

初期パーティションは次のとおりです。

gregmac@test1:~/image$ fdisk -l test.img

Disk test.img: 1389 MB, 1389363200 bytes
255 heads, 63 sectors/track, 168 cylinders, total 2713600 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: 0x5a7089a1

   Device Boot      Start         End      Blocks   Id  System
test.img1            8192      137215       64512    c  W95 FAT32 (LBA)
test.img2          137216     2713599     1288192   83  Linux

最初のディスクサイズは1389MBです。

サイズ変更

500MBを追加

gregmac@test1:~/image$ truncate -s +500M test.img
gregmac@test1:~/image$ fdisk -l test.img

Disk test.img: 1913 MB, 1913651200 bytes
255 heads, 63 sectors/track, 232 cylinders, total 3737600 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: 0x5a7089a1

  Device Boot      Start         End      Blocks   Id  System
test.img1            8192      137215       64512    c  W95 FAT32 (LBA)
test.img2          137216     2713599     1288192   83  Linux

よさそうですね。新しい合計サイズは1913MBです。

ファイルシステムのサイズ変更

ここで、新しいスペースを使用するために2番目のパーティションのサイズを変更したいと思います。

オフセットを使用してループデバイスを作成します(セクタあたり512単位* 137216セクタ)。

gregmac@test1:~/image$ sudo losetup -f --show test.img -o $((512*137216))
/dev/loop0

e2fsckを実行し(そうでなければresize2fsが苦情を示すため)、resize2fsを実行します。

gregmac@test1:~/image$ sudo e2fsck -f /dev/loop0
e2fsck 1.42.9 (4-Feb-2014)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/loop0: 37167/80640 files (0.2% non-contiguous), 250800/322048 blocks

gregmac@test1:~/image$ sudo resize2fs /dev/loop0
resize2fs 1.42.9 (4-Feb-2014)
Resizing the filesystem on /dev/loop0 to 450048 (4k) blocks.
The filesystem on /dev/loop0 is now 450048 blocks long.

サイズ変更が正常に動作しているようです。もしそうなら、e2fsckを再実行しましたが、新しいブロックが表示されている間に何かが間違っていたという他の兆候はありませんでした。

gregmac@test1:~/image$ sudo e2fsck -f /dev/loop0
e2fsck 1.42.9 (4-Feb-2014)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/loop0: 37167/112896 files (0.2% non-contiguous), 252824/450048 blocks

また、価値の少ない次のループデバイスを取り付けることもできます。

gregmac@test1:~/image$ sudo mount /dev/loop0 temp-mnt
gregmac@test1:~/image$ ls temp-mnt/
bin  boot  dev  etc  home  lib  lost+found  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var

df -h正しい寸法を表示してください。

Filesystem      Size  Used Avail Use% Mounted on
/dev/loop0      1.7G  928M  667M  59% /home/gregmac/image/temp-mnt

パーティションテーブル

これは私のものです。考える問題は、パーティションテーブルが影響を受けないことです。

gregmac@test1:~/image$ fdisk -l test.img

Disk test.img: 1913 MB, 1913651200 bytes
255 heads, 63 sectors/track, 232 cylinders, total 3737600 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: 0x5a7089a1

   Device Boot      Start         End      Blocks   Id  System
test.img1            8192      137215       64512    c  W95 FAT32 (LBA)
test.img2          137216     2713599     1288192   83  Linux

スペースの増加に関係なく、終了値とブロック値はまだ古い値です。最終値は3737599(総セクタ数から1を引いた値)でなければならないと思いますが、これについて100%明確ではありません。

私はresize2fsがパーティションテーブルを更新すると思いましたが、明らかにそうではありません。

だから..

サイズ変更ステップをスキップすると、画像が正しく起動されることにも言及する価値があります。

問題は、自動ビルドの一部としてスクリプトでこれを実行しようとしていますが、デフォルトのRaspbianイメージに必要なすべてのエントリをインストールするのに十分な空きディスク容量がないことです。

  • パーティションテーブルが原因であると仮定すると、どのように更新できますか?
  • スクリプト可能な方法でこれをどのように実行しますか? (対話型ユーザー入力は不要)

  • パーティションテーブルが原因でない場合、原因は何ですか?

ベストアンサー1

ファイルシステムのサイズを変更する前に、プライマリパーティションのサイズを変更する必要があります。

parted test.img resizepart 2 1980MB

次に、ファイルシステムのサイズを変更します。

おすすめ記事