mirror of
https://github.com/linuxkit/linuxkit.git
synced 2025-07-19 09:16:29 +00:00
Merge pull request #1264 from tych0/hoist-kernel-cmdline
Hoist kernel cmdline
This commit is contained in:
commit
c7d1438128
10
Makefile
10
Makefile
@ -26,8 +26,8 @@ test-bzImage: test-initrd.img
|
|||||||
|
|
||||||
# interactive versions need to use volume mounts
|
# interactive versions need to use volume mounts
|
||||||
.PHONY: qemu qemu-iso
|
.PHONY: qemu qemu-iso
|
||||||
qemu: moby-initrd.img moby-bzImage
|
qemu: moby-initrd.img moby-bzImage bin/moby moby.yaml
|
||||||
./scripts/qemu.sh $^
|
./scripts/qemu.sh moby-initrd.img moby-bzImage "$(shell bin/moby --cmdline moby.yaml)"
|
||||||
|
|
||||||
qemu-iso: alpine/mobylinux-bios.iso
|
qemu-iso: alpine/mobylinux-bios.iso
|
||||||
./scripts/qemu.sh $^
|
./scripts/qemu.sh $^
|
||||||
@ -56,8 +56,8 @@ else
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
.PHONY: hyperkit hyperkit-test
|
.PHONY: hyperkit hyperkit-test
|
||||||
hyperkit: scripts/hyperkit.sh bin/com.docker.hyperkit bin/vpnkit moby-initrd.img moby-bzImage
|
hyperkit: scripts/hyperkit.sh bin/com.docker.hyperkit bin/vpnkit moby-initrd.img moby-bzImage moby.yaml
|
||||||
./scripts/hyperkit.sh moby
|
./scripts/hyperkit.sh moby "$(shell bin/moby --cmdline moby.yaml)"
|
||||||
|
|
||||||
define check_test_log
|
define check_test_log
|
||||||
@cat $1 |grep -q 'Moby test suite PASSED'
|
@cat $1 |grep -q 'Moby test suite PASSED'
|
||||||
@ -65,7 +65,7 @@ endef
|
|||||||
|
|
||||||
hyperkit-test: scripts/hyperkit.sh bin/com.docker.hyperkit bin/vpnkit test-initrd.img test-bzImage
|
hyperkit-test: scripts/hyperkit.sh bin/com.docker.hyperkit bin/vpnkit test-initrd.img test-bzImage
|
||||||
rm -f disk.img
|
rm -f disk.img
|
||||||
script -q /dev/null ./scripts/hyperkit.sh test | tee test.log
|
script -q /dev/null ./scripts/hyperkit.sh test "$(shell bin/moby --cmdline moby.yaml)" | tee test.log
|
||||||
$(call check_test_log, test.log)
|
$(call check_test_log, test.log)
|
||||||
|
|
||||||
.PHONY: test
|
.PHONY: test
|
||||||
|
@ -14,7 +14,10 @@ import (
|
|||||||
|
|
||||||
// Moby is the type of a Moby config file
|
// Moby is the type of a Moby config file
|
||||||
type Moby struct {
|
type Moby struct {
|
||||||
Kernel string
|
Kernel struct {
|
||||||
|
Image string
|
||||||
|
Cmdline string
|
||||||
|
}
|
||||||
Init string
|
Init string
|
||||||
System []MobyImage
|
System []MobyImage
|
||||||
Daemon []MobyImage
|
Daemon []MobyImage
|
||||||
|
78
main.go
78
main.go
@ -4,11 +4,11 @@ import (
|
|||||||
"archive/tar"
|
"archive/tar"
|
||||||
"bytes"
|
"bytes"
|
||||||
"errors"
|
"errors"
|
||||||
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
@ -70,11 +70,38 @@ func dockerRunInput(input io.Reader, args ...string) ([]byte, error) {
|
|||||||
args = append([]string{"run", "--rm", "-i"}, args...)
|
args = append([]string{"run", "--rm", "-i"}, args...)
|
||||||
cmd := exec.Command(docker, args...)
|
cmd := exec.Command(docker, args...)
|
||||||
cmd.Stdin = input
|
cmd.Stdin = input
|
||||||
out, err := cmd.Output()
|
|
||||||
|
stderrPipe, err := cmd.StderrPipe()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return []byte{}, err
|
return []byte{}, err
|
||||||
}
|
}
|
||||||
return out, nil
|
|
||||||
|
stdoutPipe, err := cmd.StdoutPipe()
|
||||||
|
if err != nil {
|
||||||
|
return []byte{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = cmd.Start()
|
||||||
|
if err != nil {
|
||||||
|
return []byte{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
stdout, err := ioutil.ReadAll(stdoutPipe)
|
||||||
|
if err != nil {
|
||||||
|
return []byte{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
stderr, err := ioutil.ReadAll(stderrPipe)
|
||||||
|
if err != nil {
|
||||||
|
return []byte{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = cmd.Wait()
|
||||||
|
if err != nil {
|
||||||
|
return []byte{}, fmt.Errorf("%s: %s", err, stderr)
|
||||||
|
}
|
||||||
|
|
||||||
|
return stdout, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func untarKernel(buf *bytes.Buffer, bzimageName, ktarName string) (*bytes.Buffer, *bytes.Buffer, error) {
|
func untarKernel(buf *bytes.Buffer, bzimageName, ktarName string) (*bytes.Buffer, *bytes.Buffer, error) {
|
||||||
@ -129,17 +156,7 @@ func containersInitrd(containers []*bytes.Buffer) (*bytes.Buffer, error) {
|
|||||||
return w, nil
|
return w, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func build(configfile string) {
|
func build(m *Moby) {
|
||||||
config, err := ioutil.ReadFile(configfile)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("Cannot open config file: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
m, err := NewConfig(config)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("Invalid config: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
containers := []*bytes.Buffer{}
|
containers := []*bytes.Buffer{}
|
||||||
|
|
||||||
// get kernel bzImage and initrd tarball from container
|
// get kernel bzImage and initrd tarball from container
|
||||||
@ -148,7 +165,7 @@ func build(configfile string) {
|
|||||||
bzimageName = "bzImage"
|
bzimageName = "bzImage"
|
||||||
ktarName = "kernel.tar"
|
ktarName = "kernel.tar"
|
||||||
)
|
)
|
||||||
out, err := dockerRun(m.Kernel, "tar", "cf", "-", bzimageName, ktarName)
|
out, err := dockerRun(m.Kernel.Image, "tar", "cf", "-", bzimageName, ktarName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Failed to extract kernel image and tarball: %v", err)
|
log.Fatalf("Failed to extract kernel image and tarball: %v", err)
|
||||||
}
|
}
|
||||||
@ -211,11 +228,34 @@ func build(configfile string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var conf = "moby.yaml"
|
var (
|
||||||
|
conf string
|
||||||
|
cmdline bool
|
||||||
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
if len(os.Args) >= 2 {
|
flag.BoolVar(&cmdline, "cmdline", false, "Print the kernel command line and exit")
|
||||||
conf = os.Args[1]
|
flag.Parse()
|
||||||
|
|
||||||
|
conf = "moby.yaml"
|
||||||
|
if len(flag.Args()) > 0 {
|
||||||
|
conf = flag.Args()[0]
|
||||||
}
|
}
|
||||||
build(conf)
|
|
||||||
|
config, err := ioutil.ReadFile(conf)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Cannot open config file: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
m, err := NewConfig(config)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Invalid config: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if cmdline {
|
||||||
|
fmt.Printf("%s\n", m.Kernel.Cmdline)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
build(m)
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
kernel: "mobylinux/kernel:598481c08deafa37dccb33c88ad69fdecda57909"
|
kernel:
|
||||||
|
image: "mobylinux/kernel:598481c08deafa37dccb33c88ad69fdecda57909"
|
||||||
|
cmdline: "console=ttyS0 page_poison=1"
|
||||||
init: "mobylinux/init:2f1b5c1be1157cb17e5b1e6dee171dccdebb5277"
|
init: "mobylinux/init:2f1b5c1be1157cb17e5b1e6dee171dccdebb5277"
|
||||||
system:
|
system:
|
||||||
- name: sysctl
|
- name: sysctl
|
||||||
|
12
output.go
12
output.go
@ -9,8 +9,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
bios = "mobylinux/mkimage-iso-bios:6b3ef6d6bdcc5fdf2ee683febac99533c2268c89@sha256:2484146c4dfbd2eee83d9dd3adf84d9232e5dd739d8762275dcd50bf60a529c6"
|
bios = "mobylinux/mkimage-iso-bios:489b1f054a77a8f379d0bfc6cd91639b4db6b67c@sha256:0f058951aac4367d132682aa19eeb5cdcb05600a5d51fe5d0fcbd97b03ae4f87"
|
||||||
efi = "mobylinux/mkimage-iso-efi:40f35270037dae95584324427e56f829756ff145@sha256:ae5b37ae560a5e030342f3d493d4ad611f2694bcd54eba86bf42ca069da986a7"
|
efi = "mobylinux/mkimage-iso-efi:b210c58e096e53082d35b28fa2b52dba6ae200c8@sha256:10c2789bf5fbd27c35c5fe2f3b97f75a7108bbde389d0f5ed750e3e2dae95376"
|
||||||
)
|
)
|
||||||
|
|
||||||
func outputs(m *Moby, base string, bzimage []byte, initrd []byte) error {
|
func outputs(m *Moby, base string, bzimage []byte, initrd []byte) error {
|
||||||
@ -22,12 +22,12 @@ func outputs(m *Moby, base string, bzimage []byte, initrd []byte) error {
|
|||||||
return fmt.Errorf("Error writing %s output: %v", o.Format, err)
|
return fmt.Errorf("Error writing %s output: %v", o.Format, err)
|
||||||
}
|
}
|
||||||
case "iso-bios":
|
case "iso-bios":
|
||||||
err := outputISO(bios, base+".iso", bzimage, initrd)
|
err := outputISO(bios, base+".iso", bzimage, initrd, m.Kernel.Cmdline)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Error writing %s output: %v", o.Format, err)
|
return fmt.Errorf("Error writing %s output: %v", o.Format, err)
|
||||||
}
|
}
|
||||||
case "iso-efi":
|
case "iso-efi":
|
||||||
err := outputISO(efi, base+"-efi.iso", bzimage, initrd)
|
err := outputISO(efi, base+"-efi.iso", bzimage, initrd, m.Kernel.Cmdline)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Error writing %s output: %v", o.Format, err)
|
return fmt.Errorf("Error writing %s output: %v", o.Format, err)
|
||||||
}
|
}
|
||||||
@ -41,7 +41,7 @@ func outputs(m *Moby, base string, bzimage []byte, initrd []byte) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO add kernel command line
|
// TODO add kernel command line
|
||||||
func outputISO(image, filename string, bzimage []byte, initrd []byte) error {
|
func outputISO(image, filename string, bzimage []byte, initrd []byte, args ...string) error {
|
||||||
// first build the input tarball from kernel and initrd
|
// first build the input tarball from kernel and initrd
|
||||||
buf := new(bytes.Buffer)
|
buf := new(bytes.Buffer)
|
||||||
tw := tar.NewWriter(buf)
|
tw := tar.NewWriter(buf)
|
||||||
@ -75,7 +75,7 @@ func outputISO(image, filename string, bzimage []byte, initrd []byte) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
iso, err := dockerRunInput(buf, image)
|
iso, err := dockerRunInput(buf, append([]string{image}, args...)...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -7,8 +7,7 @@ PREFIX="moby"
|
|||||||
|
|
||||||
KERNEL="$PREFIX-bzImage"
|
KERNEL="$PREFIX-bzImage"
|
||||||
INITRD="$PREFIX-initrd.img"
|
INITRD="$PREFIX-initrd.img"
|
||||||
|
CMDLINE="$2"
|
||||||
CMDLINE="earlyprintk=serial console=ttyS0"
|
|
||||||
|
|
||||||
SLIRP_SOCK="$HOME/Library/Containers/com.docker.docker/Data/s50"
|
SLIRP_SOCK="$HOME/Library/Containers/com.docker.docker/Data/s50"
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
QEMU_IMAGE=mobylinux/qemu:156d2160c2ccf4d5118221bc2708f6c0981d54cc@sha256:e1345ba0400d6c45bf3bdf4f4ed425c3d7596d11e6553b83f17f5893dfc49f7b
|
QEMU_IMAGE=mobylinux/qemu:2e63db70759e37de6f9cc5cdf67c15f3aa8373c8@sha256:958c6bb1fca426cadf7a3664b8c019eba9f9e2ad4f6b4f3ed02d766fe5e709e4
|
||||||
|
|
||||||
# if not interactive
|
# if not interactive
|
||||||
if [ ! -t 0 -a -z "$1" ]
|
if [ ! -t 0 -a -z "$1" ]
|
||||||
@ -12,6 +12,7 @@ fi
|
|||||||
|
|
||||||
FILE=$1
|
FILE=$1
|
||||||
FILE2=$2
|
FILE2=$2
|
||||||
|
CMDLINE=$3
|
||||||
[ -z "$FILE" ] && FILE="$PWD/moby"
|
[ -z "$FILE" ] && FILE="$PWD/moby"
|
||||||
|
|
||||||
BASE=$(basename "$FILE")
|
BASE=$(basename "$FILE")
|
||||||
@ -32,4 +33,4 @@ BASE=$(basename "$FILE")
|
|||||||
MOUNTS="-v $FILE:/tmp/$BASE"
|
MOUNTS="-v $FILE:/tmp/$BASE"
|
||||||
BASE2=$(basename "$FILE2")
|
BASE2=$(basename "$FILE2")
|
||||||
[ ! -z "$FILE2" ] && MOUNTS="$MOUNTS -v $FILE2:/tmp/$BASE2"
|
[ ! -z "$FILE2" ] && MOUNTS="$MOUNTS -v $FILE2:/tmp/$BASE2"
|
||||||
docker run -it --rm $MOUNTS "$QEMU_IMAGE"
|
docker run -it --rm $MOUNTS "$QEMU_IMAGE" $CMDLINE
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
kernel: "mobylinux/kernel:598481c08deafa37dccb33c88ad69fdecda57909"
|
kernel:
|
||||||
|
image: "mobylinux/kernel:598481c08deafa37dccb33c88ad69fdecda57909"
|
||||||
|
cmdline: "console=ttyS0"
|
||||||
init: "mobylinux/init:2f1b5c1be1157cb17e5b1e6dee171dccdebb5277"
|
init: "mobylinux/init:2f1b5c1be1157cb17e5b1e6dee171dccdebb5277"
|
||||||
system:
|
system:
|
||||||
- name: binfmt
|
- name: binfmt
|
||||||
|
@ -10,4 +10,4 @@ RUN \
|
|||||||
|
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
CMD [ "/make-iso" ]
|
ENTRYPOINT [ "/make-iso" ]
|
||||||
|
@ -14,6 +14,7 @@ cd /tmp/iso
|
|||||||
|
|
||||||
INITRD="$(find . -name '*.img')"
|
INITRD="$(find . -name '*.img')"
|
||||||
KERNEL="$(find . -name vmlinuz64 -or -name bzImage)"
|
KERNEL="$(find . -name vmlinuz64 -or -name bzImage)"
|
||||||
|
CMDLINE="$*"
|
||||||
|
|
||||||
[ "$KERNEL" = "vmlinuz64" ] || mv "$KERNEL" vmlinuz64
|
[ "$KERNEL" = "vmlinuz64" ] || mv "$KERNEL" vmlinuz64
|
||||||
[ "$INITRD" = "initrd.img" ] || mv "$INITRD" initrd.img
|
[ "$INITRD" = "initrd.img" ] || mv "$INITRD" initrd.img
|
||||||
@ -29,7 +30,7 @@ CFG="DEFAULT linux
|
|||||||
LABEL linux
|
LABEL linux
|
||||||
KERNEL /vmlinuz64
|
KERNEL /vmlinuz64
|
||||||
INITRD /initrd.img
|
INITRD /initrd.img
|
||||||
APPEND earlyprintk=serial console=ttyS0 console=tty1 $*
|
APPEND ${CMDLINE}
|
||||||
"
|
"
|
||||||
|
|
||||||
printf "$CFG" > isolinux/isolinux.cfg
|
printf "$CFG" > isolinux/isolinux.cfg
|
||||||
|
@ -12,4 +12,4 @@ RUN \
|
|||||||
|
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
CMD [ "/make-efi" ]
|
ENTRYPOINT [ "/make-efi" ]
|
||||||
|
@ -14,6 +14,7 @@ cd /tmp/efi
|
|||||||
|
|
||||||
INITRD="$(find . -name '*.img')"
|
INITRD="$(find . -name '*.img')"
|
||||||
KERNEL="$(find . -name vmlinuz64 -or -name bzImage)"
|
KERNEL="$(find . -name vmlinuz64 -or -name bzImage)"
|
||||||
|
CMDLINE="$*"
|
||||||
|
|
||||||
[ "$KERNEL" = "vmlinuz64" ] || mv "$KERNEL" vmlinuz64
|
[ "$KERNEL" = "vmlinuz64" ] || mv "$KERNEL" vmlinuz64
|
||||||
[ "$INITRD" = "initrd.img" ] || mv "$INITRD" initrd.img
|
[ "$INITRD" = "initrd.img" ] || mv "$INITRD" initrd.img
|
||||||
@ -21,13 +22,10 @@ KERNEL="$(find . -name vmlinuz64 -or -name bzImage)"
|
|||||||
# clean up subdirectories
|
# clean up subdirectories
|
||||||
find . -mindepth 1 -maxdepth 1 -type d | xargs rm -rf
|
find . -mindepth 1 -maxdepth 1 -type d | xargs rm -rf
|
||||||
|
|
||||||
# Docker for Windows specific options, should be moved
|
|
||||||
WINDOWS_OPTIONS="mobyplatform=windows vsyscall=emulate page_poison=1 panic=1 rootdelay=300 noautodetect"
|
|
||||||
|
|
||||||
# Create a EFI boot file with kernel and initrd. From:
|
# Create a EFI boot file with kernel and initrd. From:
|
||||||
# https://github.com/haraldh/mkrescue-uefi/blob/master/mkrescue-uefi.sh
|
# https://github.com/haraldh/mkrescue-uefi/blob/master/mkrescue-uefi.sh
|
||||||
cp /usr/lib/gummiboot/linuxx64.efi.stub .
|
cp /usr/lib/gummiboot/linuxx64.efi.stub .
|
||||||
echo "earlyprintk=ttyS0,115200 console=ttyS0,115200 $WINDOWS_OPTIONS" > cmdline.txt
|
echo "${CMDLINE} rootdelay=300 noautodetect" > cmdline.txt
|
||||||
|
|
||||||
objcopy \
|
objcopy \
|
||||||
--add-section .osrel=/etc/os-release --change-section-vma .osrel=0x20000 \
|
--add-section .osrel=/etc/os-release --change-section-vma .osrel=0x20000 \
|
||||||
|
@ -30,7 +30,7 @@ then
|
|||||||
then
|
then
|
||||||
ARGS="$ARGS -initrd $INITRD"
|
ARGS="$ARGS -initrd $INITRD"
|
||||||
fi
|
fi
|
||||||
ARGS="$ARGS -append console=ttyS0 -drive file=systemdisk.img,format=raw"
|
ARGS="$ARGS -drive file=systemdisk.img,format=raw"
|
||||||
else
|
else
|
||||||
echo "no recognised boot media" >2
|
echo "no recognised boot media" >2
|
||||||
exit 1
|
exit 1
|
||||||
@ -38,4 +38,10 @@ fi
|
|||||||
|
|
||||||
echo "$ARGS" | grep -q systemdisk && qemu-img create -f raw systemdisk.img 256M
|
echo "$ARGS" | grep -q systemdisk && qemu-img create -f raw systemdisk.img 256M
|
||||||
|
|
||||||
qemu-system-x86_64 -device virtio-rng-pci -serial stdio -vnc none -m 1024 $ARGS $*
|
CMDLINE="$*"
|
||||||
|
if [ -z "${CMDLINE}" ]
|
||||||
|
then
|
||||||
|
CMDLINE="console=ttyS0"
|
||||||
|
fi
|
||||||
|
|
||||||
|
qemu-system-x86_64 -device virtio-rng-pci -serial stdio -vnc none -m 1024 -append "${CMDLINE}" $ARGS
|
||||||
|
Loading…
Reference in New Issue
Block a user