mirror of
https://github.com/siderolabs/talos.git
synced 2025-08-26 17:11:19 +02:00
feat(init): mount partitions dynamically (#169)
This commit is contained in:
parent
04bb2dab8c
commit
453bc48ae7
@ -108,7 +108,7 @@ DEFAULT Dianemo
|
|||||||
LABEL Dianemo
|
LABEL Dianemo
|
||||||
KERNEL /boot/vmlinuz
|
KERNEL /boot/vmlinuz
|
||||||
INITRD /boot/initramfs.xz
|
INITRD /boot/initramfs.xz
|
||||||
APPEND ${KERNEL_SELF_PROTECTION_PROJECT_KERNEL_PARAMS} ip=dhcp consoleblank=0 console=tty0 console=ttyS0,9600 dianemo.autonomy.io/root=${DIANEMO_ROOT} dianemo.autonomy.io/userdata=${DIANEMO_USERDATA} dianemo.autonomy.io/platform=${DIANEMO_PLATFORM}
|
APPEND ${KERNEL_SELF_PROTECTION_PROJECT_KERNEL_PARAMS} ip=dhcp consoleblank=0 console=tty0 console=ttyS0,9600 dianemo.autonomy.io/userdata=${DIANEMO_USERDATA} dianemo.autonomy.io/platform=${DIANEMO_PLATFORM}
|
||||||
EOF
|
EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -120,7 +120,6 @@ function cleanup {
|
|||||||
|
|
||||||
# Defaults
|
# Defaults
|
||||||
|
|
||||||
DIANEMO_ROOT="sda"
|
|
||||||
DIANEMO_USERDATA=""
|
DIANEMO_USERDATA=""
|
||||||
DIANEMO_PLATFORM="bare-metal"
|
DIANEMO_PLATFORM="bare-metal"
|
||||||
RAW_IMAGE="/out/image.raw"
|
RAW_IMAGE="/out/image.raw"
|
||||||
@ -136,7 +135,7 @@ KERNEL_SELF_PROTECTION_PROJECT_KERNEL_PARAMS="page_poison=1 slab_nomerge pti=on"
|
|||||||
case "$1" in
|
case "$1" in
|
||||||
image)
|
image)
|
||||||
shift
|
shift
|
||||||
while getopts "b:flt:p:u:" opt; do
|
while getopts "b:flp:u:" opt; do
|
||||||
case ${opt} in
|
case ${opt} in
|
||||||
b )
|
b )
|
||||||
DEVICE=${OPTARG}
|
DEVICE=${OPTARG}
|
||||||
@ -157,10 +156,6 @@ case "$1" in
|
|||||||
DIANEMO_PLATFORM=${OPTARG}
|
DIANEMO_PLATFORM=${OPTARG}
|
||||||
echo "Using kernel parameter dianemo.autonomy.io/platform=${DIANEMO_PLATFORM}"
|
echo "Using kernel parameter dianemo.autonomy.io/platform=${DIANEMO_PLATFORM}"
|
||||||
;;
|
;;
|
||||||
t )
|
|
||||||
DIANEMO_ROOT=${OPTARG}
|
|
||||||
echo "Using kernel parameter dianemo.autonomy.io/root=${DIANEMO_ROOT}"
|
|
||||||
;;
|
|
||||||
u )
|
u )
|
||||||
DIANEMO_USERDATA=${OPTARG}
|
DIANEMO_USERDATA=${OPTARG}
|
||||||
echo "Using kernel parameter dianemo.autonomy.io/userdata=${DIANEMO_USERDATA}"
|
echo "Using kernel parameter dianemo.autonomy.io/userdata=${DIANEMO_USERDATA}"
|
||||||
|
@ -64,7 +64,7 @@
|
|||||||
"sudo add-apt-repository \"deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable\"",
|
"sudo add-apt-repository \"deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable\"",
|
||||||
"sudo apt-get -y update",
|
"sudo apt-get -y update",
|
||||||
"sudo apt-get -y install docker-ce",
|
"sudo apt-get -y install docker-ce",
|
||||||
"sudo docker run --privileged --volume /dev:/dev autonomy/dianemo:{{ user `version` }} image -b /dev/xvdf -t /dev/xvda -f -p aws -u none"
|
"sudo docker run --privileged --volume /dev:/dev autonomy/dianemo:{{ user `version` }} image -b /dev/xvdf -f -p aws -u none"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
@ -1,10 +1,6 @@
|
|||||||
package constants
|
package constants
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// KernelParamRoot is the kernel parameter name for specifying the root
|
|
||||||
// disk.
|
|
||||||
KernelParamRoot = "dianemo.autonomy.io/root"
|
|
||||||
|
|
||||||
// KernelParamUserData is the kernel parameter name for specifying the URL
|
// KernelParamUserData is the kernel parameter name for specifying the URL
|
||||||
// to the user data.
|
// to the user data.
|
||||||
KernelParamUserData = "dianemo.autonomy.io/userdata"
|
KernelParamUserData = "dianemo.autonomy.io/userdata"
|
||||||
|
@ -16,6 +16,38 @@ import (
|
|||||||
"unsafe"
|
"unsafe"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// GetDevWithAttribute returns the dev name of a block device matching the ATTRIBUTE=VALUE
|
||||||
|
// pair. Supported attributes are:
|
||||||
|
// TYPE: filesystem type
|
||||||
|
// UUID: filesystem uuid
|
||||||
|
// LABEL: filesystem label
|
||||||
|
func GetDevWithAttribute(attribute, value string) (string, error) {
|
||||||
|
var cache C.blkid_cache
|
||||||
|
|
||||||
|
ret := C.blkid_get_cache(&cache, nil)
|
||||||
|
if ret != 0 {
|
||||||
|
return "", fmt.Errorf("failed to get blkid cache: %d", ret)
|
||||||
|
}
|
||||||
|
|
||||||
|
C.blkid_probe_all(cache)
|
||||||
|
|
||||||
|
cs_attribute := C.CString(attribute)
|
||||||
|
cs_value := C.CString(value)
|
||||||
|
defer C.free(unsafe.Pointer(cs_attribute))
|
||||||
|
defer C.free(unsafe.Pointer(cs_value))
|
||||||
|
|
||||||
|
devname := C.blkid_get_devname(cache, cs_attribute, cs_value)
|
||||||
|
defer C.free(unsafe.Pointer(devname))
|
||||||
|
|
||||||
|
// If you have called blkid_get_cache(), you should call blkid_put_cache()
|
||||||
|
// when you are done using the blkid library functions. This will save the
|
||||||
|
// cache to the blkid.tab file, if you have write access to the file. It
|
||||||
|
// will also free all associated devices and tags:
|
||||||
|
C.blkid_put_cache(cache)
|
||||||
|
|
||||||
|
return C.GoString(devname), nil
|
||||||
|
}
|
||||||
|
|
||||||
// NewProbeFromFilename executes lblkid blkid_new_probe_from_filename.
|
// NewProbeFromFilename executes lblkid blkid_new_probe_from_filename.
|
||||||
func NewProbeFromFilename(s string) (C.blkid_probe, error) {
|
func NewProbeFromFilename(s string) (C.blkid_probe, error) {
|
||||||
cs := C.CString(s)
|
cs := C.CString(s)
|
||||||
|
@ -9,7 +9,6 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/autonomy/dianemo/src/initramfs/cmd/init/pkg/constants"
|
"github.com/autonomy/dianemo/src/initramfs/cmd/init/pkg/constants"
|
||||||
"github.com/autonomy/dianemo/src/initramfs/cmd/init/pkg/kernel"
|
|
||||||
"github.com/autonomy/dianemo/src/initramfs/cmd/init/pkg/mount/blkid"
|
"github.com/autonomy/dianemo/src/initramfs/cmd/init/pkg/mount/blkid"
|
||||||
"golang.org/x/sys/unix"
|
"golang.org/x/sys/unix"
|
||||||
)
|
)
|
||||||
@ -206,54 +205,56 @@ func mountBlockDevices(s string) (err error) {
|
|||||||
func probe() (b []*BlockDevice, err error) {
|
func probe() (b []*BlockDevice, err error) {
|
||||||
b = []*BlockDevice{}
|
b = []*BlockDevice{}
|
||||||
|
|
||||||
arguments, err := kernel.ParseProcCmdline()
|
if err := appendBlockDeviceWithLabel(&b, constants.RootPartitionLabel); err != nil {
|
||||||
if err != nil {
|
return nil, err
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
if err := appendBlockDeviceWithLabel(&b, constants.DataPartitionLabel); err != nil {
|
||||||
if root, ok := arguments[constants.KernelParamRoot]; ok {
|
return nil, err
|
||||||
if _, err := os.Stat(root); os.IsNotExist(err) {
|
|
||||||
return nil, fmt.Errorf("device does not exist: %s", root)
|
|
||||||
}
|
|
||||||
pr, err := blkid.NewProbeFromFilename(root)
|
|
||||||
defer blkid.FreeProbe(pr)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("failed to probe %s: %s", root, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
ls := blkid.ProbeGetPartitions(pr)
|
|
||||||
nparts := blkid.ProbeGetPartitionsPartlistNumOfPartitions(ls)
|
|
||||||
|
|
||||||
for i := 0; i < nparts; i++ {
|
|
||||||
dev := fmt.Sprintf("%s%d", root, i+1)
|
|
||||||
pr, err = blkid.NewProbeFromFilename(dev)
|
|
||||||
defer blkid.FreeProbe(pr)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("failed to probe %s: %s", dev, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
blkid.DoProbe(pr)
|
|
||||||
UUID, err := blkid.ProbeLookupValue(pr, "UUID", nil)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
TYPE, err := blkid.ProbeLookupValue(pr, "TYPE", nil)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
LABEL, err := blkid.ProbeLookupValue(pr, "LABEL", nil)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
b = append(b, &BlockDevice{
|
|
||||||
dev: dev,
|
|
||||||
UUID: UUID,
|
|
||||||
TYPE: TYPE,
|
|
||||||
LABEL: LABEL,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return b, nil
|
return b, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func appendBlockDeviceWithLabel(b *[]*BlockDevice, value string) error {
|
||||||
|
devname, err := blkid.GetDevWithAttribute("LABEL", value)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
blockDevice, err := probeDevice(devname)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
*b = append(*b, blockDevice)
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func probeDevice(devname string) (*BlockDevice, error) {
|
||||||
|
pr, err := blkid.NewProbeFromFilename(devname)
|
||||||
|
defer blkid.FreeProbe(pr)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to probe %s: %s", devname, err)
|
||||||
|
}
|
||||||
|
blkid.DoProbe(pr)
|
||||||
|
UUID, err := blkid.ProbeLookupValue(pr, "UUID", nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
TYPE, err := blkid.ProbeLookupValue(pr, "TYPE", nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
LABEL, err := blkid.ProbeLookupValue(pr, "LABEL", nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &BlockDevice{
|
||||||
|
dev: devname,
|
||||||
|
UUID: UUID,
|
||||||
|
TYPE: TYPE,
|
||||||
|
LABEL: LABEL,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user