create and populate image partitions
This commit is contained in:
parent
0c7003eb34
commit
7313d20584
|
@ -1 +1,2 @@
|
||||||
/data
|
/data
|
||||||
|
/test.bin
|
7
build.sh
7
build.sh
|
@ -8,6 +8,7 @@ if [ "$DEBUG" ]; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
. ./patch_initramfs.sh
|
. ./patch_initramfs.sh
|
||||||
|
. ./build_image.sh
|
||||||
|
|
||||||
print_help() {
|
print_help() {
|
||||||
echo "Usage: ./build.sh path_to_shim"
|
echo "Usage: ./build.sh path_to_shim"
|
||||||
|
@ -22,12 +23,6 @@ check_deps() {
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
create_loop() {
|
|
||||||
local loop_device=$(losetup -f)
|
|
||||||
losetup -P $loop_device "${1}"
|
|
||||||
echo $loop_device
|
|
||||||
}
|
|
||||||
|
|
||||||
if [ "$EUID" -ne 0 ]; then
|
if [ "$EUID" -ne 0 ]; then
|
||||||
echo "this needs to be run as root."
|
echo "this needs to be run as root."
|
||||||
exit 1
|
exit 1
|
||||||
|
|
|
@ -5,6 +5,12 @@ if [ "$DEBUG" ]; then
|
||||||
set -x
|
set -x
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
create_loop() {
|
||||||
|
local loop_device=$(losetup -f)
|
||||||
|
losetup -P $loop_device "${1}"
|
||||||
|
echo $loop_device
|
||||||
|
}
|
||||||
|
|
||||||
make_mountable() {
|
make_mountable() {
|
||||||
sh lib/ssd_util.sh --no_resign_kernel --remove_rootfs_verification -i $1
|
sh lib/ssd_util.sh --no_resign_kernel --remove_rootfs_verification -i $1
|
||||||
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
|
||||||
|
@ -14,7 +20,7 @@ partition_disk() {
|
||||||
local image_path=$(realpath "${1}")
|
local image_path=$(realpath "${1}")
|
||||||
local bootloader_size=${2}
|
local bootloader_size=${2}
|
||||||
|
|
||||||
#create partitions
|
#create partition table with fdisk
|
||||||
(
|
(
|
||||||
echo g #new gpt disk label
|
echo g #new gpt disk label
|
||||||
|
|
||||||
|
@ -53,6 +59,50 @@ partition_disk() {
|
||||||
) | fdisk $image_path
|
) | fdisk $image_path
|
||||||
}
|
}
|
||||||
|
|
||||||
|
safe_mount() {
|
||||||
|
rm -rf $2
|
||||||
|
mkdir -p $2
|
||||||
|
mount $1 $2
|
||||||
|
}
|
||||||
|
|
||||||
|
create_partitions() {
|
||||||
|
local image_loop=$(realpath "${1}")
|
||||||
|
local kernel_path=$(realpath "${2}")
|
||||||
|
|
||||||
|
#create stateful
|
||||||
|
mkfs.ext4 "${image_loop}p1"
|
||||||
|
#copy kernel
|
||||||
|
dd if=$kernel_path of="${image_loop}p2" bs=1M oflag=sync
|
||||||
|
#create bootloader partition
|
||||||
|
mkfs.ext2 "${image_loop}p3"
|
||||||
|
#create rootfs partition
|
||||||
|
mkfs.ext4 "${image_loop}p4"
|
||||||
|
}
|
||||||
|
|
||||||
|
populate_partitions() {
|
||||||
|
local image_loop=$(realpath "${1}")
|
||||||
|
local bootloader_dir=$(realpath "${2}")
|
||||||
|
local rootfs_dir=$(realpath "${3}")
|
||||||
|
|
||||||
|
#mount and write empty file to stateful
|
||||||
|
local stateful_mount=/tmp/shim_stateful
|
||||||
|
safe_mount "${image_loop}p1" $stateful_mount
|
||||||
|
mkdir -p $stateful_mount/dev_image/etc/
|
||||||
|
touch $stateful_mount/dev_image/etc/lsb-factory
|
||||||
|
umount $stateful_mount
|
||||||
|
|
||||||
|
#mount and write to bootloader rootfs
|
||||||
|
local bootloader_mount=/tmp/shim_bootloader
|
||||||
|
safe_mount "${image_loop}p3" $bootloader_mount
|
||||||
|
cp -r $bootloader_dir/* $bootloader_mount
|
||||||
|
umount $bootloader_mount
|
||||||
|
|
||||||
|
local rootfs_mount=/tmp/shim_rootfs
|
||||||
|
safe_mount "${image_loop}p4" $rootfs_mount
|
||||||
|
cp -r $rootfs_dir/* $rootfs_mount
|
||||||
|
umount $rootfs_mount
|
||||||
|
}
|
||||||
|
|
||||||
create_image() {
|
create_image() {
|
||||||
local image_path=$(realpath "${1}")
|
local image_path=$(realpath "${1}")
|
||||||
local bootloader_size=${2}
|
local bootloader_size=${2}
|
||||||
|
@ -65,4 +115,10 @@ create_image() {
|
||||||
partition_disk $image_path $bootloader_size
|
partition_disk $image_path $bootloader_size
|
||||||
}
|
}
|
||||||
|
|
||||||
create_image ./test.bin 20 200
|
if [ $0 == "./build_image.sh" ]; then
|
||||||
|
create_image ./test.bin 20 200
|
||||||
|
image_loop=$(create_loop ./test.bin)
|
||||||
|
create_partitions $image_loop /tmp/shim_kernel/kernel.bin
|
||||||
|
populate_partitions $image_loop ./tmp/shim_initramfs ./lib
|
||||||
|
losetup -d $image_loop
|
||||||
|
fi
|
Loading…
Reference in New Issue