Skip to content

Conversation

atiq-cs
Copy link
Owner

@atiq-cs atiq-cs commented Sep 6, 2025

This PR introduces two comprehensive scripts for preparing and partitioning disks for illumos/OpenIndiana systems, addressing specific compatibility requirements that standard Linux tools don't handle.

Scripts Added

wipe_pt.sh - Complete Disk Sanitization

  • Purpose: Thoroughly wipe disk metadata to prevent illumos partition tool issues
  • Key Features:
    • Removes filesystem signatures, GPT/MBR structures
    • Zeros critical disk areas (first/last 16MB) required for illumos compatibility
    • Automated sector calculations with safety validation
    • Generic device handling via configurable DISK_DEVICE variable
  • Rationale: illumos tools (prtvtoc, fmthard, format, zfs) can behave unpredictably when encountering residual partition metadata from previous installations

create_gpt_parts.sh - Optimized GPT Layout Creation

  • Purpose: Create standardized GPT partition layout for OpenIndiana/illumos systems
  • Partition Layout:
    1. ESP (512MB FAT32) - UEFI boot partition
    2. Solaris Root (configurable, default 128GB) - System ZFS pool (type BF00)
    3. Data Partition (remaining space) - User data/additional pools (type BF05)
    4. Solaris Reserved (8MB at disk end) - Traditional compatibility marker (type BF07)
  • Key Features:
    • Proper Solaris partition type codes for illumos recognition
    • Automatic space calculation and alignment
    • Configurable root pool size
    • Compatible with both NVMe and SATA device naming

Technical Notes

  • Scripts use generic device variables (DISK_DEVICE) instead of hardcoded device names
  • Includes comprehensive error checking and user confirmation prompts
  • Follows Solaris/illumos best practices for partition alignment and type codes
  • Designed to run from Linux before illumos installation for maximum compatibility

Usage Workflow

  1. Run disk_hammer_illumos.sh to completely sanitize target disk
  2. Run create_gpt_parts.sh to create optimized partition layout
  3. Proceed with OpenIndiana/illumos installation

Both scripts include detailed documentation and are designed for review by senior illumos engineers.

Test Results
wipe_pt.sh

PT (partition table) before 'wipe_pt'

$ sudo sgdisk --print /dev/sda
Disk /dev/sda: 3907029167 sectors, 1.8 TiB
Model: BUP Slim
Sector size (logical/physical): 512/4096 bytes
Disk identifier (GUID): A11049BF-9778-2B49-B682-1B72C929286F
Partition table holds up to 9 entries
Main partition table begins at sector 2 and ends at sector 4
First usable sector is 34, last usable sector is 3907029133
Partitions will be aligned on 8-sector boundaries
Total free space is 222 sectors (111.0 KiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1             256          524543   256.0 MiB   EF00  loader
   2          524544      3907012749   1.8 TiB     BF01  zfs
   9      3907012750      3907029133   8.0 MiB     BF07

launch the script :)

$ sudo solaris/admin/wipe_pt.sh --target-disk /dev/sda
Target device: /dev/sda

WARNING: This operation will COMPLETELY DESTROY all data on /dev/sda
This includes:
  - All partitions and their data
  - Filesystem signatures
  - Boot sectors and partition tables
  - First and last 16MB of disk content

Are you absolutely sure you want to proceed? (y/N): y
Installing required tools...
... apt update verbose output ...
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

Step 1: Wiping filesystem signatures...
/dev/sda: 8 bytes were erased at offset 0x00000200 (gpt): 45 46 49 20 50 41 52 54
/dev/sda: 8 bytes were erased at offset 0x1d1c1115c00 (gpt): 45 46 49 20 50 41 52 54
/dev/sda: 2 bytes were erased at offset 0x000001fe (PMBR): 55 aa
Step 2: Destroying partition tables...
Creating new GPT entries in memory.
GPT data structures destroyed! You may now partition the disk using fdisk or
other utilities.
Step 3: Zeroing first 16MB of disk...
16+0 records in
16+0 records out
16777216 bytes (17 MB, 16 MiB) copied, 0.00577996 s, 2.9 GB/s
Step 4: Calculating disk size and zeroing last 16MB...
Logical sector size: 512 bytes
Total sectors: 3907029167
Sectors per MB: 2048
Seek offset (MB): 1907713
16+0 records in
16+0 records out
16777216 bytes (17 MB, 16 MiB) copied, 0.0066163 s, 2.5 GB/s
Step 5: Final cleanup of last 1MB with sector precision...
Final sector offset: 3907027119
2048+0 records in
2048+0 records out
1048576 bytes (1.0 MB, 1.0 MiB) copied, 0.0286873 s, 36.6 MB/s
SUCCESS: Disk cleanup complete!

/dev/sda is now ready for illumos installation or zfs/zpool creation commands.
After running this script, illumos partition management tools should work
without issues.

PT (partition table) after 'wipe_pt'

$ sudo sgdisk --print /dev/sda
Creating new GPT entries in memory.
Disk /dev/sda: 3907029167 sectors, 1.8 TiB
Model: BUP Slim
Sector size (logical/physical): 512/4096 bytes
Disk identifier (GUID): 6644B5F7-A0C4-4E2F-A007-5C9878ED3535
Partition table holds up to 128 entries
Main partition table begins at sector 2 and ends at sector 33
First usable sector is 34, last usable sector is 3907029133
Partitions will be aligned on 2048-sector boundaries
Total free space is 3907029100 sectors (1.8 TiB)
... blank here.... # no part. table entries

as per output above, all partition table entires are cleared out.

create_gpt_parts.sh
Let's create fresh new partition table and 4 entries

Disk information:
  Device: /dev/sda
  Logical sector size: 512 bytes
  Total sectors: 3907029167

Creating GPT partition layout optimized for OpenIndiana/illumos

Planned partition layout:
  1. ESP (EFI System Partition) - 512MB FAT32 for UEFI boot
  2. Solaris root ZFS pool - 128GB for system
  3. Data partition - remaining space for user data/additional pools
  4. Solaris reserved - 8MB traditional marker at end of disk

NOTE: Ensure you have run wipe_pt.sh first for clean disk state

Proceed with creating partition layout? (y/N): y

Initializing GPT label on /dev/sda...
Information: You may need to update /etc/fstab.


Creating partition 1: EFI System Partition (512MB)...
Information: You may need to update /etc/fstab.

Information: You may need to update /etc/fstab.

Information: You may need to update /etc/fstab.

mkfs.fat 4.2 (2021-01-31)
Creating partition 2: Solaris root pool (128GB)...
Information: You may need to update /etc/fstab.

The operation has completed successfully.

NOTE: The Solaris reserved partition is a traditional 8MB placeholder
and intentionally does not require 1MiB alignment for performance.
Parted may display an alignment warning - this is expected and safe
to ignore. If prompted, press 'i' to ignore the alignment warning.

Creating partition 4: Solaris reserved (8MB at end of disk)...
Calculated reserved partition:
  Start sector: 3907010734
  End sector: 3907027118
  Size: 16384 sectors (8MB)
Warning: The resulting partition is not properly aligned for best performance: 3907010734s % 2048s != 0s
Ignore/Cancel? i
Information: You may need to update /etc/fstab.

The operation has completed successfully.
Creating partition 3: Data partition (remaining space)...
Data partition end: 1907720MiB
Information: You may need to update /etc/fstab.

The operation has completed successfully.
Sorting partitions to proper numerical order...
The operation has completed successfully.

SUCCESS: Partition layout created successfully!

Disk /dev/sda: 3907029167 sectors, 1.8 TiB
Model: BUP Slim
Sector size (logical/physical): 512/4096 bytes
Disk identifier (GUID): 09322E45-7C24-4355-81FC-CAD86DBB40AD
Partition table holds up to 128 entries
Main partition table begins at sector 2 and ends at sector 33
First usable sector is 34, last usable sector is 3907029133
Partitions will be aligned on 8-sector boundaries
Total free space is 4203 sectors (2.1 MiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048         1050623   512.0 MiB   EF00  EFI System Partition
   2         1050624       269486079   128.0 GiB   BF00  solaris
   3       269486080      3907010559   1.7 TiB     BF05  data
   4      3907010734      3907027118   8.0 MiB     BF07  solaris_reserved

Final partition type codes:
  Partition 1: ESP (EFI System Partition)
  Partition 2: BF00 (Solaris root)
  Partition 3: BF05 (Solaris /home - data)
  Partition 4: BF07 (Solaris reserved)

Ready for OpenIndiana/illumos installation!
You can now proceed with ZFS pool creation and OS installation.

 add disk cleaner and gpt partitions creator scripts
@atiq-cs atiq-cs changed the title Add illumos/OpenIndiana Disk Management Scripts Add Illumos/OpenIndiana Disk Management Scripts Sep 6, 2025
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?

@atiq-cs atiq-cs self-assigned this Sep 7, 2025
@atiq-cs atiq-cs requested a review from tsoome September 7, 2025 02:58
for both scripts
- sector size wise generic computations, handles 4K native, 512 all disks

taking inputs
- take device/disk from user as cmd arg
- Interactively ask for confirmation before running destructive data loss operations / zeroing out

create_gpt_parts.sh
- use correct partition numbers for setting type code
- added sorting of partition numbers since they are not sorted
- added sgdisk print command to show the newly created part. table
@atiq-cs atiq-cs force-pushed the dev branch 4 times, most recently from 10e84c0 to 44ba882 Compare October 2, 2025 19:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants