-
-
Create a raw image file of 1G size
dd if=/dev/zero of=ubuntu_base.img bs=1G count=1
-
Installing EXT4 file system using mkfs
mkfs.ext4 ubuntu_base.img
-
-
-
Create a folder for mounting
sudo mkdir /mnt/loopback
-
Mount it
sudo mount ubuntu_base.img /mnt/loopback
-
-
sudo tar -xpf /mnt/e/Downloads/ubuntu-base-22.04.1-base-amd64.tar.gz -C /mnt/loopback
Ubuntu base can be downloaded from https://cdimage.ubuntu.com/ubuntu-base/releases
-
sudo apt install arch-install-scripts sudo arch-chroot /mnt/loopback
-
tee /etc/default/locale <<EOF LANGUAGE=en_US.UTF-8 LANG=en_US.UTF-8 LC_CTYPE=en_US.UTF-8 EOF echo "LANG=en_US.UTF-8" > /etc/local.conf tee -a /etc/fstab <<EOF tmpfs /tmp tmpfs rw,nosuid,nodev,size=99% tmpfs /var/log tmpfs rw,nosuid,nodev EOF tee /etc/hosts <<EOF 127.0.0.1 localhost localhost.localdomain 127.0.1.1 localhost.localdomain EOF
-
apt update && apt upgrade -y
-
apt install -y linux-image-virtual extlinux setools lzip patchelf e2fsprogs python3-minimal sudo finit-sysv qemu-guest-agent
-
mkdir -p /boot/syslinux tee /boot/syslinux/syslinux.cfg <<EOF PROMPT 0 TIMEOUT 0 DEFAULT Base LABEL Base LINUX ../vmlinuz APPEND root=/dev/sda rw INITRD ../initrd.img EOF extlinux --install /boot/syslinux
-
apt clean
-
echo \ '#!/bin/sh . /usr/share/initramfs-tools/hook-functions copy_exec /sbin/e2fsck /sbin copy_exec /sbin/fsck /sbin copy_exec /sbin/fsck.ext2 /sbin copy_exec /sbin/fsck.ext4 /sbin copy_exec /sbin/logsave /sbin' \ | dd of=/etc/initramfs-tools/hooks/e2fsck.sh chmod +x /etc/initramfs-tools/hooks/e2fsck.sh update-initramfs -u adduser --disabled-password lsposed passwd -d lsposed adduser lsposed adm adduser lsposed sudo chmod u+w /etc/sudoers echo "lsposed ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers chmod u-w /etc/sudoers tee /sbin/autologin <<EOF #!/bin/sh exec /usr/bin/login -f lsposed EOF chmod +x /sbin/autologin echo "tty [123456] /sbin/getty -L -n -l /sbin/autologin 0 /dev/tty1 linux nowait noclear" >> /etc/finit.conf dd if=/dev/zero of=/swapfile bs=1M count=200 chmod 0600 /swapfile mkswap /swapfile tee -a /etc/fstab <<EOF /swapfile none swap sw 0 0 EOF
-
exit
-
sudo umount /mnt/loopback
-
sudo e2fsck -pf ubuntu_base.img resize2fs -M ubuntu_base.img
-
qemu-img convert -f raw -c -O qcow2 ubuntu_base.img ubuntu_base.qcow2
-
qemu-system-x86_64 ubuntu_base.qcow2 -m 6g -smp 12 --accel whpx --snapshot
Last active
November 18, 2024 06:35
-
-
Save Howard20181/b9d44935a146d7a84fc18c4c63d01b26 to your computer and use it in GitHub Desktop.
Booting a Ubuntu base in qemu
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It is not convenient to use bash as init, consider using finit-sysv