2011년 8월 2일 화요일

CentOS를 Gentoo로 변신시키기

IDC에  설치되어 있던 CentOS를 원격지에서 Gentoo Linux로 변경시켰던 내용을 요약


<CentOS로 부팅>
* 현 시스템의 하드웨어 정보확인
--------------------------------------------------------------------------------
[root@localhost ~]# lspci
00:00.0 Host bridge: Intel Corporation 440FX - 82441FX PMC [Natoma] (rev 02)
00:01.0 ISA bridge: Intel Corporation 82371SB PIIX3 ISA [Natoma/Triton II]
00:01.1 IDE interface: Intel Corporation 82371SB PIIX3 IDE [Natoma/Triton II]
00:01.2 USB Controller: Intel Corporation 82371SB PIIX3 USB [Natoma/Triton II] (rev 01)
00:01.3 Bridge: Intel Corporation 82371AB/EB/MB PIIX4 ACPI (rev 03)
00:02.0 VGA compatible controller: Cirrus Logic GD 5446
00:03.0 Ethernet controller: Intel Corporation 82540EM Gigabit Ethernet Controller (rev 03)

[root@localhost ~]# lsmod
Module                  Size  Used by
ip_conntrack_ftp       41489  0
ip_conntrack_netbios_ns    36033  0
ipt_REJECT             38849  1
xt_tcpudp              36417  12
xt_state               35265  13
ip_conntrack           91237  3 ip_conntrack_ftp,ip_conntrack_netbios_ns,xt_state
nfnetlink              40457  1 ip_conntrack
iptable_filter         36161  1
ip_tables              55329  1 iptable_filter
x_tables               50377  4 ipt_REJECT,xt_tcpudp,xt_state,ip_tables
dm_mirror              60617  0
dm_multipath           52945  0
dm_mod                 99737  2 dm_mirror,dm_multipath
video                  53197  0
sbs                    49921  0
backlight              39873  1 video
i2c_ec                 38593  1 sbs
button                 40544  0
battery                43849  0
asus_acpi              50917  0
acpi_memhotplug        40133  0
ac                     38729  0
lp                     47121  0
floppy                 95465  0
e1000                 155601  0
i2c_piix4              42573  0
i2c_core               56129  2 i2c_ec,i2c_piix4
pcspkr                 36289  0
ide_cd                 73697  0
cdrom                  68713  1 ide_cd
parport_pc             62313  1
serio_raw              40517  0
parport                73165  2 lp,parport_pc
ata_piix               54981  0
libata                192345  1 ata_piix
sd_mod                 56257  0
scsi_mod              188665  2 libata,sd_mod
ext3                  167249  7
jbd                    93873  1 ext3
uhci_hcd               57433  0
ohci_hcd               54493  0
ehci_hcd               65741  0

[root@localhost ~]# ifconfig -a
eth0      Link encap:Ethernet  HWaddr DE:AD:BE:E0:02:39
          inet addr:115.68.20.101  Bcast:115.68.20.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:1978 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1658 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:253256 (247.3 KiB)  TX bytes:199147 (194.4 KiB)
          Base address:0xc040 Memory:f2020000-f2040000

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:996 errors:0 dropped:0 overruns:0 frame:0
          TX packets:996 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:1849560 (1.7 MiB)  TX bytes:1849560 (1.7 MiB)

[root@localhost ~]# route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
115.68.20.0     *               255.255.255.0   U     0      0        0 eth0
default         115.68.20.1     0.0.0.0         UG    0      0        0 eth0

[root@localhost ~]# cat /etc/resolv.conf
nameserver 220.90.215.11
nameserver 168.126.63.1
search localhost

[root@localhost ~]# df -m
Filesystem           1M-blocks      Used Available Use% Mounted on
/dev/hda1                  996        50       894   6% /boot
/dev/hda3                 1984       495      1387  27% /
/dev/hda5                 7933       657      6868   9% /var
/dev/hda6                 7933       147      7378   2% /usr/local
/dev/hda7                 5950      3411      2232  61% /usr
/dev/hda8                  996        34       911   4% /tmp
/dev/hda9                10973       156     10250   2% /home
tmpfs                      250         0       250   0% /dev/shm

# fdisk -l /dev/hda
Disk /dev/hda: 41.9 GB, 41943040000 bytes
255 heads, 63 sectors/track, 5099 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x000588ae

   Device Boot      Start         End      Blocks   Id  System
/dev/hda1   *           1         131     1052226   83  Linux
/dev/hda2             132         392     2096482+  82  Linux swap / Solaris
/dev/hda3             393         653     2096482+  83  Linux
/dev/hda4             654        5099    35712495    f  W95 Ext'd (LBA)
/dev/hda5             654        1697     8385898+  83  Linux
/dev/hda6            1698        2741     8385898+  83  Linux
/dev/hda7            2742        3524     6289416   83  Linux
/dev/hda8            3525        3655     1052226   83  Linux
/dev/hda9            3656        5099    11598898+  83  Linux
 

* 하드디스크 파티셔닝 계획
--------------------------------------------------------------------------------
- 원본
/dev/hda1                  996
/dev/hda3                 1984
/dev/hda5                 7933
/dev/hda6                 7933
/dev/hda7                 5950
/dev/hda8                  996
/dev/hda9                10973

- 기본
hda1 /boot 유지
hda2 swap 유지

- 변경
hda3, hda5 ~ hda8 삭제

dev  mount size
hda3 /tmp    2G
hda5 /  30G


* 설치
--------------------------------------------------------------------------------

# umount /dev/hda9
# mkfs.ext3 /dev/hda9
# mkdir /mnt/gentoo
# mount -t ext3 /dev/hda9 /mnt/gentoo
# cd /mnt/gentoo
# wget http://ftp.daum.net/gentoo/releases/amd64/current/stages/stage3-amd64-2008.0.tar.bz2
# bzip2 -d stage3-i686-2008.0.tar.bz2
# time tar xvf stage3-i686-2008.0.tar
real    1m9.484s
user    0m1.138s
sys     0m17.466s

/* 최신버전 Portage snapshot를 설치 */
# cd /mnt/gentoo/usr
# wget http://ftp.daum.net/gentoo/releases/snapshots/current/portage-2008.0.tar.bz2
# time bzip2 -d portage-2008.0.tar.bz2
real    0m36.732s
user    0m25.455s
sys     0m31.276s

# time tar xvf portage-2008.0.tar
real    1m58.076s
user    0m3.309s
sys     0m40.213s

/* Chrooting */
# cd /
# mount -t proc proc /mnt/gentoo/proc
# cp -L /etc/resolv.conf /mnt/gentoo/etc/
# chroot /mnt/gentoo /bin/bash
# env-update && source /etc/profile
>>> Regenerating /etc/ld.so.cache...

/* Set your time zone */
# ls /usr/share/zoneinfo
# cp /usr/share/zoneinfo/Asia/Seoul /etc/localtime
# date
2008. 10. 16. (목) 16:50:42 KST

/* Set your host and domain name */
localhost / # cd /etc
localhost etc # echo "127.0.0.1 ns.javaya.org ns localhost" > hosts
localhost etc # sed -i -e 's/HOSTNAME.*/HOSTNAME="ns"/' conf.d/hostname
localhost etc # hostname ns
localhost etc # hostname -f
ns.javaya.org

/* Kernel Configuration */
localhost etc # echo "GENTOO_MIRRORS=\"http://ftp.kaist.ac.kr/pub/gentoo/\"" >> make.conf
localhost etc # time emerge gentoo-sources

real  2m51.435s
user  0m58.220s
sys   0m29.890s
localhost etc # cd /usr/src/linux
localhost linux # make menuconfig
(Configure your kernel)
localhost linux # time make -j2

(Elapsed time depends highly on the options you selected)
real  3m51.962s
user  3m27.060s
sys   0m24.310s

localhost linux # make modules_install
(/boot 파티션이 마운트 되지 않았다면 마운트한다)
localhost linux # cp arch/i386/boot/bzImage /boot/bzImage-2.6.24-gentoo-r7

/* Configure the system - filesystem */
localhost linux # cd /etc
localhost etc # nano -w fstab
/dev/hda1   /boot     ext3    noauto,noatime     1 2
/dev/hda9   /         ext3    noatime            0 1
/dev/hda2   none      swap    sw                 0 0

/* Configure the system - network */
localhost etc # cd conf.d
localhost conf.d # echo 'config_eth0=( "115.68.20.101/24" )' >> net
localhost conf.d # echo 'routes_eth0=( "default via 115.68.20.1" )' >> net
localhost conf.d # rc-update add net.eth0 default
(If you compiled your network card driver as a module,
add it to /etc/modules.autoload.d/kernel-2.6)
localhost conf.d # echo sk98lin >> /etc/modules.autoload.d/kernel-2.6
(If you want to reconnect via ssh after you have rebooted your new box:)
localhost conf.d # rc-update add sshd default

/* Configure the system - password */
localhost conf.d # passwd
New UNIX password: type_the_password
Retype new UNIX password: type_the_password_again
passwd: password updated successfully

localhost conf.d # nano -w /etc/conf.d/clock
TIMEZONE="Asia/Seoul"


/* Installing System Tools  */
localhost conf.d # time emerge syslog-ng vixie-cron


/* Install extra tools if required  */
localhost conf.d # emerge xfsprogs       (If you use the XFS file system)
localhost conf.d # emerge jfsutils       (If you use the JFS file system)
localhost conf.d # emerge reiserfsprogs  (If you use the Reiser file system)
localhost conf.d # emerge dhcpcd         (If you need a DHCP client)
localhost conf.d # emerge ppp            (If you need PPPoE ADSL connectivity)


/* Configuring the Bootloader */
localhost conf.d # mount -t ext3 /dev/hda1 /mnt/gentoo/boot

localhost conf.d # time emerge grub
localhost conf.d # nano -w /boot/grub/grub.conf
--------------------------------------------------------------------------------
default 0
timeout 10

title=Gentoo
 root (hd0,0)
 kernel /bzImage-2.6.24-gentoo-r7 root=/dev/hda9
--------------------------------------------------------------------------------
localhost conf.d # grub
Probing devices to guess BIOS drives. This may take a long time.

grub> root (hd0,0)
 Filesystem type is ext2fs, partition type 0x83

grub> setup (hd0)
 Checking if "/boot/grub/stage1" exists... yes
 Checking if "/boot/grub/stage2" exists... yes
 Checking if "/boot/grub/e2fs_stage1_5" exists... yes
 Running "embed /boot/grub/e2fs_stage1_5 (hd0)"...  16 sectors are embedded.
succeeded
 Running "install /boot/grub/stage1 (hd0) (hd0)1+16 p (hd0,0)/boot/grub/stage2 /boot/
grub/menu.lst"... succeeded
Done.

grub> quit

/* Reboot */
livecd conf.d # exit
livecd / # umount /mnt/gentoo/proc /mnt/gentoo/boot /mnt/gentoo
livecd / # reboot


/* 파티션 조정 */

ns ~ # fdisk /dev/hda
<fdisk를 이용해서 다음과 같이 파티션 설정, 파티션 설정후 순서를 바로잡기 위해 extra메뉴에서 fix order를 선택>
--------------------------------------------------------------------------------
Command (m for help): x

Expert command (m for help): m
Command action
   b   move beginning of data in a partition
   c   change number of cylinders
   d   print the raw data in the partition table
   e   list extended partitions
   f   fix partition order
   g   create an IRIX (SGI) partition table
   h   change number of heads
   i   change the disk identifier
   m   print this menu
   p   print the partition table
   q   quit without saving changes
   r   return to main menu
   s   change number of sectors/track
   v   verify the partition table
   w   write table to disk and exit

Expert command (m for help): f
Expert command (m for help): r
Command (m for help): w


ns ~ # fdisk -l

Disk /dev/hda: 41.9 GB, 41943040000 bytes
255 heads, 63 sectors/track, 5099 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x000588ae

   Device Boot      Start         End      Blocks   Id  System
/dev/hda1   *           1         131     1052226   83  Linux
/dev/hda2             132         392     2096482+  82  Linux swap / Solaris
/dev/hda3             393         653     2096482+  83  Linux
/dev/hda4             654        5099    35712495    f  W95 Ext'd (LBA)
/dev/hda5             654        3455    22507033+  83  Linux
/dev/hda6            3456        3466       88326   83  Linux
/dev/hda7            3467        3476       80293+  83  Linux
/dev/hda8            3477        3486       80293+  83  Linux
/dev/hda9            3656        5099    11598898+  83  Linux


ns ~ # reboot

<reboot...>
================================================================================
/dev/hda3 -> /tmp
/dev/hda5 -> /
위와 같이 마운트 시켜서 쓸 것임
================================================================================

ns ~ # mkfs.ext3 /dev/hda3
ns ~ # mkfs.ext3 /dev/hda5
ns ~ # mkdir /mnt/newmount
ns ~ # mount /dev/hda5 /mnt/newmount

ns ~ # cp -p R /bin /mnt/newmount
ns ~ # cp -p -R /boot /mnt/newmount
ns ~ # cp -p -R /dev /mnt/newmount
ns ~ # cp -p -R /etc /mnt/newmount
ns ~ # cp -p -R /lib -> lib64 /mnt/newmount
ns ~ # cp -p -R /lib32 /mnt/newmount
ns ~ # cp -p -R /lib64 /mnt/newmount
ns ~ # cp -p -R /mnt /mnt/newmount
ns ~ # cp -p -R /opt /mnt/newmount
ns ~ # cp -p -R /root /mnt/newmount
ns ~ # cp -p -R /sbin /mnt/newmount
ns ~ # cp -p -R /sys /mnt/newmount
ns ~ # cp -p -R /usr /mnt/newmount
ns ~ # cp -p -R /var /mnt/newmount

ns ~ # mkdir /mnt/newmount/proc
ns ~ # mkdir /mnt/newmount/home
ns ~ # mkdir /mnt/newmount/tmp

ns ~ # nano -w /mnt/newmount/etc/fstab
--------------------------------------------------------------------------------
/dev/hda1   /boot     ext3    noauto,noatime     1 2
/dev/hda5   /         ext3    noatime            0 1
/dev/hda3   /tmp      ext3    noatime            0 1
/dev/hda2   none      swap    sw                 0 0
--------------------------------------------------------------------------------

ns ~ # mount -t ext3 /dev/hda1 /boot
ns ~ # nano -w /boot/grub/grub.conf
--------------------------------------------------------------------------------
title=Gentoo
    root (hd0,0)
    kernel /bzImage-2.6.24-gentoo-r7 root=/dev/hda5
title=GentooOLD
    root (hd0,0)
    kernel /bzImage-2.6.24-gentoo-r7 root=/dev/hda9
--------------------------------------------------------------------------------

ns ~ # grub
--------------------------------------------------------------------------------
Probing devices to guess BIOS drives. This may take a long time.

grub> root (hd0,0)
 Filesystem type is ext2fs, partition type 0x83

grub> setup (hd0)
 Checking if "/boot/grub/stage1" exists... yes
 Checking if "/boot/grub/stage2" exists... yes
 Checking if "/boot/grub/e2fs_stage1_5" exists... yes
 Running "embed /boot/grub/e2fs_stage1_5 (hd0)"...  16 sectors are embedded.
succeeded
 Running "install /boot/grub/stage1 (hd0) (hd0)1+16 p (hd0,0)/boot/grub/stage2 /boot/
grub/menu.lst"... succeeded
Done.

grub> quit
--------------------------------------------------------------------------------

ns ~ # reboot
<reboot...>
** 기타 파티션 정리 및 남은 파티션 필요에 따라 마운트
emerge -vpe world
echo 'USE="nptl nptlonly -ipv6 -fortran unicode svg dbus \
> X -kde -qt3 -qt4 -arts -eds -esd qtk gnome hal avahi gstreamer firefox apache2 nls"' >> /etc/make.conf

댓글 없음:

댓글 쓰기