When mount local filesystem in os starting, we will create or use a local existed logical volume to replace remote filesystem.
Signed-off-by: Xu Xijian hdxuxijian@163.com --- .../dracut-initrd/bin/set-local-sysroot.sh | 78 +++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 container/dracut-initrd/bin/set-local-sysroot.sh
diff --git a/container/dracut-initrd/bin/set-local-sysroot.sh b/container/dracut-initrd/bin/set-local-sysroot.sh new file mode 100644 index 0000000..65e6d3e --- /dev/null +++ b/container/dracut-initrd/bin/set-local-sysroot.sh @@ -0,0 +1,78 @@ +#!/bin/sh + +analyse_kernel_cmdline_params() { + rootfs="$(getarg root=)" + rootfs_src=$(echo $"$rootfs" | sed 's////') + timestamp="$(basename $root)" + export rootfs_src timestamp +} + +rsync_src_lv() { + local src_lv="$1" + + [ -e "$src_lv" ] && return # /dev/mapper/os-openeuler-aarch64-20210226104900 + + # create logical volume + src_lv_devname="$(basename $src_lv)" # os-openeuler_aarch64_20210226104900 + lvm lvcreate -L 10G --name "${src_lv_devname#os-}" os # openeuler_aarch64_20210226104900 + mke2fs -t ext4 -F "$src_lv" + + # sync nfsroot to $src_lv + mkdir -p /mnt1 && mount -t nfs "$rootfs_src" /mnt1 + mkdir -p /mnt2 && mount "$src_lv" /mnt2 + cp -a /mnt1/. /mnt2/ + umount /mnt1 /mnt2 + + # change permission of "$src_lv" to readonly + lvm lvchange --permission r "$src_lv" +} + +snapshot_boot_lv() { + local src_lv="$1" + local boot_lv="$2" + + [ "$src_lv" == "$boot_lv" ] && return + + lvm lvremove --force "$boot_lv" + boot_lv_devname="$(basename $boot_lv)" + lvm lvcreate --size 10G --name ${boot_lv_devname#os-} --snapshot "$src_lv" +} + +set_sysroot() { + boot_lv="$1" + umount "$NEWROOT" + mount "$boot_lv" "$NEWROOT" +} + +if ! getargbool 0 local; then + exit 0 +fi + +analyse_kernel_cmdline_params + +sed -i "s/^locking_type = .*/locking_type = 1/" /etc/lvm/lvm.conf + +use_root_partition="$(getarg use_root_partition=)" +if [ -n "$use_root_partition" ]; then + src_lv="$use_root_partition" # "$use_root_partition" "$root_$timestamp", root from getarg root= + rsync_src_lv "$src_lv" +else + src_lv="/dev/mapper/os-openeuler_aarch64_$timestamp" # "os-openeuler_aarch64_$timestamp" + [ -e "src_lv" ] || { + echo "warn dracut: FATAL: no src_lv with local mount, reboot" + reboot + } +fi + +save_root_partition="$(getarg save_root_partition=)" +if [ -n "$save_root_partition" ]; then + boot_lv="$save_root_partition" # "os-openeuler_aarch64_$save_partition" +else + boot_lv="/dev/mapper/os-openeuler_aarch64_default" +fi + +snapshot_boot_lv "$src_lv" "$boot_lv" + +set_sysroot "$boot_lv" + +exit 0
On Mon, Mar 08, 2021 at 12:56:24PM +0800, Xu Xijian wrote:
When mount local filesystem in os starting, we will create or use a local existed logical volume to replace remote filesystem.
Signed-off-by: Xu Xijian hdxuxijian@163.com
.../dracut-initrd/bin/set-local-sysroot.sh | 78 +++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 container/dracut-initrd/bin/set-local-sysroot.sh
diff --git a/container/dracut-initrd/bin/set-local-sysroot.sh b/container/dracut-initrd/bin/set-local-sysroot.sh new file mode 100644 index 0000000..65e6d3e --- /dev/null +++ b/container/dracut-initrd/bin/set-local-sysroot.sh @@ -0,0 +1,78 @@ +#!/bin/sh
+analyse_kernel_cmdline_params() {
- rootfs="$(getarg root=)"
Add sample like: root=172.168.131.2:/os/openeuler/aarch64/xxj-snapshot/20210226104900
- rootfs_src=$(echo $"$rootfs" | sed 's////')
- timestamp="$(basename $root)"
- export rootfs_src timestamp
+}
+rsync_src_lv() {
rsync_src_lv() => sync_src_lv()
- local src_lv="$1"
add one comment for src_lv maybe enough? /dev/mapper/os-openeuler_aarch64_20.03_20210226104900
- [ -e "$src_lv" ] && return # /dev/mapper/os-openeuler-aarch64-20210226104900
- # create logical volume
- src_lv_devname="$(basename $src_lv)" # os-openeuler_aarch64_20210226104900
- lvm lvcreate -L 10G --name "${src_lv_devname#os-}" os # openeuler_aarch64_20210226104900
maybe you need -y for lvcreate here?
- mke2fs -t ext4 -F "$src_lv"
- # sync nfsroot to $src_lv
- mkdir -p /mnt1 && mount -t nfs "$rootfs_src" /mnt1
- mkdir -p /mnt2 && mount "$src_lv" /mnt2
- cp -a /mnt1/. /mnt2/
- umount /mnt1 /mnt2
- # change permission of "$src_lv" to readonly
- lvm lvchange --permission r "$src_lv"
+}
+snapshot_boot_lv() {
- local src_lv="$1"
- local boot_lv="$2"
- [ "$src_lv" == "$boot_lv" ] && return
- lvm lvremove --force "$boot_lv"
- boot_lv_devname="$(basename $boot_lv)"
- lvm lvcreate --size 10G --name ${boot_lv_devname#os-} --snapshot "$src_lv"
+}
+set_sysroot() {
- boot_lv="$1"
- umount "$NEWROOT"
- mount "$boot_lv" "$NEWROOT"
+}
+if ! getargbool 0 local; then
- exit 0
+fi
+analyse_kernel_cmdline_params
+sed -i "s/^locking_type = .*/locking_type = 1/" /etc/lvm/lvm.conf
+use_root_partition="$(getarg use_root_partition=)" +if [ -n "$use_root_partition" ]; then
- src_lv="$use_root_partition" # "$use_root_partition" "$root_$timestamp", root from getarg root=
=> # "$use_root_partition": /dev/mapper/os-${os}_${os_arch}_${os_version}_${timestamp} The format of src_lv need to be changed.
- rsync_src_lv "$src_lv"
+else
- src_lv="/dev/mapper/os-openeuler_aarch64_$timestamp" # "os-openeuler_aarch64_$timestamp"
- [ -e "src_lv" ] || {
echo "warn dracut: FATAL: no src_lv with local mount, reboot"
reboot
- }
+fi
+save_root_partition="$(getarg save_root_partition=)" +if [ -n "$save_root_partition" ]; then
- boot_lv="$save_root_partition" # "os-openeuler_aarch64_$save_partition"
The format of boot_lv need to be changed.
+else
- boot_lv="/dev/mapper/os-openeuler_aarch64_default"
os-openeuler_aarch64_default should be os-${os}_${os_arch}_${os_version}. The same as upon.
-------- Thanks Yu Chuan
+fi
+snapshot_boot_lv "$src_lv" "$boot_lv"
+set_sysroot "$boot_lv"
+exit 0
2.23.0
On Wed, Mar 10, 2021 at 05:13:46PM +0800, Yu Chuan wrote:
On Mon, Mar 08, 2021 at 12:56:24PM +0800, Xu Xijian wrote:
When mount local filesystem in os starting, we will create or use a local existed logical volume to replace remote filesystem.
Signed-off-by: Xu Xijian hdxuxijian@163.com
.../dracut-initrd/bin/set-local-sysroot.sh | 78 +++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 container/dracut-initrd/bin/set-local-sysroot.sh
diff --git a/container/dracut-initrd/bin/set-local-sysroot.sh b/container/dracut-initrd/bin/set-local-sysroot.sh new file mode 100644 index 0000000..65e6d3e --- /dev/null +++ b/container/dracut-initrd/bin/set-local-sysroot.sh @@ -0,0 +1,78 @@ +#!/bin/sh
+analyse_kernel_cmdline_params() {
- rootfs="$(getarg root=)"
Add sample like: root=172.168.131.2:/os/openeuler/aarch64/xxj-snapshot/20210226104900
OK.
- rootfs_src=$(echo $"$rootfs" | sed 's////')
- timestamp="$(basename $root)"
- export rootfs_src timestamp
+}
+rsync_src_lv() {
rsync_src_lv() => sync_src_lv()
- local src_lv="$1"
add one comment for src_lv maybe enough? /dev/mapper/os-openeuler_aarch64_20.03_20210226104900
OK.
- [ -e "$src_lv" ] && return # /dev/mapper/os-openeuler-aarch64-20210226104900
- # create logical volume
- src_lv_devname="$(basename $src_lv)" # os-openeuler_aarch64_20210226104900
- lvm lvcreate -L 10G --name "${src_lv_devname#os-}" os # openeuler_aarch64_20210226104900
maybe you need -y for lvcreate here?
OK.
- mke2fs -t ext4 -F "$src_lv"
- # sync nfsroot to $src_lv
- mkdir -p /mnt1 && mount -t nfs "$rootfs_src" /mnt1
- mkdir -p /mnt2 && mount "$src_lv" /mnt2
- cp -a /mnt1/. /mnt2/
- umount /mnt1 /mnt2
- # change permission of "$src_lv" to readonly
- lvm lvchange --permission r "$src_lv"
+}
+snapshot_boot_lv() {
- local src_lv="$1"
- local boot_lv="$2"
- [ "$src_lv" == "$boot_lv" ] && return
- lvm lvremove --force "$boot_lv"
- boot_lv_devname="$(basename $boot_lv)"
- lvm lvcreate --size 10G --name ${boot_lv_devname#os-} --snapshot "$src_lv"
+}
+set_sysroot() {
- boot_lv="$1"
- umount "$NEWROOT"
- mount "$boot_lv" "$NEWROOT"
+}
+if ! getargbool 0 local; then
- exit 0
+fi
+analyse_kernel_cmdline_params
+sed -i "s/^locking_type = .*/locking_type = 1/" /etc/lvm/lvm.conf
+use_root_partition="$(getarg use_root_partition=)" +if [ -n "$use_root_partition" ]; then
- src_lv="$use_root_partition" # "$use_root_partition" "$root_$timestamp", root from getarg root=
=> # "$use_root_partition": /dev/mapper/os-${os}_${os_arch}_${os_version}_${timestamp} The format of src_lv need to be changed.
OK.
- rsync_src_lv "$src_lv"
+else
- src_lv="/dev/mapper/os-openeuler_aarch64_$timestamp" # "os-openeuler_aarch64_$timestamp"
- [ -e "src_lv" ] || {
echo "warn dracut: FATAL: no src_lv with local mount, reboot"
reboot
- }
+fi
+save_root_partition="$(getarg save_root_partition=)" +if [ -n "$save_root_partition" ]; then
- boot_lv="$save_root_partition" # "os-openeuler_aarch64_$save_partition"
The format of boot_lv need to be changed.
Good.
+else
- boot_lv="/dev/mapper/os-openeuler_aarch64_default"
os-openeuler_aarch64_default should be os-${os}_${os_arch}_${os_version}. The same as upon.
Good.
-------- Thanks, Xijian