github.com/mem/u-root@v2.0.1-0.20181004165302-9b18b4636a33+incompatible/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/u-root/u-root/pkg/uroot" 15 "github.com/u-root/u-root/pkg/uroot/initramfs" 16 ) 17 18 var ( 19 outputFile = flag.String("o", "initramfs.cpio", "Initramfs output file") 20 ) 21 22 func main() { 23 flag.Parse() 24 25 if flag.NArg() == 0 { 26 log.Fatalf("must specify at least one file to include in initramfs") 27 } 28 29 // Open the target initramfs file. 30 w, err := initramfs.CPIO.OpenWriter(*outputFile, "", "") 31 if err != nil { 32 log.Fatalf("failed to open cpio archive %q: %v", *outputFile, err) 33 } 34 35 files := initramfs.NewFiles() 36 archive := &initramfs.Opts{ 37 Files: files, 38 OutputFile: w, 39 BaseArchive: uroot.DefaultRamfs.Reader(), 40 } 41 logger := log.New(os.Stderr, "", log.LstdFlags) 42 if err := uroot.ParseExtraFiles(logger, archive.Files, flag.Args(), false); err != nil { 43 log.Fatalf("failed to parse file names %v: %v", flag.Args(), err) 44 } 45 46 if err := initramfs.Write(archive); err != nil { 47 log.Fatalf("failed to write archive %q: %v", *outputFile, err) 48 } 49 }