refactor: add arguments to contrl script behaivor, rename to non-suffix
Signed-off-by: Coelacanthus <CoelacanthusHex@gmail.com>
This commit is contained in:
parent
55d5af7f33
commit
ec4bad56d6
4 changed files with 140 additions and 42 deletions
|
@ -1,15 +1,63 @@
|
||||||
#!/usr/bin/bash
|
#!/usr/bin/bash
|
||||||
#
|
#
|
||||||
# SPDX-FileCopyrightText: 2022 Celeste Liu <coelacanthus@outlook.com>
|
# SPDX-FileCopyrightText: 2022 Celeste Liu <CoelacanthusHex@gmail.com>
|
||||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
# shellcheck disable=1091
|
# shellcheck disable=1091
|
||||||
. /usr/share/makepkg/util.sh
|
. /usr/share/makepkg/util.sh
|
||||||
colorize
|
colorize
|
||||||
|
|
||||||
|
verbose=0
|
||||||
|
use_fixed_password=0
|
||||||
|
varbose_arg=
|
||||||
|
|
||||||
|
show_help() {
|
||||||
|
cat << EOF
|
||||||
|
Usage: ${0##*/} [-hvf] [-p PASSWORD] [-r ROOTFS] [FILENAME]
|
||||||
|
Create Arch RISC-V qemu image.
|
||||||
|
|
||||||
|
FILENAME generated image file name
|
||||||
|
default: 'archriscv-$(date --rfc-3339=date).qcow2'
|
||||||
|
|
||||||
|
-h display this help and exit
|
||||||
|
-f use fixed password instead of using systemd-firstboot to ask
|
||||||
|
-p PASSWORD set root password to PASSWORD instead of passwd in rootfs
|
||||||
|
-r ROOTFS specify rootfs file name
|
||||||
|
-v verbose mode
|
||||||
|
EOF
|
||||||
|
}
|
||||||
|
|
||||||
|
parse-args() {
|
||||||
|
local OPTIND=1
|
||||||
|
while getopts 'hvfr:p:' opt; do
|
||||||
|
case $opt in
|
||||||
|
h)
|
||||||
|
show_help
|
||||||
|
exit 0
|
||||||
|
;;
|
||||||
|
v) verbose=$((verbose+1))
|
||||||
|
varbose_arg="--verbose"
|
||||||
|
;;
|
||||||
|
f)
|
||||||
|
use_fixed_password=1
|
||||||
|
;;
|
||||||
|
p) password=$OPTARG
|
||||||
|
;;
|
||||||
|
r) rootfs=${OPTARG:-archriscv-$(date --rfc-3339=date).tar.zst}
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
show_help >&2
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
shift "$(( OPTIND-1 ))"
|
||||||
|
filename=${1:-archriscv-$(date --rfc-3339=date).qcow2}
|
||||||
|
}
|
||||||
|
|
||||||
toggle-systemd-firstboot() {
|
toggle-systemd-firstboot() {
|
||||||
msg2 "Toggle systemd-firstboot..."
|
msg2 "Toggle systemd-firstboot..."
|
||||||
sudo rm -f qcow2/etc/{machine-id,localtime,hostname,shadow,locale.conf}
|
sudo rm -f qcow2/etc/{machine-id,hostname,shadow}
|
||||||
sudo mkdir -p qcow2/etc/systemd/system/systemd-firstboot.service.d
|
sudo mkdir -p qcow2/etc/systemd/system/systemd-firstboot.service.d
|
||||||
cat << EOF | sudo tee qcow2/etc/systemd/system/systemd-firstboot.service.d/install.conf
|
cat << EOF | sudo tee qcow2/etc/systemd/system/systemd-firstboot.service.d/install.conf
|
||||||
[Service]
|
[Service]
|
||||||
|
@ -23,10 +71,12 @@ EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
use-fixed-password() {
|
use-fixed-password() {
|
||||||
msg2 "Using fixed password..."
|
msg2 "Using fixed password... $password"
|
||||||
: # set in rootfs
|
[[ -n $password ]] && sudo usermod --root $(realpath ./qcow2) --password $(openssl passwd -6 "$password") root
|
||||||
}
|
}
|
||||||
|
|
||||||
|
parse-args "$@"
|
||||||
|
|
||||||
msg "Building u-boot..."
|
msg "Building u-boot..."
|
||||||
|
|
||||||
[[ -d u-boot ]] || git clone https://github.com/u-boot/u-boot.git
|
[[ -d u-boot ]] || git clone https://github.com/u-boot/u-boot.git
|
||||||
|
@ -62,10 +112,12 @@ make \
|
||||||
FW_PAYLOAD_PATH=../u-boot/u-boot.bin
|
FW_PAYLOAD_PATH=../u-boot/u-boot.bin
|
||||||
popd
|
popd
|
||||||
|
|
||||||
|
cp ./opensbi/build/platform/generic/firmware/fw_payload.bin opensbi_fw_payload.bin
|
||||||
|
|
||||||
msg "Create image file..."
|
msg "Create image file..."
|
||||||
qemu-img create -f qcow2 "archriscv-$(date --rfc-3339=date).qcow2" 10G
|
qemu-img create -f qcow2 "$filename" 10G
|
||||||
sudo modprobe nbd max_part=16
|
sudo modprobe nbd max_part=16
|
||||||
sudo qemu-nbd -c /dev/nbd0 "archriscv-$(date --rfc-3339=date).qcow2"
|
sudo qemu-nbd -c /dev/nbd0 "$filename"
|
||||||
|
|
||||||
sudo sfdisk /dev/nbd0 <<EOF
|
sudo sfdisk /dev/nbd0 <<EOF
|
||||||
label: dos
|
label: dos
|
||||||
|
@ -86,7 +138,7 @@ sudo chown root:root qcow2
|
||||||
msg "Extract rootfs..."
|
msg "Extract rootfs..."
|
||||||
|
|
||||||
pushd qcow2
|
pushd qcow2
|
||||||
sudo bsdtar -pxvf "../archriscv-$(date --rfc-3339=date).tar.zst"
|
sudo bsdtar $varbose_arg -pxf "../$rootfs"
|
||||||
popd
|
popd
|
||||||
|
|
||||||
msg "Install kernel package..."
|
msg "Install kernel package..."
|
||||||
|
@ -114,9 +166,7 @@ yes y | sudo pacman \
|
||||||
--sysroot ./qcow2 \
|
--sysroot ./qcow2 \
|
||||||
--sync --clean --clean
|
--sync --clean --clean
|
||||||
|
|
||||||
# https://github.com/CoelacanthusHex/archriscv-scriptlet/issues/1
|
(( use_fixed_password==0 )) && toggle-systemd-firstboot || use-fixed-password
|
||||||
toggle-systemd-firstboot
|
|
||||||
#use-fixed-password
|
|
||||||
|
|
||||||
msg2 "Unmount..."
|
msg2 "Unmount..."
|
||||||
sudo umount qcow2
|
sudo umount qcow2
|
79
mkrootfs
Executable file
79
mkrootfs
Executable file
|
@ -0,0 +1,79 @@
|
||||||
|
#!/usr/bin/bash
|
||||||
|
#
|
||||||
|
# SPDX-FileCopyrightText: 2022 Celeste Liu <CoelacanthusHex@gmail.com>
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
# shellcheck disable=1091
|
||||||
|
. /usr/share/makepkg/util.sh
|
||||||
|
colorize
|
||||||
|
|
||||||
|
verbose=0
|
||||||
|
varbose_arg=
|
||||||
|
|
||||||
|
show_help() {
|
||||||
|
cat << EOF
|
||||||
|
Usage: ${0##*/} [-hv] [-p PASSWORD] [FILENAME]
|
||||||
|
Create Arch RISC-V rootfs.
|
||||||
|
|
||||||
|
FILENAME generated rootfs file name, use the archive suffix to decide
|
||||||
|
the compression algorithm.
|
||||||
|
default: 'archriscv-$(date --rfc-3339=date).tar.zst'
|
||||||
|
|
||||||
|
-h display this help and exit
|
||||||
|
-p PASSWORD set root password to PASSWORD instead of archriscv
|
||||||
|
-v verbose mode
|
||||||
|
EOF
|
||||||
|
}
|
||||||
|
|
||||||
|
parse-args() {
|
||||||
|
local OPTIND=1
|
||||||
|
while getopts 'hvp:' opt; do
|
||||||
|
case $opt in
|
||||||
|
h)
|
||||||
|
show_help
|
||||||
|
exit 0
|
||||||
|
;;
|
||||||
|
v) verbose=$((verbose+1))
|
||||||
|
varbose_arg="--verbose"
|
||||||
|
;;
|
||||||
|
p) password=${OPTARG:-archriscv}
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
show_help >&2
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
shift "$(( OPTIND-1 ))"
|
||||||
|
filename=${1:-archriscv-$(date --rfc-3339=date).tar.zst}
|
||||||
|
echo $filename
|
||||||
|
}
|
||||||
|
|
||||||
|
parse-args "$@"
|
||||||
|
|
||||||
|
msg "Building rootfs..."
|
||||||
|
mkdir -p ./rootfs
|
||||||
|
sudo chown root:root ./rootfs
|
||||||
|
sudo pacstrap \
|
||||||
|
-C /usr/share/devtools/pacman-extra-riscv64.conf \
|
||||||
|
-M \
|
||||||
|
./rootfs \
|
||||||
|
base
|
||||||
|
|
||||||
|
msg "Clean up pacman package cache..."
|
||||||
|
yes y | sudo pacman \
|
||||||
|
--sysroot ./rootfs \
|
||||||
|
--sync --clean --clean
|
||||||
|
|
||||||
|
msg "Set root password (Default: archriscv)..."
|
||||||
|
sudo usermod --root $(realpath ./rootfs) --password $(openssl passwd -6 "$password") root
|
||||||
|
|
||||||
|
msg "Compressing rootfs..."
|
||||||
|
sudo bsdtar --create \
|
||||||
|
--auto-compress --options "compression-level=9"\
|
||||||
|
$varbose_arg \
|
||||||
|
--xattrs --acls\
|
||||||
|
-f "$filename" -C rootfs/ .
|
||||||
|
|
||||||
|
msg "Clean up rootfs directory..."
|
||||||
|
sudo rm -rf ./rootfs
|
31
mkrootfs.sh
31
mkrootfs.sh
|
@ -1,31 +0,0 @@
|
||||||
#!/usr/bin/bash
|
|
||||||
#
|
|
||||||
# SPDX-FileCopyrightText: 2022 Celeste Liu <coelacanthus@outlook.com>
|
|
||||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
||||||
|
|
||||||
# shellcheck disable=1091
|
|
||||||
. /usr/share/makepkg/util.sh
|
|
||||||
colorize
|
|
||||||
|
|
||||||
msg "Building rootfs..."
|
|
||||||
mkdir -p ./rootfs
|
|
||||||
sudo chown root:root ./rootfs
|
|
||||||
sudo pacstrap \
|
|
||||||
-C /usr/share/devtools/pacman-extra-riscv64.conf \
|
|
||||||
-M \
|
|
||||||
./rootfs \
|
|
||||||
base
|
|
||||||
|
|
||||||
msg "Clean up pacman package cache..."
|
|
||||||
yes y | sudo pacman \
|
|
||||||
--sysroot ./rootfs \
|
|
||||||
--sync --clean --clean
|
|
||||||
|
|
||||||
msg "Set root password (Default: archriscv)..."
|
|
||||||
sudo usermod --root $(realpath ./rootfs) --password $(openssl passwd -6 archriscv) root
|
|
||||||
|
|
||||||
msg "Compressing rootfs..."
|
|
||||||
sudo bsdtar --create --zstd --verbose --xattrs --acls -f "archriscv-$(date --rfc-3339=date).tar.zst" -C rootfs/ .
|
|
||||||
|
|
||||||
msg "Clean up rootfs directory..."
|
|
||||||
sudo rm -rf ./rootfs
|
|
|
@ -13,7 +13,7 @@ qemu-system-riscv64 \
|
||||||
-machine virt \
|
-machine virt \
|
||||||
-smp 8 \
|
-smp 8 \
|
||||||
-m 4G \
|
-m 4G \
|
||||||
-bios ./opensbi/build/platform/generic/firmware/fw_payload.bin \
|
-bios ./opensbi_fw_payload.bin \
|
||||||
-device virtio-blk-device,drive=hd0 \
|
-device virtio-blk-device,drive=hd0 \
|
||||||
-object rng-random,filename=/dev/urandom,id=rng0 \
|
-object rng-random,filename=/dev/urandom,id=rng0 \
|
||||||
-device virtio-rng-device,rng=rng0 \
|
-device virtio-rng-device,rng=rng0 \
|
||||||
|
|
Loading…
Add table
Reference in a new issue