LoginSignup
8
5

More than 5 years have passed since last update.

#gentooinstallbattle UEFI+GRUB2+btrfs編

Last updated at Posted at 2014-06-07

概要


Create VMWare VM and boot from SystemRescueCD

[mazgi@Ardbeg] $ grep 'efi' /Volumes/Macintosh\ HD\ Data/Documents/Virtual\ Machines.localized/Gentoo\ EFI.vmwarevm/Gentoo\ EFI.vmx
firmware = "efi"
  • boot from UEFI

UEFIから起動するとこんな表示になります。

Screen Shot 2014-06-07 at 12.57.31 PM.png

  • boot from BIOS

こちらはBIOSから起動した場合の表示。

Screen Shot 2014-06-07 at 12.58.46 PM.png

Configure network (optional)

さっさとsshでログインしたいのでネットワークの設定を行う。

root@sysresccd /root % ip addr add 0.0.0.0/24 broadcast 0.0.0.255 dev eth0
root@sysresccd /root % ip route add default via 0.0.0.1 dev eth0

Create GPT partition and FileSystems

root@sysresccd /root % gdisk -l /dev/sda
GPT fdisk (gdisk) version 0.8.8

Partition table scan:
  MBR: protective
  BSD: not present
  APM: not present
  GPT: present

Found valid GPT with protective MBR; using GPT.
Disk /dev/sda: 41943040 sectors, 20.0 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): 03971A2E-1840-4748-B2CC-E93346F2ACF0
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 41943006
Partitions will be aligned on 2048-sector boundaries
Total free space is 2014 sectors (1007.0 KiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048         1050623   512.0 MiB   EF00  EFI System
   2         1050624         3147775   1024.0 MiB  8200  Linux swap
   3         3147776        41943006   18.5 GiB    8300  Linux filesystem

ちなみにBIOS+GPTの場合はこんな感じにする

root@sysresccd /root % gdisk -l /dev/sda
GPT fdisk (gdisk) version 0.8.10

Partition table scan:
  MBR: protective
  BSD: not present
  APM: not present
  GPT: present

Found valid GPT with protective MBR; using GPT.
Disk /dev/sda: 167772160 sectors, 80.0 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): 9CC8E12D-DAD9-4A1D-BC2F-7E613E99DC45
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 167772126
Partitions will be aligned on 2048-sector boundaries
Total free space is 2014 sectors (1007.0 KiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048           10239   4.0 MiB     EF02  BIOS boot partition
   2           10240         4204543   2.0 GiB     8200  Linux swap
   3         4204544       167772126   78.0 GiB    8300  Linux filesystem
root@sysresccd /root % mkfs.vfat -F32 /dev/sda1 
mkfs.fat 3.0.22 (2013-07-19)
root@sysresccd /root % mkswap /dev/sda2 
Setting up swapspace version 1, size = 1048572 KiB
no label, UUID=341beae9-111d-4cc0-8104-4cb343099b89
root@sysresccd /root % mkfs.btrfs /dev/sda3 

WARNING! - Btrfs v3.12 IS EXPERIMENTAL
WARNING! - see http://btrfs.wiki.kernel.org before using

Turning ON incompat feature 'extref': increased hardlink limit per file to 65536
fs created label (null) on /dev/sda3
    nodesize 16384 leafsize 16384 sectorsize 4096 size 18.50GiB
Btrfs v3.12
root@sysresccd /root % mkdir -p /mnt/btrfs
root@sysresccd /root % mount /dev/sda3 /mnt/btrfs 
root@sysresccd /root % cd /mnt/btrfs 
root@sysresccd /mnt/btrfs % btrfs subvolume create gentoo
Create subvolume './gentoo'
root@sysresccd /mnt/btrfs % btrfs subvolume create usr-portage
Create subvolume './usr-portage'
root@sysresccd /mnt/btrfs % btrfs subvolume create var-log    
Create subvolume './var-log'
root@sysresccd /mnt/btrfs % mount -odefaults,subvol=gentoo,compress=lzo,autodefrag /dev/sda3 /mnt/gentoo
root@sysresccd /mnt/btrfs % cd /mnt/gentoo 
root@sysresccd /mnt/gentoo % mkdir -p usr/portage var/log
root@sysresccd /mnt/gentoo % mount -odefaults,subvol=usr-portage,compress=lzo,autodefrag /dev/sda3 usr/portage
root@sysresccd /mnt/gentoo % mount -odefaults,subvol=var-log,compress=gzip,autodefrag /dev/sda3 var/log

Download and extract stage3

ミラーサイト一覧にあるミラーサイトからstage3とportageスナップショットをダウンロードする。

root@sysresccd /mnt/gentoo % pwd
/mnt/gentoo
root@sysresccd /mnt/gentoo % curl -LO 'ftp://ftp.iij.ad.jp/pub/linux/gentoo/snapshots/portage-latest.tar.xz'
root@sysresccd /mnt/gentoo % curl -LO 'ftp://ftp.iij.ad.jp/pub/linux/gentoo/releases/amd64/autobuilds/current-stage3-amd64/stage3-amd64-20150924.tar.bz2'

stage3とportageスナップショットを展開する。

stage3はパーミッションを保持する(-p)、portageスナップショットはusr/に展開することに注意。

root@sysresccd /mnt/gentoo % tar xfp stage3-amd64-20150924.tar.bz2
root@sysresccd /mnt/gentoo % tar xf portage-latest.tar.xz -C usr/

Chroot

root@sysresccd /mnt/gentoo % mount --rbind /dev dev/
root@sysresccd /mnt/gentoo % mount --rbind /sys sys/
root@sysresccd /mnt/gentoo % mount -t proc none proc/

chroot前に /etc/resolv.conf をコピーしておかないとchroot後の環境で名前解決ができない。

root@sysresccd /mnt/gentoo % cp /etc/resolv.conf etc/
cp: overwrite 'etc/resolv.conf'? y

chrootする。

root@sysresccd /mnt/gentoo % chroot /mnt/gentoo /bin/bash
sysresccd / # env-update
>>> Regenerating /etc/ld.so.cache...
sysresccd / # source /etc/profile
sysresccd / # export PS1="(chroot)$PS1"

SystemRescueCdにはtmuxが入っているのでここから先はtmuxを起動してchroot環境とchrootしていない環境を使い分けると楽。

Screen Shot 2015-09-29 at 11.27.31 AM.png

install packages && build kernel

(chroot)sysresccd / # emerge --sync -q
(chroot)sysresccd / # emerge -uvq @world
(chroot)sysresccd / # genkernel --menuconfig --makeopts=-j$(nproc) all

Install boot loader

(chroot)sysresccd / # grub2-install --target=x86_64-efi
(chroot)sysresccd / # grub2-mkconfig -o /boot/grub/grub.cfg

BIOS+GPTの場合はこんな感じにする

(chroot)sysresccd / # grub2-install /dev/sda
(chroot)sysresccd / # grub2-mkconfig -o /boot/grub/grub.cfg

Reboot

パスワード設定して/etc/fstabを書いておく。

やらないとかなり後悔することになる。

root@sysresccd /mnt/btrfs/gentoo % grep -vE '^\s*(#|$)' etc/fstab
/dev/vda3   /       btrfs   defaults,subvol=gentoo,compress=lzo,ssd,discard,space_cache,autodefrag,inode_cache  1 2
/dev/vda3   /var/log    btrfs   defaults,subvol=var-log,compress=gzip,ssd,discard,space_cache,autodefrag,inode_cache    1 2
/dev/vda3   /usr/portage    btrfs   defaults,subvol=usr-portage,compress=lzo,ssd,discard,space_cache,autodefrag,inode_cache 1 2
/dev/vda2   none        swap    sw  0 0
  • reboot
8
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
5