ブログ移設しました。

bloggerから記事を移設しました。


HUGOで記事を書いてみると思いのほか書きやすかったので移動。
ラベル ddrescue の投稿を表示しています。 すべての投稿を表示
ラベル ddrescue の投稿を表示しています。 すべての投稿を表示

月曜日, 2月 25, 2019

HDDをコピーしてLVMも拡張する

初めに注意事項だよ。
コマンドの説明はないからちゃんとman見てやるんだよ。
あと、LVMの説明やらパーティションの説明はないから、確認してからやるんだよ。
HDD系の作業はデータ丸ごとぶっ飛ばす可能性があるから本当に本当に注意の上やるんだよ。

てなことで始まり始まり。

VMで練習するよ。
ストレージは以下のような感じ。
centos7ってところにOSをインストールする。

インストールするったらインストールする。

インストール後OSから、ディスクの認識状況を確認。
blkidってまだパーティション切っていないところを認識してくれないんかもね。

 じゃあ、とりあえずシャットダウンだ。

そのあと、lubuntuのディスクを差し込んで。
 インストールしないでターミナルを開く。
ディスクの認識状況を確認


ここからは面倒なので、sshdをインストールしてIP割り当てを行って作業を行う。

ディスク認識状況確認

sudo blkid
/dev/sr0: UUID="2018-04-26-18-40-24-00" LABEL="Lubuntu 18.04 LTS amd64" TYPE="iso9660" PTUUID="67e97428" PTTYPE="dos"
/dev/loop0: TYPE="squashfs"
/dev/sda1: UUID="8ede7911-9e96-4f12-a226-fc325ce227e2" TYPE="xfs" PARTUUID="000d50e4-01"
/dev/sda2: UUID="ezf8v9-DB0v-GNeg-RsNe-kK1L-j3xB-J4C7pG" TYPE="LVM2_member" PARTUUID="000d50e4-02"
/dev/zram0: UUID="cd9bb84f-b4e0-4a34-b95f-58a985ea074a" TYPE="swap"
/dev/zram1: UUID="e5e38316-c372-4ba5-ac62-1fa41296cf66" TYPE="swap"
/dev/zram2: UUID="3b798fca-c367-429e-8cdb-1d0700bfeb9b" TYPE="swap"
/dev/zram3: UUID="e502d3f9-61e9-4795-824a-c83cf9c54aec" TYPE="swap"
/dev/mapper/centos-swap: UUID="52585050-0010-4510-a5fa-1177abed8538" TYPE="swap"
/dev/mapper/centos-root: UUID="a7451b3a-1e88-446e-804d-e75d62b151e4" TYPE="xfs"

lubuntu@lubuntu:~$ sudo parted -l
Model: ATA VBOX HARDDISK (scsi)
Disk /dev/sda: 8590MB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:

Number  Start   End     Size    Type     File system  Flags
 1      1049kB  1075MB  1074MB  primary  xfs          boot
 2      1075MB  8590MB  7515MB  primary               lvm


Error: /dev/sdb: unrecognised disk label
Model: ATA VBOX HARDDISK (scsi)
Disk /dev/sdb: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: unknown
Disk Flags:


sdbが何も触っていないディスクだから文句言われているね。


DiskToDiskコピー

この名称は私しか使っていないかもしれない。 というか名称がないと思う。
ディスクからディスクに情報をコピーしていくよ。

 sudo apt install  gddrescue

ddrescueについての記事。
http://dspckn.blogspot.com/2017/10/ddrescue.html

sudo ddrescue -f -n -v /dev/sda /dev/sdb
GNU ddrescue 1.22
About to copy 8589 MBytes from '/dev/sda' to '/dev/sdb'
    Starting positions: infile = 0 B,  outfile = 0 B
    Copy block size: 128 sectors       Initial skip size: 256 sectors
Sector size: 512 Bytes
     ipos:  272105 kB, non-trimmed:        0 B,  current rate:  56688 kB/s
     opos:  272105 kB, non-scraped:        0 B,  average rate:  45350 kB/s
non-tried:    8317 MB,  bad-sector:        0 B,    error rate:       0 B/s
  rescued:  272105 kB,   bad areas:        0,        run time:          6s
pct rescued:    3.16%, read errors:        0,  remaining time:          3m
                              time since last successful read:          0s


終わるまで待つ。

切れるとまずいから、nohupかtmux起動しておいた方が良いかもね。

 nohup sudo ddrescue -f -n -v /dev/sda /dev/sdb &
[1] 3875
     ipos:    5267 MB, non-trimmed:        0 B,  current rate:    779 MB/st'
     opos:    5267 MB, non-scraped:        0 B,  average rate:    181 MB/s
non-tried:    3321 MB,  bad-sector:        0 B,    error rate:       0 B/s
  rescued:    5267 MB,   bad areas:        0,        run time:         29s
pct rescued:   61.32%, read errors:        0,  remaining time:         19s
                              time since last successful read:          0s
Copying non-tried blocks... Pass 1 (forwards)
lubuntu@lubuntu:~$ tail -f  nohup.out

コピーが終わったら、シャットダウンして、元のCentOSのはいったHDDを外して起動確認。
うん。起動できる。

LVMの拡張

起動後、シャットダウンして、今度は、LVMと増えた分を/に割り当てしよう。

再度lubuntuのCDをセットして起動。
gpartedで、LVM領域をHDD合わせてあげる。

そのあと、コマンドラインで、LVMの領域を拡張していく。

詳細な説明は使っているコマンドろググって内容を確認してね。
ここではコマンドと結果のみを記載するよ。

現状確認

lvdisplay
  --- Logical volume ---
  LV Path                /dev/centos/swap
  LV Name                swap
  VG Name                centos
  LV UUID                fH8DOA-Roz1-YD00-45g1-vVds-7QUh-ZrDHdV
  LV Write Access        read/write
  LV Creation host, time localhost, 2019-02-22 16:57:35 +0000
  LV Status              available
  # open                 0
  LV Size                820.00 MiB
  Current LE             205
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0

  --- Logical volume ---
  LV Path                /dev/centos/root
  LV Name                root
  VG Name                centos
  LV UUID                W12VUx-Wyl3-BrGH-tBuP-sGYq-CxIh-tWTNRk
  LV Write Access        read/write
  LV Creation host, time localhost, 2019-02-22 16:57:36 +0000
  LV Status              available
  # open                 0
  LV Size                <6.20 GiB
  Current LE             1586
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1

fdisk -l
Disk /dev/loop0: 967.6 MiB, 1014571008 bytes, 1981584 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/sda: 20 GiB, 21474836480 bytes, 41943040 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x000d50e4

Device     Boot   Start      End  Sectors Size Id Type
/dev/sda1  *       2048  2099199  2097152   1G 83 Linux
/dev/sda2       2099200 16777215 14678016   7G 8e Linux LVM

20GのHDDなのに、7Gしか割り当てがないね。悲しいね。

LVMのパーティション自体を拡張

parted /dev/sda
GNU Parted 3.2
Using /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) p
Model: ATA VBOX HARDDISK (scsi)
Disk /dev/sda: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:

Number  Start   End     Size    Type     File system  Flags
 1      1049kB  1075MB  1074MB  primary  xfs          boot
 2      1075MB  8590MB  7515MB  primary               lvm

(parted) resizepart 2 100%
(parted) p
Model: ATA VBOX HARDDISK (scsi)
Disk /dev/sda: 41943040s
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:

Number  Start     End        Size       Type     File system  Flags
 1      2048s     2099199s   2097152s   primary  xfs          boot
 2      2099200s  41943039s  39843840s  primary               lvm

(parted) unit MiB
(parted) p
Model: ATA VBOX HARDDISK (scsi)
Disk /dev/sda: 20480MiB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:

Number  Start    End       Size      Type     File system  Flags
 1      1.00MiB  1025MiB   1024MiB   primary  xfs          boot
 2      1025MiB  20480MiB  19455MiB  primary               lvm

OKパーティション自体の領域拡張は完了したね。


LVMのリサイズ

PVのリサイズ

pvscan
  PV /dev/sda2   VG centos          lvm2 [<7.00 GiB / 0    free]
  Total: 1 [<7.00 GiB] / in use: 1 [<7.00 GiB] / in no VG: 0 [0   ]

pvresize /dev/sda2
  Physical volume "/dev/sda2" changed
  1 physical volume(s) resized / 0 physical volume(s) not resized

pvscan
  PV /dev/sda2   VG centos          lvm2 [<19.00 GiB / 12.00 GiB free]
  Total: 1 [<19.00 GiB] / in use: 1 [<19.00 GiB] / in no VG: 0 [0   ]

LVのリサイズ

lvscan
  ACTIVE            '/dev/centos/swap' [820.00 MiB] inherit
  ACTIVE            '/dev/centos/root' [<6.20 GiB] inherit

lvdisplay /dev/centos/root
  --- Logical volume ---
  LV Path                /dev/centos/root
  LV Name                root
  VG Name                centos
  LV UUID                W12VUx-Wyl3-BrGH-tBuP-sGYq-CxIh-tWTNRk
  LV Write Access        read/write
  LV Creation host, time localhost, 2019-02-22 16:57:36 +0000
  LV Status              available
  # open                 0
  LV Size                <6.20 GiB
  Current LE             1586
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1

lvextend -l 100%FREE /dev/centos/root
  Size of logical volume centos/root changed from <6.20 GiB (1586 extents) to 12.00 GiB (3072 extents).
  Logical volume centos/root successfully resized.

lvscan
  ACTIVE            '/dev/centos/swap' [820.00 MiB] inherit
  ACTIVE            '/dev/centos/root' [12.00 GiB] inherit

lvextend -L +3G /dev/centos/root
  Size of logical volume centos/root changed from 12.00 GiB (3072 extents) to 15.00 GiB (3840 extents).
何回か繰り返していくよ。(なんで、上の100%FREEでダメなのかはわからないけど)

pvscan
  PV /dev/sda2   VG centos          lvm2 [<19.00 GiB / 0    free]
  Total: 1 [<19.00 GiB] / in use: 1 [<19.00 GiB] / in no VG: 0 [0   ]

ファイルシステムの拡張

root@lubuntu:/home/lubuntu# mount /dev/mapper/centos-root /mnt/root/
root@lubuntu:/home/lubuntu# lvchange --available y ^C
root@lubuntu:/home/lubuntu# xfs_growfs /mnt/root/
meta-data=/dev/mapper/centos-root isize=512    agcount=4, agsize=406016 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0 spinodes=0 rmapbt=0
         =                       reflink=0
data     =                       bsize=4096   blocks=1624064, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal               bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 1624064 to 4769792

じゃあチャックしようか。
root@lubuntu:/home/lubuntu# umount /mnt/root/
root@lubuntu:/home/lubuntu# xfs_repair -n /dev/centos/root
Phase 1 - find and verify superblock...
Phase 2 - using internal log
        - zero log...
        - scan filesystem freespace and inode maps...
        - found root inode chunk
Phase 3 - for each AG...
        - scan (but don't clear) agi unlinked lists...
        - process known inodes and perform inode discovery...
        - agno = 0
        - agno = 1
        - agno = 2
        - agno = 3
        - agno = 4
        - agno = 5
        - agno = 6
        - agno = 7
        - agno = 8
        - agno = 9
        - agno = 10
        - agno = 11
        - process newly discovered inodes...
Phase 4 - check for duplicate blocks...
        - setting up duplicate extent list...
        - check for inodes claiming duplicate blocks...
        - agno = 0
        - agno = 1
        - agno = 2
        - agno = 3
        - agno = 4
        - agno = 5
        - agno = 6
        - agno = 7
        - agno = 8
        - agno = 9
        - agno = 10
        - agno = 11
No modify flag set, skipping phase 5
Phase 6 - check inode connectivity...
        - traversing filesystem ...
        - traversal finished ...
        - moving disconnected inodes to lost+found ...
Phase 7 - verify link counts...
No modify flag set, skipping filesystem flush and exiting.

上記の場合はやらなくてもいいかもしれないけど、
tmux new -s manager
        - agno = 3
        - agno = 4
        - agno = 5
        - agno = 6
        - agno = 7
        - agno = 8
        - agno = 9
        - agno = 10
        - agno = 11
No modify flag set, skipping phase 5
Phase 6 - check inode connectivity...
        - traversing filesystem ...
        - traversal finished ...
        - moving disconnected inodes to lost+found ...
Phase 7 - verify link counts...
No modify flag set, skipping filesystem flush and exiting.
root@lubuntu:/home/lubuntu# xfs_repair /dev/centos/root
Phase 1 - find and verify superblock...
Phase 2 - using internal log
        - zero log...
        - scan filesystem freespace and inode maps...
        - found root inode chunk
Phase 3 - for each AG...
        - scan and clear agi unlinked lists...
        - process known inodes and perform inode discovery...
        - agno = 0
        - agno = 1
        - agno = 2
        - agno = 3
        - agno = 4
        - agno = 5
        - agno = 6
        - agno = 7
        - agno = 8
        - agno = 9
        - agno = 10
        - agno = 11
        - process newly discovered inodes...
Phase 4 - check for duplicate blocks...
        - setting up duplicate extent list...
        - check for inodes claiming duplicate blocks...
        - agno = 0
        - agno = 1
        - agno = 2
        - agno = 3
        - agno = 4
        - agno = 5
        - agno = 6
        - agno = 7
        - agno = 8
        - agno = 9
        - agno = 10
        - agno = 11
Phase 5 - rebuild AG headers and trees...
        - reset superblock...
Phase 6 - check inode connectivity...
        - resetting contents of realtime bitmap and summary inodes
        - traversing filesystem ...
        - traversal finished ...
        - moving disconnected inodes to lost+found ...
Phase 7 - verify and correct link counts...
done

これで、再起動をかけて。
[luna@localhost ~]$ df -h
ファイルシス            サイズ  使用  残り 使用% マウント位置
/dev/mapper/centos-root    19G 1003M   18G    6% /
devtmpfs                  484M     0  484M    0% /dev
tmpfs                     496M     0  496M    0% /dev/shm
tmpfs                     496M  6.7M  489M    2% /run
tmpfs                     496M     0  496M    0% /sys/fs/cgroup
/dev/sda1                1014M  132M  883M   13% /boot
tmpfs                     100M     0  100M    0% /run/user/1000

うん。19Gあるしこれでいいかな。