R&D/OS

우분투 Live CD 만들기

sunshout 2009. 12. 9. 15:23

현재 설치된 우분투 리눅스를 라이브 CD(또는 라이브 USB)로 쉽게 만들 수 있다.

#################################
# 1단계 환경 설정
#################################

1) 환경 설정 (bash로 가정)
환경 설정 (Language : text)

export WORK=~/work
export CD=~/cd
export FORMAT=squashfs
export FS_DIR=casper


2) CD 와 Work 디렉토리 생성
작업 디렉토리 생성 (Language : text)

sudo mkdir -p ${CD}/{${FS_DIR},boot/grub} ${WORK}/rootfs
 


3) Live CD 제작 유틸러티 설치
유틸러티 설치 (Language : text)

sudo apt-get update
sudo apt-get install mkisofs grub squashfs-tools
 


################################
# 2단계 : 설치 CD 복사 및 생성
################################

1) 설치된 파일 시스템 복사
파일 복사 (Language : text)

sudo rsync -av --one-file-system --exclude=/proc/* --exclude=/dev/*\
 --exclude=/sys/* --exclude=/tmp/* --exclude=/home/*\
 --exclude=/lost+found / ${WORK}/rootfs

* rsync 는 --exclude 옵션을 이용하여 복사에서 배제하고 싶은 파일들을 지정할 수 있다

2) 부트 파일 복사
부트 파일 복사 (Language : text)

sudo cp -av /boot/* ${WORK}/rootfs/boot


##########################################
# CHROOT를 이용한 설치 파일 작업 하기
# 이 과정에서는 chroot를 이용하여 루트 파일 시스템을 변경한다
#
##########################################

1) 필요한 시스템 파일을 마운트
시스템 파일 마운트 (Language : text)

sudo mount -o bind /dev/ ${WORK}/rootfs/dev
sudo mount -t proc proc ${WORK}/rootfs/proc
sudo mount -t sysfs sysfs ${WORK}/rootfs/sys
 


2)  chroot로 마운트 변경
chroot 하기 (Language : text)

sudo chroot ${WORK}/rootfs /bin/bash
 


이제 루트 파일 시스템은 변경되었다. (권한이 루트로 변경되어 있고, 파일 시스템들은 원복을 복사한 파일들임)

chroot 환경 확인 (Language : text)

LANG=

3) 추가 패키지 설치
추가 패키지 설치 (Language : text)

apt-get update
apt-get install casper xresprobe discover1 

4) Live CD를 하드에 설치하고 싶으면 ubiquity 패키지를 설치해야 한다
ubiquity 설치 (Language : text)

apt-get install ubiquity ubiquity-frontend-kde


5) initramfs 업데이트
initramfs 업데이트 (Language : text)

depmod -a $(uname -r)
update-initramfs -u -k $(uname -r) 


6) 기존 설정 삭제 (default 설정으로 변경하기 위해서)
기존 설정 삭제 (Language : text)

for i in "/etc/hosts /etc/hostname /etc/resolv.conf /etc/timezone /etc/fstab /etc/mtab /etc/shadow /etc/shadow- /etc/gshadow  /etc/gshadow- /etc/gdm/gdm-cdd.conf /etc/gdm/gdm.conf-custom /etc/X11/xorg.conf /boot/grub/menu.lst /boot/grub/device.map"
do
    rm $i
done 2>/dev/null
 

7) 다운받은 패키지 삭제
임시 패키지 삭제 (Language : text)

apt-get clean
 


8) 불필요한 파일 삭제
불필요한 파일 삭제 (Language : text)

rm -r /tmp/* /root/* 2>/dev/null
rm  /boot/*.bak 2>/dev/null
rm /etc/udev/rules.d/*.rules


9) User 정보 삭제



10) 불필요한 파일 삭제
파일 삭제 (Language : text)

find /var/run /var/log /var/mail /var/spool /var/lock /var/backups /var/tmp -type f -exec rm {} \;
 


11) 필요한 파일 생성

파일 생성 (Language : text)

for i in dpkg.log lastlog mail.log syslog auth.log daemon.log faillog lpr.log mail.warn user.log boot debug mail.err messages wtmp bootstrap.log dmesg kern.log mail.info
do
    touch /var/log/${i}
done

touch /var/log/news/news.err
touch /var/log/news/news.crit
touch /var/log/news/news.notice
 


12) Exit (chroot 에서 나오기)
Exit (Language : text)

exit


###############################
# CD 디렉토리 생성
###############################
1) 커널 관련 정보들 복사

커널 정보 복사 (Language : text)

sudo cp -vp ${WORK}/rootfs/boot/vmlinuz-$(uname -r) ${CD}/boot/vmlinuz
sudo cp -vp ${WORK}/rootfs/boot/initrd.img-$(uname -r) ${CD}/boot/initrd.gz
sudo cp -vp ${WORK}/rootfs/boot/memtest86+.bin ${CD}/boot


2) Ubiquity 설치용
ubiquity 설치용 (Language : text)

sudo chroot ${WORK}/rootfs dpkg-query -W --showformat='${Package} ${Version}\n' | sudo tee ${CD}/${FS_DIR}/filesystem.manifest
sudo cp -v ${CD}/${FS_DIR}/filesystem.manifest{,-desktop}
REMOVE='ubiquity casper user-setup discover1 xresprobe os-prober libdebian-installer4'

for i in $REMOVE
do
sudo sed -i "/${i}/d" ${CD}/${FS_DIR}/filesystem.manifest-desktop
done
 


3) 시스템 파일 umount
시스템 파일 umount (Language : text)

sudo umount ${WORK}/rootfs/proc
sudo umount ${WORK}/rootfs/sys
sudo umount ${WORK}/rootfs/dev
 


4) 파일을 squashfs로 변경
squashfs로 변경 (Language : text)

sudo mksquashfs ${WORK}/rootfs ${CD}/${FS_DIR}/filesystem.${FORMAT}
 

5) grub 설치
grub 정보 복사 (Language : text)

sudo find /boot /usr/lib/grub/ -iname 'stage2_eltorito' -exec cp -v {} ${CD}/boot/grub \;
 


6) grub 설정
grub 설정 파일 열기 (Language : text)

sudo vi ${CD}/boot/grub/menu.lst
 


grub 설정정보 입력 (Language : text)

# By default, boot the first entry.
default 0

# Boot automatically after 30 secs.
timeout 30

color cyan/blue white/blue


title      Start Linux in Graphical Mode
kernel    /boot/vmlinuz BOOT=casper boot=casper nopersistent rw quiet splash
initrd    /boot/initrd.gz

title      Start Linux in Safe Graphical Mode
kernel    /boot/vmlinuz BOOT=casper boot=casper xforcevesa rw quiet splash
initrd    /boot/initrd.gz

title      Start Linux in Text Mode
kernel    /boot/vmlinuz BOOT=casper boot=casper nopersistent textonly rw quiet
initrd    /boot/initrd.gz

title      Start Presistent Live CD
kernel    /boot/vmlinuz BOOT=casper boot=casper persistent rw quiet splash
initrd    /boot/initrd.gz

title      Start Linux Graphical Mode from RAM
kernel    /boot/vmlinuz BOOT=casper boot=casper toram nopersistent rw quiet splash
initrd    /boot/initrd.gz

title      Memory Test
kernel    /boot/memtest86+.bin

title      Boot the First Hard Disk
root        (hd0)
chainloader +1
 

7) MD5 다시 계산
md5 계산 (Language : text)

cd $CD && find . -type f -print0 | xargs -0 sudo md5sum | sudo tee ${CD}/md5sum.txt
 


8) CD 제작
CD 제작 (Language : text)

sudo mkisofs -b boot/grub/stage2_eltorito \
-no-emul-boot -boot-load-size 4 -boot-info-table \
-V "Custom Live CD" -cache-inodes -r -J -l \
-o ~/live-cd.iso $CD