Skip to content

Commit 32223c2

Browse files
committed
Solaris/Illumos administration:
add disk cleaner and gpt partitions creator scripts
1 parent 7855322 commit 32223c2

File tree

2 files changed

+171
-0
lines changed

2 files changed

+171
-0
lines changed

solaris/admin/create_gpt_parts.sh

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
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!"
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#!/usr/bin/env bash
2+
# =============================================================================
3+
# Disk Hammer for illumos - Complete Disk Cleanup Utility
4+
# -----------------------------------------------------------------------------
5+
# Purpose : Completely wipe disk metadata for clean illumos/OpenIndiana setup.
6+
# illumos tools (prtvtoc, fmthard, format, zfs) can behave buggy
7+
# when encountering metadata/records from previously deleted partitions.
8+
# Usage : Run from Linux before installing illumos to ensure clean disk state.
9+
# Set DISK_DEVICE variable to your target disk (e.g., sda, nvme0n1)
10+
# Notes : - Must be run as root/sudo for all operations
11+
# - Update DISK_DEVICE variable for your specific disk
12+
# - More thorough than standard Linux disk wiping for illumos compatibility
13+
# =============================================================================
14+
15+
# Configuration: Set your target disk device here
16+
# Examples: sda, sdb, nvme0n1, nvme1n1, etc.
17+
DISK_DEVICE="sdX" # CHANGE THIS TO YOUR ACTUAL DISK
18+
19+
# Validate that user has updated the device variable
20+
if [ "$DISK_DEVICE" = "sdX" ]; then
21+
echo "ERROR: Please update DISK_DEVICE variable with your actual disk device name"
22+
echo "Examples: sda, sdb, nvme0n1, etc."
23+
exit 1
24+
fi
25+
26+
# Install required tools for comprehensive disk wiping
27+
# Replace with 'dnf install --assume-yes' for Fedora-based systems
28+
# util-linux provides wipefs, parted handles partition tables, gdisk manages GPT
29+
sudo apt install --yes parted gdisk util-linux
30+
31+
echo "WARNING: This will completely wipe /dev/$DISK_DEVICE"
32+
echo "Press Ctrl+C within 10 seconds to cancel..."
33+
sleep 10
34+
35+
# Step 1: Remove filesystem signatures and partition metadata
36+
# Wipes all filesystem signatures from the entire disk (not just partitions)
37+
# This handles ext4, NTFS, ZFS, and other filesystem metadata
38+
echo "Step 1: Wiping filesystem signatures..."
39+
sudo wipefs --all --force /dev/$DISK_DEVICE
40+
41+
# Step 2: Destroy both GPT and MBR partition table structures
42+
# Creates a completely clean slate for new partitioning
43+
echo "Step 2: Destroying partition tables..."
44+
sudo sgdisk --zap-all /dev/$DISK_DEVICE
45+
46+
# Steps 3-5: Zero out critical disk areas (required for illumos compatibility)
47+
# illumos is more sensitive to residual data than Linux
48+
49+
# Step 3: Zero the beginning of the disk (first 16MB)
50+
# Clears boot sectors, partition tables, and filesystem headers
51+
echo "Step 3: Zeroing first 16MB of disk..."
52+
sudo dd if=/dev/zero of=/dev/$DISK_DEVICE bs=1M count=16 status=progress conv=sync
53+
54+
# Step 4: Calculate and zero the end of the disk (last 16MB)
55+
echo "Step 4: Calculating disk size and zeroing last 16MB..."
56+
# Get the total disk size in 512-byte sectors
57+
TOTAL_SECTORS=$(sudo blockdev --getsz /dev/$DISK_DEVICE)
58+
echo "Total sectors: $TOTAL_SECTORS"
59+
60+
# Calculate seek offset: sectors / 2048 - 16 (converts sectors to MB, minus 16MB)
61+
SEEK_OFFSET=$((TOTAL_SECTORS / 2048 - 16))
62+
echo "Seek offset (MB): $SEEK_OFFSET"
63+
64+
sudo dd if=/dev/zero of=/dev/$DISK_DEVICE bs=1M count=16 seek=$SEEK_OFFSET \
65+
status=progress conv=sync
66+
67+
# Step 5: Clean up the final sectors with precise sector-level addressing
68+
# Handles any rounding errors from MB-based calculations above
69+
echo "Step 5: Final cleanup of last 1MB with sector precision..."
70+
# OFFSET_SECTOR = TOTAL_SECTORS - 2048 (last 1MB in 512-byte sectors)
71+
OFFSET_SECTOR=$((TOTAL_SECTORS - 2048))
72+
echo "Final sector offset: $OFFSET_SECTOR"
73+
74+
sudo dd if=/dev/zero of=/dev/$DISK_DEVICE bs=512 count=2048 seek=$OFFSET_SECTOR \
75+
status=progress conv=sync
76+
77+
echo "Disk cleanup complete! /dev/$DISK_DEVICE is now ready for illumos installation."
78+
echo "After running this script, illumos partition management tools should work without issues."

0 commit comments

Comments
 (0)