Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hangingman/dad73ac514ec6fb913199d71b7fb653e to your computer and use it in GitHub Desktop.
Save hangingman/dad73ac514ec6fb913199d71b7fb653e to your computer and use it in GitHub Desktop.
ディスク容量の小さいSSDに移行する

参考

gpartedでefi用の領域を用意する

以降、SSDのデバイス名を「/dev/nvme0n1」として記載

  • GPTのエントリを書き込む
$ sudo gdisk /dev/nvme0n1
w
  • EFIシステムパーティションを作成
    • 『GParted』を開いて、対象のSSD・HDD・USBメモリを選びます。空き領域に以下の設定でパーティションを作成
容量200MB程度
Partition Name:『ESP』
基本パーティション
ラベル:『ESP』
ファイルシステム:『FAT32』

applyしたあと、作られた領域を右クリックして、『フラグを編集』をクリック。 

  • 『boot』
  • 『esp』 の二つにチェックマークを付けます

上記で2つのパーティションができる。以降、efi用の領域を「/dev/nvme0n1p1」、データ用の領域を「/dev/nvme0n1p2」として手順を記載する。

rsyncでデータ用の領域を同期

// コピー先SSD
$ sudo mkdir /mnt/ssd
$ sudo mount /dev/nvme0n1p2 /mnt/ssd
// コピー元HDD
$ sudo mkdir /mnt/hdd
$ sudo mount /dev/sda1 /mnt/hdd

// rsyncドライラン
$ sudo rsync -avr --owner --group --dry-run /mnt/hdd /mnt/ssd

// rsync実行(全体の進捗を出す、圧縮させると重いので-zはつけない)
$ sudo rsync -ar --info=progress2 --owner --group /mnt/hdd/ /mnt/ssd/

grubのインストール

  • grubをインストールする
// grub2の準備
$ sudo apt-get install grub-efi-amd64-bin

// chrootする(rootで実行していく)
$ sudo su

// データ用の領域をマウントする
# mkdir /chroot
# mount /dev/nvme0n1p2 /chroot

// プログラム実行に必要なものをbind
# mount --bind /dev /chroot/dev
# mount --bind /dev/pts /chroot/dev/pts
# mount --bind /proc /chroot/proc
# mount --bind /sys /chroot/sys
# mount --bind /run /chroot/run
# chroot /chroot
  • chrootしたらefi用の領域をマウント
// 無ければ /boot/efi は作っておく
# mkdir -p /boot/efi
# mount /dev/nvme0n1p1 /boot/efi
  • 空のEFI領域にブートプログラムであるところのgrubをインストール
# grub-install --target=x86_64-efi --efi-directory=/boot/efi --recheck
# ls -l /boot/efi/EFI/debian/
合計 5202
-rwxr-xr-x 1 root root     108  2月 27 00:40 BOOTX64.CSV
-rwxr-xr-x 1 root root 1206824  2月 27 00:40 fbx64.efi
-rwxr-xr-x 1 root root     117  2月 27 00:40 grub.cfg
-rwxr-xr-x 1 root root 1533296  2月 27 00:40 grubx64.efi
-rwxr-xr-x 1 root root 1261192  2月 27 00:40 mmx64.efi
-rwxr-xr-x 1 root root 1322936  2月 27 00:40 shimx64.efi

// 以下のコマンドは意味ないかも
# update-grub

/etc/fstabの編集

  • /etc/fstabを以下のように編集し、再起動・起動するディスクをefiをインストールしたやつにする
  • 事前にsudo blkid /dev/nvme0n1p1, sudo blkid /dev/nvme0n1p2 しておきPARTUUIDを記録しておく
$ sudo cat /etc/fstab
# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system>                               <mount point> <type> <options>         <dump> <pass>
PARTUUID=6e1ae4f9-bf29-4d76-a1b5-bfed57c80ee1 /boot/efi     vfat   errors=remount-ro 0      2
PARTUUID=ac09284a-8f98-46e0-a613-04f2b5621055 /             ext4   errors=remount-ro 0      1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment