ファイルバックアップ用ディスクを用意する(パーティションの作成とファイルシステムの作成)
- 現在、プライベートでとった写真などのファイルは外付けのHDDに格納するようにしていますが、バックアップを取っていないのでなんとかしたい
- バックアップに使えそうなHDDが余っていたので、まずは取り急ぎそのHDDにコピーするところから始める
- ちょうどLPIC201でストレージ管理周りの問題がでるので、学習を兼ねてCLIでやっていく
手順は学習用に用意したHDD(4G)で試していきます。
外付けHDDを差す
/dev/sdb
にいることを確認
sudo fdisk -l
ディスク /dev/sdb: 4 GiB, 4327464960 バイト, 8452080 セクタ 単位: セクタ (1 * 512 = 512 バイト) セクタサイズ (論理 / 物理): 512 バイト / 512 バイト I/O サイズ (最小 / 推奨): 512 バイト / 512 バイト
パーティションを確認する
特に設定されてなさそうなので、新しく作成していく。
sudo gdisk -l /dev/sdb
パーティーションの方式は、特に古い方式であるMBRにする理由はないのでGPTにしておきます。
GPT fdisk (gdisk) version 1.0.3 Partition table scan: MBR: not present BSD: not present APM: not present GPT: not present Creating new GPT entries. Disk /dev/sdb: 8452080 sectors, 4.0 GiB Model: MK4310MAT Sector size (logical/physical): 512/512 bytes Disk identifier (GUID): XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX Partition table holds up to 128 entries Main partition table begins at sector 2 and ends at sector 33 First usable sector is 34, last usable sector is 8452046 Partitions will be aligned on 2048-sector boundaries Total free space is 8452013 sectors (4.0 GiB) Number Start (sector) End (sector) Size Code Name
パーティションを作成する
sudo gdisk /dev/sdb
GPT fdisk (gdisk) version 1.0.3 Partition table scan: MBR: not present BSD: not present APM: not present GPT: not present Creating new GPT entries. Command (? for help): n Partition number (1-128, default 1): First sector (34-8452046, default = 2048) or {+-}size{KMGTP}: Last sector (2048-8452046, default = 8452046) or {+-}size{KMGTP}: Current type is 'Linux filesystem' Hex code or GUID (L to show codes, Enter = 8300): Changed type of partition to 'Linux filesystem' Command (? for help): w Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING PARTITIONS!! Do you want to proceed? (Y/N): y OK; writing new GUID partition table (GPT) to /dev/sdb. The operation has completed successfully.
ファイルシステムを作成する
sudo mke2fs -t ext4 /dev/sdb1
mke2fs 1.44.1 (24-Mar-2018) Creating filesystem with 1056249 4k blocks and 264528 inodes Filesystem UUID: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736 Allocating group tables: done Writing inode tables: done Creating journal (16384 blocks): done Writing superblocks and filesystem accounting information: done
ファイルシステムと不良ブロックのチェックする
sudo e2fsck -c /dev/sdb1
-c
で badblocks
を使って不良ブロックをチェックします。
見つかった不良ブロックはファイルやディレクトリとして確保されないようになります。
e2fsck 1.44.1 (24-Mar-2018) Checking for bad blocks (read-only test): 0.00% done, 0:00 elapsed. (0/0/0 errdone /dev/sdb1: Updating bad block inode. Pass 1: Checking iノードs, blocks, and sizes Pass 2: Checking ディレクトリ structure Pass 3: Checking ディレクトリ connectivity Pass 4: Checking reference counts Pass 5: Checking グループ summary information /dev/sdb1: ***** ファイルシステムは変更されました ***** /dev/sdb1: 11/264528 files (0.0% non-contiguous), 37125/1056249 blocks
動作確認
sudo mkdir /mnt/disk
sudo mount -t ext4 /dev/sdb1 /mnt/disk
cd /mnt/disk/ sudo touch test ls test test
書き込めたので良さそう。
次回は、バックアップしたいファイルをコピーして行こうと思います。