init+dhcp changes for Squashfs root file systems
We can do away with a bunch of hacks now, but we’ll keep them around for a little while to make updates easier (i.e. to boot with old and new gokr-packer versions, just in case people don’t update both at the same time).
This commit is contained in:
parent
d1d355d840
commit
4a126f13af
@ -235,8 +235,12 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if b, ok := opts[dhcp4.OptionDomainNameServer]; ok {
|
if b, ok := opts[dhcp4.OptionDomainNameServer]; ok {
|
||||||
|
resolvConf := "/etc/resolv.conf"
|
||||||
|
if dest, err := os.Readlink("/etc/resolv.conf"); err == nil && dest == "/tmp/resolv.conf" {
|
||||||
|
resolvConf = "/tmp/resolv.conf"
|
||||||
|
}
|
||||||
// Get the symlink out of the way, if any.
|
// Get the symlink out of the way, if any.
|
||||||
if err := os.Remove("/etc/resolv.conf"); err != nil && !os.IsNotExist(err) {
|
if err := os.Remove(resolvConf); err != nil && !os.IsNotExist(err) {
|
||||||
log.Fatalf("resolv.conf: %v", err)
|
log.Fatalf("resolv.conf: %v", err)
|
||||||
}
|
}
|
||||||
var lines []string
|
var lines []string
|
||||||
@ -245,7 +249,7 @@ func main() {
|
|||||||
lines = append(lines, fmt.Sprintf("search %s", string(domain)))
|
lines = append(lines, fmt.Sprintf("search %s", string(domain)))
|
||||||
}
|
}
|
||||||
lines = append(lines, fmt.Sprintf("nameserver %v", net.IP(b)))
|
lines = append(lines, fmt.Sprintf("nameserver %v", net.IP(b)))
|
||||||
if err := ioutil.WriteFile("/etc/resolv.conf", []byte(strings.Join(lines, "\n")+"\n"), 0644); err != nil {
|
if err := ioutil.WriteFile(resolvConf, []byte(strings.Join(lines, "\n")+"\n"), 0644); err != nil {
|
||||||
log.Fatalf("resolv.conf: %v", err)
|
log.Fatalf("resolv.conf: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
16
gokrazy.go
16
gokrazy.go
@ -68,7 +68,7 @@ func watchdog() {
|
|||||||
//
|
//
|
||||||
// - mounts /dev, /tmp, /proc, /sys and /perm file systems
|
// - mounts /dev, /tmp, /proc, /sys and /perm file systems
|
||||||
// - mounts and populate /etc tmpfs overlay
|
// - mounts and populate /etc tmpfs overlay
|
||||||
// - sets hostname from the /hostname file
|
// - sets hostname from the /etc/hostname file
|
||||||
// - sets HTTP password from the gokr-pw.txt file
|
// - sets HTTP password from the gokr-pw.txt file
|
||||||
// - configures the loopback network interface
|
// - configures the loopback network interface
|
||||||
//
|
//
|
||||||
@ -87,7 +87,10 @@ func Boot(userBuildTimestamp string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
hostnameb, err := ioutil.ReadFile("/hostname")
|
hostnameb, err := ioutil.ReadFile("/etc/hostname")
|
||||||
|
if err != nil && os.IsNotExist(err) {
|
||||||
|
hostnameb, err = ioutil.ReadFile("/hostname")
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -98,10 +101,13 @@ func Boot(userBuildTimestamp string) error {
|
|||||||
|
|
||||||
pw, err := ioutil.ReadFile("/perm/gokr-pw.txt")
|
pw, err := ioutil.ReadFile("/perm/gokr-pw.txt")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
pw, err = ioutil.ReadFile("/gokr-pw.txt")
|
pw, err = ioutil.ReadFile("/etc/gokr-pw.txt")
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("could read neither /perm/gokr-pw.txt nor /gokr-pw.txt: %v", err)
|
|
||||||
}
|
}
|
||||||
|
if err != nil && os.IsNotExist(err) {
|
||||||
|
pw, err = ioutil.ReadFile("/gokr-pw.txt")
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("could read neither /perm/gokr-pw.txt, nor /etc/gokr-pw.txt, nor /gokr-pw.txt: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
httpPassword = strings.TrimSpace(string(pw))
|
httpPassword = strings.TrimSpace(string(pw))
|
||||||
|
25
mount.go
25
mount.go
@ -8,11 +8,9 @@ import (
|
|||||||
"syscall"
|
"syscall"
|
||||||
)
|
)
|
||||||
|
|
||||||
func mountfs() error {
|
// mountCompat deals with old FAT root file systems, to cover the case where
|
||||||
if err := syscall.Mount("tmpfs", "/tmp", "tmpfs", syscall.MS_NOSUID|syscall.MS_NODEV|syscall.MS_RELATIME, "size=50M"); err != nil {
|
// users use an old gokr-packer with a new github.com/gokrazy/gokrazy package.
|
||||||
return fmt.Errorf("tmpfs on /tmp: %v", err)
|
func mountCompat() error {
|
||||||
}
|
|
||||||
|
|
||||||
// Symlink /etc/resolv.conf. We cannot do this in the root file
|
// Symlink /etc/resolv.conf. We cannot do this in the root file
|
||||||
// system itself, as FAT does not support symlinks.
|
// system itself, as FAT does not support symlinks.
|
||||||
if err := syscall.Mount("tmpfs", "/etc", "tmpfs", syscall.MS_NOSUID|syscall.MS_NODEV|syscall.MS_RELATIME, "size=1M"); err != nil {
|
if err := syscall.Mount("tmpfs", "/etc", "tmpfs", syscall.MS_NOSUID|syscall.MS_NODEV|syscall.MS_RELATIME, "size=1M"); err != nil {
|
||||||
@ -40,6 +38,23 @@ func mountfs() error {
|
|||||||
if err := ioutil.WriteFile("/etc/hosts", []byte("127.0.0.1 localhost\n::1 localhost\n"), 0644); err != nil {
|
if err := ioutil.WriteFile("/etc/hosts", []byte("127.0.0.1 localhost\n::1 localhost\n"), 0644); err != nil {
|
||||||
return fmt.Errorf("/etc/hosts: %v", err)
|
return fmt.Errorf("/etc/hosts: %v", err)
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func mountfs() error {
|
||||||
|
if err := syscall.Mount("tmpfs", "/tmp", "tmpfs", syscall.MS_NOSUID|syscall.MS_NODEV|syscall.MS_RELATIME, "size=50M"); err != nil {
|
||||||
|
return fmt.Errorf("tmpfs on /tmp: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := os.Symlink("/proc/net/pnp", "/tmp/resolv.conf"); err != nil {
|
||||||
|
return fmt.Errorf("etc: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err := os.Lstat("/etc/resolv.conf"); err != nil && os.IsNotExist(err) {
|
||||||
|
if err := mountCompat(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if err := syscall.Mount("devtmpfs", "/dev", "devtmpfs", 0, ""); err != nil {
|
if err := syscall.Mount("devtmpfs", "/dev", "devtmpfs", 0, ""); err != nil {
|
||||||
if sce, ok := err.(syscall.Errno); ok && sce == syscall.EBUSY {
|
if sce, ok := err.(syscall.Errno); ok && sce == syscall.EBUSY {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user