Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- The script will automatically detect the USB device and prompt the user for any necessary information.
- The script automatically detects the USB device.
- It prompts the user for the root device and video mode, with a default value for the video mode if none is provided.
- It mounts the USB device, loads the kernel and initrd using kexec, and executes the loaded kernel.
- Finally, it disables any swap space to prevent conflicts.
- #!/bin/bash
- # Function to detect the USB device
- detect_usb_device() {
- echo "Detecting USB device..."
- USB_DEVICE=$(lsblk -o NAME,MOUNTPOINT | grep -E "sd[b-z]1\s*$" | awk '{print $1}')
- if [ -z "$USB_DEVICE" ]; then
- echo "Error: No USB device detected."
- exit 1
- fi
- echo "USB device detected: /dev/$USB_DEVICE"
- USB_DEVICE="/dev/$USB_DEVICE"
- }
- # Function to mount the USB device
- mount_usb_device() {
- echo "Mounting USB device to $USB_MOUNT_POINT..."
- mount $USB_DEVICE $USB_MOUNT_POINT
- if [ $? -ne 0 ]; then
- echo "Error: Failed to mount USB device."
- exit 1
- fi
- echo "USB device mounted successfully."
- }
- # Function to get user input for the root device and video mode
- get_user_input() {
- read -p "Enter the root device (e.g., /dev/ps3da1): " ROOT_DEVICE
- read -p "Enter the video mode (default is 720p): " VIDEO_MODE
- VIDEO_MODE=${VIDEO_MODE:-720p}
- }
- # Set variables for USB mount point and kernel/initrd paths
- USB_MOUNT_POINT="/mnt/usb"
- # Detect the USB device
- detect_usb_device
- # Check if USB device is already mounted
- if ! mount | grep -q "$USB_MOUNT_POINT"; then
- mount_usb_device
- else
- echo "USB device already mounted."
- fi
- # Get user input for root device and video mode
- get_user_input
- # Set kernel and initrd paths
- KERNEL_PATH="$USB_MOUNT_POINT/vmlinux"
- INITRD_PATH="$USB_MOUNT_POINT/initrd.gz"
- # Load the kernel and initrd using kexec
- echo "Loading kernel and initrd..."
- kexec -l $KERNEL_PATH --initrd=$INITRD_PATH --append="root=$ROOT_DEVICE video=$VIDEO_MODE"
- if [ $? -ne 0 ]; then
- echo "Error: Failed to load kernel and initrd."
- exit 1
- fi
- # Synchronize filesystem changes
- echo "Synchronizing filesystem changes..."
- sync
- # Execute the loaded kernel
- echo "Executing the loaded kernel..."
- kexec -e
- if [ $? -ne 0 ]; then
- echo "Error: Failed to execute the loaded kernel."
- exit 1
- fi
- # Disable swap (if any)
- echo "Disabling swap..."
- swapoff -a
- if [ $? -ne 0 ]; then
- echo "Error: Failed to disable swap."
- exit 1
- fi
- echo "Boot process complete."
- How it works:
- The script detects and mounts the USB device.
- It prompts the user for the root device and video mode.
- It displays a menu of available firmware files on the USB device and allows the user to select one.
- It flashes the selected firmware file to the HDD (you need to specify the appropriate flashing command and target HDD device).
- It loads the kernel and initrd using kexec and boots into the new environment.
- It disables any swap space to prevent conflicts.
- #!/bin/bash
- # Function to detect the USB device
- detect_usb_device() {
- echo "Detecting USB device..."
- USB_DEVICE=$(lsblk -o NAME,MOUNTPOINT | grep -E "sd[b-z]1\s*$" | awk '{print $1}')
- if [ -z "$USB_DEVICE" ]; then
- echo "Error: No USB device detected."
- exit 1
- fi
- echo "USB device detected: /dev/$USB_DEVICE"
- USB_DEVICE="/dev/$USB_DEVICE"
- }
- # Function to mount the USB device
- mount_usb_device() {
- echo "Mounting USB device to $USB_MOUNT_POINT..."
- mount $USB_DEVICE $USB_MOUNT_POINT
- if [ $? -ne 0 ]; then
- echo "Error: Failed to mount USB device."
- exit 1
- fi
- echo "USB device mounted successfully."
- }
- # Function to get user input for the root device and video mode
- get_user_input() {
- read -p "Enter the root device (e.g., /dev/ps3da1): " ROOT_DEVICE
- read -p "Enter the video mode (default is 720p): " VIDEO_MODE
- VIDEO_MODE=${VIDEO_MODE:-720p}
- }
- # Function to display a menu and let the user select the firmware file
- select_firmware_file() {
- echo "Available firmware files:"
- PS3='Please select the firmware file to flash: '
- options=($(ls $USB_MOUNT_POINT/*.bin))
- select opt in "${options[@]}"; do
- if [[ -n "$opt" ]]; then
- FIRMWARE_FILE="$opt"
- break
- else
- echo "Invalid option. Try again."
- fi
- done
- echo "Selected firmware file: $FIRMWARE_FILE"
- }
- # Function to flash the firmware to the HDD
- flash_firmware() {
- echo "Flashing firmware to HDD..."
- # Add your firmware flashing command here. For example:
- # dd if=$FIRMWARE_FILE of=/dev/ps3da bs=4096
- # Note: Replace /dev/ps3da with the actual HDD device
- if [ $? -ne 0 ]; then
- echo "Error: Failed to flash firmware."
- exit 1
- fi
- echo "Firmware flashed successfully."
- }
- # Set variables for USB mount point
- USB_MOUNT_POINT="/mnt/usb"
- # Detect the USB device
- detect_usb_device
- # Check if USB device is already mounted
- if ! mount | grep -q "$USB_MOUNT_POINT"; then
- mount_usb_device
- else
- echo "USB device already mounted."
- fi
- # Get user input for root device and video mode
- get_user_input
- # Display the menu to select the firmware file
- select_firmware_file
- # Flash the selected firmware file to the HDD
- flash_firmware
- # Load the kernel and initrd using kexec
- echo "Loading kernel and initrd..."
- kexec -l $KERNEL_PATH --initrd=$INITRD_PATH --append="root=$ROOT_DEVICE video=$VIDEO_MODE"
- if [ $? -ne 0 ]; then
- echo "Error: Failed to load kernel and initrd."
- exit 1
- fi
- # Synchronize filesystem changes
- echo "Synchronizing filesystem changes..."
- sync
- # Execute the loaded kernel
- echo "Executing the loaded kernel..."
- kexec -e
- if [ $? -ne 0 ]; then
- echo "Error: Failed to execute the loaded kernel."
- exit 1
- fi
- # Disable swap (if any)
- echo "Disabling swap..."
- swapoff -a
- if [ $? -ne 0 ]; then
- echo "Error: Failed to disable swap."
- exit 1
- fi
- echo "Boot process complete."
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement