add: partitioning functionality

This commit is contained in:
Peter Šurda 2021-02-26 22:19:36 +01:00
parent 6e8fc65465
commit 7ac8630a57
Signed by: PeterSurda
GPG Key ID: 0C5F50C0B5F37D87
3 changed files with 48 additions and 0 deletions

25
drive.inc Normal file
View File

@ -0,0 +1,25 @@
#!/bin/bash
function setup_drive
{
local drive="$1"
parted -s "$drive" -- \
mklabel gpt \
unit MiB \
mkpart '"EFI system partition"' fat32 1 1024 \
set 1 esp on \
mkpart '"root unused"' ext4 1025 2048 \
mkpart '"root unused"' ext4 2049 3072 \
mkpart '"root unused"' ext4 3073 4096 \
mkpart Encrypted ext4 4097 -1
}
function rename_partition
{
local drive="$1"
local partition="$2"
local new_label="$3"
parted -s "$drive" -- name "$partition" '"'"$new_label"'"'
}
# vim: set ft=sh:

View File

@ -1,3 +1,4 @@
#!/bin/bash #!/bin/bash
tests/maas.sh tests/maas.sh
tests/drive.sh

22
tests/drive.sh Executable file
View File

@ -0,0 +1,22 @@
#!/bin/bash
function test_partitioning()
{
local img
img=$(mktemp -u)
qemu-img create -f qcow2 "$img" 16G
sudo modprobe nbd
sudo qemu-nbd -c /dev/nbd0 "$img"
sudo setup_drive /dev/nbd0
sudo parted -ms /deb/nbd0 -- print
sudo qemu-nbd -d /dev/nbd0
rm -f "$img"
}
function oneTimeSetUp()
{
. drive.inc
}
# Load shUnit2.
. /usr/bin/shunit2