OE4T / tegra-demo-distro

Reference/demonstration distro for meta-tegra
MIT License
73 stars 74 forks source link

/data on another disk #241

Closed maggu2810 closed 1 year ago

maggu2810 commented 1 year ago

Hello, I already created a custom distribution for a special board setup. The board I am using consists of a Jetson Xavier NX and a 16 GB SD/MMC (/dev/mmcblk0). Flashing using ./doflash works as expected.

The hardware also contains a 128GB SSD (/dev/sda). I would like to create a GPT partition table, one primary ext4 partition and mount that one as /data.

I tested this setup using the normal doflash, boot the board, mount -o remount,rw /, edit fstab to use sda1 as data, parted to create partition layout (mktable, mkpart), mkfs.ext4, ...

Now I would like to automate the process, so it requires only a doflash and all is set up automatically.

Can you help me what to do?

repos/meta-mender/meta-mender-core/classes/mender-setup.bbclass:MENDER_DATA_PART ??= "${MENDER_DATA_PART_DEFAULT}"
repos/meta-mender/meta-mender-core/classes/mender-setup.bbclass:MENDER_DATA_PART_DEFAULT = "${MENDER_STORAGE_DEVICE_BASE}${MENDER_DATA_PART_NUMBER}"

I assume one thing I need to do is to define MENDER_DATA_PART to /dev/sda1. Correct?

How can I automate the the parted + mkfs.ext4 step? Should I create a service that checks if /dev/sda1 exists and if it is missing, it creates it using parted and mkfs.ext4 calls? Hook this before /data is mounted? E.g. something like that:

if [ -e /dev/sda -a -e /dev/sda1 -a "$(blkid --output value --match-tag PTTYPE /dev/sda)" = "gpt" -a "$(blkid --output value --match-tag LABEL /dev/sda1)" = "magic_identifier" ]; then
  echo "all fine"
else
  parted -a opt -s /dev/sda "mktable gpt"
  while [ -e /dev/sda1 ]; do usleep 10000; done
  parted -a opt -s /dev/sda "mkpart primary ext4 1M 100%"
  while [ ! -e /dev/sda1 ]; do usleep 10000; done
  mkfs.ext4 -F -L magic_identifier /dev/sda1
  #systemctl reboot
fi

??

dwalkes commented 1 year ago

Hi @maggu2810

Should I create a service that checks if /dev/sda1 exists and if it is missing, it creates it using parted and mkfs.ext4 calls? Hook this before /data is mounted?

The way I've handled this in the past is by using a custom platform-pre-switchroot which will allow you to run custom steps during the init process and before the rootfs is mounted and the remaining services which may need to use the /data partition try to start.

Since the last time I set this up there have been some new changes in https://github.com/OE4T/meta-tegra/wiki/initrd-flashing-support to support flashing alternate devices at startup, however based on a quick search of the script at https://github.com/OE4T/meta-tegra/blob/master/recipes-bsp/tegra-binaries/tegra-helper-scripts/initrd-flash.sh it appears this will only support flashing other devices when the rootfs is located there ($ROOTFS_DEVICE). So I suspect your best option is still to use platform-pre-switchroot or similar.

maggu2810 commented 1 year ago

Hi @dwalkes , /etc/platform-pre-switchroot is a possible hook. Thanks for pointing me to that direction. I will give it a try.

I am pretty sure I will find it while reading the existing recipes etc. As you did already something similar can you point me to some changes that are necessary? Then I can move forward faster.

Thanks again

maggu2810 commented 1 year ago

I assume I found the most of relevant information.