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