centos7 新增lvm磁碟

孤竹星發表於2015-07-28
df -h
fdisk -l
fdisk /dev/sdb
n
p
根據情況整理大小設定起始和終止(這裡我敲兩個回車,使用所有的空間)
t
L
8e
wq
fdisk -l
pvcreate /dev/sdb1
vgcreate centosvg /dev/sdb1
vgchange -ay centosvg
vgdisplay centosvg | grep "Total PE"
lvcreate -l 2047 centosvg -n lvvar
mkfs.ext4 /dev/centosvg/lvvar 
mkdir /new_var
echo '/dev/centosvg/lvvar /new_var ext4 defaults 0 0'>>/etc/fstab
mount -a 
df -hal
cd /var
tar cpf - .|(cd /new_var/; tar xvpf -)
cd /
mv /var /old_var
mkdir /var
umount /new_var/
mount /dev/centosvg/lvvar /var
 
[root@localhost /]# df -l
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda1        14G  3.9G  9.4G  30% /
devtmpfs        741M     0  741M   0% /dev
tmpfs           749M   80K  749M   1% /dev/shm
tmpfs           749M  8.7M  740M   2% /run
tmpfs           749M     0  749M   0% /sys/fs/cgroup
[root@localhost ~]# fdisk -l

Disk /dev/sdb: 8589 MB, 8589934592 bytes, 16777216 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk /dev/sda: 15.4 GB, 15350530048 bytes, 29981504 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x0001ffba

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048    29980671    14989312   83  Linux

[root@localhost ~]# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x02242155.

Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-16777215, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-16777215, default 16777215): 
Using default value 16777215
Partition 1 of type Linux and of size 8 GiB is set

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

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

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

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

[root@localhost ~]# fdisk -l

Disk /dev/sdb: 8589 MB, 8589934592 bytes, 16777216 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x02242155

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048    16777215     8387584   8e  Linux LVM


Disk /dev/sda: 15.4 GB, 15350530048 bytes, 29981504 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x0001ffba


   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048    29980671    14989312   83  Linux
[root@localhost ~]# pvcreate /dev/sdb1
  Physical volume "/dev/sdb1" successfully created
[root@localhost ~]# vgcreate centosvg /dev/sdb1
  Volume group "centosvg" successfully created
[root@localhost ~]# vgchange -ay centosvg
  0 logical volume(s) in volume group "centosvg" now active
[root@localhost ~]# vgdisplay centosvg | grep "Total PE"
  Total PE              2047  
[root@localhost ~]# lvcreate -l 2047 centosvg -n lvvar
  Logical volume "lvvar" created.
[root@localhost ~]# mkfs.ext4 /dev/centosvg/lvvar 
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
524288 inodes, 2096128 blocks
104806 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2147483648
64 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


Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done 
[root@localhost ~]# mkdir /new_var
[root@localhost ~]# echo '/dev/centosvg/lvvar /new_var ext4 defaults 0 0'>>/etc/fstab
[root@localhost ~]# cat /etc/fstab 


#
# /etc/fstab
# Created by anaconda on Mon Jul 27 09:00:45 2015
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
UUID=acc32c5f-5cef-43d4-bb4e-1e7e03a08b2e /                       ext4    defaults        1 1
/dev/centosvg/lvvar /new_var ext4 defaults 0 0
[root@localhost ~]# mount -a
[root@localhost ~]# df -hal
Filesystem                  Size  Used Avail Use% Mounted on
rootfs                       14G  3.9G  9.4G  30% /
proc                           0     0     0    - /proc
sysfs                          0     0     0    - /sys
devtmpfs                    741M     0  741M   0% /dev
securityfs                     0     0     0    - /sys/kernel/security
tmpfs                       749M   80K  749M   1% /dev/shm
devpts                         0     0     0    - /dev/pts
tmpfs                       749M  8.7M  740M   2% /run
tmpfs                       749M     0  749M   0% /sys/fs/cgroup
cgroup                         0     0     0    - /sys/fs/cgroup/systemd
pstore                         0     0     0    - /sys/fs/pstore
cgroup                         0     0     0    - /sys/fs/cgroup/cpuset
cgroup                         0     0     0    - /sys/fs/cgroup/cpu,cpuacct
cgroup                         0     0     0    - /sys/fs/cgroup/memory
cgroup                         0     0     0    - /sys/fs/cgroup/devices
cgroup                         0     0     0    - /sys/fs/cgroup/freezer
cgroup                         0     0     0    - /sys/fs/cgroup/net_cls
cgroup                         0     0     0    - /sys/fs/cgroup/blkio
cgroup                         0     0     0    - /sys/fs/cgroup/perf_event
cgroup                         0     0     0    - /sys/fs/cgroup/hugetlb
configfs                       0     0     0    - /sys/kernel/config
/dev/sda1                    14G  3.9G  9.4G  30% /
selinuxfs                      0     0     0    - /sys/fs/selinux
systemd-1                      0     0     0    - /proc/sys/fs/binfmt_misc
hugetlbfs                      0     0     0    - /dev/hugepages
mqueue                         0     0     0    - /dev/mqueue
debugfs                        0     0     0    - /sys/kernel/debug
/dev/mapper/centosvg-lvvar  7.8G   36M  7.3G   1% /new_var


[root@localhost var]# tar cpf - .|(cd /new_var/; tar xvpf -)
[root@localhost var]# cd /
[root@localhost var]# mv /var /old_var
[root@localhost var]# mkdir /var
[root@localhost var]# umount /new_var/
[root@localhost var]# mount /dev/centosvg/lvvar /var
[root@localhost var]# vim /etc/fstab 

修改
/dev/centosvg/lvvar /new_var ext4 defaults 0 0

/dev/centosvg/lvvar /var ext4 defaults 0 0

新增新硬碟處理過程

fdisk -l
fdisk /dev/sdc
n
p
1

t
8e
pvcreate /dev/sdc1
vgextend centosvg  /dev/sdc1
lvresize -l +4095 /dev/centosvg/lvvar
resize2fs /dev/centosvg/lvvar

[root@localhost ~]# fdisk -l
Disk /dev/sdb: 8589 MB, 8589934592 bytes, 16777216 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x02242155


   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048    16777215     8387584   8e  Linux LVM


Disk /dev/sda: 15.4 GB, 15350530048 bytes, 29981504 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x0001ffba

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048    29980671    14989312   83  Linux

Disk /dev/sdc: 17.2 GB, 17179869184 bytes, 33554432 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk /dev/mapper/centosvg-lvvar: 8585 MB, 8585740288 bytes, 16769024 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

[root@localhost ~]# fdisk /dev/sdc
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x03dfe0b3.

Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
Partition number (1-4, default 1): 
First sector (2048-33554431, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-33554431, default 33554431): 
Using default value 33554431
Partition 1 of type Linux and of size 16 GiB is set


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


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


Calling ioctl() to re-read partition table.
Syncing disks.
[root@localhost ~]# fdisk -l


Disk /dev/sdb: 8589 MB, 8589934592 bytes, 16777216 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x02242155


   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048    16777215     8387584   8e  Linux LVM


Disk /dev/sda: 15.4 GB, 15350530048 bytes, 29981504 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x0001ffba


   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048    29980671    14989312   83  Linux


Disk /dev/sdc: 17.2 GB, 17179869184 bytes, 33554432 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x03dfe0b3


   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1            2048    33554431    16776192   8e  Linux LVM


Disk /dev/mapper/centosvg-lvvar: 8585 MB, 8585740288 bytes, 16769024 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


[root@localhost ~]# pvcreate /dev/sdc1
  Physical volume "/dev/sdc1" successfully created


[root@localhost ~]# vgextend centosvg  /dev/sdc1
  Volume group "centosvg" successfully extended


[root@localhost ~]# lvresize -l +4095 /dev/centosvg/lvvar
  Size of logical volume centosvg/lvvar changed from 8.00 GiB (2047 extents) to 23.99 GiB (6142 extents).
  Logical volume lvvar successfully resized
[root@localhost ~]# lvdisplay
  --- Logical volume ---
  LV Path                /dev/centosvg/lvvar
  LV Name                lvvar
  VG Name                centosvg
  LV UUID                P5MD5F-ihCE-4bZx-Xktb-okid-HP6N-1jNfY4
  LV Write Access        read/write
  LV Creation host, time localhost.localdomain, 2015-07-28 11:34:09 +0800
  LV Status              available
  # open                 1
  LV Size                23.99 GiB
  Current LE             6142
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0


[root@localhost ~]# resize2fs /dev/centosvg/lvvar 
resize2fs 1.42.9 (28-Dec-2013)
Filesystem at /dev/centosvg/lvvar is mounted on /var; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 3
The filesystem on /dev/centosvg/lvvar is now 6289408 blocks long.


[root@localhost ~]# df -h
Filesystem                  Size  Used Avail Use% Mounted on
/dev/sda1                    14G  3.6G  9.7G  28% /
devtmpfs                    741M     0  741M   0% /dev
tmpfs                       749M   80K  749M   1% /dev/shm
tmpfs                       749M  8.7M  740M   2% /run
tmpfs                       749M     0  749M   0% /sys/fs/cgroup
/dev/mapper/centosvg-lvvar   24G  322M   23G   2% /var

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/28282660/viewspace-1754121/,如需轉載,請註明出處,否則將追究法律責任。

相關文章