1+ #! /bin/bash
2+ # noble 24.04 LTS mới nhất (2024)
3+ # jammy 22.04 LTS ổn định phổ biến
4+ # focal 20.04 LTS lâu dài, ổn định
5+ # bionic 18.04 LTS cũ
6+
7+ sudo apt update
8+ sudo apt install mtools xorriso -y
9+ sudo apt install qemu-system
10+ sudo apt install debootstrap squashfs-tools xorriso grub-pc-bin grub-efi-amd64-bin
11+ sudo mkdir -p build/chroot
12+ sudo chown -R hcode:hcode build/chroot # hcode:hcode = $USER:$USER
13+ sudo chmod -R u+rw build/chroot
14+ sudo debootstrap --arch=amd64 noble build/chroot http://archive.ubuntu.com/ubuntu
15+
16+
17+ # vào chroot
18+ sudo rm -f build/chroot/etc/resolv.conf
19+ sudo cp /etc/resolv.conf build/chroot/etc/resolv.conf
20+ sudo mount -t proc proc build/chroot/proc
21+ sudo mount -t sysfs sys build/chroot/sys
22+ sudo mount --bind /dev build/chroot/dev
23+ sudo mkdir -p build/chroot/dev/pts
24+ sudo mount -t devpts devpts build/chroot/dev/pts
25+
26+ # vào choot
27+ sudo chroot build/chroot
28+ export HOME=/root
29+ export LC_ALL=C
30+
31+ # thực thi lệnh trong chroot k cần vào chroot
32+ sudo chroot build/chroot apt update
33+
34+ # cập nhật cho live-boot trong chroot
35+ nano /etc/apt/sources.list
36+
37+ # Thay nội dung thành (cho Ubuntu 24.04 Noble):
38+ deb http://archive.ubuntu.com/ubuntu noble main universe
39+ deb http://archive.ubuntu.com/ubuntu noble-updates main universe
40+ deb http://archive.ubuntu.com/ubuntu noble-security main universe
41+
42+ # Nếu bạn dùng Ubuntu 22.04 (Jammy):
43+ deb http://archive.ubuntu.com/ubuntu jammy main universe
44+ deb http://archive.ubuntu.com/ubuntu jammy-updates main universe
45+ deb http://archive.ubuntu.com/ubuntu jammy-security main universe
46+
47+ # cài đặt cần thiết trong chroot
48+ apt update
49+ apt install -y lvm2 gdisk parted dosfstools rsync
50+ apt install -y live-boot live-boot-initramfs-tools live-tools live-config-systemd
51+ apt install -y grub-pc-bin grub-efi-amd64-bin grub-common
52+ apt install -y grub-efi grub-efi-amd64 grub-efi-amd64-signed shim-signed
53+ apt install net-tools openssh-server systemd-sysv nano
54+ apt install systemd-networkd systemd-resolved
55+ apt install linux-image-generic -y
56+ apt install locales -y
57+ locale-gen en_US.UTF-8
58+ update-locale LANG=en_US.UTF-8
59+ export LANG=en_US.UTF-8
60+ export LC_ALL=en_US.UTF-8
61+ echo ' LANG="en_US.UTF-8"' > /etc/default/locale
62+
63+ # cài đặt mật khẩu root trong chroot
64+ echo " root:1234" | chpasswd
65+
66+ # Tạo file cấu hình mạng tự động: trong chroot
67+ mkdir -p /etc/systemd/network
68+ cat << EOF > /etc/systemd/network/20-wired.network
69+ [Match]
70+ Name=en*
71+
72+ [Network]
73+ DHCP=yes
74+ EOF
75+ ln -sf /run/systemd/resolve/resolv.conf /etc/resolv.conf
76+ systemctl enable systemd-networkd
77+ systemctl enable systemd-resolved
78+
79+ # đăng nhập ssh bằng root trong chroot
80+ sed -i ' s/^#*PermitRootLogin.*/PermitRootLogin yes/' /etc/ssh/sshd_config
81+ sed -i ' s/^#*PasswordAuthentication.*/PasswordAuthentication yes/' /etc/ssh/sshd_config
82+ systemctl enable ssh
83+
84+ # set các thông tin cho custom ubuntu trong chroot
85+ echo " Welcome Ubuntu Lite by DEV BETA.,JSC (2025)" > /etc/motd
86+ echo " ubuntu-lite" > /etc/hostname
87+
88+
89+ # cập nhât trong chroot
90+ update-initramfs -u -k all
91+
92+ # thoát chroot
93+ exit
94+
95+ # gỡ mount
96+ sudo umount build/chroot/dev/pts
97+ sudo umount build/chroot/dev
98+ sudo umount build/chroot/sys
99+ sudo umount build/chroot/proc
0 commit comments