Giter VIP home page Giter VIP logo

Comments (2)

unnamedd avatar unnamedd commented on May 24, 2024

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

from baremetal-arm.

qianfan-Zhao avatar qianfan-Zhao commented on May 24, 2024

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

from baremetal-arm.

Related Issues (14)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.