1. Chạy LAB
Copy 6 lệnh dưới → dán trên PowerShell bằng cách click chuột phải
→ không phải gõ gõ từng lệnh mất thời gian
Chạy 6 lệnh sau trên Powershell quyền Administrator → dấu # là giải thích (comment)
# Giả sử có ổ đĩa D:
# Tạo thư mục D:compile-vb + chuyển vào thư mục
mkdir D:compile-vb > $null ; cd D:compile-vb
# Khai báo biến là link tới file cần download
$URL="https://devsecops.edu.vn/wp-content/uploads/2023/12/compile-vb-emmjOFqw3SPwMljZfxb95wY5hXQour.zip"
# Download file zìa
Invoke-WebRequest -URI $URL -OutFile compile-vb.zip
# Giải nén file + đổi tên
Expand-Archive compile-vb.zip -DestinationPath .
# Coi trong thư mục đang đứng có gì
dir
# Tạo máy ảo + biên dịch Linux Kernel
vagrant up
# Tự động reboot lại máy + vào kernel mới biên dịch kiểm tra các thứ
vagrant halt ; vagrant up ; vagrant provision compile --provision-with show-config
2. Các file nội dung mới nhất ở đây
Vagrantfile
Vagrant.configure("2") do |config|
config.vm.define "compile" do |compile|
compile.vm.box = "ubuntu/jammy64"
compile.vm.hostname = 'DevSecOps-Edu-VN'
compile.vm.synced_folder ".", "/vagrant"
compile.vm.provider :virtualbox do |v|
v.gui = true
v.cpus = 8
v.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
v.customize ["modifyvm", :id, "--memory", 8192]
v.customize ["modifyvm", :id, "--name", "Ubuntu2204-Compile-Kernel-Config-Module"]
end
compile.vm.provision "shell", path: "compile-kernel-config-module.sh"
compile.vm.provision "show-config", type: "shell", path: "kernel-config-module.sh", run: "never"
end
end
compile-kernel-config-module.sh
#!/bin/bash
echo -e "nB1. Cài các gói cần thiết để biên dịchn"
export DEBIAN_FRONTEND=noninteractive
apt update
apt install curl tar xz-utils make gcc flex bison bc libelf-dev libssl-dev -y
echo -e "nB2. Tải Linux kernel zìan"
version="6.6.7"
# Về /root
cd
curl -O https://cdn.kernel.org/pub/linux/kernel/v6.x/linux-${version}.tar.xz
tar xf linux-${version}.tar.xz
rm -f linux-${version}.tar.xz
cd linux-${version}
echo -e "nB3. Chuẩn bị biên dịch Linux kerneln"
# Tắt 1 số chức năng của make defconfig
# https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/x86/configs/x86_64_defconfig
# Bật .config thành là 1 moldule tháo lắp vào kernel
# /proc/config.gz
echo "CONFIG_IKCONFIG=m" >> arch/x86/configs/x86_64_defconfig
echo "CONFIG_IKCONFIG_PROC=y" >> arch/x86/configs/x86_64_defconfig
# Thêm để nhận đĩa SCSI loại LSI mặc định trên VirtualBox
echo "CONFIG_FUSION=y" >> arch/x86/configs/x86_64_defconfig
echo "CONFIG_FUSION_SPI=y" >> arch/x86/configs/x86_64_defconfig
echo "CONFIG_FUSION_FC=y" >> arch/x86/configs/x86_64_defconfig
echo "CONFIG_FUSION_SAS=y" >> arch/x86/configs/x86_64_defconfig
echo "CONFIG_FUSION_MAX_SGE=128" >> arch/x86/configs/x86_64_defconfig
echo "CONFIG_FUSION_CTL=y" >> arch/x86/configs/x86_64_defconfig
echo "CONFIG_FUSION_LAN=y" >> arch/x86/configs/x86_64_defconfig
echo "CONFIG_FUSION_LOGGING=y" >> arch/x86/configs/x86_64_defconfig
echo "CONFIG_SCSI_DH_RDAC=y" >> arch/x86/configs/x86_64_defconfig
echo "CONFIG_SCSI_DH_EMC=y" >> arch/x86/configs/x86_64_defconfig
echo "CONFIG_SCSI_DH_ALUA=y" >> arch/x86/configs/x86_64_defconfig
echo "CONFIG_VMWARE_PVSCSI=y" >> arch/x86/configs/x86_64_defconfig
# Biên dịch module của VirtualBox để xài được Shared Folders là /vagrant
echo "CONFIG_VBOXSF_FS=y" >> arch/x86/configs/x86_64_defconfig
make defconfig
# Đổi tên Linux thành CayTreOS trong lệnh uname -a
sed -i 's/Linux/CayTreOS/' include/linux/uts.h
echo -e "n--- Số dòng biên dịch Linux kernel ---n"
grep ^[^#] .config | wc -l
echo "Thời gian bắt đầu: `date`" > /vagrant/compile-linux-kernel-defconfig-run-ok.txt
make -j`nproc`
make modules_install install
echo "Thời gian kết thúc: `date`" >> /vagrant/compile-linux-kernel-defconfig-run-ok.txt
echo -e "nB4. Giải nén .config ra khỏi vmlinuzn"
curl -O https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/plain/scripts/extract-ikconfig
chmod +x extract-ikconfig
./extract-ikconfig /boot/vmlinuz-${version} > config-${version}
echo -e "nThời gian bắt đầu biên dịch + xong phimn"
cat /vagrant/compile-linux-kernel-defconfig-run-ok.txt
echo -e "nvmlinuz mới biên dịch nặng bi nhiu?n"
ls -lh /boot
#-------------------------------------------#
echo -e "nDevSecOps.Edu.VN mần cái nàyn"
# END
kernel-config-module.sh
#!/bin/bash
echo -e "nCoi Linux kernel mới biên dịchn"
uname -a
echo -e "nCoi phiên bản hệ điều hành Linuxn"
cat /etc/os-release
# Gắn module vào Linux kernel
modprobe configs
echo -e "nĐã có Kernel config trên /procn"
ls -l /proc/config.gz
echo -e "nTìm kernel config trực tiếp trên /proc/config.gzn"
zgrep 'IKCONFIG' /proc/config.gz
# END