summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNatanael Copa <ncopa@alpinelinux.org>2023-01-23 19:58:57 +0100
committerNatanael Copa <ncopa@alpinelinux.org>2023-01-24 10:41:58 +0000
commitbe385e614eafdf5f95e35ad3cbd4eaa378b96752 (patch)
tree0b9a4b7fd12bc4186839e7dc02249c1f8ccfc9e3
parentf62775fc697446d1d969faa55adcdeca5400b8ea (diff)
downloadalpine-conf-be385e614eafdf5f95e35ad3cbd4eaa378b96752.zip
setup-disk: add test for install_mounted_root
-rw-r--r--setup-disk.in23
-rwxr-xr-xtests/setup_disk_test27
2 files changed, 38 insertions, 12 deletions
diff --git a/setup-disk.in b/setup-disk.in
index 30d0258..6fb3075 100644
--- a/setup-disk.in
+++ b/setup-disk.in
@@ -65,7 +65,7 @@ enumerate_fstab() {
local fs_spec= fs_file= fs_vfstype= fs_mntops= fs_freq= fs_passno=
[ -z "$mnt" ] && return
local escaped_mnt="$(echo $mnt | sed -e 's:/*$::' -e 's:/:\\/:g')"
- awk "\$2 ~ /^$escaped_mnt(\/|\$)/ {print \$0}" /proc/mounts | \
+ awk "\$2 ~ /^$escaped_mnt(\/|\$)/ {print \$0}" "$ROOT"/proc/mounts | \
sed "s:$mnt:/:g; s: :\t:g" | sed -E 's:/+:/:g' | \
while read fs_spec fs_file fs_vfstype fs_mntops fs_freq fs_passno; do
if [ "$fs_file" = / ]; then
@@ -221,13 +221,13 @@ unpack_apkovl() {
# find filesystem of given mounted dir
find_mount_fs() {
local mount_point="$1"
- awk "\$2 == \"$mount_point\" {print \$3}" /proc/mounts | tail -n 1
+ awk "\$2 == \"$mount_point\" {print \$3}" "$ROOT"/proc/mounts | tail -n 1
}
# find device for given mounted dir
find_mount_dev() {
local mnt="$1"
- awk "\$2 == \"$mnt\" { print \$1 }" /proc/mounts | tail -n 1
+ awk "\$2 == \"$mnt\" { print \$1 }" "$ROOT"/proc/mounts | tail -n 1
}
supported_boot_fs() {
@@ -264,14 +264,14 @@ init_chroot_mounts() {
local mnt="$1" i=
for i in proc dev; do
mkdir -p "$mnt"/$i
- mount --bind /$i "$mnt"/$i
+ $MOCK mount --bind /$i "$mnt"/$i
done
}
cleanup_chroot_mounts() {
local mnt="$1" i=
for i in proc dev; do
- umount "$mnt"/$i
+ $MOCK umount "$mnt"/$i
done
}
@@ -304,10 +304,10 @@ setup_grub() {
fi
# currently disabling nvram so grub doesnt call efibootmgr
# installing to alpine directory so other distros dont overwrite it
- grub-install --target=$target --efi-directory="$efi_directory" \
+ $MOCK grub-install --target=$target --efi-directory="$efi_directory" \
--bootloader-id=alpine --boot-directory="$mnt"/boot --no-nvram
# fallback mode will use boot/boot${fw arch}.efi
- install -D "$efi_directory"/EFI/alpine/grub$fwa.efi \
+ $MOCK install -D "$efi_directory"/EFI/alpine/grub$fwa.efi \
"$efi_directory"/EFI/boot/boot$fwa.efi
# install GRUB for ppc64le
elif [ "$ARCH" = "ppc64le" ]; then
@@ -378,7 +378,7 @@ setup_uboot() {
# Rely on update-u-boot to automatically determine the
# board, imagedir, etc. this may not work in all cases.
- update-u-boot
+ $MOCK update-u-boot
}
rpi_gen_config() {
@@ -469,7 +469,7 @@ setup_raspberrypi_bootloader() {
# detect which firmware packages to install, if any
select_firmware_pkgs() {
- local firmware_pkgs="$( (cd "$ROOT"/sys/module/ && echo *) \
+ local firmware_pkgs="$( (cd "$ROOT"/sys/module/ 2>/dev/null && echo *) \
| xargs modinfo -F firmware 2>/dev/null \
| awk -F/ '{print $1 == $0 ? "linux-firmware-other" : "linux-firmware-"$1}' \
| sort -u)"
@@ -489,7 +489,7 @@ is_nvme_dev() {
}
install_mounted_root() {
- local mnt="$1"
+ local mnt="$(realpath "$1")"
shift 1
local disks="${@}" mnt_boot= boot_fs= root_fs= use_crypt=
local initfs_features="ata base ide scsi usb virtio"
@@ -500,7 +500,7 @@ install_mounted_root() {
rootdev=$(find_mount_dev "$mnt")
if [ -z "$rootdev" ]; then
- echo "$mnt does not seem to be a mount point" >&2
+ echo "'$mnt' does not seem to be a mount point" >&2
return 1
fi
root_fs=$(find_mount_fs "$mnt")
@@ -585,6 +585,7 @@ install_mounted_root() {
if [ -f "$mnt"/etc/fstab ]; then
mv "$mnt"/etc/fstab "$mnt"/etc/fstab.old
fi
+ mkdir -p "$mnt"/etc
enumerate_fstab "$mnt" >> "$mnt"/etc/fstab
if [ -n "$SWAP_DEVICES" ]; then
local swap_dev
diff --git a/tests/setup_disk_test b/tests/setup_disk_test
index 1fee4aa..061caa3 100755
--- a/tests/setup_disk_test
+++ b/tests/setup_disk_test
@@ -9,7 +9,8 @@ init_tests \
setup_disk_func_setup_partitions_dos \
setup_disk_func_setup_partitions_gpt \
setup_disk_func_find_efi_size \
- setup_disk_non_existing_block_dev
+ setup_disk_non_existing_block_dev \
+ setup_disk_install_mounted_root_nvme
setup_disk_usage_body() {
test_usage setup-disk
@@ -198,3 +199,27 @@ setup_disk_non_existing_block_dev_body() {
setup-disk -m sys /dev/vda
}
+setup_disk_install_mounted_root_nvme_body() {
+ init_env
+ mkdir -p target/boot/efi \
+ sys/firmware/efi
+
+ # simulate nvme0n1p2 being mounted
+ fake_mount "/dev/nvme0n1p2 $PWD/target ext4 rw,noatime,data=ordered 0 0"
+ fake_mount "/dev/nvme0n1p3 $PWD/target/boot/efi vfat rw,relatime,fmask=0022 0 0"
+
+ atf_check -s exit:0 \
+ -o match:"Installing system on /dev/nvme0n1p2" \
+ -o match:"grub-install .* --efi-directory=$PWD/target/boot/efi .* --boot-directory=$PWD/target/boot" \
+ -o match:"install -D $PWD/target/boot/efi/EFI/alpine/grub.*efi $PWD/target/boot/efi/EFI/boot/bootaa64.efi" \
+ setup-disk target
+
+ atf_check \
+ -o match:"/dev/nvme0n1p2 / ext4 rw,noatime,data=ordered 0 1" \
+ -o match:"/dev/nvme0n1p3 /boot/efi vfat rw,relatime,fmask=0022 0 2" \
+ cat target/etc/fstab
+
+ atf_check -o match:"GRUB_CMDLINE_LINUX_DEFAULT=.*ext4,nvme" \
+ cat target/etc/default/grub
+
+}