Skip to content

Commit 3892016

Browse files
committed
fix debian rootfs building on non-debian distros, detect newer binwalk
1 parent 7acc0e1 commit 3892016

4 files changed

Lines changed: 35 additions & 4 deletions

File tree

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,20 @@ $ nmcli connection edit <your connection name>
250250
> activate
251251
```
252252

253+
#### My binwalk version is unsupported.
254+
255+
[Binwalk](https://github.com/ReFirmLabs/binwalk) is a tool that the Shimboot build scripts use to find and extract the initramfs from the shim kernel. Newer versions of binwalk (v3.x and higher) were rewritten in Rust for performance reasons. However, the new version is still feature incomplete and does not work for Shimboot's purposes.
256+
257+
Therefore, you need the older version of binwalk (v2.x) which was written in Python. To install it, run the following commands:
258+
259+
```
260+
git clone https://salsa.debian.org/pkg-security-team/binwalk.git -b debian/2.4.3+dfsg1-2 --depth=1
261+
cd binwalk
262+
sudo python3 setup.py install
263+
```
264+
265+
See the old [binwalk install instructions](https://salsa.debian.org/pkg-security-team/binwalk/-/blob/debian/2.4.3+dfsg1-2/INSTALL.md?ref_type=tags) for more information.
266+
253267
## Copyright:
254268
Shimboot is licensed under the [GNU GPL v3](https://www.gnu.org/licenses/gpl-3.0.txt).
255269

build.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,15 @@ print_help() {
1616
}
1717

1818
assert_root
19-
assert_deps "cpio binwalk pcregrep realpath cgpt mkfs.ext4 mkfs.ext2 fdisk lz4"
19+
assert_deps "cpio binwalk pcregrep realpath cgpt mkfs.ext4 mkfs.ext2 fdisk lz4 7z"
2020
assert_args "$3"
2121
parse_args "$@"
2222

23+
if ! supported_binwalk; then
24+
print_error "your version of binwalk is unsupported. you need binwalk 2.3.4 or older"
25+
exit 1
26+
fi
27+
2328
output_path="$(realpath -m "${1}")"
2429
shim_path="$(realpath -m "${2}")"
2530
rootfs_dir="$(realpath -m "${3}")"

rootfs/opt/setup_rootfs.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ custom_repo_domain="shimboot.ading.dev"
2626
sources_entry="deb [trusted=yes arch=$arch] ${custom_repo} ${release_name} main"
2727

2828
export DEBIAN_FRONTEND="noninteractive"
29+
source /etc/profile
2930

3031
#add shimboot repos
3132
echo -e "${sources_entry}\n$(cat /etc/apt/sources.list)" > /etc/apt/sources.list

shim_utils.sh

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,24 @@
33
#utilties for reading shim disk images
44

55
run_binwalk() {
6-
if binwalk -h | grep -- '--run-as' >/dev/null; then
7-
binwalk "$@" --run-as=root
6+
binwalk_cmd="python3 -m binwalk"
7+
if ! $binwalk_cmd -h > /dev/null; then
8+
binwalk_cmd="binwalk"
9+
fi
10+
if $binwalk_cmd -h | grep -- '--run-as' >/dev/null; then
11+
$binwalk_cmd "$@" --run-as=root
812
else
9-
binwalk "$@"
13+
$binwalk_cmd "$@"
1014
fi
1115
}
1216

17+
#binwalk 3.x and newer is not supported
18+
#see https://github.com/ReFirmLabs/binwalk/issues/829
19+
supported_binwalk() {
20+
#the --version flag only exists on the newer binwalk
21+
! binwalk --version >/dev/null 2>&1
22+
}
23+
1324
#extract the initramfs from a kernel image
1425
extract_initramfs() {
1526
local kernel_bin="$1"

0 commit comments

Comments
 (0)