最近比较想折腾 Linux, 就下载了一个 Gentoo 玩玩,打算装在 VMWare 虚拟机里。

首先从官方下载 Gentoo Minimal 的 64 位版本:

http://distfiles.gentoo.org/releases/amd64/autobuilds/current-iso/install-amd64-minimal-20110421.iso

然后,在 WMWare 里新建一个虚拟机,我大方地给了它 32GB(动态扩充)的磁盘……

再然后,将这个虚拟机用这个光盘镜像启动。启动选项和键盘布局我都没有理它,它就自动启动好了。启动完之后,出现了控制台:

livecd # _

看来这个 Gentoo 还是要折腾啊,它是没有类似 Ubuntu, Fedora 之类的图形化安装界面的。

然后我就到网上 Google 了一下,发现不仅仅是没有图形化的安装界面那么简单,这完全就是需要自己手动安装……

首先给 LiveCD 的 root 设置一个密码:

livecd ~ # passwd
New password:
Retype new password:
passwd: password updated successfully
livecd ~ # modprobe pcnet32
livecd ~ # net-setup eth0
...
Type "ifconfig" to make sure the interface was configured correctly.
livecd ~ # ifconfig
...
livecd ~ # /etc/init.d/sshd start
...

之后我就打开了一个 PuTTY 来输入命令,因为虚拟机里 Gentoo 的分辨率太高,看着不爽。

然后给磁盘分区,和挂载磁盘:

livecd ~ # fdisk /dev/sda
Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4, default 1):
Using default value 1
First sector (63-67108863, default 63):
Using default value 63
Last sector, +sectors or +size{K,M,G} (63-67108863, default 67108863): 2097152
Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4, default 2):
Using default value 2
First sector (2097153-67108863, default 2097153):
Using default value 2097153
Last sector, +sectors or +size{K,M,G} (2097153-67108863, default 67108863): +8388608
Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4, default 3):
Using default value 3
First sector (10485762-67108863, default 10485762):
Using default value 10485762
Last sector, +sectors or +size{K,M,G} (10485762-67108863, default 67108863):
Using default value 67108863
Command (m for help): a
Partition number (1-4): 1
Command (m for help): t
Partition number (1-4): 2
Hex code (type L to list codes): 82
Changed system type of partition 2 to 82 (Linux swap / Solaris)
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
livecd ~ # mkfs -t ext2 /dev/sda1
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
65536 inodes, 262136 blocks
13106 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=268435456
8 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376
Writing inode tables: done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 34 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
livecd ~ # mkfs -t ext4 /dev/sda3
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
1769472 inodes, 7077887 blocks
353894 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
216 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
        4096000
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 31 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
livecd ~ # mkswap /dev/sda2
Setting up swapspace version 1, size = 4194300 KiB
no label, UUID=1d0bd3cc-a2d2-40c5-8c33-0a1413dec24b
livecd ~ # swapon /dev/sda2
livecd ~ # mount /dev/sda3 /mnt/gentoo
livecd ~ # mkdir /mnt/gentoo/boot
livecd ~ # mount /dev/sda1 /mnt/gentoo/boot
livecd ~ # mkdir /mnt/gentoo/proc
livecd ~ # mount -t proc none /mnt/gentoo/proc
livecd ~ # mkdir /mnt/gentoo/dev
livecd ~ # mount -o bind /dev /mnt/gentoo/dev
livecd ~ # cd /mnt/gentoo

然后把 stage3 复制或者下载到这里来。

livecd gentoo # tar xjvf stage3-amd64-20110421.tar.bz2

然后搞来 portage .

livecd gentoo # tar xjvf portage-latest.tar.bz2 -C /mnt/gentoo/usr/
livecd gentoo # mkdir /mnt/gentoo/usr/portage/distfiles

然后进入 etc:

livecd gentoo # cd etc
livecd etc # mirrorselect -i -r

选择中国的镜像。然后去 /etc/make.conf 找到下面这些:

SYNC="rsync://rsync.cn.gentoo.org/gentoo-portage"

把它加入 /mnt/gentoo/etc/make.conf 最下面。

nano make.conf

复制 DNS 设置:

livecd etc # cp /etc/resolv.conf /mnt/gentoo/etc/

接下来是 chroot 的时候了:

livecd etc # chroot /mnt/gentoo /bin/bash
livecd / # env-update
>>> Regenerating /etc/ld.so.cache...
livecd / # source /etc/profile

注意此时如果要开两个 SSH 控制台,都需要分别 chroot.

接下来更新 portage, 下面两行执行一行就可以了。

livecd / # emerge --sync
livecd / # emerge-webrsync

似乎是初始化 portage 的步骤:

livecd / # cd /usr/portage/scripts/
livecd scripts # ./bootstrap.sh -f
livecd scripts # ./bootstrap.sh
livecd scripts # source /etc/profile

设置时区:

livecd / # cd /etc
livecd etc # rm localtime
livecd etc # ln -s /usr/share/zoneinfo/Asia/Shanghai localtime
livecd etc # nano rc.conf
livecd etc # cd conf.d
livecd conf.d # nano clock

我把 clock 设置成了 local, 因为是在虚拟机里,虚拟机给 Gentoo 的 BIOS 时间是外面 Windows 的时间,也就是本地时间。

设置网络:

livecd etc # echo gentoo > /etc/hostname
livecd etc # echo euyuil > /etc/dnsdomainname
livecd etc # echo 127.0.0.1 gentoo.euyuil gentoo localhost > /etc/hosts
livecd etc # sed -i -e 's/HOSTNAME.*/HOSTNAME="gentoo"/' conf.d/hostname
livecd etc # rc-update add hostname default
 * hostname added to runlevel default
livecd etc # rc-update add domainname default
 * rc-update: '/etc/init.d/domainname' not found; aborting
livecd etc # rc-update add net.eth0 default
 * net.eth0 added to runlevel default
livecd conf.d # hostname gentoo
livecd conf.d # hostname -f
gentoo.euyuil

接下来编译内核:

livecd / # emerge gentoo-sources
livecd / # cd /usr/src/linux
livecd linux # make menuconfig

在 VMWare 虚拟机里至少需要选中以下项目:

Device Drivers
    SCSI device support  --->
        <*> SCSI disk support
        <*> SCSI generic support
            SCSI low-level drivers  --->
                [*] LSI Logic New Generation RAID Device Drivers
        <*> Serial ATA (SATA) support
            <*> Intel PIIX/ICH SATA support
    Fusion MPT device support  --->
        <*> Fusion MPT ScsiHost drivers for SPI
        <*> Fusion MPT ScsiHost drivers for FC
        <*> Fusion MPT ScsiHost drivers for SAS
        (128) Maximum number of scatter gather entries (16 - 128)
        <*> Fusion MPT misc device (ioctl) driver
        <*> Fusion MPT LAN driver
    Network device support  --->
        Ethernet (10 or 100Mbit)  --->
            [*] EISA, VLB, PCI and on board controllers
                <*> AMD PCnet32 PCI support

最后选择 Save an alternative configuration 什么的,文件名默认 .config .

livecd linux # make && make modules_install

我不知道官方教程的 make -j2 是什么意思。

安装系统工具:

livecd / # emerge syslog-ng vixie-cron
livecd / # rc-update add syslog-ng default
livecd / # rc-update add vixie-cron default
livecd / # emerge dhcpcd
livecd / # emerge ppp

配置引导:

livecd / # emerge grub

去修改 /boot/grub/grub.conf , 这里我删掉了 real_root=/dev/sda3 如果有问题再回来。

然后:

livecd / # grub
Probing devices to guess BIOS drives. This may take a long time.
grub> root (hd0,0)
 Filesystem type is ext2fs, partition type 0xfd
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

最后退出 chroot, 然后重启:

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

或者:

livecd / # poweroff

这样就可以拿出光盘了。

原创文章,转载请注明来源:http://euyuil.com/2372/note-about-gentoo-installation/