1
0
mirror of https://github.com/rancher/os.git synced 2025-05-09 08:36:20 +00:00
os/scripts/installer/set-disk-partitions
Sven Dowideit 69d1077169 gpt disk in BIOS boot mode
Signed-off-by: Sven Dowideit <SvenDowideit@home.org.au>
2016-12-14 22:04:31 +10:00

50 lines
1.2 KiB
Bash
Executable File

#!/bin/bash
set -e
set -x
DEVICE=${1}
DISKTYPE=${2}
if [[ -z $DISKTYPE ]]; then
DISKTYPE="msdos"
fi
if [[ -z $DEVICE ]]; then
echo "Need to Pass a device name as arg1." 1>&2
exit 1
fi
PARTITION_COUNT=$(grep $(echo $DEVICE | cut -d '/' -f3) /proc/partitions | wc -l)
if [ "$PARTITION_COUNT" -gt "1" ]; then
echo "Device ${DEVICE} already partitioned!"
echo "Checking to see if it is mounted"
# Check this container first...
if grep -q "${DEVICE}" /proc/mounts; then
echo "Device is mounted, we can not repartition" 1>&2
exit 1
fi
# Check other system containers...
for container in $(system-docker ps -q); do
if system-docker exec $container grep -q "${DEVICE}" /proc/mounts; then
echo "Device is mounted in system container ${container}, we can not repartition" 1>&2
exit 1
fi
done
fi
dd if=/dev/zero of=${DEVICE} bs=512 count=2048
partprobe ${DEVICE}
# https://www.gnu.org/software/parted/manual/html_node/set.html
# https://wiki.archlinux.org/index.php/syslinux
BOOTFLAG="boot"
if [ "${DISKTYPE}" == "gpt" ]; then
BOOTFLAG="legacy_boot"
fi
parted -s -a optimal ${DEVICE} mklabel ${DISKTYPE} -- \
mkpart primary ext4 1 -1 \
set 1 ${BOOTFLAG} on