did stuff
Some checks failed
particle-os CI / Test particle-os (push) Failing after 2s
particle-os CI / Integration Test (push) Has been skipped
particle-os CI / Security & Quality (push) Failing after 1s
Test particle-os Basic Functionality / test-basic (push) Failing after 1s
Tests / test (1.21.x) (push) Failing after 1s
Tests / test (1.22.x) (push) Failing after 1s
particle-os CI / Build and Release (push) Has been skipped
Some checks failed
particle-os CI / Test particle-os (push) Failing after 2s
particle-os CI / Integration Test (push) Has been skipped
particle-os CI / Security & Quality (push) Failing after 1s
Test particle-os Basic Functionality / test-basic (push) Failing after 1s
Tests / test (1.21.x) (push) Failing after 1s
Tests / test (1.22.x) (push) Failing after 1s
particle-os CI / Build and Release (push) Has been skipped
This commit is contained in:
parent
99272a8177
commit
d782a8a4fb
14 changed files with 1839 additions and 35 deletions
|
|
@ -93,27 +93,97 @@ func main() {
|
|||
os.Exit(1)
|
||||
}
|
||||
|
||||
// Create a single partition
|
||||
fmt.Println("Creating partition...")
|
||||
cmd = exec.Command("sudo", "parted", loopDevice, "mkpart", "primary", "ext4", "1MiB", "100%")
|
||||
// Create BIOS Boot Partition (1MB) for GRUB
|
||||
fmt.Println("Creating BIOS Boot Partition...")
|
||||
cmd = exec.Command("sudo", "parted", loopDevice, "mkpart", "primary", "1MiB", "2MiB")
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
if err := cmd.Run(); err != nil {
|
||||
fmt.Printf("Error creating partition: %v\n", err)
|
||||
fmt.Printf("Error creating BIOS Boot Partition: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// Get the partition device
|
||||
partitionDevice := loopDevice + "p1"
|
||||
// Set BIOS Boot Partition type flag
|
||||
fmt.Println("Setting BIOS Boot Partition type...")
|
||||
cmd = exec.Command("sudo", "parted", loopDevice, "set", "1", "bios_grub", "on")
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
if err := cmd.Run(); err != nil {
|
||||
fmt.Printf("Warning: could not set BIOS Boot Partition type: %v\n", err)
|
||||
}
|
||||
|
||||
// Create EFI System Partition (501MB) for UEFI boot
|
||||
fmt.Println("Creating EFI System Partition...")
|
||||
cmd = exec.Command("sudo", "parted", loopDevice, "mkpart", "primary", "fat32", "2MiB", "503MiB")
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
if err := cmd.Run(); err != nil {
|
||||
fmt.Printf("Error creating EFI System Partition: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// Set EFI System Partition type flag
|
||||
fmt.Println("Setting EFI System Partition type...")
|
||||
cmd = exec.Command("sudo", "parted", loopDevice, "set", "2", "esp", "on")
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
if err := cmd.Run(); err != nil {
|
||||
fmt.Printf("Warning: could not set EFI System Partition type: %v\n", err)
|
||||
}
|
||||
|
||||
// Create Boot Partition (1GB) for GRUB and kernel
|
||||
fmt.Println("Creating Boot Partition...")
|
||||
cmd = exec.Command("sudo", "parted", loopDevice, "mkpart", "primary", "ext4", "503MiB", "1527MiB")
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
if err := cmd.Run(); err != nil {
|
||||
fmt.Printf("Error creating Boot Partition: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// Create Root Partition (remaining space)
|
||||
fmt.Println("Creating Root Partition...")
|
||||
cmd = exec.Command("sudo", "parted", loopDevice, "mkpart", "primary", "ext4", "1527MiB", "100%")
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
if err := cmd.Run(); err != nil {
|
||||
fmt.Printf("Error creating Root Partition: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// Get the partition devices
|
||||
bootPartitionDevice := loopDevice + "p3"
|
||||
partitionDevice := loopDevice + "p4"
|
||||
fmt.Printf("Partition device: %s\n", partitionDevice)
|
||||
|
||||
// Format the partition with ext4
|
||||
fmt.Println("Formatting partition with ext4...")
|
||||
// Format EFI partition with FAT32
|
||||
fmt.Printf("Formatting EFI partition with FAT32...\n")
|
||||
efiPartitionDevice := loopDevice + "p2"
|
||||
cmd = exec.Command("sudo", "mkfs.fat", "-F", "32", efiPartitionDevice)
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
if err := cmd.Run(); err != nil {
|
||||
fmt.Printf("Error formatting EFI partition: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// Format Boot partition with ext4
|
||||
fmt.Printf("Formatting Boot partition with ext4...\n")
|
||||
cmd = exec.Command("sudo", "mkfs.ext4", bootPartitionDevice)
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
if err := cmd.Run(); err != nil {
|
||||
fmt.Printf("Error formatting Boot partition: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// Format Root partition with ext4
|
||||
fmt.Printf("Formatting Root partition with ext4...\n")
|
||||
cmd = exec.Command("sudo", "mkfs.ext4", partitionDevice)
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
if err := cmd.Run(); err != nil {
|
||||
fmt.Printf("Error formatting partition: %v\n", err)
|
||||
fmt.Printf("Error formatting Root partition: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
|
|
@ -124,19 +194,77 @@ func main() {
|
|||
os.Exit(1)
|
||||
}
|
||||
|
||||
// Mount the partition
|
||||
fmt.Printf("Mounting partition to %s...\n", mountPoint)
|
||||
// Mount Root partition
|
||||
fmt.Printf("Mounting Root partition to %s...\n", mountPoint)
|
||||
cmd = exec.Command("sudo", "mount", partitionDevice, mountPoint)
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
if err := cmd.Run(); err != nil {
|
||||
fmt.Printf("Error mounting partition: %v\n", err)
|
||||
fmt.Printf("Error mounting Root partition: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// Create boot directory first
|
||||
fmt.Printf("Creating boot directory structure...\n")
|
||||
bootMountPoint := filepath.Join(mountPoint, "boot")
|
||||
|
||||
// Create boot directory and set ownership
|
||||
cmd = exec.Command("sudo", "mkdir", "-p", bootMountPoint)
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
if err := cmd.Run(); err != nil {
|
||||
fmt.Printf("Warning: could not create boot directory: %v\n", err)
|
||||
}
|
||||
|
||||
// Set ownership to root
|
||||
cmd = exec.Command("sudo", "chown", "root:root", bootMountPoint)
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
if err := cmd.Run(); err != nil {
|
||||
fmt.Printf("Warning: could not set ownership: %v\n", err)
|
||||
}
|
||||
|
||||
// Mount Boot partition
|
||||
fmt.Printf("Mounting Boot partition to %s...\n", bootMountPoint)
|
||||
cmd = exec.Command("sudo", "mount", bootPartitionDevice, bootMountPoint)
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
if err := cmd.Run(); err != nil {
|
||||
fmt.Printf("Warning: could not mount Boot partition: %v\n", err)
|
||||
}
|
||||
|
||||
// Now create EFI directory inside the mounted boot partition
|
||||
efiMountPoint := filepath.Join(mountPoint, "boot", "efi")
|
||||
cmd = exec.Command("sudo", "mkdir", "-p", efiMountPoint)
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
if err := cmd.Run(); err != nil {
|
||||
fmt.Printf("Warning: could not create EFI directory: %v\n", err)
|
||||
}
|
||||
|
||||
// Set ownership to root
|
||||
cmd = exec.Command("sudo", "chown", "root:root", efiMountPoint)
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
if err := cmd.Run(); err != nil {
|
||||
fmt.Printf("Warning: could not set ownership: %v\n", err)
|
||||
}
|
||||
|
||||
// Mount EFI partition
|
||||
fmt.Printf("Mounting EFI partition to %s...\n", efiMountPoint)
|
||||
cmd = exec.Command("sudo", "mount", efiPartitionDevice, efiMountPoint)
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
if err := cmd.Run(); err != nil {
|
||||
fmt.Printf("Warning: could not mount EFI partition: %v\n", err)
|
||||
}
|
||||
|
||||
// Clean up mount on exit
|
||||
defer func() {
|
||||
fmt.Printf("Unmounting %s...\n", mountPoint)
|
||||
fmt.Printf("Unmounting all partitions...\n")
|
||||
// Unmount in reverse order: EFI, Boot, then Root
|
||||
exec.Command("sudo", "umount", efiMountPoint).Run()
|
||||
exec.Command("sudo", "umount", bootMountPoint).Run()
|
||||
exec.Command("sudo", "umount", mountPoint).Run()
|
||||
}()
|
||||
|
||||
|
|
@ -186,7 +314,13 @@ func main() {
|
|||
// Create OSTree-specific fstab
|
||||
fmt.Println("Creating OSTree fstab...")
|
||||
fstabContent := `# /etc/fstab for OSTree particle-os
|
||||
/dev/sda1 / ext4 rw,errors=remount-ro 0 1
|
||||
# Root filesystem (4th partition)
|
||||
/dev/sda4 / ext4 rw,errors=remount-ro 0 1
|
||||
# Boot partition (3rd partition)
|
||||
/dev/sda3 /boot ext4 rw,errors=remount-ro 0 2
|
||||
# EFI System Partition (2nd partition)
|
||||
/dev/sda2 /boot/efi vfat umask=0077,shortname=winnt 0 2
|
||||
# BIOS Boot Partition (1st partition) - not mounted
|
||||
proc /proc proc defaults 0 0
|
||||
sysfs /sys sysfs defaults 0 0
|
||||
devpts /dev/pts devpts gid=5,mode=620 0 0
|
||||
|
|
@ -203,17 +337,15 @@ tmpfs /run tmpfs defaults 0 0
|
|||
// Try to install GRUB for OSTree
|
||||
fmt.Println("Installing GRUB for OSTree...")
|
||||
|
||||
// Bind mount necessary directories for GRUB
|
||||
grubDirs := []string{"/dev", "/proc", "/sys"}
|
||||
for _, dir := range grubDirs {
|
||||
bindMount := filepath.Join(mountPoint, dir)
|
||||
if err := exec.Command("sudo", "mount", "--bind", dir, bindMount).Run(); err != nil {
|
||||
fmt.Printf("Warning: could not bind mount %s: %v\n", dir, err)
|
||||
}
|
||||
}
|
||||
|
||||
// Install GRUB
|
||||
cmd = exec.Command("sudo", "chroot", mountPoint, "grub-install", "--target=i386-pc", loopDevice)
|
||||
// Install GRUB using podman run to access the Debian container with GRUB tools
|
||||
// Mount the host's /dev directory to access loop devices
|
||||
// Use the actual loop device name that was created
|
||||
grubInstallCmd := fmt.Sprintf("grub-install --target=i386-pc --boot-directory=/mnt/boot --root-directory=/mnt %s", loopDevice)
|
||||
cmd = exec.Command("sudo", "podman", "run", "--rm", "--privileged", "--tty",
|
||||
"-v", "/dev:/dev:z",
|
||||
"-v", mountPoint+":/mnt:z",
|
||||
"238208cf481a",
|
||||
"bash", "-c", grubInstallCmd)
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
if err := cmd.Run(); err != nil {
|
||||
|
|
@ -222,19 +354,21 @@ tmpfs /run tmpfs defaults 0 0
|
|||
fmt.Println("GRUB installed successfully")
|
||||
}
|
||||
|
||||
// Generate GRUB config
|
||||
cmd = exec.Command("sudo", "chroot", mountPoint, "update-grub")
|
||||
// Generate GRUB config using podman run
|
||||
grubMkconfigCmd := fmt.Sprintf("grub-mkconfig -o /mnt/boot/grub/grub.cfg")
|
||||
cmd = exec.Command("sudo", "podman", "run", "--rm", "--privileged", "--tty",
|
||||
"-v", mountPoint+":/mnt:z",
|
||||
"238208cf481a",
|
||||
"bash", "-c", grubMkconfigCmd)
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
if err := cmd.Run(); err != nil {
|
||||
fmt.Printf("Warning: GRUB config generation failed: %v\n", err)
|
||||
} else {
|
||||
fmt.Println("GRUB config generated successfully")
|
||||
}
|
||||
|
||||
// Unbind mount directories
|
||||
for _, dir := range grubDirs {
|
||||
bindMount := filepath.Join(mountPoint, dir)
|
||||
exec.Command("sudo", "umount", bindMount).Run()
|
||||
}
|
||||
// GRUB installation complete
|
||||
|
||||
} else {
|
||||
// Handle standard bootable image setup
|
||||
|
|
|
|||
Binary file not shown.
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue