2

I'm trying to make a Debian installation manually from scratch to an external disk within a live Debian CD.

I created a Debian Stretch rootfs via multistrap by following the instructions from here (44fbcc).

Inside chroot environment, when it comes to Grub installation, I install the Grub2 to MBR:

debian:~# grub-install /dev/sdX --boot-directory=/boot

Command runs without error. When I need to create the /boot/grub/grub.cfg, it throws the following error:

debian:~# grub-mkconfig
/usr/sbin/grub-probe: error: cannot find a device for / (is /dev mounted?).

Yes, /dev is mounted along with /sys, /proc and /run here.

How can I generate grub.cfg inside chroot environment?

ceremcem
  • 2,351

1 Answers1

6

The meaningful part of the error message was cannot find a device for /, because mount command does not output the device entry for /.

What I didn't tell in the question is that I was trying to directly install the rootfs into a BTRFS subvolume. Apparently, chroot can not detect the / device in this scenario.

Here is what I was currently doing: (X is the root partition (device), Y is the boot partition)

host:# mount /dev/X /mnt/mydiskroot
host:# btrfs sub create /mnt/mydiskroot/rootfs
host:# mkdir /mnt/mydiskroot/rootfs/boot
host:# mount /dev/Y /mnt/mydiskroot/rootfs/boot
host:# rsync -avP debian-stretch-rootfs/ /mnt/mydiskroot/rootfs
host:# do-chroot.sh /mnt/mydiskroot/rootfs
root@guest:/#  mount | awk '$3 == "/" {print}' # nothing shows up, so update-grub throws the mentioned error

Here is how I solved:

root@guest:/# exit
host:# mkdir /mnt/actual-rootfs
host:# mount -t btrfs -o subvol=rootfs,defaults /dev/X /mnt/actual-rootfs/
host:# umount /dev/Y
host:# mount /dev/Y /mnt/actual-rootfs/boot
host:# do-chroot.sh /mnt/actual-rootfs
root@guest:/# mount | awk '$3 == "/" {print}'
/dev/X on / type btrfs (rw,relatime,space_cache,subvolid=257,subvol=/rootfs)
root@guest:/# update-grub
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-4.9.0-11-amd64
Found initrd image: /boot/initrd.img-4.9.0-11-amd64
done
ceremcem
  • 2,351
  • 1
    Thanks for this! Really helped me out.. had been completely baffled about wth was going on with the bit about /dev not being mounted after I had already mounted it. Only difference for me was that since my btrfs partition was inside a luks2 container, after opening it with cryptsetup, I'd use a /dev/mapper path e.g. mount -o "noatime,subvol=@fedora-root,compress=zstd:1" /dev/mapper/mappedname /mnt/mountpoint. Other than that it worked perfectly and completely got me over that roadblock. Thank you, sir. – zpangwin May 22 '22 at 03:18