finish 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #!/bin/sh
  2. # Copyright (C) 2011 O.S. Systems Software LTDA.
  3. # Licensed on MIT
  4. finish_enabled() {
  5. return 0
  6. }
  7. finish_run() {
  8. if [ -n "$ROOTFS_DIR" ]; then
  9. if [ ! -d $ROOTFS_DIR/dev ]; then
  10. fatal "ERROR: There's no '/dev' on rootfs."
  11. fi
  12. # Unmount anything that was automounted by busybox via mdev-mount.sh.
  13. # We're about to switch_root, and leaving anything mounted will prevent
  14. # the next rootfs from modifying the block device. Ignore ROOT_DISK,
  15. # if it was set by setup-live, because it'll be mounted over loopback
  16. # to ROOTFS_DIR.
  17. local dev
  18. for dev in /run/media/*; do
  19. if mountpoint -q "${dev}" && [ "${dev##*/}" != "${ROOT_DISK}" ]; then
  20. umount -f "${dev}" || debug "Failed to unmount ${dev}"
  21. fi
  22. done
  23. info "Switching root to '$ROOTFS_DIR'..."
  24. debug "Moving basic mounts onto rootfs"
  25. for dir in `awk '/\/dev.* \/run\/media/{print $2}' /proc/mounts`; do
  26. # Parse any OCT or HEX encoded chars such as spaces
  27. # in the mount points to actual ASCII chars
  28. dir=`printf $dir`
  29. mkdir -p "${ROOTFS_DIR}/media/${dir##*/}"
  30. mount -n --move "$dir" "${ROOTFS_DIR}/media/${dir##*/}"
  31. done
  32. debug "Moving /dev, /proc, /sys and /run onto rootfs..."
  33. mount --move /dev $ROOTFS_DIR/dev
  34. mount --move /proc $ROOTFS_DIR/proc
  35. mount --move /sys $ROOTFS_DIR/sys
  36. mount --move /run $ROOTFS_DIR/run
  37. cd $ROOTFS_DIR
  38. exec switch_root $ROOTFS_DIR ${bootparam_init:-/sbin/init}
  39. else
  40. debug "No rootfs has been set"
  41. fi
  42. }