Advertisement
Sweetening

Untitled

Jul 20th, 2024
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.00 KB | None | 0 0
  1. The script will automatically detect the USB device and prompt the user for any necessary information.
  2. The script automatically detects the USB device.
  3. It prompts the user for the root device and video mode, with a default value for the video mode if none is provided.
  4. It mounts the USB device, loads the kernel and initrd using kexec, and executes the loaded kernel.
  5. Finally, it disables any swap space to prevent conflicts.
  6.  
  7. #!/bin/bash
  8.  
  9. # Function to detect the USB device
  10. detect_usb_device() {
  11. echo "Detecting USB device..."
  12. USB_DEVICE=$(lsblk -o NAME,MOUNTPOINT | grep -E "sd[b-z]1\s*$" | awk '{print $1}')
  13. if [ -z "$USB_DEVICE" ]; then
  14. echo "Error: No USB device detected."
  15. exit 1
  16. fi
  17. echo "USB device detected: /dev/$USB_DEVICE"
  18. USB_DEVICE="/dev/$USB_DEVICE"
  19. }
  20.  
  21. # Function to mount the USB device
  22. mount_usb_device() {
  23. echo "Mounting USB device to $USB_MOUNT_POINT..."
  24. mount $USB_DEVICE $USB_MOUNT_POINT
  25. if [ $? -ne 0 ]; then
  26. echo "Error: Failed to mount USB device."
  27. exit 1
  28. fi
  29. echo "USB device mounted successfully."
  30. }
  31.  
  32. # Function to get user input for the root device and video mode
  33. get_user_input() {
  34. read -p "Enter the root device (e.g., /dev/ps3da1): " ROOT_DEVICE
  35. read -p "Enter the video mode (default is 720p): " VIDEO_MODE
  36. VIDEO_MODE=${VIDEO_MODE:-720p}
  37. }
  38.  
  39. # Set variables for USB mount point and kernel/initrd paths
  40. USB_MOUNT_POINT="/mnt/usb"
  41.  
  42. # Detect the USB device
  43. detect_usb_device
  44.  
  45. # Check if USB device is already mounted
  46. if ! mount | grep -q "$USB_MOUNT_POINT"; then
  47. mount_usb_device
  48. else
  49. echo "USB device already mounted."
  50. fi
  51.  
  52. # Get user input for root device and video mode
  53. get_user_input
  54.  
  55. # Set kernel and initrd paths
  56. KERNEL_PATH="$USB_MOUNT_POINT/vmlinux"
  57. INITRD_PATH="$USB_MOUNT_POINT/initrd.gz"
  58.  
  59. # Load the kernel and initrd using kexec
  60. echo "Loading kernel and initrd..."
  61. kexec -l $KERNEL_PATH --initrd=$INITRD_PATH --append="root=$ROOT_DEVICE video=$VIDEO_MODE"
  62. if [ $? -ne 0 ]; then
  63. echo "Error: Failed to load kernel and initrd."
  64. exit 1
  65. fi
  66.  
  67. # Synchronize filesystem changes
  68. echo "Synchronizing filesystem changes..."
  69. sync
  70.  
  71. # Execute the loaded kernel
  72. echo "Executing the loaded kernel..."
  73. kexec -e
  74. if [ $? -ne 0 ]; then
  75. echo "Error: Failed to execute the loaded kernel."
  76. exit 1
  77. fi
  78.  
  79. # Disable swap (if any)
  80. echo "Disabling swap..."
  81. swapoff -a
  82. if [ $? -ne 0 ]; then
  83. echo "Error: Failed to disable swap."
  84. exit 1
  85. fi
  86.  
  87. echo "Boot process complete."
  88.  
  89.  
  90.  
  91.  
  92. How it works:
  93. The script detects and mounts the USB device.
  94. It prompts the user for the root device and video mode.
  95. It displays a menu of available firmware files on the USB device and allows the user to select one.
  96. It flashes the selected firmware file to the HDD (you need to specify the appropriate flashing command and target HDD device).
  97. It loads the kernel and initrd using kexec and boots into the new environment.
  98. It disables any swap space to prevent conflicts.
  99.  
  100.  
  101. #!/bin/bash
  102.  
  103. # Function to detect the USB device
  104. detect_usb_device() {
  105. echo "Detecting USB device..."
  106. USB_DEVICE=$(lsblk -o NAME,MOUNTPOINT | grep -E "sd[b-z]1\s*$" | awk '{print $1}')
  107. if [ -z "$USB_DEVICE" ]; then
  108. echo "Error: No USB device detected."
  109. exit 1
  110. fi
  111. echo "USB device detected: /dev/$USB_DEVICE"
  112. USB_DEVICE="/dev/$USB_DEVICE"
  113. }
  114.  
  115. # Function to mount the USB device
  116. mount_usb_device() {
  117. echo "Mounting USB device to $USB_MOUNT_POINT..."
  118. mount $USB_DEVICE $USB_MOUNT_POINT
  119. if [ $? -ne 0 ]; then
  120. echo "Error: Failed to mount USB device."
  121. exit 1
  122. fi
  123. echo "USB device mounted successfully."
  124. }
  125.  
  126. # Function to get user input for the root device and video mode
  127. get_user_input() {
  128. read -p "Enter the root device (e.g., /dev/ps3da1): " ROOT_DEVICE
  129. read -p "Enter the video mode (default is 720p): " VIDEO_MODE
  130. VIDEO_MODE=${VIDEO_MODE:-720p}
  131. }
  132.  
  133. # Function to display a menu and let the user select the firmware file
  134. select_firmware_file() {
  135. echo "Available firmware files:"
  136. PS3='Please select the firmware file to flash: '
  137. options=($(ls $USB_MOUNT_POINT/*.bin))
  138. select opt in "${options[@]}"; do
  139. if [[ -n "$opt" ]]; then
  140. FIRMWARE_FILE="$opt"
  141. break
  142. else
  143. echo "Invalid option. Try again."
  144. fi
  145. done
  146. echo "Selected firmware file: $FIRMWARE_FILE"
  147. }
  148.  
  149. # Function to flash the firmware to the HDD
  150. flash_firmware() {
  151. echo "Flashing firmware to HDD..."
  152. # Add your firmware flashing command here. For example:
  153. # dd if=$FIRMWARE_FILE of=/dev/ps3da bs=4096
  154. # Note: Replace /dev/ps3da with the actual HDD device
  155. if [ $? -ne 0 ]; then
  156. echo "Error: Failed to flash firmware."
  157. exit 1
  158. fi
  159. echo "Firmware flashed successfully."
  160. }
  161.  
  162. # Set variables for USB mount point
  163. USB_MOUNT_POINT="/mnt/usb"
  164.  
  165. # Detect the USB device
  166. detect_usb_device
  167.  
  168. # Check if USB device is already mounted
  169. if ! mount | grep -q "$USB_MOUNT_POINT"; then
  170. mount_usb_device
  171. else
  172. echo "USB device already mounted."
  173. fi
  174.  
  175. # Get user input for root device and video mode
  176. get_user_input
  177.  
  178. # Display the menu to select the firmware file
  179. select_firmware_file
  180.  
  181. # Flash the selected firmware file to the HDD
  182. flash_firmware
  183.  
  184. # Load the kernel and initrd using kexec
  185. echo "Loading kernel and initrd..."
  186. kexec -l $KERNEL_PATH --initrd=$INITRD_PATH --append="root=$ROOT_DEVICE video=$VIDEO_MODE"
  187. if [ $? -ne 0 ]; then
  188. echo "Error: Failed to load kernel and initrd."
  189. exit 1
  190. fi
  191.  
  192. # Synchronize filesystem changes
  193. echo "Synchronizing filesystem changes..."
  194. sync
  195.  
  196. # Execute the loaded kernel
  197. echo "Executing the loaded kernel..."
  198. kexec -e
  199. if [ $? -ne 0 ]; then
  200. echo "Error: Failed to execute the loaded kernel."
  201. exit 1
  202. fi
  203.  
  204. # Disable swap (if any)
  205. echo "Disabling swap..."
  206. swapoff -a
  207. if [ $? -ne 0 ]; then
  208. echo "Error: Failed to disable swap."
  209. exit 1
  210. fi
  211.  
  212. echo "Boot process complete."
  213.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement