LVMガイド · 7 min read · Oct 09, 2025

LVMの初心者ガイド - ページ6

6 システムの元の状態に戻す

この章では、前の章からのすべての変更を元に戻して、システムの元の状態に戻します。これは、LVMのセットアップを元に戻す方法を学ぶためのトレーニング目的です。

まず、論理ボリュームをアンマウントする必要があります:

umount /var/share  
 umount /var/backup  
 umount /var/media
df -h
server1:~# df -h  
 Filesystem            Size  Used Avail Use% Mounted on  
 /dev/sda2             19G  665M   17G   4% /  
 tmpfs                 78M     0   78M   0% /lib/init/rw  
 udev                  10M   92K   10M   1% /dev  
 tmpfs                 78M     0   78M   0% /dev/shm  
 /dev/sda1             137M   17M  114M  13% /boot

次に、それぞれを削除します:

lvremove /dev/fileserver/share

server1:~# lvremove /dev/fileserver/share
Do you really want to remove active logical volume “share”? [y/n]: <– y
Logical volume “share” successfully removed

lvremove /dev/fileserver/backup

server1:~# lvremove /dev/fileserver/backup
Do you really want to remove active logical volume “backup”? [y/n]: <– y
Logical volume “backup” successfully removed

lvremove /dev/fileserver/media

server1:~# lvremove /dev/fileserver/media
Do you really want to remove active logical volume “media”? [y/n]: <– y
Logical volume “media” successfully removed

次に、ボリュームグループfileserverを削除します:

vgremove fileserver
server1:~# vgremove fileserver  
 Volume group "fileserver" successfully removed

最後に、これを行います:

pvremove /dev/sdc1 /dev/sdd1 /dev/sde1 /dev/sdf1
server1:~# pvremove  /dev/sdc1 /dev/sdd1 /dev/sde1 /dev/sdf1  
 Labels on physical volume "/dev/sdc1" successfully wiped  
 Labels on physical volume "/dev/sdd1" successfully wiped  
 Labels on physical volume "/dev/sde1" successfully wiped  
 Labels on physical volume "/dev/sdf1" successfully wiped
vgdisplay
server1:~# vgdisplay  
 No volume groups found
pvdisplay

何も表示されないはずです:

server1:~# pvdisplay

次に、/etc/fstabの変更を元に戻して、システムが存在しないデバイスをマウントしようとしないようにする必要があります。幸いなことに、元のファイルのバックアップを作成しているので、今それをコピーできます:

mv /etc/fstab_orig /etc/fstab

システムを再起動します:

shutdown -r now

その後、

df -h

の出力は次のようになります:

server1:~# df -h  
 Filesystem            Size  Used Avail Use% Mounted on  
 /dev/sda2             19G  666M   17G   4% /  
 tmpfs                 78M     0   78M   0% /lib/init/rw  
 udev                  10M   92K   10M   1% /dev  
 tmpfs                 78M     0   78M   0% /dev/shm  
 /dev/sda1             137M   17M  114M  13% /boot

これで、システムは最初の状態に戻りました(/dev/sdb1 - /dev/sdf1のパーティションはまだ存在します - fdiskで削除できますが、今はこれを行いません - また、/var/share、/var/backup、/var/mediaのディレクトリも削除しません)。

7 RAID1上のLVM

この章では、再びLVMをセットアップし、高可用性を保証するためにRAID1アレイに移動します。最終的には次のようになります:

これは、/dev/sdb1 + /dev/sdc1からRAIDアレイ/dev/md0を作成し、/dev/sdd1 + /dev/sde1からRAIDアレイ/dev/md1を作成することを意味します。/dev/md0と/dev/md1は、その後LVMの物理ボリュームになります。

その前に、前と同様にLVMをセットアップします:

pvcreate /dev/sdb1 /dev/sdc1 /dev/sdd1 /dev/sde1  
 vgcreate fileserver /dev/sdb1 /dev/sdc1 /dev/sdd1 /dev/sde1  
 lvcreate --name share --size 40G fileserver  
 lvcreate --name backup --size 5G fileserver  
 lvcreate --name media --size 1G fileserver
mkfs.ext3 /dev/fileserver/share  
 mkfs.xfs /dev/fileserver/backup  
 mkfs.reiserfs /dev/fileserver/media

次に、論理ボリュームをマウントします:

mount /dev/fileserver/share /var/share  
 mount /dev/fileserver/backup /var/backup  
 mount /dev/fileserver/media /var/media
df -h

の出力は次のようになります:

server1:~# df -h  
 Filesystem            Size  Used Avail Use% Mounted on  
 /dev/sda2             19G  666M   17G   4% /  
 tmpfs                 78M     0   78M   0% /lib/init/rw  
 udev                  10M   92K   10M   1% /dev  
 tmpfs                 78M     0   78M   0% /dev/shm  
 /dev/sda1             137M   17M  114M  13% /boot  
 /dev/mapper/fileserver-share  
                     40G  177M   38G   1% /var/share  
 /dev/mapper/fileserver-backup  
                     5.0G  144K  5.0G   1% /var/backup  
 /dev/mapper/fileserver-media  
                     1.0G   33M  992M   4% /var/media

次に、/dev/sdc1と/dev/sde1の内容を残りのパーティションに移動する必要があります(/dev/sdc1は将来の/dev/md0の2番目のパーティション、/dev/sde1は将来の/dev/md1の2番目のパーティションです)。その後、これらをLVMから削除し、fdタイプ(Linux RAID自動検出)でフォーマットし、/dev/md0および/dev/md1に移動します。

modprobe dm-mirror  
 pvmove /dev/sdc1
vgreduce fileserver /dev/sdc1  
 pvremove /dev/sdc1
pvdisplay
server1:~# pvdisplay  
 --- Physical volume ---  
 PV Name               /dev/sdb1  
 VG Name               fileserver  
 PV Size               23.29 GB / not usable 0  
 Allocatable           yes (but full)  
 PE Size (KByte)      4096  
 Total PE              5961  
 Free PE               0  
 Allocated PE          5961  
 PV UUID               USDJyG-VDM2-r406-OjQo-h3eb-c9Mp-4nvnvu  
   
 --- Physical volume ---  
 PV Name               /dev/sdd1  
 VG Name               fileserver  
 PV Size               23.29 GB / not usable 0  
 Allocatable           yes  
 PE Size (KByte)      4096  
 Total PE              5961  
 Free PE               4681  
 Allocated PE          1280  
 PV UUID               qdEB5d-389d-O5UA-Kbwv-mn1y-74FY-4zublN  
   
 --- Physical volume ---  
 PV Name               /dev/sde1  
 VG Name               fileserver  
 PV Size               23.29 GB / not usable 0  
 Allocatable           yes  
 PE Size (KByte)      4096  
 Total PE              5961  
 Free PE               1426  
 Allocated PE          4535  
 PV UUID               4vL1e0-sr2M-awGd-qDJm-ZrC9-wuxW-2lEqp2
pvmove /dev/sde1
vgreduce fileserver /dev/sde1  
 pvremove /dev/sde1
pvdisplay
server1:~# pvdisplay  
 --- Physical volume ---  
 PV Name               /dev/sdb1  
 VG Name               fileserver  
 PV Size               23.29 GB / not usable 0  
 Allocatable           yes (but full)  
 PE Size (KByte)      4096  
 Total PE              5961  
 Free PE               0  
 Allocated PE          5961  
 PV UUID               USDJyG-VDM2-r406-OjQo-h3eb-c9Mp-4nvnvu  
   
 --- Physical volume ---  
 PV Name               /dev/sdd1  
 VG Name               fileserver  
 PV Size               23.29 GB / not usable 0  
 Allocatable           yes  
 PE Size (KByte)      4096  
 Total PE              5961  
 Free PE               146  
 Allocated PE          5815  
 PV UUID               qdEB5d-389d-O5UA-Kbwv-mn1y-74FY-4zublN

次に、/dev/sdc1をfdタイプ(Linux RAID自動検出)でフォーマットします:

fdisk /dev/sdc

server1:~# fdisk /dev/sdc
The number of cylinders for this disk is set to 10443.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:

  1. software that runs at boot time (e.g., old versions of LILO)
  2. booting and partitioning software from other OSs
    (e.g., DOS FDISK, OS/2 FDISK)

Command (m for help): <– m
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition’s system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)

Command (m for help): <– t
Selected partition 1
Hex code (type L to list codes): <– L

0 Empty 1e Hidden W95 FAT1 80 Old Minix be Solaris boot
1 FAT12 24 NEC DOS 81 Minix / old Lin bf Solaris
2 XENIX root 39 Plan 9 82 Linux swap / So c1 DRDOS/sec (FAT-
3 XENIX usr 3c PartitionMagic 83 Linux c4 DRDOS/sec (FAT-
4 FAT16 <32M 40 Venix 80286 84 OS/2 hidden C: c6 DRDOS/sec (FAT-
5 Extended 41 PPC PReP Boot 85 Linux extended c7 Syrinx
6 FAT16 42 SFS 86 NTFS volume set da Non-FS data
7 HPFS/NTFS 4d QNX4.x 87 NTFS volume set db CP/M / CTOS / .
8 AIX 4e QNX4.x 2nd part 88 Linux plaintext de Dell Utility
9 AIX bootable 4f QNX4.x 3rd part 8e Linux LVM df BootIt
a OS/2 Boot Manag 50 OnTrack DM 93 Amoeba e1 DOS access
b W95 FAT32 51 OnTrack DM6 Aux 94 Amoeba BBT e3 DOS R/O
c W95 FAT32 (LBA) 52 CP/M 9f BSD/OS e4 SpeedStor
e W95 FAT16 (LBA) 53 OnTrack DM6 Aux a0 IBM Thinkpad hi eb BeOS fs
f W95 Ext’d (LBA) 54 OnTrackDM6 a5 FreeBSD ee EFI GPT
10 OPUS 55 EZ-Drive a6 OpenBSD ef EFI (FAT-12/16/
11 Hidden FAT12 56 Golden Bow a7 NeXTSTEP f0 Linux/PA-RISC b
12 Compaq diagnost 5c Priam Edisk a8 Darwin UFS f1 SpeedStor
14 Hidden FAT16 <3 61 SpeedStor a9 NetBSD f4 SpeedStor
16 Hidden FAT16 63 GNU HURD or Sys ab Darwin boot f2 DOS secondary
17 Hidden HPFS/NTF 64 Novell Netware b7 BSDI fs fd Linux raid auto
18 AST SmartSleep 65 Novell Netware b8 BSDI swap fe LANstep
1b Hidden W95 FAT3 70 DiskSecure Mult bb Boot Wizard hid ff BBT
1c Hidden W95 FAT3 75 PC/IX
Hex code (type L to list codes): <– fd
Changed system type of partition 1 to fd (Linux raid autodetect)

Command (m for help): <– w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

次に、/dev/sde1でも同じことを行います:

fdisk /dev/sde
fdisk -l

の出力は次のようになります:

server1:~# fdisk -l  
  
 Disk /dev/sda: 21.4 GB, 21474836480 bytes  
 255 heads, 63 sectors/track, 2610 cylinders  
 Units = cylinders of 16065 * 512 = 8225280 bytes  
  
    Device Boot      Start         End      Blocks   Id  System  
 /dev/sda1   *         1          18      144553+  83  Linux  
 /dev/sda2             19        2450    19535040   83  Linux  
 /dev/sda4            2451        2610     1285200   82  Linux swap / Solaris  
  
 Disk /dev/sdb: 85.8 GB, 85899345920 bytes  
 255 heads, 63 sectors/track, 10443 cylinders  
 Units = cylinders of 16065 * 512 = 8225280 bytes  
  
    Device Boot      Start         End      Blocks   Id  System  
 /dev/sdb1               1        3040    24418768+  8e  Linux LVM  
  
 Disk /dev/sdc: 85.8 GB, 85899345920 bytes  
 255 heads, 63 sectors/track, 10443 cylinders  
 Units = cylinders of 16065 * 512 = 8225280 bytes  
  
    Device Boot      Start         End      Blocks   Id  System  
 /dev/sdc1               1        3040    24418768+  fd  Linux raid autodetect  
  
 Disk /dev/sdd: 85.8 GB, 85899345920 bytes  
 255 heads, 63 sectors/track, 10443 cylinders  
 Units = cylinders of 16065 * 512 = 8225280 bytes  
  
    Device Boot      Start         End      Blocks   Id  System  
 /dev/sdd1               1        3040    24418768+  8e  Linux LVM  
  
 Disk /dev/sde: 85.8 GB, 85899345920 bytes  
 255 heads, 63 sectors/track, 10443 cylinders  
 Units = cylinders of 16065 * 512 = 8225280 bytes  
  
    Device Boot      Start         End      Blocks   Id  System  
 /dev/sde1               1        3040    24418768+  fd  Linux raid autodetect  
  
 Disk /dev/sdf: 85.8 GB, 85899345920 bytes  
 255 heads, 63 sectors/track, 10443 cylinders  
 Units = cylinders of 16065 * 512 = 8225280 bytes  
  
    Device Boot      Start         End      Blocks   Id  System  
 /dev/sdf1               1        3040    24418768+  8e  Linux LVM

次に、/dev/sdc1を/dev/md0に、/dev/sde1を/dev/md1に追加します。2番目のノード(/dev/sdb1と/dev/sdd1)がまだ準備できていないため、次のコマンドではmissingを指定する必要があります:

mdadm --create /dev/md0 --auto=yes -l 1 -n 2 /dev/sdc1 missing
server1:~# mdadm --create /dev/md0 --auto=yes -l 1 -n 2 /dev/sdc1 missing  
 mdadm: array /dev/md0 started.
mdadm --create /dev/md1 --auto=yes -l 1 -n 2 /dev/sde1 missing
server1:~# mdadm --create /dev/md1 --auto=yes -l 1 -n 2 /dev/sde1 missing  
 mdadm: array /dev/md1 started.
Share: X/Twitter LinkedIn

新しい投稿を受信箱で受け取る

スパムはありません。いつでも購読を解除できます。