Comprehensive Step-by-Step Guide to Install, Configure, and Run Ubuntu on Lenovo P15 Gen-1 Laptop
Dual-Boot Setup with Dedicated AI Environment Optimization
Key Takeaways
- Data Backup Essential: Always back up your data before starting the installation to prevent data loss.
- BIOS Configuration: Properly configure BIOS settings, including disabling Secure Boot and enabling virtualization.
- AI Environment Setup: Install necessary development tools and optimize the system for running local AI models effectively.
1. Pre-Installation Preparation
1.1 Backup Important Data
Before proceeding with the installation of Ubuntu, it is crucial to back up all important data to avoid any potential data loss. This includes files on both your primary Windows drive and the secondary drive where Ubuntu will be installed.
1.2 Disable Secure Boot
Secure Boot must be disabled to ensure a smooth installation of Ubuntu. Follow these steps:
- Restart your Lenovo P15 Gen-1 laptop.
- Press
F1
or F2
during startup to enter the BIOS settings.
- Navigate to the Security tab.
- Locate the Secure Boot option and set it to Disabled.
- Save the changes and exit the BIOS.
1.3 Enable Virtualization
Enabling virtualization is essential for optimal performance, especially when running AI models.
- Enter the BIOS settings by pressing
F1
or F2
during boot.
- Navigate to the Config tab.
- Under CPU, enable Intel Virtualization Technology.
- Save the changes and exit the BIOS.
1.4 Verify BIOS Settings
Ensure that the BIOS settings are correctly configured for Ubuntu installation.
- Boot Mode: UEFI
- Virtualization: Enabled
- SATA Mode: AHCI
1.5 Create a Bootable Ubuntu USB Drive
You need a bootable USB drive to install Ubuntu. Follow these steps:
- Download the latest Ubuntu LTS ISO from the official Ubuntu website.
- Use a tool like Rufus (for Windows) or
dd
(for Linux) to create a bootable USB drive.
- For
dd
on Linux, use the following command:
sudo dd if=/path/to/ubuntu.iso of=/dev/sdX bs=4M status=progress && sync
Replace /dev/sdX
with your USB drive identifier.
1.6 Partition the Secondary Drive
Prepare the secondary drive for Ubuntu installation.
- Boot into Windows.
- Open Disk Management by pressing
Win + X
and selecting it from the menu.
- Identify the secondary drive (
SKHynix_HFS256GD
in your case).
- Right-click on the secondary drive and choose Shrink Volume.
- Allocate at least 100 GB of unallocated space for Ubuntu.
- Click Shrink to apply the changes.
1.7 Troubleshooting Pre-Installation
- If Secure Boot cannot be disabled, ensure that Legacy Boot Support is enabled in the BIOS settings.
- If the USB drive does not appear in the boot menu, try using a different USB port or recreate the bootable USB using GPT/UEFI mode with Rufus.
2. Installing Ubuntu on the Secondary Drive
2.1 Boot from the Ubuntu USB Drive
- Insert the bootable Ubuntu USB drive into the laptop.
- Restart the laptop.
- Press
F12
during boot to access the boot menu.
- Select the USB drive from the list of bootable devices.
2.2 Start Ubuntu Installation
- Once the Ubuntu live environment loads, select Install Ubuntu.
- Choose your preferred language and keyboard layout.
- Connect to a Wi-Fi network if prompted to ensure updates can be downloaded during installation.
2.3 Configure Partitions
Manual partitioning allows you to designate specific partitions for Ubuntu on the secondary drive.
- At the Installation Type screen, select Something else.
- Identify the secondary drive (e.g.,
/dev/sdb
).
- Create the following partitions on the secondary drive:
-
EFI System Partition (ESP):
- Size: 512 MB
- Type: EFI System Partition
- Mount point:
/boot/efi
-
Root Partition:
- Size: 80 GB
- Type: Ext4
- Mount point:
/
-
Swap Partition:
- Size: 32 GB (matching your RAM size)
- Type: Swap area
-
Home Partition (Optional):
- Size: Remaining space
- Type: Ext4
- Mount point:
/home
2.4 Install GRUB Bootloader
Ensure that GRUB is installed on the secondary drive to manage the dual-boot setup.
- Set the Device for boot loader installation to the secondary drive (e.g.,
/dev/sdb
).
- Proceed with the installation by clicking Install Now.
2.5 Complete Installation
- Follow the on-screen instructions to set up your user account and timezone.
- Wait for the installation to complete.
- Restart the laptop when prompted and remove the USB drive.
2.6 Troubleshooting Installation
- If the installation process hangs or encounters errors, try recreating the bootable USB or verify the integrity of the downloaded Ubuntu ISO.
- If Ubuntu does not boot after installation, use the Boot-Repair tool to fix GRUB.
3. Configuring GRUB for Dual-Boot
3.1 Verify GRUB Menu
- Upon restarting, the GRUB menu should appear, allowing you to choose between Ubuntu and Windows.
- If GRUB does not appear, boot into Ubuntu from the USB drive and run the following commands in the terminal:
sudo update-grub
Then reboot the laptop to check again.
3.2 Set Default Boot Option
- To set Ubuntu as the default operating system, open the terminal in Ubuntu.
- Edit the GRUB configuration file by running:
sudo nano /etc/default/grub
- Find the line
GRUB_DEFAULT=0
and set it to the desired menu entry for Ubuntu.
- Save the file by pressing
Ctrl + O
and exit with Ctrl + X
.
- Update GRUB with the new settings:
sudo update-grub
- Reboot the laptop to apply the changes.
3.3 Troubleshooting GRUB Issues
- GRUB Not Showing Windows: Boot into Ubuntu and run
sudo update-grub
to refresh the GRUB configuration.
- NVIDIA Driver Issues: Reinstall NVIDIA drivers using
sudo ubuntu-drivers autoinstall
.
- Bootloader Not Loading: Use the Boot-Repair tool to reinstall and repair GRUB.
4. Post-Installation Optimizations
4.1 Update and Upgrade System
Ensure your Ubuntu system is up-to-date with the latest packages and security updates.
sudo apt update && sudo apt upgrade -y
4.2 Install NVIDIA Drivers
Install the NVIDIA Quadro T1000 drivers to enable GPU acceleration for AI models.
- Add the NVIDIA PPA repository:
sudo add-apt-repository ppa:graphics-drivers/ppa
- Update package lists:
sudo apt update
- Install the NVIDIA driver:
sudo apt install nvidia-driver-535
- Reboot the system to apply changes:
sudo reboot
4.3 Install CUDA and cuDNN
CUDA and cuDNN are essential for running AI models efficiently.
- Download the CUDA Toolkit from the NVIDIA website.
- Follow the installation instructions provided on the CUDA download page.
- Download cuDNN from the NVIDIA cuDNN page and follow the official installation guide.
4.4 Set Up Python Environment
Creating a virtual environment isolates your AI projects and manages dependencies effectively.
- Install Python and necessary libraries:
sudo apt install python3 python3-pip python3-venv -y
- Create a virtual environment:
python3 -m venv ai_env
- Activate the virtual environment:
source ai_env/bin/activate
- Install AI libraries:
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118
pip install diffusers transformers
4.5 Optimize System Performance
Enhancing system performance ensures efficient AI model processing.
- Disable unnecessary services to free up resources:
sudo systemctl disable bluetooth.service
sudo systemctl disable cups.service
- Enable
zram
for swap compression:
sudo apt install zram-config
sudo systemctl enable zram-config
- Install power management tools:
sudo apt install tlp tlp-rdw -y
sudo systemctl enable tlp
4.6 Install Essential Development Tools
Install tools necessary for AI development and model training.
sudo apt install build-essential git cmake python3-pip -y
4.7 Troubleshooting Post-Installation
- GPU Not Recognized: Ensure NVIDIA drivers are correctly installed and run
nvidia-smi
to verify GPU status.
- CUDA Errors: Confirm that CUDA and cuDNN versions are compatible with the installed NVIDIA driver.
- Virtual Environment Issues: Recreate the virtual environment if dependencies are not correctly installed.
5. Setting Up the AI Environment
5.1 Install AI Frameworks
Install popular AI frameworks like PyTorch and TensorFlow for model development and execution.
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118
pip install tensorflow
5.2 Install Model Libraries
Install libraries that facilitate working with various AI models.
pip install transformers diffusers
5.3 Download and Setup AI Models
- Clone repositories for AI models, such as Stable Diffusion:
git clone https://github.com/CompVis/stable-diffusion.git
cd stable-diffusion
pip install -r requirements.txt
- Download pre-trained models as required by the specific AI framework.
5.4 Optimize Execution for AI Tasks
Enhance AI model performance by utilizing mixed-precision training and efficient resource management.
- Install NVIDIA Apex for mixed-precision training:
git clone https://github.com/NVIDIA/apex
cd apex
pip install -v --disable-pip-version-check --no-cache-dir .
- Ensure that models are utilizing the GPU by specifying the device in your scripts:
import torch
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
model.to(device)
5.5 Manage Larger Datasets
Efficiently handle large datasets required for training AI models.
- Mount external drives or leverage cloud storage solutions like AWS S3 or Google Drive.
- Use symbolic links to reference datasets stored externally:
ln -s /path/to/external/dataset /home/user/dataset
5.6 Install System Monitors
Monitor system performance to ensure optimal AI model execution.
sudo apt install htop nvtop -y
5.7 Troubleshooting AI Environment Setup
- Library Installation Errors: Ensure all dependencies are met and versions are compatible.
- Model Loading Failures: Verify the integrity of the downloaded model files and ensure correct paths.
- Performance Bottlenecks: Use monitoring tools like
htop
and nvtop
to identify and address resource constraints.
6. Testing AI Workloads
6.1 Verify GPU Usage
Ensure that the GPU is correctly recognized and utilized by running:
nvidia-smi
This command should display your NVIDIA Quadro T1000 GPU along with its current usage statistics.
6.2 Run a Sample AI Model
Test the AI environment by running a simple image generation script using the diffusers
library.
from diffusers import StableDiffusionPipeline
import torch
model_id = "stabilityai/stable-diffusion-2-1"
pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
pipe = pipe.to("cuda")
prompt = "A futuristic cityscape"
image = pipe(prompt).images[0]
image.save("output.png")
This script generates an image based on the provided prompt and saves it as output.png
.
6.3 Evaluate GPU Utilization
Monitor how effectively the GPU is being used during AI model runs:
watch -n 1 nvidia-smi
This command updates the GPU usage statistics every second.
6.4 Troubleshooting AI Workloads
- CUDA Not Detected: Ensure that CUDA is correctly installed and that the environment variables are set appropriately.
- Model Inference Errors: Check for compatibility issues between the model and the installed libraries.
- Low GPU Utilization: Optimize batch sizes and model configurations to better leverage GPU capabilities.
7. Maintenance and Further Optimization
7.1 Regular System Updates
Keep your Ubuntu system updated to ensure security and performance improvements:
sudo apt update && sudo apt upgrade -y
7.2 Performance Monitoring
Continuously monitor system performance to maintain optimal AI model execution.
- Use
htop
for CPU and memory monitoring:
htop
- Use
nvtop
for real-time GPU monitoring:
nvtop
7.3 Manage Resources
Efficiently manage system resources to prevent bottlenecks during AI processing.
- Limit the number of concurrent AI processes to prevent overloading the GPU.
- Utilize job scheduling tools like tmux or screen for managing long-running tasks.
7.4 Backup AI Projects
Regularly back up your AI projects and configurations to safeguard against data loss.
- Use version control systems like Git to track changes in your projects.
- Store backups on external drives or cloud storage services.
7.5 Further Optimization
Enhance system performance with advanced optimizations.
sudo nvidia-settings
Set the GPU to "Maximum Performance Mode" under PowerMizer settings.
Enable mixed-precision training to accelerate AI model training.
Utilize containerization tools like Docker for environment consistency.
8. Conclusion
By following this comprehensive guide, you have successfully installed Ubuntu on a dedicated secondary drive of your Lenovo P15 Gen-1 laptop, configured a dual-boot system with GRUB, and set up an optimized environment for running local AI models. Regular maintenance and continuous optimization will ensure that your system remains efficient and capable of handling demanding AI workloads.
References