make kernel bootable
This commit is contained in:
parent
2db4cdc814
commit
ffbe350dd4
|
@ -13,7 +13,7 @@ set -x
|
||||||
. /lib/init.sh
|
. /lib/init.sh
|
||||||
|
|
||||||
setup_environment() {
|
setup_environment() {
|
||||||
initialize
|
#initialize
|
||||||
|
|
||||||
# Install additional utility programs.
|
# Install additional utility programs.
|
||||||
/bin/busybox --install /bin || true
|
/bin/busybox --install /bin || true
|
||||||
|
|
4
build.sh
4
build.sh
|
@ -15,7 +15,7 @@ print_help() {
|
||||||
}
|
}
|
||||||
|
|
||||||
check_deps() {
|
check_deps() {
|
||||||
local needed_commands="cpio binwalk pcregrep realpath"
|
local needed_commands="cpio binwalk pcregrep realpath cgpt"
|
||||||
for command in $needed_commands; do
|
for command in $needed_commands; do
|
||||||
if ! command -v $command &> /dev/null; then
|
if ! command -v $command &> /dev/null; then
|
||||||
echo $command
|
echo $command
|
||||||
|
@ -61,7 +61,7 @@ binwalk_out=$(binwalk --extract kernel.bin --run-as=root)
|
||||||
#i can't be bothered to learn how to use sed
|
#i can't be bothered to learn how to use sed
|
||||||
extracted_file=$(echo $binwalk_out | pcregrep -o1 "\d+\s+0x([0-9A-F]+)\s+gzip compressed data")
|
extracted_file=$(echo $binwalk_out | pcregrep -o1 "\d+\s+0x([0-9A-F]+)\s+gzip compressed data")
|
||||||
|
|
||||||
echo "extracting initramfs archive from kernel"
|
echo "extracting initramfs archive from kernel (this may take a while)"
|
||||||
cd _kernel.bin.extracted/
|
cd _kernel.bin.extracted/
|
||||||
binwalk --extract $extracted_file --run-as=root > /dev/null
|
binwalk --extract $extracted_file --run-as=root > /dev/null
|
||||||
cd "_${extracted_file}.extracted/"
|
cd "_${extracted_file}.extracted/"
|
||||||
|
|
|
@ -17,6 +17,11 @@ make_mountable() {
|
||||||
printf '\000' | dd of=$1 seek=$((0x464 + 3)) conv=notrunc count=1 bs=1
|
printf '\000' | dd of=$1 seek=$((0x464 + 3)) conv=notrunc count=1 bs=1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#set required flags on the kernel partition
|
||||||
|
make_bootable() {
|
||||||
|
cgpt add -i 2 -S 1 -T 5 -P 10 -l kernel $1
|
||||||
|
}
|
||||||
|
|
||||||
partition_disk() {
|
partition_disk() {
|
||||||
local image_path=$(realpath "${1}")
|
local image_path=$(realpath "${1}")
|
||||||
local bootloader_size=${2}
|
local bootloader_size=${2}
|
||||||
|
@ -61,7 +66,7 @@ partition_disk() {
|
||||||
}
|
}
|
||||||
|
|
||||||
safe_mount() {
|
safe_mount() {
|
||||||
umount $2 || /bin/true
|
umount $2 2> /dev/null || /bin/true
|
||||||
rm -rf $2
|
rm -rf $2
|
||||||
mkdir -p $2
|
mkdir -p $2
|
||||||
mount $1 $2
|
mount $1 $2
|
||||||
|
@ -75,6 +80,7 @@ create_partitions() {
|
||||||
mkfs.ext4 "${image_loop}p1"
|
mkfs.ext4 "${image_loop}p1"
|
||||||
#copy kernel
|
#copy kernel
|
||||||
dd if=$kernel_path of="${image_loop}p2" bs=1M oflag=sync
|
dd if=$kernel_path of="${image_loop}p2" bs=1M oflag=sync
|
||||||
|
make_bootable $image_loop
|
||||||
#create bootloader partition
|
#create bootloader partition
|
||||||
mkfs.ext2 "${image_loop}p3"
|
mkfs.ext2 "${image_loop}p3"
|
||||||
#create rootfs partition
|
#create rootfs partition
|
||||||
|
@ -117,6 +123,7 @@ create_image() {
|
||||||
partition_disk $image_path $bootloader_size
|
partition_disk $image_path $bootloader_size
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#for testing only
|
||||||
if [ $0 == "./build_image.sh" ]; then
|
if [ $0 == "./build_image.sh" ]; then
|
||||||
create_image ./test.bin 20 200
|
create_image ./test.bin 20 200
|
||||||
image_loop=$(create_loop ./test.bin)
|
image_loop=$(create_loop ./test.bin)
|
||||||
|
|
Loading…
Reference in New Issue