Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 536802 - sys-boot/grub-0.97-r14 -- grub-install fails to install to loop device
Summary: sys-boot/grub-0.97-r14 -- grub-install fails to install to loop device
Status: RESOLVED WONTFIX
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] Core system (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Gentoo's Team for Core System packages
URL:
Whiteboard:
Keywords:
Depends on: 674364
Blocks:
  Show dependency tree
 
Reported: 2015-01-16 20:29 UTC by Sebastian Pipping
Modified: 2019-02-08 15:25 UTC (History)
2 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Sebastian Pipping gentoo-dev 2015-01-16 20:29:00 UTC
Hi!


To my understanding, it should be possible and supported to install Grub 0.9x
onto a loop device.  In practice, it seems impossible with (the latest stable)
sys-boot/grub-0.97-r14 and produces unexpected

  expr: non-integer argument

output too, see below.


Disk preparation
----------------

The idea of using a linear device mapper device is from

  http://ebroder.net/2009/08/04/installing-grub-onto-a-disk-image/ ,

was a hope of mine, fails similar to going straight to the loop the device,
but has the advantage of making the rest of the script easier to read and
re-produce.


# touch grubdisk
# truncate --size $((200 * 1024**2)) grubdisk
# /usr/sbin/parted grubdisk mklabel msdos
# /usr/sbin/parted --script grubdisk mkpart primary 0% 50%
# /usr/sbin/parted --script grubdisk mkpart primary 50% 100%
# GRUB_DISK_DEVICE="$(sudo losetup --show -f grubdisk)"
# sudo dmsetup create grub-disk-linear --table \
  "0 $(sudo blockdev --getsz ${GRUB_DISK_DEVICE}) linear ${GRUB_DISK_DEVICE} 0"
# sudo kpartx -a /dev/mapper/grub-disk-linear
# sudo mkfs.ext4 /dev/mapper/grub-disk-linear1
# sudo mkfs.ext2 /dev/mapper/grub-disk-linear2
# mkdir mnt
# sudo mount /dev/mapper/grub-disk-linear1 mnt/
# sudo mkdir mnt/boot
# sudo mount /dev/mapper/grub-disk-linear2 mnt/boot/


Installing Grub 0.9x
--------------------

# sudo grub-install --root-directory="${PWD}/mnt" /dev/mapper/grub-disk-linear
Probing devices to guess BIOS drives. This may take a long time.
Unknown partition table signature
/dev/mapper/../dm-8 does not have any corresponding BIOS drive.

# ls -l /dev/mapper/grub-disk-linear*
lrwxrwxrwx 1 root root 7 Jan 16 21:00 /dev/mapper/grub-disk-linear -> ../dm-8
lrwxrwxrwx 1 root root 7 Jan 16 21:02 /dev/mapper/grub-disk-linear1 -> ../dm-9
lrwxrwxrwx 1 root root 8 Jan 16 21:02 /dev/mapper/grub-disk-linear2 -> ../dm-10

# cat mnt/boot/grub/device.map 
(fd0)   /dev/fd0
(hd0)   /dev/sda
(hd1)   /dev/sdb

# sudo sed 's|^\((hd0).\).*|\1/dev/mapper/../dm-8|' -i mnt/boot/grub/device.map

# cat mnt/boot/grub/device.map 
(fd0)   /dev/fd0
(hd0)   /dev/mapper/../dm-8
(hd1)   /dev/sdb

# sudo grub-install --root-directory="${PWD}/mnt" /dev/mapper/grub-disk-linear
expr: non-integer argument
/dev/mapper/../dm-10 does not have any corresponding BIOS drive.

## NOTE: So what are my options now?
##       I cannot put "(hd0,0)<tab>..." in there as that is unsupported syntax
##       and would give a (misleading) "No close parenthesis found" error.
##       So let's try mapping to yet another "(hd2)".

# sudo sh -c 'echo -e "(hd2)\t/dev/mapper/../dm-10" >> mnt/boot/grub/device.map'

# cat mnt/boot/grub/device.map 
(fd0)   /dev/fd0
(hd0)   /dev/mapper/../dm-8
(hd1)   /dev/sdb
(hd2)   /dev/mapper/../dm-10

# sudo grub-install --root-directory="${PWD}/mnt" /dev/mapper/grub-disk-linear
expr: non-integer argument
expr: non-integer argument
Unknown partition table signature
Unknown partition table signature
Unknown partition table signature
Unknown partition table signature
Unknown partition table signature
Unknown partition table signature
Unknown partition table signature
Unknown partition table signature
Unknown partition table signature
Unknown partition table signature
The file [..]/mnt/boot/grub/stage1 not read correctly.


## Any ideas?
Comment 1 Mike Gilbert gentoo-dev 2015-01-16 21:17:52 UTC
This does work properly with sys-boot/grub:2, so you might consider switching to that.
Comment 2 Sebastian Pipping gentoo-dev 2015-01-16 21:28:14 UTC
(In reply to Mike Gilbert from comment #1)
> This does work properly with sys-boot/grub:2, so you might consider
> switching to that.

Thanks, I'm aware.  I am working on a Grub theme preview tool that does support Grub2 only so far.  I tried adding support for Grub 0.9x for people sticking to that version.  That's how I ran into the issue.
Comment 3 Mikle Kolyada (RETIRED) archtester Gentoo Infrastructure gentoo-dev Security 2019-02-08 15:25:18 UTC
grub:0 is gone