Kinaconの技術ブログ

Ubuntuはじめました。

UbuntuをポータブルSSDで運用する

f:id:m-oota-711:20180824075049j:plain

PCを頻繁に換える必要があり、どのPCでも同じ環境で作業できるように

ポータブルSSDにUbuntu18.04をフルインストールした。

作業内容

準備品

参考

USB HDDにMBR/EFI両ブート可能なUbuntuイメージを作る方法 - bellbind

1. ポータブルSSDの初期化

SSDパーティションスタイルをMBRにする。

sudo fdisk -l

下のように表示されるので容量を見て確認する
ここでは /dev/sdc がポータブルSSDです。

Disk /dev/sdc: 59 GiB, 63350767616 bytes, 123731968 sectors
sudo gdisk -l /dev/sdc

GPTになっている場合は以下のように表示される。

GPT fdisk (gdisk) version 1.0.3

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

Found valid GPT with protective MBR; using GPT.
sudo parted /dev/sdd


#GNU Parted 3.2
#Using /dev/sdd
#Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted)<span style="color: #0000cc"> mklabel</span>  

New disk label type? <span style="color: #0000cc">msdos</span>  

#Warning: Partition(s) on /dev/sdd are being used.
Ignore/Cancel? <span style="color: #0000cc">Ignore</span>  

#Warning: The existing disk label on /dev/sdd will be destroyed and all data on this disk will be lost.  
Do you want to continue?
Yes/No?<span style="color: #0000cc"> yes</span>  

#Error: Partition(s) 1 on /dev/sdd have been written, but we have been unable to inform the kernel of the change, probably because it/they are in use.  
#As a result, the old partition(s) will remain in use.  
#You should reboot now beforemaking further changes.
Ignore/Cancel? <span style="color: #0000cc">Ignore</span>  

(parted)<span style="color: #0000cc"> q</span>

この操作でパーティションunlocatedになっている。
パーティション作成はUbuntu18.04のインストーラで行う。

2. レガシーブートでUbuntuをインストール

BIOSの設定を変更する

  • ブートデバイスの優先をUSBHDDにする
  • ブートモードはレガシー ※UEFIではない
  • セキュアブートは解除

LiveUSBでインストールを実行する

インストールを進めていき、
「インストールの種類」でそれ以外を選択する。

パーティション サイズ 利用方法 マウントポイント
sdc1 200MB fat32
sdc2 30000MB ext4 /
sdc3 8000MB swap

※残りの空き容量は後でデータ移行用に残しておいた。

ブートローダをインストールするデバイスsdcとしてインストールする。

3. EFIブートローダの作成

イントールが終了したら、
レガシーブートでインストールしたUbuntu(ポータブルSSD)を起動する。

  • linux-image更新時などにOSのブートメニューをgrubに登録しないようにする。
sudo chmod -x /etc/grub.d/30_os-prober
  • OSのアップグレード
sudo apt update
sudo apt full-upgrade
sudo apt-get install grub-efi-amd64-binbash
grub-mkimage -d /usr/lib/grub/x86_64-efi/ \
  -o BOOTx64.EFI \
  -O x86_64-efi \
  -p "" \
  part_gpt part_msdos ntfs ntfscomp hfsplus fat ext2 \
  normal chain boot configfile linux multiboot
mkdir efi
sudo mount /dev/sdc1 efi
mkdir -p efi/EFI/BOOT
cp BOOTx64.EFI efi/EFI/BOOT/
cp -r /usr/lib/grub/x86_64-efi efi/EFI/BOOT/
  • grub.cfgファイルの作成
sudo gedit efi/EFI/BOOT/grub.cfg
  • grub.cfgの内容

    configfile (hd0,msdos2)/boot/grub/grub.cfg

  • unicode.pf2ファイルのコピー

mkdir efi/EFI/BOOT/fonts
cp /usr/share/grub/unicode.pf2 efi/EFI/BOOT/fonts/

再起動

レガシーブートでもUEFIブートでも起動できるはず。

以上。