イメージが 64 MB の場合は grub-install が失敗し、イメージが 256 MB の場合は grub-install が成功します。

イメージが 64 MB の場合は grub-install が失敗し、イメージが 256 MB の場合は grub-install が成功します。

どちらの場合も、tst.shスクリプトは、ddが最初の場合に64MBのイメージを生成し、2番目の場合に256MBのイメージを生成することを除いて、まったく同じです。 (画像サイズは、スクリプトの最初のdd行にあるcountパラメータとして定義されます。)

イメージサイズが256 MBの場合、grubのインストールはエラーなしで失敗し、イメージサイズが64MBの場合はgrubのインストールは失敗します。

推測はありますか?

1. バージョン:

(venv3.4)root@ugbuildserver:/home/ubuntu/ubuntucore# grub-install -V
grub-install (GRUB) 2.02~beta2-22ubuntu1.1

シナリオ1:dd count = 64のときGRUBが失敗する

(venv3.4)root@server:/home/ubuntu/ubuntucore# cat tst.sh
sudo dd if=/dev/zero of=./test.img oflag=direct bs=1M count=64
sudo mkdir -p /mnt/build
sudo parted -s test.img mklabel msdos
sudo parted -s -a optimal test.img mkpart primary ext2 '0%' '100%'
sudo parted -s test.img set 1 boot on
sudo kpartx -av test.img
sudo mke2fs -L '/' -t ext2 /dev/mapper/loop0p1
sudo mount /dev/mapper/loop0p1 /mnt/build
sudo grub-install --root-directory=/mnt/build /dev/loop0

# release mount
sudo umount -l /mnt/build
# release loopback
sudo dmsetup remove loop0p1
sudo losetup -d /dev/loop0

(venv3.4)root@server:/home/ubuntu/ubuntucore# . tst.sh
64+0 records in
64+0 records out
67108864 bytes (67 MB) copied, 0.15139 s, 443 MB/s
Warning: The resulting partition is not properly aligned for best performance.
add map loop0p1 (252:2): 0 131071 linear /dev/loop0 1
mke2fs 1.42.12 (29-Aug-2014)
Discarding device blocks: done
Creating filesystem with 65532 1k blocks and 16384 inodes
Filesystem UUID: 2a52b053-c671-428d-bc13-6b967e0781c5
Superblock backups stored on blocks:
    8193, 24577, 40961, 57345

Allocating group tables: done
Writing inode tables: done
Writing superblocks and filesystem accounting information: done

Installing for i386-pc platform.
grub-install: warning: this msdos-style partition label has no post-MBR gap; embedding won't be possible.
grub-install: warning: Embedding is not possible.  GRUB can only be installed in this setup by using blocklists.  However, blocklists are UNRELIABLE and their use is discouraged..
grub-install: error: will not proceed with blocklists.

シナリオ2:dd count = 256でGRUBが成功

(venv3.4)root@userver:/home/ubuntu/ubuntucore# cat tst.sh
sudo dd if=/dev/zero of=./test.img oflag=direct bs=1M count=256
sudo mkdir -p /mnt/build
sudo parted -s test.img mklabel msdos
sudo parted -s -a optimal test.img mkpart primary ext2 '0%' '100%'
sudo parted -s test.img set 1 boot on
sudo kpartx -av test.img
sudo mke2fs -L '/' -t ext2 /dev/mapper/loop0p1
sudo mount /dev/mapper/loop0p1 /mnt/build
sudo grub-install --root-directory=/mnt/build /dev/loop0

# release mount
sudo umount -l /mnt/build
# release loopback
sudo dmsetup remove loop0p1
sudo losetup -d /dev/loop0

(venv3.4)root@server:/home/ubuntu/ubuntucore# . tst.sh
256+0 records in
256+0 records out
268435456 bytes (268 MB) copied, 0.637421 s, 421 MB/s
add map loop0p1 (252:2): 0 522240 linear /dev/loop0 2048
mke2fs 1.42.12 (29-Aug-2014)
Discarding device blocks: done
Creating filesystem with 261120 1k blocks and 65280 inodes
Filesystem UUID: 1bf70e68-8f27-426d-b66e-c9c90aaa01b4
Superblock backups stored on blocks:
    8193, 24577, 40961, 57345, 73729, 204801, 221185

Allocating group tables: done
Writing inode tables: done
Writing superblocks and filesystem accounting information: done

Installing for i386-pc platform.
Installation finished. No error reported.

ベストアンサー1

grubメーリングリストの良い人々は、異なるブートセクタを表示する両方の画像でfdisk -lを実行することを提案しました。 0%の代わりに明示的な開始セクタを持つようにddコマンドを変更すると、うまく機能します。

sudo parted -s -a optimal {0} mkpart primary ext2 '2048s' '100%'

両方の画像に「fdisk -l」と表示します。

ubuntu@ugbuildserver:~$ sudo fdisk -l /dev/loop0

Disk /dev/loop0: 64 MiB, 67108864 bytes, 131072 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
Disklabel type: dos
Disk identifier: 0x0e508c47

Device       Boot Start    End Sectors Size Id Type
/dev/loop0p1 *        1 131071  131071  64M 83 Linux



ubuntu@ugbuildserver:~$ sudo fdisk -l /dev/loop0

Disk /dev/loop0: 256 MiB, 268435456 bytes, 524288 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
Disklabel type: dos
Disk identifier: 0x0dde66d2

Device       Boot Start    End Sectors  Size Id Type
/dev/loop0p1 *     2048 524287  522240  255M 83 Linux

おすすめ記事