[Why] The current way to get timestamp is strongly dependent on the directory layout, but our os_version is a symbolic link, which corresponds to a source folder structure that is not fixed.
But its suffix format is the same, so we get timestamp by intercepting the suffix.
Signed-off-by: Yu Chuan 13186087857@163.com --- container/dracut-initrd/bin/set-local-sysroot.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/container/dracut-initrd/bin/set-local-sysroot.sh b/container/dracut-initrd/bin/set-local-sysroot.sh index c6aa8d114d68..0a1125eaace7 100644 --- a/container/dracut-initrd/bin/set-local-sysroot.sh +++ b/container/dracut-initrd/bin/set-local-sysroot.sh @@ -14,7 +14,11 @@ analyse_kernel_cmdline_params() {
# example: $nfs_server_ip:/os/${os}/${os_arch}/${os_version}-snapshots/20210310005959 rootfs_src=$(echo $"$rootfs" | sed 's////') - timestamp="$(basename $rootfs_src)" + + # adapt $nfs_server_ip:/os/${os}/${os_arch}/${os_version}-2021-03-10-00-59-59 + timestamp="$(echo ${rootfs_src//-/} | grep -oE '[0-9]{14}$')" + [ -n "$timestamp" ] || reboot_with_msg "cannot find right timestamp" + os="$(echo $rootfs_src | awk -F '/|-' '{print $2}')" os_arch="$(echo $rootfs_src | awk -F '/|-' '{print $3}')" os_version="$(echo $rootfs_src | awk -F '/|-' '{print $4}')"
Reviewed-by: Xu Xijian hdxuxijian@163.com
On Tue, Apr 27, 2021 at 03:10:54PM +0800, Yu Chuan wrote:
[Why] The current way to get timestamp is strongly dependent on the directory layout, but our os_version is a symbolic link, which corresponds to a source folder structure that is not fixed.
But its suffix format is the same, so we get timestamp by intercepting the suffix.
Signed-off-by: Yu Chuan 13186087857@163.com
container/dracut-initrd/bin/set-local-sysroot.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/container/dracut-initrd/bin/set-local-sysroot.sh b/container/dracut-initrd/bin/set-local-sysroot.sh index c6aa8d114d68..0a1125eaace7 100644 --- a/container/dracut-initrd/bin/set-local-sysroot.sh +++ b/container/dracut-initrd/bin/set-local-sysroot.sh @@ -14,7 +14,11 @@ analyse_kernel_cmdline_params() {
# example: $nfs_server_ip:/os/${os}/${os_arch}/${os_version}-snapshots/20210310005959 rootfs_src=$(echo $"$rootfs" | sed 's/\///')
- timestamp="$(basename $rootfs_src)"
- # adapt $nfs_server_ip:/os/${os}/${os_arch}/${os_version}-2021-03-10-00-59-59
- timestamp="$(echo ${rootfs_src//-/} | grep -oE '[0-9]{14}$')"
- [ -n "$timestamp" ] || reboot_with_msg "cannot find right timestamp"
- os="$(echo $rootfs_src | awk -F '/|-' '{print $2}')" os_arch="$(echo $rootfs_src | awk -F '/|-' '{print $3}')" os_version="$(echo $rootfs_src | awk -F '/|-' '{print $4}')"
-- 2.23.0