zoukankan      html  css  js  c++  java
  • 在linux中扩展磁盘容量(2)LVM

    场景,假设/home 下已经没有足够的空间,由于预算的问题,也不太可能购买一块足够大的磁盘,用来作为/home的空间。

    1 备份你的数据

    使用工具打包你/home目录下的数据,因为LVM会破坏其physical volumn上的数据。

    因为/home下存放了你所有用户的数据,并且/home挂载在/dev/hde5 上, 所有为了在对/home进行操作的时候不受其他人的干扰,首先进入single-user mode

    who命令查看同时登录的用户

    wall “warning message” 通知其他登录的用户。

    init 1 进入到single-user mode, 因为runlevel 1下需要网络service不可用所以,确保你是从VGA console登录到你的系统的。

    接下来你就可以umount 你的/home 挂载点了。

    2 查看你的partition的type ID

    fdisk /dev/hde5

    sh-2.05b# fdisk -l /dev/hde

    Disk /dev/hde: 4311 MB, 4311982080 bytes
    16 heads, 63 sectors/track, 8355 cylinders
    Units = cylinders of 1008 * 512 = 516096 bytes

    Device Boot Start End Blocks Id System
    /dev/hde1 1 4088 2060320+ fd Linux raid autodetect
    /dev/hde2 4089 5713 819000 83 Linux
    /dev/hde3 5714 6607 450576 83 Linux
    /dev/hde4 6608 8355 880992 5 Extended
    /dev/hde5 6608 7500 450040+ 83 Linux
    sh-2.05b#
     

    接下来同fdisk命令来修改/dev/hde5 的type ID 以及新增加的盘/dev/hdf的type ID 同时对新增加的盘进行分区。

    sh-2.05b# fdisk /dev/hde

    The number of cylinders for this disk is set to 8355.
    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):
    Command (m for help): t
    Partition number (1-6): 5
    Hex code (type L to list codes): 8e # Linux LVM type ID
    Changed system type of partition 5 to 8e (Linux LVM)

    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):

    检查下 确保你的修改已经生效

    Command (m for help): p

    Disk /dev/hde: 4311 MB, 4311982080 bytes
    16 heads, 63 sectors/track, 8355 cylinders
    Units = cylinders of 1008 * 512 = 516096 bytes

    Device Boot Start End Blocks Id System
    /dev/hde1 1 4088 2060320+ fd Linux raid autodetect
    /dev/hde2 4089 5713 819000 83 Linux
    /dev/hde3 5714 6607 450576 83 Linux
    /dev/hde4 6608 8355 880992 5 Extended
    /dev/hde5 6608 7500 450040+ 8e Linux LVM

    Command (m for help):
     

    保存对partition table 的修改

    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.
    Syncing disks.
    sh-2.05b#

    创建PV (physical volumn)

    sh-2.05b# pvcreate /dev/hde5
    pvcreate -- physical volume "/dev/hde5" successfully created

    sh-2.05b# pvcreate /dev/hdf1
    pvcreate -- physical volume "/dev/hdf1" successfully created

    扫描系统中存在的VG (Volumn Group) 命令VGscan 如果系统中没有存在的volumn group,则创建一个新的VG。

    vgcreate lvm-hde /dev/hdf1 /dev/hde5

    如果一切顺利,系统中一个新的VG “lvm-hde” 被创建出来,查看下VG的状态

    sh-2.05b# vgdisplay lvm-hde
    
    --- Volume group ---
    VG Name lvm-hde
    VG Access read/write
    VG Status available/resizable
    VG # 0
    MAX LV 256
    Cur LV 0
    Open LV 0
    MAX LV Size 255.99 GB
    Max PV 256
    Cur PV 2
    Act PV 2
    VG Size 848 MB
    PE Size 4 MB
    Total PE 212
    Alloc PE / Size 0 / 0
    Free PE / Size 212 / 848 MB
    VG UUID W7bgLB-lAFW-wtKi-wZET-jDJF-8VYD-snUaSZ

    接下了 就可以从VG “lvm-hde”中创建LV (Logical Volumn)

    sh-2.05b# lvcreate -l 212 lvm-hde -n lvm0 #通过指定PE (Physical extends)来创建LV
    
    Logical volume "lvm0" created
    sh-2.05b# lvcreate -l 100%FREE -n lvm0 lvm-hde #通过指定VG的百分比大小来创建新的LV
    sh-2.05b# lvcreate -l 50%VG -n lvm0 lvm-hde

    当LV被创建完成以后,需要对其格式化后才可以被使用

    格式化过程如下

    sh-2.05b# mkfs -t ext3 /dev/lvm-hde/lvm0
    mke2fs 1.32 (09-Nov-2002)
    Filesystem label=
    OS type: Linux
    Block size=4096 (log=2)
    Fragment size=4096 (log=2)
    108640 inodes, 217088 blocks
    10854 blocks (5.00%) reserved for the super user
    First data block=0
    7 block groups
    32768 blocks per group, 32768 fragments per group
    15520 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 38 mounts or
    180 days, whichever comes first. Use tune2fs -c or -i to override.
    到这里,/dev/lvm-hde/lvm0这个LV创建,格式化完成,下面创建挂载点将其挂载。
    mkdir /home
    修改/etc/fstab
    /dev/lvm-hde/lvm0   /home      ext3    defaults        1 2

    mount –a 挂载/dev/lvm-hde/lvm0 到/home 挂载点下

    到这时,你的新的/home空间大小是/dev/hde5 /dev/hdf1大小的和,所以你可以将你备份的/home目录下的历史数据迁移会/home目录下

    总结

    一, Logical Volumn创建的基本步骤:

    1 初始化将被你用作PV的parition, 修改partition type ID –》 Linux LVM

    2 使用创建好的PV来创建 VG

    3 从VG中创建新的LV

    image

    4 为创建好的LV创建文件系统 (ext3, GFS , etc)

    5 创建挂载点

    6 挂载,如果需要自动挂载,修改/etc/fstab 配置文件。

    完毕。

  • 相关阅读:
    Hadoop学习之路(十四)MapReduce的核心运行机制
    Hadoop学习之路(十三)MapReduce的初识
    Hadoop学习之路(十二)分布式集群中HDFS系统的各种角色
    Hadoop学习之路(十一)HDFS的读写详解
    Hadoop学习之路(十)HDFS API的使用
    Hadoop学习之路(九)HDFS深入理解
    Hadoop学习之路(八)在eclispe上搭建Hadoop开发环境
    Guava的使用
    如何用纯 CSS 创作一个过山车 loader
    如何用纯 CSS 创作一组昂首阔步的圆点
  • 原文地址:https://www.cnblogs.com/yuboyue/p/2109859.html
Copyright © 2011-2022 走看看