use blockdev --rereadpt instead of sleep

FTR, this may not be needed. i have realized after this change that
the pendrive i was using was too small and fdisk errored out in a
way that was not visible in the log, only its symptoms.

but this is a nicer way than arbitrary sleeps for not much extra space.
This commit is contained in:
Attila Lendvai
2023-08-17 23:12:45 +02:00
parent a21e995567
commit 309e6dd80c
2 changed files with 15 additions and 3 deletions

View File

@@ -31,14 +31,24 @@ hasBigEnoughPendrive()
fi
}
rereadPartitionTable()
{
log "Rereading partition table"
blockdev --rereadpt /dev/sda
}
setupPendrivePartitions()
{
log "Erasing partition table"
# erase partition table
dd if=/dev/zero of=/dev/sda bs=1M count=1
rereadPartitionTable
log "Creating partitions"
# sda1 is 'swap'
# sda2 is 'root'
# sda3 is 'data'
# sda3 is 'data', if there's any space left
fdisk /dev/sda <<EOF
o
n
@@ -64,7 +74,7 @@ q
EOF
log "Finished partitioning /dev/sda using fdisk"
sleep 2
rereadPartitionTable
until [ -e /dev/sda1 ]
do
@@ -76,6 +86,7 @@ EOF
mkfs.ext4 -F -L root -U $rootUUID /dev/sda2
mkfs.ext4 -F -L data -U $dataUUID /dev/sda3
rereadPartitionTable
log "Finished setting up filesystems"
}