|
| 1 | +#!/usr/bin/env bash |
| 2 | +# ============================================================================= |
| 3 | +# Solaris GPT Partition Creator - OpenIndiana/illumos System Layout |
| 4 | +# ----------------------------------------------------------------------------- |
| 5 | +# Purpose : Create GPT partition layout optimized for OpenIndiana/illumos systems. |
| 6 | +# Sets up ESP, Solaris root ZFS pool, data partition, and reserved partition. |
| 7 | +# Usage : Run after disk_hammer_illumos.sh to create clean partition layout. |
| 8 | +# Set DISK_DEVICE variable to your target disk. |
| 9 | +# Notes : - Requires prior run of disk_hammer_illumos.sh for clean disk state |
| 10 | +# - Creates 4 partitions: ESP (512MB), Solaris root, data, reserved (8MB) |
| 11 | +# - Uses proper Solaris partition type codes (BF00, BF05, BF07) |
| 12 | +# ============================================================================= |
| 13 | + |
| 14 | +# Configuration: Set your target disk device here |
| 15 | +# Examples: sda, sdb, nvme0n1, nvme1n1, etc. |
| 16 | +DISK_DEVICE="sdX" # CHANGE THIS TO YOUR ACTUAL DISK |
| 17 | + |
| 18 | +# Validate that user has updated the device variable |
| 19 | +if [ "$DISK_DEVICE" = "sdX" ]; then |
| 20 | + echo "ERROR: Please update DISK_DEVICE variable with your actual disk device name" |
| 21 | + echo "Examples: sda, sdb, nvme0n1, etc." |
| 22 | + exit 1 |
| 23 | +fi |
| 24 | + |
| 25 | +# Configuration: Solaris root partition size (adjust as needed) |
| 26 | +SOLARIS_ROOT_SIZE_GB=128 |
| 27 | +SOLARIS_ROOT_END_MIB=$((513 + SOLARIS_ROOT_SIZE_GB * 1024)) |
| 28 | + |
| 29 | +echo "Creating GPT partition layout on /dev/$DISK_DEVICE" |
| 30 | +echo "Solaris root partition will be ${SOLARIS_ROOT_SIZE_GB}GB" |
| 31 | +echo "Press Ctrl+C within 5 seconds to cancel..." |
| 32 | +sleep 5 |
| 33 | + |
| 34 | +# Prerequisite: Clean/hammer GPT partition table using disk_hammer_illumos.sh |
| 35 | +echo "NOTE: Ensure you have run disk_hammer_illumos.sh first for clean disk state" |
| 36 | + |
| 37 | +# Layout: 4 partitions total |
| 38 | +# 1. ESP (EFI System Partition) - 512MB FAT32 for UEFI boot |
| 39 | +# 2. Solaris root ZFS pool - configurable size for system installation |
| 40 | +# 3. Data partition - remaining space for user data/additional pools |
| 41 | +# 4. Solaris reserved - traditional 8MB marker at end of disk |
| 42 | + |
| 43 | +# ===== Partition 1: EFI System Partition (ESP) ===== |
| 44 | +echo "Creating partition 1: EFI System Partition (512MB)..." |
| 45 | +# Create 512MB ESP partition starting at 1MiB for proper alignment |
| 46 | +sudo parted /dev/$DISK_DEVICE 'mkpart "EFI System Partition" fat32 1MiB 513MiB' |
| 47 | +# Set ESP and boot flags required for UEFI systems |
| 48 | +sudo parted /dev/$DISK_DEVICE set 1 esp on |
| 49 | +sudo parted /dev/$DISK_DEVICE set 1 boot on |
| 50 | +# Format as FAT32 with "EFI" label for bootloader compatibility |
| 51 | +sudo mkfs.fat -F 32 -n EFI /dev/${DISK_DEVICE}p1 || sudo mkfs.fat -F 32 -n EFI /dev/${DISK_DEVICE}1 |
| 52 | + |
| 53 | +# ===== Partition 2: Solaris Root Pool ===== |
| 54 | +echo "Creating partition 2: Solaris root pool (${SOLARIS_ROOT_SIZE_GB}GB)..." |
| 55 | +# Create partition for OpenIndiana/illumos root ZFS pool |
| 56 | +sudo parted /dev/$DISK_DEVICE mkpart "solaris" 513MiB ${SOLARIS_ROOT_END_MIB}MiB |
| 57 | +# Set Solaris root partition type (BF00) for proper recognition by illumos tools |
| 58 | +sudo sgdisk --typecode=2:BF00 /dev/$DISK_DEVICE |
| 59 | + |
| 60 | +# ===== Partition 4: Solaris Reserved (create before data partition) ===== |
| 61 | +echo "Creating partition 4: Solaris reserved (8MB at end of disk)..." |
| 62 | +# Calculate sectors for 8MB reserved partition at end of disk |
| 63 | +# Get total sectors, reserve last 1MB, then place 8MB reserved partition before it |
| 64 | +TOTAL_SECTORS=$(sudo blockdev --getsz /dev/$DISK_DEVICE) |
| 65 | +LAST_USABLE_SECTOR=$((TOTAL_SECTORS - 2048)) # Reserve last 1MB (2048 sectors) |
| 66 | +RESERVED_START_SECTOR=$((LAST_USABLE_SECTOR - 16384)) # 8MB = 16384 sectors |
| 67 | + |
| 68 | +# Create traditional Solaris reserved partition for compatibility |
| 69 | +sudo parted /dev/$DISK_DEVICE unit s mkpart solaris_reserved \ |
| 70 | + $RESERVED_START_SECTOR $LAST_USABLE_SECTOR |
| 71 | +# Set Solaris reserved partition type (BF07) |
| 72 | +sudo sgdisk --typecode=4:BF07 /dev/$DISK_DEVICE |
| 73 | + |
| 74 | +# ===== Partition 3: Data Partition ===== |
| 75 | +echo "Creating partition 3: Data partition (remaining space)..." |
| 76 | +# Create data partition using remaining space between root and reserved partitions |
| 77 | +# parted will automatically use available space up to the reserved partition |
| 78 | +sudo parted /dev/$DISK_DEVICE mkpart data ${SOLARIS_ROOT_END_MIB}MiB -8200MiB |
| 79 | +# Set Solaris /home partition type (BF05) for user data |
| 80 | +sudo sgdisk --typecode=3:BF05 /dev/$DISK_DEVICE |
| 81 | + |
| 82 | +# ===== Display final partition layout ===== |
| 83 | +echo "" |
| 84 | +echo "Partition layout created successfully:" |
| 85 | +sudo parted /dev/$DISK_DEVICE print |
| 86 | +echo "" |
| 87 | +echo "Partition type codes set:" |
| 88 | +echo " Partition 1: ESP (EFI System Partition)" |
| 89 | +echo " Partition 2: BF00 (Solaris root)" |
| 90 | +echo " Partition 3: BF05 (Solaris /home)" |
| 91 | +echo " Partition 4: BF07 (Solaris reserved)" |
| 92 | +echo "" |
| 93 | +echo "Ready for OpenIndiana/illumos installation!" |
0 commit comments