LoginSignup
2
3

More than 5 years have passed since last update.

Gentooインストール(無線LANで): LUKS, LVM, UEFI, systemd, GNOME3

Last updated at Posted at 2016-12-30

現在ブートプロセス中にエラーが発生しております。
Loading initial ramdisk ...
を最後に動きません。。。

[解決済]現在grub-installでエラーが発生しております。
https://teratail.com/questions/61991

以下のサイトを参考にしました。
https://wiki.gentoo.org/wiki/Sakaki%27s_EFI_Install_Guide/Building_the_Gentoo_Base_System_Minus_Kernel
https://wiki.gentoo.org/wiki/Handbook:AMD64/Installation/Base/ja
http://note.kurodigi.com/gentoo-uefi-install/
http://ririgon.hatenadiary.jp/entry/20150401/1427821349
https://sharpencryptedpig.noblogs.org/post/2014/05/29/how-to-install-gentoo-hardened-with-encrypted-root-and-swapexpress-procedure/
https://wiki.gentoo.org/wiki/Systemd/ja
https://wiki.gentoo.org/wiki/Intel
https://ja.wikipedia.org/wiki/Intel_HD_Graphics
http://www.hivestream.de/gentoo-installation-with-raid-lvm-luks-and-systemd.html
http://yuex.in/post/2016/12/gentoo-install-mbp-1.html

UEFIモードか確認
# ls /sys/firmware/
apci dmi efi memmap
キーボードレイアウトを変更
# loadkeys jp106
無線LAN設定
# ip link show
# ip link set <interface> up
# iwlist <interface> scanning | grep ESSID
# wpa_supplicant -B -i <interface> -c <(wpa_passphrase <ESSID> <password>)
# dhcpcd
# ping google.com
ディスクをLUKSで暗号化している場合は復号化
# cryptsetup open <device-path> <luks-device-name>
ディスク・lvmの使用状況を確認
# lsblk
# df -h
# lvscan

パーティションを作成する場合

sda1はESP(ef00)に設定
sda2はlvm用(8e00)に設定

# gdisk /dev/sdX
GPT fdisk (gdisk) version 0.8.6

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

Creating new GPT entries.

Command (? for help): o
This option deletes all partitions and creates a new protective MBR.
Proceed? (Y/N): y

Command (? for help): n
Partition number :
First sector:
Last sector: +512M
Hex code or GUID: ef00

Command (? for help): n
Partition number:
First sector:
Last sector: 
Hex code or GUID: 8e00

Command (? for help): w
Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!

Do you want to proceed?: y
OK; writing new GUID partition table (GPT) to /dev/sda.
The operation has completed successfully.
Logical Volumeの作成

作成するのはルートディレクトリのみです

lvcreate -L 64G vg1 -n <lv-root-name>
ファイルシステムの作成

ext4で作成します。

mkfs.ext4 <lv-root-path>
スワップはオンにする
# swapon <lv-swap-path>
ルートをマウント
# mount <lv-root-path> /mnt/gentoo
EFIディレクトリ作成とマウント
mkdir -p /mnt/gentoo/boot/efi
mount /dev/sda1 /mnt/gentoo/boot/efi

ちゃんとできたか確認

# lsblk
時刻を確認
#date
tarball(ステージ3)をダウンロードして展開します。
cd /mnt/gentoo

wget http://ftp.jaist.ac.jp/pub/Linux/Gentoo/releases/amd64/autobuilds/current-stage3-amd64/stage3-amd64-<yyyymmdd>.tar.bz2

tar xvjpf stage3-amd64-<yyyymmdd>.tar.bz2 --xattrs

make.confの編集

VIDEO_CARDSの値は以下参照

lspci | grep VGA

https://wiki.gentoo.org/wiki/Intel
https://ja.wikipedia.org/wiki/Intel_HD_Graphics

vi /mnt/gentoo/etc/portage/make.conf

# These settings were set by the catalyst build script that automatically
# built this stage.
# Please consult /usr/share/portage/config/make.conf.example for a more
# detailed example.
CFLAGS="-O2 -pipe"
CXXFLAGS="${CFLAGS}"

# WARNING: Changing your CHOST is not something that should be done lightly.
# Please consult http://www.gentoo.org/doc/en/change-chost.xml before changing.
CHOST="x86_64-pc-linux-gnu"

# These are the USE and USE_EXPAND flags that were used for
# buidling in addition to what is provided by the profile.
USE="bindist"
CPU_FLAGS_X86="mmx sse sse2"

# Important Portage directories
PORTDIR="/usr/portage"
DISTDIR="${PORTDIR}/distfiles"
PKGDIR="${PORTDIR}/packages"

# Turn on logging
PORTAGE_ELOG_CLASSES="info warn error log qa"
PORTAGE_ELOG_SYSTEM="save"

# Setting for X11
VIDEO_CARDS="intel i965"
INPUT_DEVICES="evdev synaptics"

MAKEOPTS="-j4"
LINGUAS="en ja"

GRUB_PLATFORMS="efi-64"
ミラーの設定
mirrorselect -i -o >> /mnt/gentoo/etc/portage/make.conf

以下、引用
メインのGentooリポジトリ
ミラーを選択するために次に重要なステップは、/etc/portage/repos.conf/gentoo.confファイルでメインのGentooリポジトリを設定すること。
このファイルはPortageツリーを更新するときに必要になる同期情報を含んでいます
Portageツリー:
Portageがソフトウェアパッケージをダウンロード、インストールする時に必要なすべての情報を含むebuildと関連ファイルを集めたもの

メインのGentooリポジトリの設定は単純です。
最初に(存在しなければ)repos.confディレクトリを作成。

mkdir /mnt/gentoo/etc/portage/repos.conf

次に、Portageが提供するGentooリポジトリ設定ファイルを(新規作成した)repos.confディレクトリにコピーします。

cp /mnt/gentoo/usr/share/portage/config/repos.conf /mnt/gentoo/etc/portage/repos.conf/gentoo.conf
DNS情報のコピー

/etc/resolv.confをコピーしておく

cp -L /etc/resolv.conf /mnt/gentoo/etc/
色々マウントする

以下、引用
必要なファイルシステムをマウントする
新しい環境を適切に動作させるために、いくつかのファイルシステムを使えるようにしなければなりません。
/proc/
Linuxカーネルから情報を引き出すための擬似ファイルシステム
/sys/
/proc/同様、擬似ファイルシステムです。/proc/より構造化されており、一度は/proc/を置き換えることが目的
/dev/
通常のファイルシステムです。一部はLinuxのデバイス管理機構(通常はudev)により管理されており、すべてのデバイスファイルを含む。

/proc/は、/mnt/gentoo/proc/にマウントされるでしょう。
他の2つはbindマウントされます。

mount -t proc proc /mnt/gentoo/proc
mount --rbind /sys /mnt/gentoo/sys
mount --make-rslave /mnt/gentoo/sys
mount --rbind /dev /mnt/gentoo/dev
mount --make-rslave /mnt/gentoo/dev
chrootします。
chroot /mnt/gentoo /bin/bash
source /etc/profile
export PS1="(chroot) $PS1"
portageのスナップショットをインストールする
emerge-webrsync

Portageツリーを最新版にアップデート
(やらなくてもよいと公式HPに書いてありました。結構長かったです。)

emerge --sync --quiet

Portageからのニュース
飛ばします

選択できるプロファイルの確認
eselect profile list
プロファイルを変更
eselect profile set default/linux/amd64/13.0/desktop/gnome/systemd

プロファイルの変更を確認

eselect profile list
プロファイルを変更したので、更新する
emerge --ask --update --deep --newuse @world
無線LANツールをインストールしておく
emerge -av net-wireless/wireless-tools net-wireless/wpa_supplicant net-misc/dhcpcd
いろいろemerge
# emerge -av vim app-misc/screen cryptsetup lvm2
ロケールを設定する。
ls /usr/share/zoneinfo
echo "Japan" > /etc/timezone
emerge --config sys-libs/timezone-data
vim /etc/locale.gen
:
en_US.UTF-8 UTF-8
:
jp_JP.UTF-8 UTF-8
:
locale-gen
eselect locale list
eselect locale set [0-9]
env-update
source /etc/profile
export PS1="(chroot) $PS1"
genkernelではなくマニュアルでカーネルを設定します。

カーネルソースのインストール
カーネルソースを/usr/src/にインストールします

emerge -av sys-kernel/gentoo-sources

カーネルをMake

カーネルコンフィギュレーション設定をする
cd /usr/src/linux
make menuconfig
    Gentoo Linux --->
            [*] Gentoo Linux support (NEW)
            [*] Linux dynamic and persistent device naming (userspace devfs) support (NEW)
            [*] Select options required by Portage features (NEW)
          Support for init systems, system and service managers --->
            [*] OpenRC, runit and other script based systems and managers
            [*] systemd
[*] 64-bit kernel
    General Setup --->
      ()  Cross-compiler tool prefix (NEW)
      [ ] Compile also drivers which will not load (NEW)
      ()  Local version - append to kernel release (NEW)
      [ ] Automatically append version information to the version string
          Kernel compression mode (Gzip) --->
      ((none)) Default hostname (NEW)
      [*] Support for paging of anonymous memory (swap) (NEW)
      :
      -*- System V IPC
      :
      -*- Control Group support --->
            --- Control Group support
            [ ]   Example debug cgroup subsystem
            [*]   Freezer cgroup subsystem
            :
            [*]   Device controller for cgroups
            [*]   Cpuset support
            [*]     Include legacy /proc/<pid>/cpuset file
            [*]   Simple CPU accounting cgroup subsystem
            [*]   Resource counters
            [*]     Memory Resource Controller for Control Groups
            [*]       Memory Resource Controller Swap Extension
            [*]         Memory Resource Controller Swap Extension enabled by default
            [*]       Memory Resource Controller for Kernel Memory accounting
            [ ]     HugeTLB Resource Controller for Control Groups
            [*]   Enable perf_event per-cpu per-container group (cgroup) monitoring
            [*]   Group CPU scheduler --->
            [*]   Block IO contoroller
            [ ]     Enable Block IO controller debugging
      -*- Namespaces support --->
            --- Namespaces support
            [*] UTS namespace
            [*] IPC namespace
            [*] User namepace
            [*] PID Namespaces
            -*- Network namespace
      :
      [*] Initial RAM filesystem and RAM disk (initramfs/initrd) support
      :
      [*] Configure standard kernel features (expert users)  --->
            :
            [*] Enable eventpoll support
            [*] Enable signalfd() system call
            [*] Enable timerfd() system call
      :
    -*- Enable the block layer --->
      --- Enable the block layer
          Partition Types --->
             :
            [*]   EFI GUID partition support

    Processor type and features --->
      :
      [*] EFI runtime service support
      [*]   EFI stub support
      [ ]     EFI mixed-mode support
       :
      [*] Built-in kernel command line
      :
    :
    Device Drivers --->
          Generic Driver Options --->
            [*] Support for uevent helper
            (/sbin/hotplug)    path to uevent helper
          :
          Multiple devices driver support (RAID and LVM)  --->
                 <*> Device mapper support
                 <*> Crypt target support
                 <*> Snapshot target
                 <*> Mirror target
                 <*> Multipath target
                 <*>   I/O Path Selector based on the number of in-flight I/Os
                 <*>   I/O Path Selector based on the service time

    Firmware Drivers --->
          EFI (Extensible Firmware Interface)  Support >
                 <*> EFI Variable Support via sysfs
-*- Cryptographic API
     <*>  SHA256 digest algorithm (SSSE3/AVX/AVX2)
     <*>  SHA512 digest algorithm
     <*>  AES cipher algorithms (x86_64)
カーネルのコンパイルとモジュールインストールとカーネルのインストール
make && make modules_install && make install

initramfsの生成

次回はdracutでやってみよう
http://www.hivestream.de/gentoo-installation-with-raid-lvm-luks-and-systemd.html

genkernelのemerge

# echo "sys-kernel/genkernel-next cryptsetup" > /etc/portage/package.use/genkernel-next
# emerge -av genkernel-next

initramfsの作成

genkernel --udev –-lvm –-luks –-install initramfs
ls /boot/initramfs*

以下引用
/etc/mtab

開発元は、 /etc/mtab ファイルが /proc/self/mounts へのシンボリックリンクである環境のみをサポートしています。
また、このシンボリックリンクが存在しない場合、mount (bug #434090) および df (bug #477240) にも問題が発生します。
かつて一部のユーティリティがマウントオプションなどを書き込んでいたため、/etc/mtab は通常のファイルであることが期待されていましたが、現在ではあらゆるソフトウェアが対策を終えているものと思われます。
とはいえ念のため、ファイルをリンクに変更する作業を行う前に、 bug #477498 を閲覧の上、システムが既知の問題を抱えていないことをお確かめください。
シンボリックリンクを作成するには、以下を実行します:

# ln -sf /proc/self/mounts /etc/mtab

LVM を使用するシステムでは、LVM ボリュームをマウントするため、systemd と共に lvmetad デーモンが起動されなければなりません。
lvmetad は /etc/lvm/lvm.conf で有効化できます:

# vim /etc/lvm/lvm.conf
:
use_lvmetad = 1
:

任意自由選択: ファームウェアのインストール

emerge -av sys-kernel/linux-firmware
自動マウントの設定

まず、コピペできるようにUUIDを/etc/fstabに追記します。

blkid >> /etc/fstab

/etc/fstabを編集する

vim /etc/fstab
:
# <fs>            <mountpoint>    <type>     <opts>                  <dump/pass>
UUID=<UUID>       /               ext4       defaults,noatime        0 1
UUID=<UUID>       /boot/efi       vfat       defaults,noatime        0 2
UUID=<UUID>       none            swap       sw                      0 0
:
ホストネームの設定
echo <hostname> > /etc/conf.d/hostname
ルートパスワードの設定
passwd root
キーマップの設定
vim /etc/conf.d/keymaps
:
keymap="jp106"
:

サービス・デーモンのインストール
やらなかった

emerge -av app-admin/sysklogd sys-apps/systemd net-misc/dhcpcd

/etc/hostsの編集

vim /etc/hosts
:
# IPv4 and IPv6 localhost aliases
127.0.0.1       localhost <hostname>
::1             localhost <hostname>
:

ブートローダー

GRUB2とsys-fs/dosfstoolとefibootmgrのインストール
lvmとluksを使用するためにはGRUBがdevice mapperをサポートする必要があります。

# echo "sys-boot/grub:2 device-mapper" >> /etc/portage/package.use/grub:2
# emerge -av sys-boot/grub:2 sys-fs/dosfstools sys-boot/efibootmgr
# emerge -av sys-fs/dosfstools sys-boot/efibootmgr

/etc/default/grubを編集

Note
dracut が systemd をとりこんで生成した initramfs を使用するときには、この作業は必要ありません。initramfs が systemd を起動することになります。
FILE /etc/default/grubConfigure GRUB2 for systemd

/etc/crypttab is for when you need to decrypt any partition except 'root (/)'. In your use case scenario decryption occurs only in initramfs.

vim /etc/default/grub
:
GRUB_CMDLINE_LINUX="cryptdevice=/dev/disk/by-uuid/<UUId>:<luks-disk-name>" init=/usr/lib/systemd/systemd"
:
GRUB_ENABLE_CRYPTODISK=y

use_lvmetad = 0
https://wiki.archlinuxjp.org/index.php/%E6%97%A2%E5%AD%98%E3%81%AE_Linux_%E3%81%8B%E3%82%89%E3%82%A4%E3%83%B3%E3%82%B9%E3%83%88%E3%83%BC%E3%83%AB#lvmetad

vim /etc/lvm/lvm.conf
:
volume_list = { "vg1" }
:
GRUB2をESPにインストール(ここでエラー発生中)
grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=gentoo_grub --recheck
# mkdir /boot/efi/EFI/boot
# cp /boot/efi/EFI/arch_grub/grubx64.efi  /boot/efi/EFI/boot/bootx64.efi
# grub-mkconfig -o /boot/grub/grub.cfg
これで終了なので、アンマウントしてリブート
exit
umount -R /mnt/gentoo/
reboot
2
3
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
2
3