github.com/mvdan/u-root-coreutils@v0.0.0-20230122170626-c2eef2898555/tools/mkinitramfs/main.go (about) 1 // Copyright 2015-2018 the u-root Authors. All rights reserved 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 // mkinitramfs creates a u-root initramfs given the list of files on the 6 // command line. 7 package mkinitramfs 8 9 import ( 10 "flag" 11 "log" 12 "os" 13 14 "github.com/mvdan/u-root-coreutils/pkg/uroot" 15 "github.com/mvdan/u-root-coreutils/pkg/uroot/initramfs" 16 ) 17 18 var outputFile = flag.String("o", "initramfs.cpio", "Initramfs output file") 19 20 func main() { 21 flag.Parse() 22 23 if flag.NArg() == 0 { 24 log.Fatalf("must specify at least one file to include in initramfs") 25 } 26 logger := log.New(os.Stderr, "", log.LstdFlags) 27 28 // Open the target initramfs file. 29 w, err := initramfs.CPIO.OpenWriter(logger, *outputFile) 30 if err != nil { 31 log.Fatalf("failed to open cpio archive %q: %v", *outputFile, err) 32 } 33 34 files := initramfs.NewFiles() 35 archive := &initramfs.Opts{ 36 Files: files, 37 OutputFile: w, 38 BaseArchive: uroot.DefaultRamfs().Reader(), 39 } 40 if err := uroot.ParseExtraFiles(logger, archive.Files, flag.Args(), false); err != nil { 41 log.Fatalf("failed to parse file names %v: %v", flag.Args(), err) 42 } 43 44 if err := initramfs.Write(archive); err != nil { 45 log.Fatalf("failed to write archive %q: %v", *outputFile, err) 46 } 47 }