ITPub博客

首页 > Linux操作系统 > Linux操作系统 > Linux 挂载新添加磁盘&LVM配置

Linux 挂载新添加磁盘&LVM配置

原创 Linux操作系统 作者:Oc_Chxin 时间:2015-12-03 09:34:27 0 删除 编辑
  • Linux 直接挂载磁盘

[root@11g-primary ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda1              18G   15G  1.7G  91% /
tmpfs                 635M     0  635M   0% /dev/shm
[root@11g-primary ~]# 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        2349    18868311   83  Linux
/dev/sda2            2350        2610     2096482+  82  Linux swap / Solaris

Disk /dev/sdb: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Disk /dev/sdb doesn't contain a valid partition table
[root@11g-primary ~]# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel. Changes will remain in memory only,
until you decide to write them. After that, of course, the previous
content won't be recoverable.


The number of cylinders for this disk is set to 2610.
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)
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

Command (m for help): p

Disk /dev/sdb: 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

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
1
Invalid partition number for type `1'
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-2610, default 1): 
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-2610, default 2610): 
Using default value 2610

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

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

		
[root@11g-primary ~]# 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        2349    18868311   83  Linux
/dev/sda2            2350        2610     2096482+  82  Linux swap / Solaris

Disk /dev/sdb: 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


		
[root@11g-primary ~]# mkfs -t ext3 -c /dev/sdb1

mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
2621440 inodes, 5241198 blocks
262059 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
160 block groups
32768 blocks per group, 32768 fragments per group
16384 inodes per group
Superblock backups stored on blocks: 
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
4096000

Checking for bad blocks (read-only test): done                                
Writing inode tables: done                            
Creating journal (32768 blocks):  done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 22 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.


[root@11g-primary ~]# mkdir /u02

[root@11g-primary ~]#  mount /dev/sdb1 /u02
[root@11g-primary ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda1              18G   15G  1.7G  91% /
tmpfs                 635M     0  635M   0% /dev/shm
/dev/sdb1              20G  173M   19G   1% /u02

[root@11g-primary ~]# vi /etc/fstab 

LABEL=/                 /                       ext3    defaults        1 1
tmpfs                   /dev/shm                tmpfs   defaults        0 0
devpts                  /dev/pts                devpts  gid=5,mode=620  0 0
sysfs                   /sys                    sysfs   defaults        0 0
proc                    /proc                   proc    defaults        0 0
LABEL=SWAP-sda2         swap                    swap    defaults        0 0
/dev/sdb1               /u02                    ext3    defaults        0 0



  • Linux LVM配置过程
[root@DB02 ~]# fdisk -l

Disk /dev/sda: 32.2 GB, 32212254720 bytes
255 heads, 63 sectors/track, 3916 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000724a8

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          26      204800   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              26         548     4194304   82  Linux swap / Solaris
Partition 2 does not end on cylinder boundary.
/dev/sda3             548        3917    27057152   83  Linux

Disk /dev/sdb: 32.2 GB, 32212254720 bytes
255 heads, 63 sectors/track, 3916 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

[root@DB02 ~]# fdisk /dev/sdb 
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x447e4e60.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

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

Disk /dev/sdb: 32.2 GB, 32212254720 bytes
255 heads, 63 sectors/track, 3916 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x447e4e60

   Device Boot      Start         End      Blocks   Id  System

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-3916, default 1): 
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-3916, default 3916): 
Using default value 3916

Command (m for help): t
Selected partition 1
Hex code (type L to list codes): 8e
Changed system type of partition 1 to 8e (Linux LVM)

Command (m for help): p

Disk /dev/sdb: 32.2 GB, 32212254720 bytes
255 heads, 63 sectors/track, 3916 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x447e4e60

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1        3916    31455238+  8e  Linux LVM

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

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

  • 一、创建逻辑卷
将新创建的两个分区/dev/sdb1转化成物理卷,主要是添加LVM属性信息并划分PE存储单元

[root@DB02 ~]# pvcreate /dev/sdb1 
  dev_is_mpath: failed to get device for 8:17
  Physical volume "/dev/sdb1" successfully created
[root@DB02 ~]# pvs
  PV         VG   Fmt  Attr PSize  PFree 
  /dev/sdb1       lvm2 a--  30.00g 30.00g
[root@DB02 ~]# pvdisplay
  "/dev/sdb1" is a new physical volume of "30.00 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sdb1
  VG Name               
  PV Size               30.00 GiB
  Allocatable           NO
  PE Size               0   
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               L1fQpn-ovur-Xgu2-XdcE-IdPq-RAW7-QlFJ6g

  • 创建卷组 vgdata ,并将刚才创建好的物理卷加入该卷组.可以看出默认PE大小为4MB,PE是卷组的最小存储单元.可以通过 –s参数修改大小。

[root@DB02 ~]# vgcreate vgdata /dev/sdb1 
  Volume group "vgdata" successfully created
[root@DB02 ~]# vgs
  VG     #PV #LV #SN Attr   VSize  VFree 
  vgdata   1   0   0 wz--n- 30.00g 30.00g
[root@DB02 ~]# vgdisplay
  --- Volume group ---
  VG Name               vgdata
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  1
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                0
  Open LV               0
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               30.00 GiB
  PE Size               4.00 MiB
  Total PE              7679
  Alloc PE / Size       0 / 0   
  Free  PE / Size       7679 / 30.00 GiB
  VG UUID               B65XI5-sxuT-3dYE-Sgh9-gFAT-ejVf-bgCScs


  • 从物理卷vgdata上面分割15G给新的逻辑卷lvdata1.
[root@DB02 ~]# lvcreate -L 15G -n lvdata01 vgdata
  Logical volume "lvdata01" created
[root@DB02 ~]# lvs
  LV       VG     Attr       LSize  Pool Origin Data%  Move Log Cpy%Sync Convert
  lvdata01 vgdata -wi-a----- 15.00g                                             
[root@DB02 ~]# lvdisplay
  --- Logical volume ---
  LV Path                /dev/vgdata/lvdata01
  LV Name                lvdata01
  VG Name                vgdata
  LV UUID                VGalZV-etmj-yoob-QKLo-8RdX-3JC4-wS7s7l
  LV Write Access        read/write
  LV Creation host, time DB02, 2015-11-24 13:29:13 +0800
  LV Status              available
  # open                 0
  LV Size                15.00 GiB
  Current LE             3840
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0

  • 使用mkfs.ext4命令在逻辑卷lvdata01上创建ext4文件系统.
[root@DB02 ~]# mkfs.ext4 /dev/vgdata/lvdata01 
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
983040 inodes, 3932160 blocks
196608 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4026531840
120 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks: 
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208

Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 25 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

  • 挂载逻辑卷
[root@DB02 ~]# mkdir -p /u01
[root@DB02 ~]# mount /dev/vgdata/lvdata01 /u01
[root@DB02 ~]# df -h
Filesystem                   Size  Used Avail Use% Mounted on
/dev/sda3                     26G  6.9G   18G  29% /
tmpfs                       1000M   76K 1000M   1% /dev/shm
/dev/sda1                    194M   34M  151M  19% /boot
/dev/sr0                     3.6G  3.6G     0 100% /media/RHEL_6.5 x86_64 Disc 1
/dev/mapper/vgdata-lvdata01   15G  166M   14G   2%/u01

  • 修改/etc/fstab最后一行加入
/dev/mapper/vgdata-lvdata01     /u01        ext4    defaults        0 0


  • 二、扩展逻辑卷
给逻辑卷增加空间并不会影响以前空间的使用,所以无需卸载文件系统,直接通过命令lvextend –L +500M /dev/vgdata/lvdata01或者lvextend –l 2.5G /dev/vgdata/lvdata01 给lvdata01增加500M空间(lvdata01目前是15G空间)设置完成之后,记得使用resize2fs命令来同步文件系统。

[root@DB02 ~]# lvextend -L +500M /dev/vgdata/lvdata01 
  Extending logical volume lvdata01 to 15.49 GiB
  Logical volume lvdata01 successfully resized
[root@DB02 ~]# lvs
  LV       VG     Attr       LSize  Pool Origin Data%  Move Log Cpy%Sync Convert
  lvdata01 vgdata -wi-ao---- 15.49g                                             
[root@DB02 ~]# resize2fs /dev/vgdata/lvdata01 
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/vgdata/lvdata01 is mounted on /u01; on-line resizing required
old desc_blocks = 1, new_desc_blocks = 1
Performing an on-line resize of /dev/vgdata/lvdata01 to 4060160 (4k) blocks.
The filesystem on /dev/vgdata/lvdata01 is now 4060160 blocks long.

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/30560130/viewspace-1852168/,如需转载,请注明出处,否则将追究法律责任。

上一篇: Oracle expdb/impdp
请登录后发表评论 登录
全部评论

注册时间:2015-11-11

  • 博文量
    10
  • 访问量
    21731