Chinaunix首页 | 论坛 | 博客
  • 博客访问: 179812
  • 博文数量: 42
  • 博客积分: 2185
  • 博客等级: 大尉
  • 技术积分: 455
  • 用 户 组: 普通用户
  • 注册时间: 2009-06-11 21:32
文章分类

全部博文(42)

文章存档

2012年(5)

2011年(13)

2010年(6)

2009年(18)

我的朋友

分类: LINUX

2011-07-16 22:48:02

gentoo install with rsync

To add more fun, we also use grub2 + GPT + lvm2

Table of Contents

1 Partition

HD: 500G harddisk.

1.1 Set up partition with GPT

harddisk with parted as follow:

Model: ATA Hitachi HTS54505 (scsi)
Disk /dev/sdb: 500GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt

Number  Start   End     Size    File system  Name       Flags
 1      17.4kB  50.0MB  50.0MB               bios_grub  bios_grub
 2      50.3MB  500GB   500GB                lvm        lvm

NOTE:

  • To set flag bios_grub or lvm, run set 1 bios_grub or set 2 lvm.
  • Since grub2 can boot lvm, so we don't have to create a dedicated partition for /boot.

1.2 Setup LVM

Create physical volumne on new created lvm:

#  pvcreate /dev/sdb2 

Create virtual volumne, and physical volumne: We can use vgdisplay to show virtual volumne status at any time.

#  vgcreate vg02 /dev/sdb2 
#  vgchange -a y           # may not necessary.
#  vgdisplay vg02

Create logical volumne on virtual volumne: We can run lvdisplay to display logical volumne status at any time.

#  lvcreate vg02 -n gentoo -L 20G
#  lvcreate vg02 -n xen -L 10G
#  lvcreate vg02 -n debian -L 10G
#  lvcreate vg02 -n swap -L 4G
#  lvdisplay 

Run vgdisplay vg02, show how much free PEs left, and create partition for the last free PEs:

#  vgdisplay
#  lvcreate vg02 -n exports -l 107958         # all free PEs
#  lvdisplay

1.3 Create file systems on lvm

#  mkfs.ext4 /dev/mapper/vg02-gentoo
#  mkfs.ext4 /dev/mapper/vg02-xen
#  mkfs.ext4 /dev/mapper/vg02-debian
#  mkswap /dev/mapper/vg02-swap
#  mkfs.reiserfs /dev/mapper/vg02-exports

1.4 Mounting file system, prepare for install

We'd like to use UUID to mount file system, to get a UUID:

#  blkid /dev/mapper/vg02-gentoo
/dev/mapper/vg02-gentoo: UUID="f6f96ca8-6826-43cc-8f5e-9230ff5b7f04" TYPE="ext4"

Desired filesystem structure:

  • vg02-gentoo: Used for gentoo rootfs (We need install gentoo on this partition in this session).
  • vg02-xen: plan for xen, not used in this session
  • vg02-debian: plan for debian, not used in this session
  • vg02-swap: for swap
  • vg02-exports: for misc usage and home

The structure of partition is something like:


Mount PointMount Dst
vg02-gentoo/
vg02-exports/exports
vg02-swapSWAP
/exports/home/home (all home, IE: for debian/xen)
/exports/tmp/tmp (all tmp)
/exports/gentoo/portage/usr/portage
/exports/gentoo/src/usr/src
/exports/gentoo/tmp/var/tmp
/exports/debian/cache(debian)/var/cache

Prepare mount file system:

#  mount UUID="f6f96ca8-6826-43cc-8f5e-9230ff5b7f04" /mnt/install/
#  cd /mnt/install
#  mkdir exports
#  mount /dev/mapper/vg02-exports exports
#  mkdir -p usr/{portage,src} exports/tmp exports/{debian,gentoo,xen}
#  mkdir -p exports/gentoo/{tmp,src,portage}
#  mkdir -p exports/debian/{src,cache}
#  mkdir -p dev/pts sys proc
#  mkdir -p tmp var/tmp
#  chmod 1777 tmp var/tmp
#  chmod 1777 exports/tmp exports/gentoo/tmp

After the above partition layout have been mounted, we can start gentoo install.

2 Gentoo install

2.1 install with rsync (with another existing gentoo system).

Sync root file system, please note some directory shouldn't be synced, IE: /home, /proc

#  rsync -av root@192.168.1.11:/* . --exclude=/home --exclude=/backup --exclude=/exports --exclude=/usr/portage --exclude=/var/tmp --exclude=/usr/src --exclude=/root --exclude=/dev --exclude=/sys --exclude=/proc

/dev should also synced deperately, because /dev on a running system is mouted by udev.

(on remote server)
#  mount -L/gentoo /mnt/cdrom
(on client/install machine)
#  cd /mnt/install/dev
#  rsync -av root@192.168.1.11:/mnt/cdrom/dev * .
(on remote server)
#  umount /mnt/cdrom

After /dev has been mounted, we can then prepare for chroot:

#  mount -t sysfs none sys
#  mount -t proc none proc
#  mount -o bind /dev dev
#  mount -t devpts none dev/pts
#  mount -o bind /mnt/install/exports/tmp tmp
#  mount -o bind /mnt/install/exports/home home
#  mount -o bind /mnt/install/exports/gentoo/src usr/src
#  mount -o bind /mnt/install/exports/gentoo/portage usr/portage  
#  mount -o bind /mnt/install/exports/gentoo/tmp var/tmp

Chroot to the newly synced system /mnt/install:

#  chroot /mnt/install
#  export PS1="(chroot) $PS1"
(chroot) #  emerge --sync

2.2 (Optional) Gentoo install from stage3

You can find details from:

3 Tune the chrooted system.

3.1 (Optional) Change host name

This can be done by modify /etc/hostname

3.2 Account mangement

Modify /etc/passwd, /etc/group, /etc/shadow, or use tools like passwd, useradd, instead.

3.3 Install grub

Since we are using GPT partition table, we need use grub2 intead of grub:

(chroot) #  echo "=sys-boot/grub-9999     **" >> /etc/portage/package.keywords/default
(chroot) #  emerge -av grub            (Make sure grub2 is installed)
(chroot) #  grub-install /dev/sdX      (Change to the right sdX for grub installation)
(chroot) #  grub-mkconfig -o /boot/grub/grub.cfg

Please note we also need modify grub.cfg, add dolvm to kenrel commnad line. To support lvm & mount by uuid, we also need add --disklabel --lvm to genkernel when build kernel. And since grub2 have lvm support, so we don't have a dedicated /boot partition. /boot/grub/grub.cfg may something like:

...
insmod part_gpt
insmod lvm
insmod ext2
set root='(lvm/vg02-gentoo)'
search --no-floppy --fs-uuid --set=root f6f96ca8-xxxx-43cc-8f5e-9230ff5byyyy
if loadfont /usr/share/grub/unicode.pf2 ; then
  set gfxmode=640x480
  load_video
  insmod gfxterm
  insmod part_gpt
  insmod lvm
  insmod ext2
  set root='(lvm/vg02-gentoo)'
  search --no-floppy --fs-uuid --set=root f6f96ca8-xxxx-43cc-8f5e-9230ff5byyyy
  set locale_dir=($root)/boot/grub/locale
  set lang=
  insmod gettext
fi
terminal_output gfxterm
if sleep --interruptible 0 ; then
  set timeout=10
fi
### END /etc/grub.d/00_header ###

### BEGIN /etc/grub.d/10_linux ###
menuentry 'Gentoo GNU/Linux, with Linux x86_64-3.0.0-rc7' --class gentoo --class gnu-linux --class gnu --class os {
        load_video
        insmod gzio
        insmod part_gpt
        insmod lvm
        insmod ext2
        set root='(lvm/vg02-gentoo)'
        search --no-floppy --fs-uuid --set=root f6f96ca8-xxxx-43cc-8f5e-9230ff5byyyy
        echo    'Loading Linux x86_64-3.0.0-rc7 ...'
        linux   /boot/kernel-genkernel-x86_64-3.0.0-rc7 root=UUID=f6f96ca8-xxxx-43cc-8f5e-9230ff5byyyy ro dolvm 
        echo    'Loading initial ramdisk ...'
        initrd  /boot/initramfs-genkernel-x86_64-3.0.0-rc7
}
...

3.4 Modify /etc/fstab

Add mount point for rootfs, like: the UUID can be detected by run `` blkid ''.

UUID=f6f96ca8-xxxx-43cc-8f5e-9230ff5b7xxx       /               ext4            noatime         0 1
UUID=5d9b146b-xxxx-4111-82df-4ffa4826exxx       /exports        reiserfs        noatime,nodev,nosuid    0 0

/exports/gentoo/tmp     /var/tmp        none            bind            0 0
/exports/gentoo/portage /usr/portage    none            bind            0 0
/exports/gentoo/src     /usr/src        none            bind            0 0
UUID=aa180052-xxxx-4fa5-bfbc-18ff50ccxxxx               none            swap            sw              0 0
/dev/cdrom              /mnt/cdrom      auto            noauto,ro       0 0

/exports/home           /home           none            bind            0 0
(chroot) # 

3.5 Tune system services

(chroot) #  rc-update        (Show active services)
(chroot) #  rc-update del net.br0 default (Remove net.br0)
(chroot) #  rc-update add sshd default  (Add sshd, default on)

3.6 Configure network

Modify /etc/conf.d/net, if no setting applied in this file, by default, DHCP is used.

(chroot) #  echo > /etc/conf.d/net     (use default DHCP)

3.7 Remove persist net rules

(chroot) #  rm /etc/udev/rules.d/70-persistent-net.rules

3.8 Change ssh server public key

Please make sure use /etc/ssh/ssh_host_xxx_key instead of default key location ${HOME}/.ssh/id_xxx:

  (chroot) #  cd /etc/ssh
  (chroot) #  rm -i ssh_host_dsa_key  ssh_host_dsa_key.pub  ssh_host_ecdsa_key  ssh_host_ecdsa_key.pub  ssh_host_rsa_key  ssh_host_rsa_key.pub
  (chroot) # ssh-keygen -t ecdsa
Generating public/private ecdsa key pair.
Enter file in which to save the key (/root/.ssh/id_ecdsa): /etc/ssh/ssh_host_ecdsa_key
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /etc/ssh/ssh_host_ecdsa_key.
Your public key has been saved in /etc/ssh/ssh_host_ecdsa_key.pub.
The key fingerprint is:
14:a2:67:b7:85:ac:b9:57:3b:92:99:0a:75:8a:18:70 root@localhost
The key's randomart image is:
+--[ECDSA  256]---+
|      . .        |
|     . o o       |
|. E . o = .      |
| o   o = o       |
|  .   + S .      |
|   o o + = .     |
|  . o o * o      |
|     . o . .     |
|      .          |
+-----------------+
(chroot) # ssh-keygen -t dsa
Generating public/private dsa key pair.
Enter file in which to save the key (/root/.ssh/id_dsa): /etc/ssh/ssh_host_dsa_key
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /etc/ssh/ssh_host_dsa_key.
Your public key has been saved in /etc/ssh/ssh_host_dsa_key.pub.
The key fingerprint is:
0d:48:79:3d:d6:00:0b:35:e2:2a:24:bd:f2:4e:31:c9 root@localhost
The key's randomart image is:
+--[ DSA 1024]----+
|      +o+o.o     |
| .   o.+.o+ .    |
|. o   o.o. .     |
| + o .   o       |
|. E .   S .      |
| o +             |
|  o              |
| o               |
|  .              |
+-----------------+
(chroot) # ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): /etc/ssh/ssh_host_rsa_key
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /etc/ssh/ssh_host_rsa_key.
Your public key has been saved in /etc/ssh/ssh_host_rsa_key.pub.
The key fingerprint is:
bf:1a:f9:79:7a:03:3e:56:55:8a:13:75:d1:ed:2c:40 root@localhost
The key's randomart image is:
+--[ RSA 2048]----+
|           .E...=|
|            o  .+|
|             + = |
|            o + o|
|        S    o . |
|         o. .    |
|        o..o     |
|         o+o+    |
|        .o== .   |
+-----------------+
(chroot) licj-pc ssh # ls
moduli  ssh_config  sshd_config  ssh_host_dsa_key  ssh_host_dsa_key.pub  ssh_host_ecdsa_key  ssh_host_ecdsa_key.pub  ssh_host_rsa_key  ssh_host_rsa_key.pub

3.9 Tune /etc/make.conf

This is the same as gentoo stage3 install, but since /etc/make.conf already configured on target (rsync server) system, so please modify it as your own.

3.10 Umount filesystem, reboot to the new system

阅读(1865) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~