6 恢复到系统初始状态
本小节我们将会把所作的改动都撤销,恢复到系统的初始状态,这仅仅是为了让您学会怎样撤销一个lvm的安装过程。
首先写在三个lv:
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
删除lv:
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
删除 vg:
vgremove fileserver
server1:~# vgremove fileserver
Volume group ”fileserver” successfully removed
最后删除pv:
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:让系统不在试图挂在不存在的设备,我们只需要把之前备份的fstab文件恢复回来即可。
mv /etc/fstab_orig /etc/fstab
重启系统:
shutdown -r now
查看系统状态:现在又恢复如初了。
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, and /var/media 。
7 创建RAID1上的lvm
本节,我们创建再一次创建lvm,并将它架设在raid1上来保证高可用性。最终效果如下:

这意味着我们将要使用sdb1和sdc1创建md0 raid阵列,使用sdd1和sdfe1创建md1 raid阵列,md0和md1这两个raid阵列将作为pv来建构lvm fileserver。(结构如上图)
在做这个任务之前,我们先像之前那样创建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
看一下输出结果:
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
首先我们先备份要移走的分区的数据:把sdc1和sde1的数据移动到sdb1和sdd1。然后把sdc1和sde1从lvm中移走,然后把他们格式化成为fd格式(raid的格式),并且把它们分别添加到raid md0和md1中。
modprobe dm-mirror
pvmove /dev/sdc1
vgreduce fileserver /dev/sdc1
pvremove /dev/sdc1
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
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
将sdc变成fd(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.
sde也是一样:
fdisk /dev/sde
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
现在我们将sdc1添加到md0,将sde1添加到md1,因为sdb1和sdd1还没有准备好,所以我们要在命令的末尾加上:missing
Next we add /dev/sdc1 to /dev/md0 and /dev/sde1 to /dev/md1. Because the second nodes (/dev/sdb1 and /dev/sdd1) are not ready yet, we must specifymissing in the following commands:
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.
本文由www.iluther.net翻译(原文在howtoforge),转载请注明出处