Skip to content

Commit

Permalink
set rootfs partition name based on the distro
Browse files Browse the repository at this point in the history
  • Loading branch information
ading2210 committed Jun 23, 2024
1 parent 1114669 commit 079e1f9
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ Debian Sid (the rolling release version of Debian) is also supported if you just
sudo ./build_complete.sh dedede release=unstable
```

There is also experimental support for Alpine Linux. Pass the `distro=alpine` to use it:
There is also experimental support for Alpine Linux. The Alpine disk image is about half the size compared to Debian. Pass the `distro=alpine` to use it:
```bash
sudo ./build_complete.sh dedede distro=alpine
```
Expand Down
11 changes: 8 additions & 3 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ print_help() {
echo "Valid named arguments (specify with 'key=value'):"
echo " quiet - Don't use progress indicators which may clog up log files."
echo " arch - Set this to 'arm64' to specify that the shim is for an ARM chromebook."
echo " name - The name for the shimboot rootfs partition."
}

assert_root
Expand All @@ -22,11 +23,15 @@ output_path=$(realpath -m "${1}")
shim_path=$(realpath -m "${2}")
rootfs_dir=$(realpath -m "${3}")

quiet="${args['quiet']}"
arch="${args['arch']}"
name="${args['name']}"

print_info "reading the shim image"
initramfs_dir=/tmp/shim_initramfs
kernel_img=/tmp/kernel.img
rm -rf $initramfs_dir $kernel_img
extract_initramfs_full $shim_path $initramfs_dir $kernel_img "${args['arch']}"
extract_initramfs_full $shim_path $initramfs_dir $kernel_img "$arch"

print_info "patching initramfs"
patch_initramfs $initramfs_dir
Expand All @@ -36,7 +41,7 @@ rootfs_size=$(du -sm $rootfs_dir | cut -f 1)
rootfs_part_size=$(($rootfs_size * 12 / 10 + 5))
#create a 20mb bootloader partition
#rootfs partition is 20% larger than its contents
create_image $output_path 20 $rootfs_part_size
create_image $output_path 20 $rootfs_part_size $name

print_info "creating loop device for the image"
image_loop=$(create_loop ${output_path})
Expand All @@ -45,7 +50,7 @@ print_info "creating partitions on the disk image"
create_partitions $image_loop $kernel_img

print_info "copying data into the image"
populate_partitions $image_loop $initramfs_dir $rootfs_dir "${args['quiet']}"
populate_partitions $image_loop $initramfs_dir $rootfs_dir "$quiet"
rm -rf $initramfs_dir $kernel_img

print_info "cleaning up loop devices"
Expand Down
2 changes: 1 addition & 1 deletion build_complete.sh
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ retry_cmd ./patch_rootfs.sh $shim_bin $reco_bin $rootfs_dir "quiet=$quiet"
print_title "building final disk image"
final_image="$data_dir/shimboot_$board.bin"
rm -rf $final_image
retry_cmd ./build.sh $final_image $shim_bin $rootfs_dir "quiet=$quiet" "arch=$arch"
retry_cmd ./build.sh $final_image $shim_bin $rootfs_dir "quiet=$quiet" "arch=$arch" "name=$distro"
print_info "build complete! the final disk image is located at $final_image"

print_title "cleaning up"
Expand Down
12 changes: 7 additions & 5 deletions image_utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ make_bootable() {

partition_disk() {
local image_path=$(realpath -m "${1}")
local bootloader_size=${2}
local bootloader_size="$2"
local rootfs_name="$3"

#create partition table with fdisk
(
Expand Down Expand Up @@ -57,7 +58,7 @@ partition_disk() {
echo x #enter expert mode
echo n #change the partition name
echo #accept default partition number
echo "shimboot_rootfs:default" #set partition name
echo "shimboot_rootfs:$rootfs_name" #set partition name
echo r #return to normal more

#write changes
Expand Down Expand Up @@ -128,15 +129,16 @@ populate_partitions() {

create_image() {
local image_path=$(realpath -m "${1}")
local bootloader_size=${2}
local rootfs_size=${3}
local bootloader_size="$2"
local rootfs_size="$3"
local rootfs_name="$4"

#stateful + kernel + bootloader + rootfs
local total_size=$((1 + 32 + $bootloader_size + $rootfs_size))
rm -rf "${image_path}"
fallocate -l "${total_size}M" "${image_path}"

partition_disk $image_path $bootloader_size
partition_disk $image_path $bootloader_size $rootfs_name
}

patch_initramfs() {
Expand Down

0 comments on commit 079e1f9

Please sign in to comment.