Debian 기반 rootfs 제작하기
필요한 도구 설치
1
2
sudo apt update
sudo apt install qemu qemu-system-x86 debootstrap
debian기반 rootfs 이미지 생성
1) QEMU 디스크 이미지 생성
1
qemu-img create -f qcow2 debian-rootfs.img 10G
2) 디스크 이미지 포맷 및 마운트
1
2
3
4
5
6
7
8
sudo modprobe nbd max_part=8
sudo qemu-nbd --connect=/dev/nbd0 debian-rootfs.img
# 연결된 디스크를 포맷합니다.
sudo mkfs.ext4 /dev/nbd0
# 파일 시스템을 마운트합니다.
sudo mount /dev/nbd0 /mnt
3) debootstrap 실행
1
sudo debootstrap --arch=amd64 bullseye /mnt http://deb.debian.org/debian
4) 초기 설정 (network 설정 포함)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
sudo chroot /mnt
passwd # root에 대한 password를 설정해 줍니다.
# -----------------------------------
#eth0 는 ip link 통해 내 network에 맞게 수정해주어야 합니다.
cat <<EOT > /etc/network/interfaces
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet dhcp
EOT
# -----------------------------------
cat <<EOT > /etc/fstab
/dev/sda / ext4 errors=remount-ro 0 1
EOT
# -----------------------------------
exit
sudo umount /mnt
sudo qemu-nbd --disconnect /dev/nbd0
QEMU 부팅
1
2
3
4
5
6
7
8
sudo qemu-system-x86_64 \
-kernel /path/to/linux/arch/x86/boot/bzImage \
-append "root=/dev/sda console=ttyS0" \
-hda /path/to/debian-rootfs.img \
-m 1024 \
-netdev user,id=usernet,hostfwd=tcp::2222-:22,hostfwd=tcp::8080-:80 \
-device e1000,netdev=usernet \
-nographic
“root / 설정한 비밀번호” 로그인하면 됩니다.
만약 인터넷이 안될 시
- QEMU 환경 내에서
ip link
를 통해 네트워크 인터페이스(eth0, enp0s3, …)를 확인합니다.1
nano /etc/network/interfaces
네트워크 인터페이스가 올바르게 되어 있는지 확인합니다.
- 수정 후 네트워크를 재실행합니다.
1
/etc/init.d/networking restart
- 네트워크 연결 상태를 확인합니다.
1
ping -c 4 google.com
user 추가하기
처음 실행했을 때는 root user밖에 없습니다. ssh-server 등을 사용하기 위해서는 새로운 user를 추가해 줄 필요가 있습니다.
1
2
3
4
adduser newuser
usermod -aG sudo newuser
apt install sudo
This post is licensed under CC BY 4.0 by the author.