升级内核
日期:2011-08-02 来源: 未知 分享至:
-
一、下载最新内核源码。
从内核官网下载至当前目录下
wget http://www.kernel.org/pub/linux/kernel/v3.0/linux-3.0.tar.bz2
二、解压内核源码,移动到合适的位置。
tar jxvf linux-3.0.tar.bz2 -C /usr/src
cd /usr/src
ln -s linux-3.0 linux 做个软链接也有人说可以不做。
lrwxrwxrwx 1 root root 9 Jul 29 17:24 linux -> linux-3.0
drwxrwxr-x 24 root root 4096 Aug 1 11:14 linux-3.0
三、编译安装内核源码
1,make mrproper
用来消除原来编译的影响,对之前没编译过内核的可以跳过此步,但建议使用一下这条命令 。
2,make oldconfig
用你当前内核的设置作为配置标准,重新编译新内核,这样升级简单。
这里还有几种方式可以选择:
(1)make config 单行模式
(2)make menuconfig 图形模式
(3)make xconfig 基于xwindows模式
(4)make gconfig 基于gtk模式
(5)make defconfig 根据机器类型对内核默认配置
3,make
编译内核,由于是完全编译,所以时间比较长,大概需要60分钟。
4,make modules_install
其作用是将模块拷贝到需要的目录中。但先要 cd /lib/modules,mkdir 3.0.0,cd 3.0.0,mkdir build source
如果开始不建这些目录,这步时会提醒你建的。内核升级成功后可以用ll查看
lrwxrwxrwx 1 root root 18 Aug 1 09:22 build -> /usr/src/linux-3.0
drwxrwxr-x 12 root root 4096 Aug 1 09:23 kernel
-rw-rw-r-- 1 root root 590623 Aug 1 09:31 modules.alias
-rw-rw-r-- 1 root root 575812 Aug 1 09:31 modules.alias.bin
-rw-rw-r-- 1 root root 6411 Aug 1 09:22 modules.builtin
-rw-rw-r-- 1 root root 8037 Aug 1 09:31 modules.builtin.bin
-rw-rw-r-- 1 root root 69 Aug 1 09:31 modules.ccwmap
-rw-rw-r-- 1 root root 220714 Aug 1 09:31 modules.dep
-rw-rw-r-- 1 root root 321992 Aug 1 09:31 modules.dep.bin
-rw-rw-r-- 1 root root 665 Aug 1 09:31 modules.ieee1394map
-rw-rw-r-- 1 root root 218 Aug 1 09:31 modules.inputmap
-rw-rw-r-- 1 root root 15756 Aug 1 09:31 modules.isapnpmap
-rw-rw-r-- 1 root root 153 Aug 1 09:31 modules.ofmap
-rw-rw-r-- 1 root root 84721 Aug 1 09:22 modules.order
-rw-rw-r-- 1 root root 383664 Aug 1 09:31 modules.pcimap
-rw-rw-r-- 1 root root 1261 Aug 1 09:31 modules.seriomap
-rw-rw-r-- 1 root root 209839 Aug 1 09:31 modules.symbols
-rw-rw-r-- 1 root root 267370 Aug 1 09:31 modules.symbols.bin
-rw-rw-r-- 1 root root 924556 Aug 1 09:31 modules.usbmap
lrwxrwxrwx 1 root root 18 Aug 1 09:22 source -> /usr/src/linux-3.0
5,make install
复制内核和System.map,及修改Grub.conf的步骤,都由make install自动实现。
cat /boot/grub/grub.conf
default=0 //把1改成0就好了。
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
#hiddenmenu
title Fedora (3.0.0)
root (hd0,0)
kernel /vmlinuz-3.0.0 ro root=/dev/mapper/vg_fc13-lv_root rd_LVM_LV=vg_fc13/lv_root rd_LVM_LV=vg_fc13/lv_swap rd_NO_LUKS rd_NO_MD rd_NO_DM LANG=en_US.UTF-8 KEYTABLE=us rhgb quiet
initrd /initramfs-3.0.0.img
title Fedora (2.6.38)
root (hd0,0)
kernel /vmlinuz-2.6.38 ro root=/dev/mapper/vg_fc13-lv_root rd_LVM_LV=vg_fc13/lv_root rd_LVM_LV=vg_fc13/lv_swap rd_NO_LUKS rd_NO_MD rd_NO_DM LANG=zh_CN.UTF-8 KEYTABLE=us rhgb quiet
initrd /initramfs-2.6.38.img
四、安装完毕,重启。
init 6
重启后没问题就算成功,若有问题,大部分是make config这一部分没有定制好内核模块等,根据提示可以重新编译,加上需要的模块,
重来几次就好了。
五、检测
uname -r
3.0.0
http://www.linuxso.com/linuxrumen/2214.html
------------------------------------------------------------------------------------------------------------------------------------------
RHEL6 LVM管理 partx -a /dev/sda
时间:2012-03-30 11:55来源:未知 作者:admin 点击:210次
建立LVM分区------------- [root@localhost ~]# fdisk /dev/sda WARNING: DOS-compatible mode is deprecated. It's strongly recommended to switch off the mode (command 'c') and change display units to sectors (command 'u'). Command (m for help):
建立LVM分区-------------
[root@localhost ~]# fdisk /dev/sda
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
switch off the mode (command 'c') and change display units to
sectors (command 'u').
Command (m for help): n
First cylinder (781-1305, default 781):
Using default value 781
Last cylinder, +cylinders or +size{K,M,G} (781-1305, default 1305): +1G
Command (m for help): t
Partition number (1-5): 5
Hex code (type L to list codes): 8e
Changed system type of partition 5 to 8e (Linux LVM)
Command (m for help): n
First cylinder (913-1305, default 913):
Using default value 913
Last cylinder, +cylinders or +size{K,M,G} (913-1305, default 1305): +1G
Command (m for help): t
Partition number (1-6): 6
Hex code (type L to list codes): 8e
Changed system type of partition 6 to 8e (Linux LVM)
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
[root@localhost ~]# partx -a /dev/sda
BLKPG: Device or resource busy
error adding partition 1
BLKPG: Device or resource busy
error adding partition 2
BLKPG: Device or resource busy
error adding partition 3
BLKPG: Device or resource busy
error adding partition 4
BLKPG: Device or resource busy
error adding partition 5
BLKPG: Device or resource busy
error adding partition 6
建立PV-------------
[root@localhost ~]# pvcreate /dev/sda5
Physical volume "/dev/sda5" successfully created
[root@localhost ~]# pvcreate /dev/sda6
Physical volume "/dev/sda6" successfully created
建立VG-------------
[root@localhost ~]# vgcreate myvg /dev/sda5
Volume group "myvg" successfully created
扩展VG-------------
[root@localhost ~]# vgextend myvg /dev/sda6
Volume group "myvg" successfully extended
缩减VG-------------
[root@localhost ~]# vgreduce myvg /dev/sda6
Removed "/dev/sda6" from volume group "myvg"
建立LV-------------
[root@localhost ~]# lvcreate -n mylv -L 800M myvg
Logical volume "mylv" created
建立文件系统-------------
[root@localhost ~]# mkfs.ext4 /dev/myvg/mylv
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
51296 inodes, 204800 blocks
10240 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=209715200
7 block groups
32768 blocks per group, 32768 fragments per group
7328 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840
Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 32 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
建立挂载点-------------
[root@localhost ~]# mkdir /new
编辑fstab-------------
[root@localhost ~]# vi /etc/fstab
挂载分区-------------
[root@localhost ~]# mount -a
扩展LV-------------
[root@localhost ~]# lvresize -L +800M /dev/myvg/mylv
Extending logical volume mylv to 1.27 GiB
Logical volume mylv successfully resized
调整文件系统大小-------------
[root@localhost ~]# resize2fs /dev/myvg/mylv
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/myvg/mylv is mounted on /new; on-line resizing required
old desc_blocks = 2, new_desc_blocks = 6
Performing an on-line resize of /dev/myvg/mylv to 1331200 (1k) blocks.
The filesystem on /dev/myvg/mylv is now 1331200 blocks long.
卸载分区-------------
[root@localhost ~]# umount /dev/myvg/mylv
检查分区-------------
[root@localhost ~]# fsck -f /dev/myvg/mylv
fsck from util-linux-ng 2.17.2
e2fsck 1.41.12 (17-May-2010)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/mapper/myvg-mylv: 11/331216 files (0.0% non-contiguous), 52784/1331200 blocks
调整文件系统大小-------------
[root@localhost ~]# resize2fs /dev/myvg/mylv 600M
resize2fs 1.41.12 (17-May-2010)
Resizing the filesystem on /dev/myvg/mylv to 614400 (1k) blocks.
The filesystem on /dev/myvg/mylv is now 614400 blocks long.
调整LV大小-------------
[root@localhost ~]# lvreduce -L 600M /dev/myvg/mylv
WARNING: Reducing active logical volume to 600.00 MiB
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce mylv? [y/n]: y
Reducing logical volume mylv to 600.00 MiB
Logical volume mylv successfully resized
挂载分区-------------
[root@localhost ~]# mount -a
移动PV-------------
[root@localhost ~]# pvmove /dev/sda5
/dev/sda5: Moved: 2.0%
/dev/sda5: Moved: 91.3%
/dev/sda5: Moved: 100.0%
缩减VG-------------
[root@localhost ~]# vgreduce myvg /dev/sda5
Removed "/dev/sda5" from volume group "myvg"
删除PV-------------
[root@localhost ~]# pvremove /dev/sda5
Labels on physical volume "/dev/sda5" successfully wiped
卸载分区-------------
[root@localhost /]# umount /dev/myvg/mylv
修改LV活动状态
[root@localhost /]# lvchange -an /dev/myvg/mylv
移除LV-------------
[root@localhost /]# lvremove /dev/myvg/mylv
Logical volume "mylv" successfully removed
移除VG-------------
[root@localhost /]# vgremove myvg
Volume group "myvg" successfully removed
移除PV-------------
[root@localhost /]# pvremove /dev/sda6
Labels on physical volume "/dev/sda6" successfully wiped
----------------------------------------------------------------------------------------------------------------------------------------------------------
kpartx命令的作用,是让Linux内核读取一个设备上的分区表,然后生成代表相应分区的设备。
kpartx -l imagefile 可以查看一个映像文件中的分区,使用 kpartx -a imagefile 命令后,就可以通过 /dev/mapper/loop0pX (其中X是 分区号)来访问映像。
通过losetup和kpartx使用磁盘文件备份和恢复LVM卷
在使用Kvm和XEN虚拟系统时,常常要对虚拟机进行clone。一种方式是采用img磁盘文件来作为虚拟机磁盘,另一种方式是采用卷管理(LVM)来管理虚拟机磁盘。
推荐使用LVM卷管理,可以充分利用LVM的snapshot进行备份和复制。不过,在使用LVM卷管理时,有时候也需要直接访问LVM的LV,从中复制一些文件。
这里解释 kpartx 工具,可以实现对块文件(包括卷管理的LV)到设备文件的映射,这样就可以使用fdisk和mount命令访问逻辑卷了。
参考
* Kpartx: a tool for mounting partitions within an image file
* Playing with KVM and LVM on Linux
说明
kpartx 是用来映像任何分区块设备到设备文件的工具,是Linux multipath-tools 中的一个部分。
使用命令 kpartx -l imagefile 可以产看一个映像文件中的分区,使用 kpartx -a imagefile 命令后,就可以通过 /dev/mapper/loop0pX (其中X是 分区号)来访问映像。
此外,可以通过 mount /dev/mapper/loop0pX /mnt/ -o loop,ro 来访问,使用后可以使用 kpartx -d imagefile 来卸载。
对于使用 dd 命令复制的LVM卷(我采用此方法备份KVM虚拟机),也可以使用 kpartx 来映射为设备文件。
复制逻辑卷到磁盘镜像
使用virt-manger生成一个磁盘映像文件,然后使用losetup命令回环挂载
losetup /dev/loop2 /vms/win2k3.img
然后再使用dd命令进行镜像成功
dd if=/dev/mapper/VGwindows-LVwindows of=/dev/loop2
完成后,先卸载loop设备
losetup -d /dev/loop2
之后,就可以在kvm中使用这个磁盘镜像了,完全没有任何问题。
备份的LVM卷挂载和文件复制
以下是将备份的LVM逻辑卷采用 kpartx 映射为设备文件,然后挂载分区进行文件复制。
kpartx -av /nfs_share/x-box_LV/LVmyinfoserv_opt
add map loop2p1 (253:0): 0 12578832 linear /dev/loop2 63
mount /dev/mapper/loop2p1 /mnt
挂载后可以直接访问分区中的文件(Ext3文件系统)。
PARTX(8)
PARTX(8)
NAME
partx - telling the kernel about presence and numbering of on-disk partitions.
SYNOPSIS
partx [-a|-d|-l] [--type TYPE] [--nr M-N] [partition] disk
DESCRIPTION
Given a block device (
disk
) and a partition table
type
, try to parse the partition table, and list the con-
tents. Optionally add or remove partitions.
This is not an fdisk - adding and removing partitions is not a change of the disk, but just telling the kernel
about presence and numbering of on-disk partitions.
OPTIONS
-a
add specified partitions or read disk and add all partitions
-d delete specified or all partitions
-l list partitions
-
一、下载最新内核源码。
从内核官网下载至当前目录下
wget http://www.kernel.org/pub/linux/kernel/v3.0/linux-3.0.tar.bz2
二、解压内核源码,移动到合适的位置。
tar jxvf linux-3.0.tar.bz2 -C /usr/src
cd /usr/src
ln -s linux-3.0 linux 做个软链接也有人说可以不做。
lrwxrwxrwx 1 root root 9 Jul 29 17:24 linux -> linux-3.0
drwxrwxr-x 24 root root 4096 Aug 1 11:14 linux-3.0
三、编译安装内核源码
1,make mrproper
用来消除原来编译的影响,对之前没编译过内核的可以跳过此步,但建议使用一下这条命令 。
2,make oldconfig
用你当前内核的设置作为配置标准,重新编译新内核,这样升级简单。
这里还有几种方式可以选择:
(1)make config 单行模式
(2)make menuconfig 图形模式
(3)make xconfig 基于xwindows模式
(4)make gconfig 基于gtk模式
(5)make defconfig 根据机器类型对内核默认配置
3,make
编译内核,由于是完全编译,所以时间比较长,大概需要60分钟。
4,make modules_install
其作用是将模块拷贝到需要的目录中。但先要 cd /lib/modules,mkdir 3.0.0,cd 3.0.0,mkdir build source
如果开始不建这些目录,这步时会提醒你建的。内核升级成功后可以用ll查看
lrwxrwxrwx 1 root root 18 Aug 1 09:22 build -> /usr/src/linux-3.0
drwxrwxr-x 12 root root 4096 Aug 1 09:23 kernel
-rw-rw-r-- 1 root root 590623 Aug 1 09:31 modules.alias
-rw-rw-r-- 1 root root 575812 Aug 1 09:31 modules.alias.bin
-rw-rw-r-- 1 root root 6411 Aug 1 09:22 modules.builtin
-rw-rw-r-- 1 root root 8037 Aug 1 09:31 modules.builtin.bin
-rw-rw-r-- 1 root root 69 Aug 1 09:31 modules.ccwmap
-rw-rw-r-- 1 root root 220714 Aug 1 09:31 modules.dep
-rw-rw-r-- 1 root root 321992 Aug 1 09:31 modules.dep.bin
-rw-rw-r-- 1 root root 665 Aug 1 09:31 modules.ieee1394map
-rw-rw-r-- 1 root root 218 Aug 1 09:31 modules.inputmap
-rw-rw-r-- 1 root root 15756 Aug 1 09:31 modules.isapnpmap
-rw-rw-r-- 1 root root 153 Aug 1 09:31 modules.ofmap
-rw-rw-r-- 1 root root 84721 Aug 1 09:22 modules.order
-rw-rw-r-- 1 root root 383664 Aug 1 09:31 modules.pcimap
-rw-rw-r-- 1 root root 1261 Aug 1 09:31 modules.seriomap
-rw-rw-r-- 1 root root 209839 Aug 1 09:31 modules.symbols
-rw-rw-r-- 1 root root 267370 Aug 1 09:31 modules.symbols.bin
-rw-rw-r-- 1 root root 924556 Aug 1 09:31 modules.usbmap
lrwxrwxrwx 1 root root 18 Aug 1 09:22 source -> /usr/src/linux-3.0
5,make install
复制内核和System.map,及修改Grub.conf的步骤,都由make install自动实现。
cat /boot/grub/grub.conf
default=0 //把1改成0就好了。
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
#hiddenmenu
title Fedora (3.0.0)
root (hd0,0)
kernel /vmlinuz-3.0.0 ro root=/dev/mapper/vg_fc13-lv_root rd_LVM_LV=vg_fc13/lv_root rd_LVM_LV=vg_fc13/lv_swap rd_NO_LUKS rd_NO_MD rd_NO_DM LANG=en_US.UTF-8 KEYTABLE=us rhgb quiet
initrd /initramfs-3.0.0.img
title Fedora (2.6.38)
root (hd0,0)
kernel /vmlinuz-2.6.38 ro root=/dev/mapper/vg_fc13-lv_root rd_LVM_LV=vg_fc13/lv_root rd_LVM_LV=vg_fc13/lv_swap rd_NO_LUKS rd_NO_MD rd_NO_DM LANG=zh_CN.UTF-8 KEYTABLE=us rhgb quiet
initrd /initramfs-2.6.38.img
四、安装完毕,重启。
init 6
重启后没问题就算成功,若有问题,大部分是make config这一部分没有定制好内核模块等,根据提示可以重新编译,加上需要的模块,
重来几次就好了。
五、检测
uname -r
3.0.0
http://www.linuxso.com/linuxrumen/2214.html
------------------------------------------------------------------------------------------------------------------------------------------
RHEL6 LVM管理 partx -a /dev/sda
时间:2012-03-30 11:55来源:未知 作者:admin 点击:210次
建立LVM分区------------- [root@localhost ~]# fdisk /dev/sda WARNING: DOS-compatible mode is deprecated. It's strongly recommended to switch off the mode (command 'c') and change display units to sectors (command 'u'). Command (m for help):
建立LVM分区-------------
[root@localhost ~]# fdisk /dev/sda
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
switch off the mode (command 'c') and change display units to
sectors (command 'u').
Command (m for help): n
First cylinder (781-1305, default 781):
Using default value 781
Last cylinder, +cylinders or +size{K,M,G} (781-1305, default 1305): +1G
Command (m for help): t
Partition number (1-5): 5
Hex code (type L to list codes): 8e
Changed system type of partition 5 to 8e (Linux LVM)
Command (m for help): n
First cylinder (913-1305, default 913):
Using default value 913
Last cylinder, +cylinders or +size{K,M,G} (913-1305, default 1305): +1G
Command (m for help): t
Partition number (1-6): 6
Hex code (type L to list codes): 8e
Changed system type of partition 6 to 8e (Linux LVM)
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
[root@localhost ~]# partx -a /dev/sda
BLKPG: Device or resource busy
error adding partition 1
BLKPG: Device or resource busy
error adding partition 2
BLKPG: Device or resource busy
error adding partition 3
BLKPG: Device or resource busy
error adding partition 4
BLKPG: Device or resource busy
error adding partition 5
BLKPG: Device or resource busy
error adding partition 6
建立PV-------------
[root@localhost ~]# pvcreate /dev/sda5
Physical volume "/dev/sda5" successfully created
[root@localhost ~]# pvcreate /dev/sda6
Physical volume "/dev/sda6" successfully created
建立VG-------------
[root@localhost ~]# vgcreate myvg /dev/sda5
Volume group "myvg" successfully created
扩展VG-------------
[root@localhost ~]# vgextend myvg /dev/sda6
Volume group "myvg" successfully extended
缩减VG-------------
[root@localhost ~]# vgreduce myvg /dev/sda6
Removed "/dev/sda6" from volume group "myvg"
建立LV-------------
[root@localhost ~]# lvcreate -n mylv -L 800M myvg
Logical volume "mylv" created
建立文件系统-------------
[root@localhost ~]# mkfs.ext4 /dev/myvg/mylv
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
51296 inodes, 204800 blocks
10240 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=209715200
7 block groups
32768 blocks per group, 32768 fragments per group
7328 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840
Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 32 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
建立挂载点-------------
[root@localhost ~]# mkdir /new
编辑fstab-------------
[root@localhost ~]# vi /etc/fstab
挂载分区-------------
[root@localhost ~]# mount -a
扩展LV-------------
[root@localhost ~]# lvresize -L +800M /dev/myvg/mylv
Extending logical volume mylv to 1.27 GiB
Logical volume mylv successfully resized
调整文件系统大小-------------
[root@localhost ~]# resize2fs /dev/myvg/mylv
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/myvg/mylv is mounted on /new; on-line resizing required
old desc_blocks = 2, new_desc_blocks = 6
Performing an on-line resize of /dev/myvg/mylv to 1331200 (1k) blocks.
The filesystem on /dev/myvg/mylv is now 1331200 blocks long.
卸载分区-------------
[root@localhost ~]# umount /dev/myvg/mylv
检查分区-------------
[root@localhost ~]# fsck -f /dev/myvg/mylv
fsck from util-linux-ng 2.17.2
e2fsck 1.41.12 (17-May-2010)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/mapper/myvg-mylv: 11/331216 files (0.0% non-contiguous), 52784/1331200 blocks
调整文件系统大小-------------
[root@localhost ~]# resize2fs /dev/myvg/mylv 600M
resize2fs 1.41.12 (17-May-2010)
Resizing the filesystem on /dev/myvg/mylv to 614400 (1k) blocks.
The filesystem on /dev/myvg/mylv is now 614400 blocks long.
调整LV大小-------------
[root@localhost ~]# lvreduce -L 600M /dev/myvg/mylv
WARNING: Reducing active logical volume to 600.00 MiB
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce mylv? [y/n]: y
Reducing logical volume mylv to 600.00 MiB
Logical volume mylv successfully resized
挂载分区-------------
[root@localhost ~]# mount -a
移动PV-------------
[root@localhost ~]# pvmove /dev/sda5
/dev/sda5: Moved: 2.0%
/dev/sda5: Moved: 91.3%
/dev/sda5: Moved: 100.0%
缩减VG-------------
[root@localhost ~]# vgreduce myvg /dev/sda5
Removed "/dev/sda5" from volume group "myvg"
删除PV-------------
[root@localhost ~]# pvremove /dev/sda5
Labels on physical volume "/dev/sda5" successfully wiped
卸载分区-------------
[root@localhost /]# umount /dev/myvg/mylv
修改LV活动状态
[root@localhost /]# lvchange -an /dev/myvg/mylv
移除LV-------------
[root@localhost /]# lvremove /dev/myvg/mylv
Logical volume "mylv" successfully removed
移除VG-------------
[root@localhost /]# vgremove myvg
Volume group "myvg" successfully removed
移除PV-------------
[root@localhost /]# pvremove /dev/sda6
Labels on physical volume "/dev/sda6" successfully wiped
----------------------------------------------------------------------------------------------------------------------------------------------------------
kpartx命令的作用,是让Linux内核读取一个设备上的分区表,然后生成代表相应分区的设备。
kpartx -l imagefile 可以查看一个映像文件中的分区,使用 kpartx -a imagefile 命令后,就可以通过 /dev/mapper/loop0pX (其中X是 分区号)来访问映像。
通过losetup和kpartx使用磁盘文件备份和恢复LVM卷
在使用Kvm和XEN虚拟系统时,常常要对虚拟机进行clone。一种方式是采用img磁盘文件来作为虚拟机磁盘,另一种方式是采用卷管理(LVM)来管理虚拟机磁盘。
推荐使用LVM卷管理,可以充分利用LVM的snapshot进行备份和复制。不过,在使用LVM卷管理时,有时候也需要直接访问LVM的LV,从中复制一些文件。
这里解释 kpartx 工具,可以实现对块文件(包括卷管理的LV)到设备文件的映射,这样就可以使用fdisk和mount命令访问逻辑卷了。
参考
* Kpartx: a tool for mounting partitions within an image file
* Playing with KVM and LVM on Linux
说明
kpartx 是用来映像任何分区块设备到设备文件的工具,是Linux multipath-tools 中的一个部分。
使用命令 kpartx -l imagefile 可以产看一个映像文件中的分区,使用 kpartx -a imagefile 命令后,就可以通过 /dev/mapper/loop0pX (其中X是 分区号)来访问映像。
此外,可以通过 mount /dev/mapper/loop0pX /mnt/ -o loop,ro 来访问,使用后可以使用 kpartx -d imagefile 来卸载。
对于使用 dd 命令复制的LVM卷(我采用此方法备份KVM虚拟机),也可以使用 kpartx 来映射为设备文件。
复制逻辑卷到磁盘镜像
使用virt-manger生成一个磁盘映像文件,然后使用losetup命令回环挂载
losetup /dev/loop2 /vms/win2k3.img
然后再使用dd命令进行镜像成功
dd if=/dev/mapper/VGwindows-LVwindows of=/dev/loop2
完成后,先卸载loop设备
losetup -d /dev/loop2
之后,就可以在kvm中使用这个磁盘镜像了,完全没有任何问题。
备份的LVM卷挂载和文件复制
以下是将备份的LVM逻辑卷采用 kpartx 映射为设备文件,然后挂载分区进行文件复制。
kpartx -av /nfs_share/x-box_LV/LVmyinfoserv_opt
add map loop2p1 (253:0): 0 12578832 linear /dev/loop2 63
mount /dev/mapper/loop2p1 /mnt
挂载后可以直接访问分区中的文件(Ext3文件系统)。
PARTX(8)
PARTX(8)
NAME
partx - telling the kernel about presence and numbering of on-disk partitions.
SYNOPSIS
partx [-a|-d|-l] [--type TYPE] [--nr M-N] [partition] disk
DESCRIPTION
Given a block device (
disk
) and a partition table
type
, try to parse the partition table, and list the con-
tents. Optionally add or remove partitions.
This is not an fdisk - adding and removing partitions is not a change of the disk, but just telling the kernel
about presence and numbering of on-disk partitions.
OPTIONS
-a
add specified partitions or read disk and add all partitions
-d delete specified or all partitions
-l list partitions
--type TYPE
Specify the partition type -- dos, bsd, solaris, unixware or gpt.
--nr M-N Specify the range of partitions (e.g --nr 2-4)
Specify the partition type -- dos, bsd, solaris, unixware or gpt.
--nr M-N Specify the range of partitions (e.g --nr 2-4)
SEE ALSO
addpart(8),
delpart(8),
fdisk(8),
parted(8),
partprobe(8)
addpart(8),
delpart(8),
fdisk(8),
parted(8),
partprobe(8)
本文转自 geekwolf 51CTO博客,原文链接:http://blog.51cto.com/linuxgeek/1057630