-
Notifications
You must be signed in to change notification settings - Fork 156
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
65 additions
and
32 deletions.
There are no files selected for viewing
52 changes: 38 additions & 14 deletions
52
build-tests/x86/leap/test-image-custom-partitions/custom_partitions_create.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,59 @@ | ||
image_fs=$1 | ||
# shellcheck shell=bash | ||
set -x | ||
|
||
# image_fs=$1 | ||
|
||
root_partnum=$2 | ||
|
||
root_device=/dev/loop*p${root_partnum} | ||
is_kpartx=false | ||
|
||
# shellcheck disable=SC2125 | ||
root_device=/dev/loop*p${root_partnum} | ||
# shellcheck disable=SC2086 | ||
if [ ! -e ${root_device} ];then | ||
# shellcheck disable=SC2125 | ||
root_device=/dev/mapper/loop*p${root_partnum} | ||
is_kpartx=true | ||
fi | ||
|
||
# shellcheck disable=SC2086 | ||
loop_name=$(basename $root_device | cut -f 1-2 -d'p') | ||
|
||
disk_device=/dev/${loop_name} | ||
disk_device=/dev/"${loop_name}" | ||
|
||
sgdisk --delete=4 $disk_device || exit 1 | ||
sgdisk --delete=4 "$disk_device" || exit 1 | ||
|
||
# /var 100MB | ||
sgdisk --new=4:0:+100M $disk_device || exit 1 | ||
sgdisk --new=4:0:+100M "$disk_device" || exit 1 | ||
|
||
# /var/log 100MB | ||
sgdisk --new=6:0:+100M $disk_device || exit 1 | ||
sgdisk --new=6:0:+100M "$disk_device" || exit 1 | ||
|
||
# /var/audit rest of spare (500 - 200 = 300MB) | ||
sgdisk --new=7:0:0 $disk_device || exit 1 | ||
sgdisk --new=7:0:0 "$disk_device" || exit 1 | ||
|
||
# reread partition changes | ||
partprobe $disk_device || exit 1 | ||
partprobe "$disk_device" || exit 1 | ||
|
||
# recreate partition maps | ||
partx --delete $disk_device || exit 1 | ||
partx --add $disk_device || exit 1 | ||
if [ "${is_kpartx}" = "false" ];then | ||
partx --delete "$disk_device" || exit 1 | ||
partx --add "$disk_device" || exit 1 | ||
else | ||
kpartx -d "$disk_device" || exit 1 | ||
kpartx -a "$disk_device" || exit 1 | ||
fi | ||
|
||
# create filesystems on partitions, use labels | ||
mkfs.ext4 -L var /dev/${loop_name}p4 || exit 1 | ||
mkfs.ext4 -L log /dev/${loop_name}p6 || exit 1 | ||
mkfs.ext4 -L audit /dev/${loop_name}p7 || exit 1 | ||
if [ "${is_kpartx}" = "false" ];then | ||
mkfs.ext4 -L var /dev/"${loop_name}"p4 || exit 1 | ||
mkfs.ext4 -L log /dev/"${loop_name}"p6 || exit 1 | ||
mkfs.ext4 -L audit /dev/"${loop_name}"p7 || exit 1 | ||
else | ||
mkfs.ext4 -L var /dev/mapper/"${loop_name}"p4 || exit 1 | ||
mkfs.ext4 -L log /dev/mapper/"${loop_name}"p6 || exit 1 | ||
mkfs.ext4 -L audit /dev/mapper/"${loop_name}"p7 || exit 1 | ||
fi | ||
|
||
# order partitions | ||
sgdisk --sort $disk_device | ||
sgdisk --sort "$disk_device" |
45 changes: 27 additions & 18 deletions
45
build-tests/x86/leap/test-image-custom-partitions/custom_partitions_setup.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,48 @@ | ||
image_file=$1 | ||
# shellcheck shell=bash | ||
set -x | ||
|
||
# image_file=$1 | ||
|
||
root_device=$2 | ||
|
||
loop_name=$(basename $root_device | cut -f 1-2 -d'p') | ||
loop_name=$(basename "${root_device}" | cut -f 1-2 -d'p') | ||
|
||
disk_device=/dev/"${loop_name}" | ||
|
||
disk_device=/dev/${loop_name} | ||
if [ -e "/dev/mapper/${loop_name}p5" ];then | ||
loop_name="mapper/${loop_name}" | ||
fi | ||
|
||
# mount root part | ||
root=$(mktemp -d /tmp/rootmount-XXX) | ||
mount /dev/${loop_name}p5 $root || exit 1 | ||
mount /dev/"${loop_name}"p5 "$root" || exit 1 | ||
|
||
# move root part contents to individual partitions | ||
part=$(mktemp -d /tmp/partmount-XXX) | ||
log_uuid=$(blkid -s UUID -o value /dev/${loop_name}p6) | ||
mount /dev/${loop_name}p6 $part && mv $root/var/log/* $part/ | ||
umount --lazy $part && rmdir $part | ||
log_uuid=$(blkid -s UUID -o value /dev/"${loop_name}"p6) | ||
mount /dev/"${loop_name}"p6 "$part" && mv "$root"/var/log/* "$part"/ | ||
umount --lazy "$part" && rmdir "$part" | ||
|
||
part=$(mktemp -d /tmp/partmount-XXX) | ||
audit_uuid=$(blkid -s UUID -o value /dev/${loop_name}p7) | ||
mount /dev/${loop_name}p7 $part && mv $root/var/audit/* $part/ | ||
umount --lazy $part && rmdir $part | ||
audit_uuid=$(blkid -s UUID -o value /dev/"${loop_name}"p7) | ||
mount /dev/"${loop_name}"p7 "$part" && mv "$root"/var/audit/* "$part"/ | ||
umount --lazy "$part" && rmdir "$part" | ||
|
||
part=$(mktemp -d /tmp/partmount-XXX) | ||
var_uuid=$(blkid -s UUID -o value /dev/${loop_name}p4) | ||
mount /dev/${loop_name}p4 $part && mv $root/var/* $part/ | ||
umount --lazy $part && rmdir $part | ||
var_uuid=$(blkid -s UUID -o value /dev/"${loop_name}"p4) | ||
mount /dev/"${loop_name}"p4 "$part" && mv "$root"/var/* "$part"/ | ||
umount --lazy "$part" && rmdir "$part" | ||
|
||
echo "UUID=$var_uuid /var ext4 defaults 0 0" >> $root/etc/fstab | ||
echo "UUID=$log_uuid /var/log ext4 defaults 0 0" >> $root/etc/fstab | ||
echo "UUID=$audit_uuid /var/audit ext4 defaults 0 0" >> $root/etc/fstab | ||
{ | ||
echo "UUID=$var_uuid /var ext4 defaults 0 0" | ||
echo "UUID=$log_uuid /var/log ext4 defaults 0 0" | ||
echo "UUID=$audit_uuid /var/audit ext4 defaults 0 0" | ||
} >> "$root"/etc/fstab | ||
|
||
# umount root part | ||
umount --lazy $root && rmdir $root | ||
umount --lazy "$root" && rmdir "$root" | ||
|
||
# cleanup maps | ||
partx --delete $disk_device | ||
partx --delete "$disk_device" | ||
|
||
exit 0 |