Serve full ISO for PXE boot via proxmox-iso-url kernel param
The Proxmox installer needs the full ISO to access packages and installer data. Previously the ISO was deleted after extracting kernel+initrd. Now we keep it as original.iso and serve it via HTTP. The iPXE script passes proxmox-iso-url=<url> so the installer fetches the ISO over the network instead of scanning block devices. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1 @@
|
|||||||
|
ALTER TABLE images ADD COLUMN iso_path TEXT NOT NULL DEFAULT '';
|
||||||
@@ -13,6 +13,7 @@ import (
|
|||||||
type ExtractResult struct {
|
type ExtractResult struct {
|
||||||
KernelFilename string
|
KernelFilename string
|
||||||
InitrdFilename string
|
InitrdFilename string
|
||||||
|
ISOFilename string
|
||||||
}
|
}
|
||||||
|
|
||||||
type ProgressFunc func(stage string, detail string)
|
type ProgressFunc func(stage string, detail string)
|
||||||
@@ -33,22 +34,21 @@ func ExtractFromISOWithProgress(r io.Reader, destDir string, progress ProgressFu
|
|||||||
|
|
||||||
report("receiving", "Writing ISO to disk...")
|
report("receiving", "Writing ISO to disk...")
|
||||||
|
|
||||||
tmp, err := os.CreateTemp(filepath.Dir(destDir), "iso-upload-*.tmp")
|
isoPath := filepath.Join(destDir, "original.iso")
|
||||||
|
tmp, err := os.Create(isoPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("create temp file: %w", err)
|
return nil, fmt.Errorf("create ISO file: %w", err)
|
||||||
}
|
}
|
||||||
tmpPath := tmp.Name()
|
|
||||||
defer os.Remove(tmpPath)
|
|
||||||
|
|
||||||
if _, err := io.Copy(tmp, r); err != nil {
|
if _, err := io.Copy(tmp, r); err != nil {
|
||||||
tmp.Close()
|
tmp.Close()
|
||||||
return nil, fmt.Errorf("write ISO to temp file: %w", err)
|
return nil, fmt.Errorf("write ISO to disk: %w", err)
|
||||||
}
|
}
|
||||||
tmp.Close()
|
tmp.Close()
|
||||||
|
|
||||||
report("parsing", "Parsing ISO image...")
|
report("parsing", "Parsing ISO image...")
|
||||||
|
|
||||||
f, err := os.Open(tmpPath)
|
f, err := os.Open(isoPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("open temp ISO: %w", err)
|
return nil, fmt.Errorf("open temp ISO: %w", err)
|
||||||
}
|
}
|
||||||
@@ -102,6 +102,7 @@ func ExtractFromISOWithProgress(r io.Reader, destDir string, progress ProgressFu
|
|||||||
return &ExtractResult{
|
return &ExtractResult{
|
||||||
KernelFilename: kernelName,
|
KernelFilename: kernelName,
|
||||||
InitrdFilename: initrdName,
|
InitrdFilename: initrdName,
|
||||||
|
ISOFilename: "original.iso",
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -55,6 +55,7 @@ func (s *Service) Upload(ctx context.Context, p UploadParams) (*model.Image, err
|
|||||||
|
|
||||||
kernelPath := filepath.Join(p.Name, result.KernelFilename)
|
kernelPath := filepath.Join(p.Name, result.KernelFilename)
|
||||||
initrdPath := filepath.Join(p.Name, result.InitrdFilename)
|
initrdPath := filepath.Join(p.Name, result.InitrdFilename)
|
||||||
|
isoPath := filepath.Join(p.Name, result.ISOFilename)
|
||||||
|
|
||||||
id, err := s.Store.Create(ctx, model.Image{
|
id, err := s.Store.Create(ctx, model.Image{
|
||||||
Name: p.Name,
|
Name: p.Name,
|
||||||
@@ -62,6 +63,7 @@ func (s *Service) Upload(ctx context.Context, p UploadParams) (*model.Image, err
|
|||||||
Version: p.Version,
|
Version: p.Version,
|
||||||
KernelPath: kernelPath,
|
KernelPath: kernelPath,
|
||||||
InitrdPath: initrdPath,
|
InitrdPath: initrdPath,
|
||||||
|
ISOPath: isoPath,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
os.RemoveAll(destDir)
|
os.RemoveAll(destDir)
|
||||||
|
|||||||
@@ -62,6 +62,7 @@ type Image struct {
|
|||||||
Version string
|
Version string
|
||||||
KernelPath string
|
KernelPath string
|
||||||
InitrdPath string
|
InitrdPath string
|
||||||
|
ISOPath string
|
||||||
IsDefault bool
|
IsDefault bool
|
||||||
CreatedAt time.Time
|
CreatedAt time.Time
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,14 +9,15 @@ import (
|
|||||||
func BuildIPXEScript(publicURL string, img *model.Image, mac string) string {
|
func BuildIPXEScript(publicURL string, img *model.Image, mac string) string {
|
||||||
kernelURL := fmt.Sprintf("%s/images/boot/%s", publicURL, img.KernelPath)
|
kernelURL := fmt.Sprintf("%s/images/boot/%s", publicURL, img.KernelPath)
|
||||||
initrdURL := fmt.Sprintf("%s/images/boot/%s", publicURL, img.InitrdPath)
|
initrdURL := fmt.Sprintf("%s/images/boot/%s", publicURL, img.InitrdPath)
|
||||||
|
isoURL := fmt.Sprintf("%s/images/boot/%s", publicURL, img.ISOPath)
|
||||||
|
|
||||||
return fmt.Sprintf(`#!ipxe
|
return fmt.Sprintf(`#!ipxe
|
||||||
echo Provisioning: booting %s on ${mac}
|
echo Provisioning: booting %s on ${mac}
|
||||||
echo Loading kernel...
|
echo Loading kernel...
|
||||||
kernel %s ramdisk_size=16777216 vga=791 video=vesafb:lfb:on rw quiet splash=verbose initrd=initrd
|
kernel %s ramdisk_size=16777216 vga=791 video=vesafb:lfb:on rw quiet splash=verbose proxmox-iso-url=%s initrd=initrd
|
||||||
echo Loading initrd...
|
echo Loading initrd...
|
||||||
initrd --name initrd %s
|
initrd --name initrd %s
|
||||||
echo Booting...
|
echo Booting...
|
||||||
boot
|
boot
|
||||||
`, img.Name, kernelURL, initrdURL)
|
`, img.Name, kernelURL, isoURL, initrdURL)
|
||||||
}
|
}
|
||||||
|
|||||||
+11
-11
@@ -15,9 +15,9 @@ type Images struct {
|
|||||||
|
|
||||||
func (s *Images) Create(ctx context.Context, img model.Image) (int64, error) {
|
func (s *Images) Create(ctx context.Context, img model.Image) (int64, error) {
|
||||||
res, err := s.DB.ExecContext(ctx, `
|
res, err := s.DB.ExecContext(ctx, `
|
||||||
INSERT INTO images(name, kind, version, kernel_path, initrd_path, is_default)
|
INSERT INTO images(name, kind, version, kernel_path, initrd_path, iso_path, is_default)
|
||||||
VALUES(?,?,?,?,?,?)
|
VALUES(?,?,?,?,?,?,?)
|
||||||
`, img.Name, img.Kind, img.Version, img.KernelPath, img.InitrdPath, boolToInt(img.IsDefault))
|
`, img.Name, img.Kind, img.Version, img.KernelPath, img.InitrdPath, img.ISOPath, boolToInt(img.IsDefault))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, fmt.Errorf("insert image: %w", err)
|
return 0, fmt.Errorf("insert image: %w", err)
|
||||||
}
|
}
|
||||||
@@ -25,7 +25,7 @@ func (s *Images) Create(ctx context.Context, img model.Image) (int64, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *Images) List(ctx context.Context) ([]model.Image, error) {
|
func (s *Images) List(ctx context.Context) ([]model.Image, error) {
|
||||||
rows, err := s.DB.QueryContext(ctx, `SELECT id, name, kind, version, kernel_path, initrd_path, is_default, created_at FROM images ORDER BY name`)
|
rows, err := s.DB.QueryContext(ctx, `SELECT id, name, kind, version, kernel_path, initrd_path, iso_path, is_default, created_at FROM images ORDER BY name`)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("list images: %w", err)
|
return nil, fmt.Errorf("list images: %w", err)
|
||||||
}
|
}
|
||||||
@@ -35,7 +35,7 @@ func (s *Images) List(ctx context.Context) ([]model.Image, error) {
|
|||||||
var img model.Image
|
var img model.Image
|
||||||
var isDefault int
|
var isDefault int
|
||||||
var createdAt string
|
var createdAt string
|
||||||
if err := rows.Scan(&img.ID, &img.Name, &img.Kind, &img.Version, &img.KernelPath, &img.InitrdPath, &isDefault, &createdAt); err != nil {
|
if err := rows.Scan(&img.ID, &img.Name, &img.Kind, &img.Version, &img.KernelPath, &img.InitrdPath, &img.ISOPath, &isDefault, &createdAt); err != nil {
|
||||||
return nil, fmt.Errorf("scan image: %w", err)
|
return nil, fmt.Errorf("scan image: %w", err)
|
||||||
}
|
}
|
||||||
img.IsDefault = isDefault == 1
|
img.IsDefault = isDefault == 1
|
||||||
@@ -46,11 +46,11 @@ func (s *Images) List(ctx context.Context) ([]model.Image, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *Images) GetDefault(ctx context.Context) (*model.Image, error) {
|
func (s *Images) GetDefault(ctx context.Context) (*model.Image, error) {
|
||||||
row := s.DB.QueryRowContext(ctx, `SELECT id, name, kind, version, kernel_path, initrd_path, is_default, created_at FROM images WHERE is_default = 1 LIMIT 1`)
|
row := s.DB.QueryRowContext(ctx, `SELECT id, name, kind, version, kernel_path, initrd_path, iso_path, is_default, created_at FROM images WHERE is_default = 1 LIMIT 1`)
|
||||||
var img model.Image
|
var img model.Image
|
||||||
var isDefault int
|
var isDefault int
|
||||||
var createdAt string
|
var createdAt string
|
||||||
if err := row.Scan(&img.ID, &img.Name, &img.Kind, &img.Version, &img.KernelPath, &img.InitrdPath, &isDefault, &createdAt); err != nil {
|
if err := row.Scan(&img.ID, &img.Name, &img.Kind, &img.Version, &img.KernelPath, &img.InitrdPath, &img.ISOPath, &isDefault, &createdAt); err != nil {
|
||||||
if err == sql.ErrNoRows {
|
if err == sql.ErrNoRows {
|
||||||
return nil, ErrNotFound
|
return nil, ErrNotFound
|
||||||
}
|
}
|
||||||
@@ -62,11 +62,11 @@ func (s *Images) GetDefault(ctx context.Context) (*model.Image, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *Images) Get(ctx context.Context, id int64) (*model.Image, error) {
|
func (s *Images) Get(ctx context.Context, id int64) (*model.Image, error) {
|
||||||
row := s.DB.QueryRowContext(ctx, `SELECT id, name, kind, version, kernel_path, initrd_path, is_default, created_at FROM images WHERE id = ?`, id)
|
row := s.DB.QueryRowContext(ctx, `SELECT id, name, kind, version, kernel_path, initrd_path, iso_path, is_default, created_at FROM images WHERE id = ?`, id)
|
||||||
var img model.Image
|
var img model.Image
|
||||||
var isDefault int
|
var isDefault int
|
||||||
var createdAt string
|
var createdAt string
|
||||||
if err := row.Scan(&img.ID, &img.Name, &img.Kind, &img.Version, &img.KernelPath, &img.InitrdPath, &isDefault, &createdAt); err != nil {
|
if err := row.Scan(&img.ID, &img.Name, &img.Kind, &img.Version, &img.KernelPath, &img.InitrdPath, &img.ISOPath, &isDefault, &createdAt); err != nil {
|
||||||
if err == sql.ErrNoRows {
|
if err == sql.ErrNoRows {
|
||||||
return nil, ErrNotFound
|
return nil, ErrNotFound
|
||||||
}
|
}
|
||||||
@@ -94,11 +94,11 @@ func (s *Images) SetDefault(ctx context.Context, id int64) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *Images) GetByName(ctx context.Context, name string) (*model.Image, error) {
|
func (s *Images) GetByName(ctx context.Context, name string) (*model.Image, error) {
|
||||||
row := s.DB.QueryRowContext(ctx, `SELECT id, name, kind, version, kernel_path, initrd_path, is_default, created_at FROM images WHERE name = ?`, name)
|
row := s.DB.QueryRowContext(ctx, `SELECT id, name, kind, version, kernel_path, initrd_path, iso_path, is_default, created_at FROM images WHERE name = ?`, name)
|
||||||
var img model.Image
|
var img model.Image
|
||||||
var isDefault int
|
var isDefault int
|
||||||
var createdAt string
|
var createdAt string
|
||||||
if err := row.Scan(&img.ID, &img.Name, &img.Kind, &img.Version, &img.KernelPath, &img.InitrdPath, &isDefault, &createdAt); err != nil {
|
if err := row.Scan(&img.ID, &img.Name, &img.Kind, &img.Version, &img.KernelPath, &img.InitrdPath, &img.ISOPath, &isDefault, &createdAt); err != nil {
|
||||||
if err == sql.ErrNoRows {
|
if err == sql.ErrNoRows {
|
||||||
return nil, ErrNotFound
|
return nil, ErrNotFound
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user