別々の.img準備を作成する

別々の.img準備を作成する

問題がある「別のコマンドラインは同じ結果を提供しません。」、正解の選択(「parted」を使用したIMGファイルシステムとパーティションの作成)は次のとおりです。

# parted MyDrive.img \
    mklabel msdos \
    mkpart primary NTFS 1 1024 \
    set 1 lba on \
    align-check optimal 1 \
    print

Model:  (file)
Disk /dev/shm/MyDrive.img: 1074MB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags: 

Number  Start   End     Size    Type     File system  Flags
  1      1049kB  1074MB  1073MB  primary  ntfs         lba

fat32/ext4も同様です。ただし、/dev/loop()sudo losetup loop1 MyDrive.imgにイメージをマウントしても機能しませんunknown partition

したがって、注文が不完全です。

誰かがループにインストールしたときに認識されるように、ext4 / ntfs / fat32(GPTおよび)の.img生成順序を助けることができます(準備作業)MSDOS

ありがとうございます!

ベストアンサー1

パーティショニングが不要な場合は、リクエストされた方法と簡単な方法を提供します。私はext4の例だけを実行し、残りは推論できます。

パーティションを含むイメージファイル:

#!/bin/sh

FILE=MyDrive.img

# create new 2Gb image file, will overwrite $FILE if it already exists
dd if=/dev/zero of=$FILE bs=1M count=2048

# make two 1Gb partitions and record the offsets
offset1=$(parted $FILE \
    mklabel msdos \
    mkpart primary ext2 1 1024 \
    unit B \
    print | awk '$1 == 1 {gsub("B","",$2); print $2}')
offset2=$(parted $FILE \
    mkpart primary ext2 1024 2048 \
    unit B \
    print | awk '$1 == 2 {gsub("B","",$2); print $2}')

# loop mount the partitions and record the device
loop1=$(losetup -o $offset1 -f $FILE --show)
loop2=$(losetup -o $offset2 -f $FILE --show)

# create and mount the filesystems
mkdir -p /tmp/mnt{1,2}
mkfs.ext4 $loop1
mount $loop1 /tmp/mnt1
mkfs.ext4 $loop2
mount $loop2 /tmp/mnt2

# file write test
touch /tmp/mnt1/file_on_partition_1
touch /tmp/mnt2/file_on_partition_2

# cleanup
umount /tmp/mnt1 /tmp/mnt2
losetup -d $loop1 $loop2

パーティションのないイメージファイル:

#!/bin/sh

FILE=MyDrive.img

# create new 2Gb image file, will overwrite $FILE if it already exists
dd if=/dev/zero of=$FILE bs=1M count=2048

# create and mount filesystem
mkfs.ext4 -F $FILE
mount $FILE /mnt

# file write test
touch /tmp/mnt/file_in_imagefile

# cleanup
umount /mnt

これは説明を必要とせず、シェルスクリプトでこの答えを表現する方が簡単であることを願っています。

おすすめ記事