Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Note on ndb not being available #5

Open
dueringa opened this issue Mar 6, 2019 · 2 comments
Open

Note on ndb not being available #5

dueringa opened this issue Mar 6, 2019 · 2 comments

Comments

@dueringa
Copy link

dueringa commented Mar 6, 2019

Hi,

also in doc/03_bootloader.md, there's a note regarding the nbd module.
At least under Debian Stretch, I had some issues with section, and the SD card creation script, since nbd is not loaded by default. Also, simply executing modprobe nbd didn't solve the problem. Specifically, I had to execute modprobe nbd max_part=16, and after "connecting" the image with qemu-nbd -c /dev/nbd0 sdcard.img, I had to execute partprobe /dev/nbd0 so the /dev/nbd0p1 device gets created. (Otherwise I could not execute mkfs.ext2 on it).

I'm not sure if it's worth mentioning this in the note, since this might be fairly Debian-specific, and other Linux distros might behave differently. (Related bug: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=824553)

@unnamedd
Copy link

Based on @dueringa's suggestion, this is the create-sd.sh script that worked for me.
In case you are facing problems with that script.

#!/usr/bin/env bash

SDNAME="$1"
UIMGNAME="$2"

if [ "$#" -ne 2 ]; then
    echo "Usage: "$0" sdimage uimage"
    exit 1
fi

command -v qemu-img > /dev/null || { echo "qemu-img not installed"; exit 1; }
command -v qemu-nbd > /dev/null || { echo "qemu-nbd not installed"; exit 1; }

sudo modprobe nbd max_part=16  # <-----  Added after @dueringa's suggestion
qemu-img create "$SDNAME" 64M
sudo qemu-nbd -c /dev/nbd0 "$SDNAME"
partprobe /dev/nbd0 # <-----  Added after @dueringa's suggestion

(echo o;
echo n; echo p;
echo 1
echo ; echo
echo w; echo p) | sudo fdisk /dev/nbd0
sudo mkfs.ext2 /dev/nbd0p1

mkdir tmp || true
sudo mount -o user /dev/nbd0p1 tmp/
sudo cp "$UIMGNAME" tmp/
sudo umount /dev/nbd0p1
rmdir tmp/ || true
sudo qemu-nbd -d /dev/nbd0

@qianfan-Zhao
Copy link

qianfan-Zhao commented Mar 23, 2023

nbd seems not available on WSL, seems we should find a better way to handle this.

make_ext4fs can create a ext based filesystem and genimage can make a mbr image, and they doesn't need root permission. Next is a simple scripts can replace nbd.

#!/usr/bin/env bash

SDNAME="$1"
UIMGNAME="$2"

if [ "$#" -ne 2 ]; then
    echo "Usage: "$0" sdimage uimage"
    exit 1
fi

command -v genimage >/dev/null || { echo "genimage not installed"; exit 1; }

rm -rf tmp rootfs
mkdir rootfs

cp "$UIMGNAME" rootfs
make_ext4fs -l 32M rootfs.ext4 rootfs

cat << EOF > genimage.cfg
image genimage_output.img {
	hdimage {
	}

	partition rootfs {
		partition-type = 0x83
		image = "rootfs.ext4"
	}
}
EOF

genimage --inputpath . --outputpath . genimage.cfg
mv genimage_output.img "${SDNAME}"
qemu-img resize "${SDNAME}" 64M

rm rootfs.ext4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants