Files
backup_to_external_m.2/old_scripts/bootstrap_usb_tools.sh
root 56c07dbe49 Complete rewrite: Single working LVM block-level backup script
- Removed 40+ broken/messy scripts, moved to old_scripts/
- Created lvm_block_backup.sh - proper block-level LVM snapshot backup
- Uses dd for block-level cloning instead of file-level rsync
- Successfully tested: 462GB backup in 33 minutes
- Creates exact, bootable clone of internal drive to external drive
- Proper LVM snapshot management with cleanup
- Clear documentation in README_BACKUP.md
- Clean, minimal solution that actually works
2025-09-30 17:35:22 +02:00

166 lines
4.6 KiB
Bash
Executable File

#!/bin/bash
# USB Live System Migration Bootstrap Script
# This script downloads and sets up the LVM migration tools on a live system
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
echo -e "${GREEN}=== LVM Migration Bootstrap ===${NC}"
echo "Setting up LVM migration tools on live system..."
# Create working directory
WORK_DIR="/tmp/lvm-migration"
mkdir -p "$WORK_DIR"
cd "$WORK_DIR"
echo "Working directory: $WORK_DIR"
# Function to create the prepare script inline
create_prepare_script() {
cat > prepare_live_system.sh << 'EOF'
#!/bin/bash
# Live System Preparation Script for LVM Migration
set -e
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m'
log() { echo -e "${BLUE}[$(date '+%H:%M:%S')]${NC} $1"; }
error() { echo -e "${RED}[ERROR]${NC} $1" >&2; exit 1; }
success() { echo -e "${GREEN}[SUCCESS]${NC} $1"; }
log "Updating package lists..."
apt update || { error "Failed to update package lists"; }
log "Installing required packages..."
apt install -y lvm2 cryptsetup rsync parted pv grub-efi-amd64 e2fsprogs dosfstools || {
error "Failed to install required packages"
}
log "Loading kernel modules..."
modprobe dm_mod dm_crypt dm_snapshot || true
success "Live system prepared for LVM migration!"
echo "Now run: ./migrate_to_lvm.sh"
EOF
chmod +x prepare_live_system.sh
}
# Function to create the main migration script inline
create_migration_script() {
# This is a simplified version - the full script is quite large
cat > migrate_to_lvm.sh << 'EOF'
#!/bin/bash
# LVM Migration Script - Bootstrap Version
# Downloads the full migration script and runs it
REPO_URL="YOUR_REPO_URL_HERE" # Replace with actual repo URL
FULL_SCRIPT_URL="$REPO_URL/migrate_to_lvm.sh"
echo "Downloading full migration script..."
wget -O migrate_to_lvm_full.sh "$FULL_SCRIPT_URL" || {
echo "Cannot download from repository. Using embedded version..."
# Here you would embed the full script or provide local copy
echo "Please manually copy the full migrate_to_lvm.sh script"
exit 1
}
chmod +x migrate_to_lvm_full.sh
./migrate_to_lvm_full.sh "$@"
EOF
chmod +x migrate_to_lvm.sh
}
# Create a manual setup guide
create_manual_setup() {
cat > SETUP_INSTRUCTIONS.txt << 'EOF'
LVM Migration Setup Instructions
===============================
1. Boot from this USB stick into live system
2. Open terminal and run: sudo -i
3. Run: /media/*/migration_tools/bootstrap.sh
OR manually follow these steps:
Manual Setup:
1. Update packages: apt update
2. Install tools: apt install -y lvm2 cryptsetup rsync parted pv grub-efi-amd64
3. Load modules: modprobe dm_mod dm_crypt dm_snapshot
4. Create workspace: mkdir -p /tmp/lvm-migration && cd /tmp/lvm-migration
5. Copy migration scripts from external drive or USB
6. Run: ./migrate_to_lvm.sh
Drive Configuration (adjust as needed):
- Internal drive: /dev/nvme0n1 (source)
- External M.2: /dev/sdc (target)
- USB stick: /dev/sdb (tools)
Important Notes:
- This will DESTROY all data on the external M.2 drive
- Internal drive remains unchanged as backup
- External M.2 will become bootable LVM system
- Update BIOS boot order after migration
For full documentation, see LIVE_USB_MIGRATION_GUIDE.md
EOF
}
# Create all the files
echo "Creating preparation script..."
create_prepare_script
echo "Creating migration bootstrap..."
create_migration_script
echo "Creating setup instructions..."
create_manual_setup
# Create a simple launcher script
cat > bootstrap.sh << 'EOF'
#!/bin/bash
echo "=== LVM Migration Bootstrap ==="
echo "1. Prepare live system (install packages)"
echo "2. Run LVM migration"
echo "3. Show instructions"
read -p "Select option [1-3]: " choice
case $choice in
1) sudo ./prepare_live_system.sh ;;
2) sudo ./migrate_to_lvm.sh ;;
3) cat SETUP_INSTRUCTIONS.txt ;;
*) echo "Invalid option" ;;
esac
EOF
chmod +x bootstrap.sh
echo -e "${GREEN}Bootstrap scripts created in $WORK_DIR${NC}"
echo
echo "Contents:"
ls -la
echo
echo -e "${YELLOW}Next steps:${NC}"
echo "1. Copy the migration tools from your development directory to a location accessible from live USB"
echo "2. Boot from the USB stick"
echo "3. Run the bootstrap script to set up the migration environment"
# Copy the actual migration tools if they exist in current directory
if [ -f "../migrate_to_lvm.sh" ]; then
echo
echo "Copying actual migration tools..."
cp ../migrate_to_lvm.sh ../lvm_snapshot_backup.sh ../validate_lvm_migration.sh . 2>/dev/null || true
cp ../LIVE_USB_MIGRATION_GUIDE.md . 2>/dev/null || true
echo "Migration tools copied to $WORK_DIR"
fi
success "Bootstrap setup complete!"