安装gentoo详细步骤

因公司使用的系统为gentoo,故安装gentoo并做个笔记,以下骤来自http://showerlee.blog.51cto.com/2047005/1314053。

所需的镜像文件和软件包地址:

http://mirror.sohu.com/gentoo/releases/x86/current-iso/install-x86-minimal-20140415.iso

http://mirror.sohu.com/gentoo/releases/x86/current-iso/stage3-i686-20140415.tar.bz2

http://mirror.sohu.com/gentoo/releases/snapshots/current/portage-latest.tar.bz2


1)引导启动后输入如下命令

boot:gentoo dopcmcia

2)配置root用户密码

livecd~#passwd root

3)开启ssh服务

livecd~#/etc/init.d/sshd start

4)因为我使用的连接方式为:与我的MAC共享,所以现在已通过 dhcp服务器获取到了IP,并可以上网

livecd ~ # ifconfig
enp2s1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.16.82.132  netmask 255.255.255.0  broadcast 172.16.82.255
        inet6 fe80::20c:29ff:fe7f:8c8d  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:7f:8c:8d  txqueuelen 1000  (Ethernet)
        RX packets 83  bytes 10212 (9.9 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 74  bytes 12851 (12.5 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        device interrupt 19  base 0x2000
lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 0  (Local Loopback)
        RX packets 6  bytes 212 (212.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 6  bytes 212 (212.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
livecd ~ # ping www.baidu.com
PING www.a.shifen.com (115.239.210.27) 56(84) bytes of data.
64 bytes from 115.239.210.27: icmp_seq=1 ttl=128 time=10.7 ms
64 bytes from 115.239.210.27: icmp_seq=2 ttl=128 time=11.3 ms
64 bytes from 115.239.210.27: icmp_seq=3 ttl=128 time=12.4 ms
^C
--- www.a.shifen.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2002ms
rtt min/avg/max/mdev = 10.733/11.507/12.465/0.724 ms
livecd ~ #

5)对硬盘分区

分区方案:/boot  200M  swap 1024M /  剩余所有空间

livecd ~ #fdisk -l
Disk /dev/sda: 64.4 GB, 64424509440 bytes, 125829120 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x551a2ca1
   Device Boot      Start         End      Blocks   Id  System
livecd ~ #
livecd ~ # fdisk /dev/sda
Welcome to fdisk (util-linux 2.22.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-125829119, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-125829119, default 125829119): +200M
Partition 1 of type Linux and of size 200 MiB is set
Command (m for help): n
Partition type:
   p   primary (1 primary, 0 extended, 3 free)
   e   extended
Select (default p): p
Partition number (1-4, default 2): 2
First sector (411648-125829119, default 411648):
Using default value 411648
Last sector, +sectors or +size{K,M,G} (411648-125829119, default 125829119): +1024M
Partition 2 of type Linux and of size 1 GiB is set
Command (m for help): n
Partition type:
   p   primary (2 primary, 0 extended, 2 free)
   e   extended
Select (default p): p
Partition number (1-4, default 3): 3
First sector (2508800-125829119, default 2508800):
Using default value 2508800
Last sector, +sectors or +size{K,M,G} (2508800-125829119, default 125829119):
Using default value 125829119
Partition 3 of type Linux and of size 58.8 GiB is set
Command (m for help): p
Disk /dev/sda: 64.4 GB, 64424509440 bytes, 125829120 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x551a2ca1
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1            2048      411647      204800   83  Linux
/dev/sda2          411648     2508799     1048576   83  Linux
/dev/sda3         2508800   125829119    61660160   83  Linux
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
livecd ~ #

6)将/dev/sda1和/dev/sda3格式化为ext4文件系统,将/dev/sda2格式化为swap文件分区

livecd ~ # mkfs.ext4 /dev/sda1
mke2fs 1.42.7 (21-Jan-2013)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
51200 inodes, 204800 blocks
10240 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=67371008
25 block groups
8192 blocks per group, 8192 fragments per group
2048 inodes per group
Superblock backups stored on blocks:
8193, 24577, 40961, 57345, 73729
Allocating group tables: done                          
Writing inode tables: done                          
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done
livecd ~ # mkfs.ext4 /dev/sda3
mke2fs 1.42.7 (21-Jan-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
3858432 inodes, 15415040 blocks
770752 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=0
471 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, 7962624, 11239424
Allocating group tables: done                          
Writing inode tables: done                          
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done 
livecd ~ # mkswap /dev/sda2
mkswap: /dev/sda2: warning: wiping old swap signature.
Setting up swapspace version 1, size = 1048572 KiB
no label, UUID=0cd7ad9e-0192-4e68-bf4b-bb80ec54b351
livecd ~ # swapon /dev/sda2
livecd ~ # swapon -s
Filename     Type    Size   Used    Priority
/dev/sda2                               partition   1048572 0   -1
livecd ~ #

7)创建系统临时挂载点

livecd ~ # mount /dev/sda3 /mnt/gentoo
livecd ~ # mkdir /mnt/gentoo/boot
livecd ~ # mount /dev/sda1 /mnt/gentoo/boot
livecd ~ #

8)下载系统编译包portage和stage3到/mnt/gentoo目录下

livecd ~ # cd /mnt/gentoo/
livecd gentoo # pwd
/mnt/gentoo
livecd gentoo # ll
total 17
drwxr-xr-x 3 root root  1024 May  6 10:02 boot
drwx------ 2 root root 16384 May  6 10:03 lost+found
livecd gentoo #
livecd gentoo # ll
total 237849
drwxr-xr-x 3 root root      1024 May  6 10:02 boot
drwx------ 2 root root     16384 May  6 10:03 lost+found
-rw-r--r-- 1 root root  69680314 May  4 00:45 portage-latest.tar.bz2
-rw-r--r-- 1 root root 173858657 Apr 15 14:25 stage3-i686-20140415.tar.bz2

9)解压stage3和portage两个文件

livecd gentoo # tar xf stage3-i686-20140415.tar.bz2
livecd gentoo # tar xf portage-latest.tar.bz2 -C /mnt/gentoo/usr
livecd gentoo #

10)切换系统到/dev/sda3根分区上并更新系统环境变量

livecd gentoo # mount -t proc none /mnt/gentoo/proc
livecd gentoo # mount -o bind /dev /mnt/gentoo/dev
livecd gentoo # chroot /mnt/gentoo /bin/bash
livecd / # env-update
>>> Regenerating /etc/ld.so.cache...
livecd / # source /etc/profile
livecd / # export PS1="(HBSSLIULEI)$PS1"
(HBSSLIULEI)livecd / #

11)设置时区

(HBSSLIULEI)livecd / # cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
(HBSSLIULEI)livecd / #

12)设置主机名

(HBSSLIULEI)livecd / # cat /etc/conf.d/hostname
# Set to the hostname of this machine
hostname="localhost"
(HBSSLIULEI)livecd / # sed -i 's/localhost/gentoo-02/' /etc/conf.d/hostname
(HBSSLIULEI)livecd / #
(HBSSLIULEI)livecd / # cat /etc/conf.d/hostname
# Set to the hostname of this machine
hostname="gentoo-02"
(HBSSLIULEI)livecd / #
(HBSSLIULEI)livecd / # echo "127.0.0.1 gentoo-02 localhost" > /etc/hosts
(HBSSLIULEI)livecd / # cat /etc/hosts
127.0.0.1 gentoo-02 localhost
(HBSSLIULEI)livecd / #

13)设置DNS

(HBSSLIULEI)livecd / # echo "nameserver 172.16.82.2" >> /etc/resolv.conf
(HBSSLIULEI)livecd / # cat /etc/resolv.conf
nameserver 172.16.82.2
(HBSSLIULEI)livecd / #

14)安装内核源码

(HBSSLIULEI)livecd / # emerge gentoo-sources
 * IMPORTANT: 6 news items need reading for repository 'gentoo'.
 * Use eselect news to read news items.
Calculating dependencies... done!
>>> Verifying ebuild manifests
>>> Emerging (1 of 2) sys-devel/bc-1.06.95
 * Fetching files in the background. To view fetch progress, run
 * `tail -f /var/log/emerge-fetch.log` in another terminal.
>>> Recording sys-kernel/gentoo-sources in "world" favorites file...
 * Messages for package sys-kernel/gentoo-sources-3.12.13:
 * If you are upgrading from a previous kernel, you may be interested
 * in the following document:
 *   - General upgrade guide: http://www.gentoo.org/doc/en/kernel-upgrade.xml
>>> Auto-cleaning packages...
>>> No outdated packages were found on your system.
 * Regenerating GNU info directory index...
 * Processed 77 info files.
 * IMPORTANT: 6 news items need reading for repository 'gentoo'.
 * Use eselect news to read news items.
(HBSSLIULEI)livecd / #

15)安装自动编译内核工具genkernel

(HBSSLIULEI)livecd / # emerge genkernel
…….
>>> Auto-cleaning packages...
>>> No outdated packages were found on your system.
 * Regenerating GNU info directory index...
 * Processed 78 info files.
 * IMPORTANT: 6 news items need reading for repository 'gentoo'.
 * Use eselect news to read news items.
(HBSSLIULEI)livecd / #

16)复制安装光盘的配置文件到genkernel搜索配置文件的默认位置

(HBSSLIULEI)livecd / # zcat /proc/config.gz > /usr/share/genkernel/arch/x86/kernel-config
(HBSSLIULEI)livecd / #

17)运行genkernel

(HBSSLIULEI)livecd / # cd /usr/src/
(HBSSLIULEI)livecd src # ll
bash: ll: command not found
(HBSSLIULEI)livecd src # ls
linux  linux-3.12.13-gentoo
(HBSSLIULEI)livecd src # mv linux linux.bak
(HBSSLIULEI)livecd src # ln -s linux-3.12.13-gentoo linux
(HBSSLIULEI)livecd src # ls
linux  linux-3.12.13-gentoo  linux.bak
(HBSSLIULEI)livecd src #
(HBSSLIULEI)livecd src # genkernel all        漫长的等待
* Gentoo Linux Genkernel; Version 3.4.45.1
* Running with options: all
* Kernel compiled successfully!
*
* Required Kernel Parameters:
*     root=/dev/$ROOT
*
*     Where $ROOT is the device node for your root partition as the
*     one specified in /etc/fstab
*
* If you require Genkernel's hardware detection features; you MUST
* tell your bootloader to use the provided INITRAMFS file.
* WARNING... WARNING... WARNING...
* Additional kernel cmdline arguments that *may* be required to boot properly...
* With support for several ext* filesystems available, it may be needed to
* add "rootfstype=ext3" or "rootfstype=ext4" to the list of boot parameters.
* Do NOT report kernel bugs as genkernel bugs unless your bug
* is about the default genkernel configuration...
*
* Make sure you have the latest ~arch genkernel before reporting bugs.
(HBSSLIULEI)livecd src #

18)查看内核和initrd的名字

(HBSSLIULEI)livecd src # ls /boot/                                  
System.map-genkernel-x86-3.12.13-gentoo  kernel-genkernel-x86-3.12.13-gentoo
initramfs-genkernel-x86-3.12.13-gentoo   lost+found
(HBSSLIULEI)livecd src #

19)安装vim编辑器

(HBSSLIULEI)livecd src # emerge vim

20)修改fstab文件

(HBSSLIULEI)livecd src # vim /etc/fstab
在尾部添加
/dev/sda1       /boot   ext4    defaults        1 2
/dev/sda2       swap    swap    defaults        0 0
/dev/sda3       /       ext4    defaults        1 1


(HBSSLIULEI)livecd src # vim /etc/fstab

21)配置网络

(HBSSLIULEI)livecd src # vim /etc/conf.d/net
config_enp2s1="172.16.82.128/24"
routes_enp2s1="default via 172.16.82.2"
(HBSSLIULEI)livecd src #
(HBSSLIULEI)livecd src # ln -s /etc/init.d/net.lo /etc/init.d/net.enp2s1
(HBSSLIULEI)livecd src # rc-update add net.enp2s1 default
(HBSSLIULEI)livecd src #echo "nameserver 172.16.82.2" >> /etc/resolv.conf
(HBSSLIULEI)livecd src # rc-update add sshd default

22)设置新安装gentoo系统用户root密码

(HBSSLIULEI)livecd ~ # passwd root
New password:
Retype new password:
passwd: password updated successfully
(HBSSLIULEI)livecd ~ #

23)配置时区

(HBSSLIULEI)livecd ~ # vim /etc/conf.d/clock
TIMEZONE="Asia/Shanghai"

24)安装常用系统工具

(HBSSLIULEI)livecd ~ # emerge syslog-ng
(HBSSLIULEI)livecd ~ # emerge logrotate
(HBSSLIULEI)livecd ~ # emerge vixie-cron
(HBSSLIULEI)livecd ~ # emerge dhcpcd
(HBSSLIULEI)livecd ~ # emerge slocate

25)加入开机自启动

(HBSSLIULEI)livecd ~ # rc-update add syslog-ng default
 * service syslog-ng added to runlevel default
(HBSSLIULEI)livecd ~ # rc-update add vixie-cron default
 * service vixie-cron added to runlevel default
(HBSSLIULEI)livecd ~ #

26)配置默认编辑器

(HBSSLIULEI)livecd ~ # echo "export EDITOR='/usr/bin/vim'" >> /etc/profile
(HBSSLIULEI)livecd ~ #
27)安装grub
(HBSSLIULEI)livecd ~ # emerge grub

28)配置grub

(HBSSLIULEI)livecd ~ # grub2-install --no-floppy /dev/sda
Installation finished. No error reported.
(HBSSLIULEI)livecd ~ # grub2-mkconfig -o /boot/grub/grub.cfg
Generating grub.cfg ...
Found linux image: /boot/kernel-genkernel-x86-3.12.13-gentoo
Found initrd image: /boot/initramfs-genkernel-x86-3.12.13-gentoo
done
(HBSSLIULEI)livecd ~ #
(HBSSLIULEI)livecd ~ #reboot

29)收尾,删除stage3,portage文件

(HBSSLIULEI)livecd ~ #rm -f /stage3-*.tar.bz2
(HBSSLIULEI)livecd ~ #rm -f /portage-lates.tar.bz2







你可能感兴趣的:(服务器,用户,密码,软件包)