Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 93 additions & 0 deletions solaris/admin/create_gpt_parts.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
#!/usr/bin/env bash
# =============================================================================
# Solaris GPT Partition Creator - OpenIndiana/illumos System Layout
# -----------------------------------------------------------------------------
# Purpose : Create GPT partition layout optimized for OpenIndiana/illumos systems.
# Sets up ESP, Solaris root ZFS pool, data partition, and reserved partition.
# Usage : Run after disk_hammer_illumos.sh to create clean partition layout.
# Set DISK_DEVICE variable to your target disk.
# Notes : - Requires prior run of disk_hammer_illumos.sh for clean disk state
# - Creates 4 partitions: ESP (512MB), Solaris root, data, reserved (8MB)
# - Uses proper Solaris partition type codes (BF00, BF05, BF07)
# =============================================================================

# Configuration: Set your target disk device here
# Examples: sda, sdb, nvme0n1, nvme1n1, etc.
DISK_DEVICE="sdX" # CHANGE THIS TO YOUR ACTUAL DISK

# Validate that user has updated the device variable
if [ "$DISK_DEVICE" = "sdX" ]; then
echo "ERROR: Please update DISK_DEVICE variable with your actual disk device name"
echo "Examples: sda, sdb, nvme0n1, etc."
exit 1
fi

# Configuration: Solaris root partition size (adjust as needed)
SOLARIS_ROOT_SIZE_GB=128
SOLARIS_ROOT_END_MIB=$((513 + SOLARIS_ROOT_SIZE_GB * 1024))

echo "Creating GPT partition layout on /dev/$DISK_DEVICE"
echo "Solaris root partition will be ${SOLARIS_ROOT_SIZE_GB}GB"
echo "Press Ctrl+C within 5 seconds to cancel..."
sleep 5

# Prerequisite: Clean/hammer GPT partition table using disk_hammer_illumos.sh
echo "NOTE: Ensure you have run disk_hammer_illumos.sh first for clean disk state"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

its better to use something like basename $0

Copy link
Owner Author

@atiq-cs atiq-cs Sep 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that is a separate script, basename $0 won't work.

Did I get this right?


# Layout: 4 partitions total
# 1. ESP (EFI System Partition) - 512MB FAT32 for UEFI boot
# 2. Solaris root ZFS pool - configurable size for system installation
# 3. Data partition - remaining space for user data/additional pools
# 4. Solaris reserved - traditional 8MB marker at end of disk

# ===== Partition 1: EFI System Partition (ESP) =====
echo "Creating partition 1: EFI System Partition (512MB)..."
# Create 512MB ESP partition starting at 1MiB for proper alignment
sudo parted /dev/$DISK_DEVICE 'mkpart "EFI System Partition" fat32 1MiB 513MiB'
# Set ESP and boot flags required for UEFI systems
sudo parted /dev/$DISK_DEVICE set 1 esp on
sudo parted /dev/$DISK_DEVICE set 1 boot on
# Format as FAT32 with "EFI" label for bootloader compatibility
sudo mkfs.fat -F 32 -n EFI /dev/${DISK_DEVICE}p1 || sudo mkfs.fat -F 32 -n EFI /dev/${DISK_DEVICE}1

# ===== Partition 2: Solaris Root Pool =====
echo "Creating partition 2: Solaris root pool (${SOLARIS_ROOT_SIZE_GB}GB)..."
# Create partition for OpenIndiana/illumos root ZFS pool
sudo parted /dev/$DISK_DEVICE mkpart "solaris" 513MiB ${SOLARIS_ROOT_END_MIB}MiB
# Set Solaris root partition type (BF00) for proper recognition by illumos tools
sudo sgdisk --typecode=2:BF00 /dev/$DISK_DEVICE

# ===== Partition 4: Solaris Reserved (create before data partition) =====
echo "Creating partition 4: Solaris reserved (8MB at end of disk)..."
# Calculate sectors for 8MB reserved partition at end of disk
# Get total sectors, reserve last 1MB, then place 8MB reserved partition before it
TOTAL_SECTORS=$(sudo blockdev --getsz /dev/$DISK_DEVICE)
LAST_USABLE_SECTOR=$((TOTAL_SECTORS - 2048)) # Reserve last 1MB (2048 sectors)
RESERVED_START_SECTOR=$((LAST_USABLE_SECTOR - 16384)) # 8MB = 16384 sectors

# Create traditional Solaris reserved partition for compatibility
sudo parted /dev/$DISK_DEVICE unit s mkpart solaris_reserved \
$RESERVED_START_SECTOR $LAST_USABLE_SECTOR
# Set Solaris reserved partition type (BF07)
sudo sgdisk --typecode=4:BF07 /dev/$DISK_DEVICE

# ===== Partition 3: Data Partition =====
echo "Creating partition 3: Data partition (remaining space)..."
# Create data partition using remaining space between root and reserved partitions
# parted will automatically use available space up to the reserved partition
sudo parted /dev/$DISK_DEVICE mkpart data ${SOLARIS_ROOT_END_MIB}MiB -8200MiB
# Set Solaris /home partition type (BF05) for user data
sudo sgdisk --typecode=3:BF05 /dev/$DISK_DEVICE

# ===== Display final partition layout =====
echo ""
echo "Partition layout created successfully:"
sudo parted /dev/$DISK_DEVICE print
echo ""
echo "Partition type codes set:"
echo " Partition 1: ESP (EFI System Partition)"
echo " Partition 2: BF00 (Solaris root)"
echo " Partition 3: BF05 (Solaris /home)"
echo " Partition 4: BF07 (Solaris reserved)"
echo ""
echo "Ready for OpenIndiana/illumos installation!"
78 changes: 78 additions & 0 deletions solaris/admin/disk_hammer_illumos.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#!/usr/bin/env bash
# =============================================================================
# Disk Hammer for illumos - Complete Disk Cleanup Utility
# -----------------------------------------------------------------------------
# Purpose : Completely wipe disk metadata for clean illumos/OpenIndiana setup.
# illumos tools (prtvtoc, fmthard, format, zfs) can behave buggy
# when encountering metadata/records from previously deleted partitions.
# Usage : Run from Linux before installing illumos to ensure clean disk state.
# Set DISK_DEVICE variable to your target disk (e.g., sda, nvme0n1)
# Notes : - Must be run as root/sudo for all operations
# - Update DISK_DEVICE variable for your specific disk
# - More thorough than standard Linux disk wiping for illumos compatibility
# =============================================================================

# Configuration: Set your target disk device here
# Examples: sda, sdb, nvme0n1, nvme1n1, etc.
DISK_DEVICE="sdX" # CHANGE THIS TO YOUR ACTUAL DISK

# Validate that user has updated the device variable
if [ "$DISK_DEVICE" = "sdX" ]; then
echo "ERROR: Please update DISK_DEVICE variable with your actual disk device name"
echo "Examples: sda, sdb, nvme0n1, etc."
exit 1
fi

# Install required tools for comprehensive disk wiping
# Replace with 'dnf install --assume-yes' for Fedora-based systems
# util-linux provides wipefs, parted handles partition tables, gdisk manages GPT
sudo apt install --yes parted gdisk util-linux

echo "WARNING: This will completely wipe /dev/$DISK_DEVICE"
echo "Press Ctrl+C within 10 seconds to cancel..."
sleep 10

# Step 1: Remove filesystem signatures and partition metadata
# Wipes all filesystem signatures from the entire disk (not just partitions)
# This handles ext4, NTFS, ZFS, and other filesystem metadata
echo "Step 1: Wiping filesystem signatures..."
sudo wipefs --all --force /dev/$DISK_DEVICE

# Step 2: Destroy both GPT and MBR partition table structures
# Creates a completely clean slate for new partitioning
echo "Step 2: Destroying partition tables..."
sudo sgdisk --zap-all /dev/$DISK_DEVICE

# Steps 3-5: Zero out critical disk areas (required for illumos compatibility)
# illumos is more sensitive to residual data than Linux

# Step 3: Zero the beginning of the disk (first 16MB)
# Clears boot sectors, partition tables, and filesystem headers
echo "Step 3: Zeroing first 16MB of disk..."
sudo dd if=/dev/zero of=/dev/$DISK_DEVICE bs=1M count=16 status=progress conv=sync

# Step 4: Calculate and zero the end of the disk (last 16MB)
echo "Step 4: Calculating disk size and zeroing last 16MB..."
# Get the total disk size in 512-byte sectors
TOTAL_SECTORS=$(sudo blockdev --getsz /dev/$DISK_DEVICE)
echo "Total sectors: $TOTAL_SECTORS"

# Calculate seek offset: sectors / 2048 - 16 (converts sectors to MB, minus 16MB)
SEEK_OFFSET=$((TOTAL_SECTORS / 2048 - 16))
echo "Seek offset (MB): $SEEK_OFFSET"

sudo dd if=/dev/zero of=/dev/$DISK_DEVICE bs=1M count=16 seek=$SEEK_OFFSET \
status=progress conv=sync

# Step 5: Clean up the final sectors with precise sector-level addressing
# Handles any rounding errors from MB-based calculations above
echo "Step 5: Final cleanup of last 1MB with sector precision..."
# OFFSET_SECTOR = TOTAL_SECTORS - 2048 (last 1MB in 512-byte sectors)
OFFSET_SECTOR=$((TOTAL_SECTORS - 2048))
echo "Final sector offset: $OFFSET_SECTOR"

sudo dd if=/dev/zero of=/dev/$DISK_DEVICE bs=512 count=2048 seek=$OFFSET_SECTOR \
status=progress conv=sync

echo "Disk cleanup complete! /dev/$DISK_DEVICE is now ready for illumos installation."
echo "After running this script, illumos partition management tools should work without issues."