既存のディスク装置をQEMUネイティブイメージに追加

既存のディスク装置をQEMUネイティブイメージに追加

生のQEMUイメージ(vda.raw)があり、サイズを変更し、データが埋め込まれた生のext3ファイルシステム(vdb.raw)を含むファイルのデータを使用して既存のパーティションを追加したいと思います。両方のファイルは次のようになります。

$ file vda.raw
vda.raw: x86 boot sector; partition 1: ID=0x83, active, starthead 0, startsector 16065, 20948760 sectors, code offset 0x63
$ file vdb.raw
vdb.raw: Linux rev 1.0 ext3 filesystem data, UUID=14555b9c-4837-4b43-a8e8-fe4e19194e88, volume name "ephemeral0" (large files)

vdb.rawの内容がvda.rawで新しいディスクパーティションとして表示される2つの組み合わせを使用して新しいイメージを作成する簡単な方法はありますか?私は避けたい:

  1. vda.raw サイズ変更
  2. vda.rawに新しいパーティションを作成します。
  3. vda.rawマウント
  4. vdb.raw マウント
  5. vdb.rawの内容をvda.rawにコピーします。

ddで接続し、イメージに新しいパーティションがあることを確認するためにパーティションテーブルを変更する方法はありますか?

ベストアンサー1

確実な方法を試してみましたか? vdbをvdaに接続し、新しいパーティションを作成します。私はそれを試してみました、それはうまくいくようです。これは私がしたことです...

2つのファイルで始まります。

# ls -l vd*
-rw-r--r-- 1 root root 104857600 Feb 27 20:31 vda.raw
-rw-r--r-- 1 root root 104857600 Feb 27 20:31 vdb.raw

# file vd[ab].raw
vda.raw: x86 boot sector; partition 1: ID=0x83, starthead 32, startsector 2048, 202752 sectors, extended partition table (last)\011, code offset 0x0
vdb.raw: Linux rev 1.0 ext3 filesystem data, UUID=734fa0ee-0bc8-4428-a13c-3147c9c0866f

このファイルには、vda.raw単一パーティション(ext3ファイルシステムを含む)を持つ標準パーティションマップが含まれています。

# fdisk -l vda.raw 

Disk vda.raw: 104 MB, 104857600 bytes
191 heads, 50 sectors/track, 21 cylinders, total 204800 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: 0xad0a5dfe

  Device Boot      Start         End      Blocks   Id  System
vda.raw1            2048      204799      101376   83  Linux

vdb.rawファイルシステムが含まれていますext3

まず、次の2つのファイルを一緒にリンクします。

# cat vda.raw vdb.raw > combined.raw

次に、新しいデータを含む新しいパーティションを作成します。

# fdisk combined.raw

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

Command (m for help): p

Disk combined.raw: 209 MB, 209715200 bytes
191 heads, 50 sectors/track, 42 cylinders, total 409600 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: 0xad0a5dfe

       Device Boot      Start         End      Blocks   Id  System
combined.raw1            2048      204799      101376   83  Linux

ここで、開始セクタとサイズのデフォルト値を受け入れて新しいセクタを作成します。

Command (m for help): n
Partition type:
   p   primary (1 primary, 0 extended, 3 free)
   e   extended
Select (default p): p
Partition number (1-4, default 2): 2
First sector (204800-409599, default 204800): 
Using default value 204800
Last sector, +sectors or +size{K,M,G} (204800-409599, default 409599): 
Using default value 409599

Command (m for help): w
The partition table has been altered!

Syncing disks.

それでは、私たちが何を持っているのか見てみましょう。

# kpartx -a combined.raw 
# mkdir /mnt/{1,2}
# mount /dev/mapper/loop1p1 /mnt/1
# mount /dev/mapper/loop1p2 /mnt/2
# ls /mnt/1
lost+found  README.vda
# ls /mnt/2
lost+found  README.vdb
# 

ダダ!

おすすめ記事