磁盘分区管理

普通分区

[root@zhaikaiyun ~]# fdisk /dev/sdb  #给磁盘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 0xd3faf8cb.

Command (m for help): p

Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 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: 0xd3faf8cb

   Device Boot      Start         End      Blocks   Id  System

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-20971519, default 2048): 
Using default value 2048  #分区大小是全部磁盘的容量
Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519): 
Using default value 20971519
Partition 1 of type Linux and of size 10 GiB is set

Command (m for help): p  #显示现有分区信息

Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 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: 0xd3faf8cb

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048    20971519    10484736   83  Linux

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

Calling ioctl() to re-read partition table.
Syncing disks.
You have new mail in /var/spool/mail/root
[root@zhaikaiyun ~]#

[root@zhaikaiyun ~]# lsblk -a  #查看磁盘分区大小
NAME                                                                                     MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
fd0                                                                                        2:0    1    4K  0 disk 
sda                                                                                        8:0    0   20G  0 disk 
├─sda1                                                                                     8:1    0    2G  0 part [SWAP]
└─sda2                                                                                     8:2    0   18G  0 part /
sdb                                                                                        8:16   0   10G  0 disk 
└─sdb1                                                                                     8:17   0   10G  0 part 

[root@zhaikaiyun data]# mkfs -t ext4 /dev/sdb1  #分区格式化
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
655360 inodes, 2621184 blocks
131059 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2151677952
80 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@zhaikaiyun data]#
[root@zhaikaiyun data]# mount /dev/sdb1 /zhaiky  #其中/zhaiky目录是已经创建好的
[root@zhaikaiyun data]#
[root@zhaikaiyun data]# cd /zhaiky/
[root@zhaikaiyun zhaiky]# ll
total 16
drwx------ 2 root root 16384 Jun 22 18:40 lost+found
[root@zhaikaiyun zhaiky]# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda2        18G   14G  4.6G  75% /
devtmpfs        481M     0  481M   0% /dev
tmpfs           492M     0  492M   0% /dev/shm
tmpfs           492M  7.6M  484M   2% /run
tmpfs           492M     0  492M   0% /sys/fs/cgroup
tmpfs            99M     0   99M   0% /run/user/0
/dev/sdb1       9.8G   37M  9.2G   1% /zhaiky
[root@zhaikaiyun zhaiky]# 

[root@zhaikaiyun zhaiky]# echo "/dev/sdb1   /zhiaky  ext4  noatime,defaults  1 1" >>/etc/fstab
You have new mail in /var/spool/mail/root
[root@zhaikaiyun zhaiky]# more /etc/fstab 

#
# /etc/fstab
# Created by anaconda on Wed Aug 24 11:24:13 2016
#
# 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=827427d9-40e4-4001-898d-b4e1d16c359a /                       xfs     defaults        1 1
UUID=ff480a5f-8466-4b82-a675-d2d6a9499ca2 swap                    swap    defaults        0 0
/dev/sdb1   /zhiaky  ext4  noatime,defaults  1 1
[root@zhaikaiyun zhaiky]# 

 

LVM逻辑卷管理(PV、VG、LV)

作用:>可以整合分散的空间     >容量大小可以扩大
– 零散空闲存储 ---->整合的虚拟磁盘 ---->虚拟的分区
   物理卷 PV                卷组 VG                逻辑卷LV
将众多的物理卷( PV),组成卷组(VG),再从卷组中划分出逻辑卷(LV)

[root@zhaikaiyun ~]# umount /dev/sdb1
[root@zhaikaiyun ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda2        18G   14G  4.6G  75% /
devtmpfs        481M     0  481M   0% /dev
tmpfs           492M     0  492M   0% /dev/shm
tmpfs           492M  7.6M  484M   2% /run
tmpfs           492M     0  492M   0% /sys/fs/cgroup
tmpfs            99M     0   99M   0% /run/user/0
[root@zhaikaiyun ~]# 

[root@zhaikaiyun ~]# 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.


Command (m for help): p #显示现有分区信息

Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 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: 0xd3faf8cb

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048    20971519    10484736   83  Linux

Command (m for help): t   #修改分区类型
Selected partition 1
Hex code (type L to list all codes): 8e  #Linux LVM
Changed type of partition 'Linux' to 'Linux LVM'

Command (m for help): p #显示现有分区信息

Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 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: 0xd3faf8cb

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048    20971519    10484736   8e  Linux LVM

Command (m for help): 

Command (m for help): w  #保存并退出
The partition table has been altered!

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

[root@zhaikaiyun ~]# pvcreate /dev/sdb1  #创建物理卷/dev/sdb1来替换块设备
  Physical volume "/dev/sdb1" successfully created.
[root@zhaikaiyun ~]# 

[root@zhaikaiyun ~]# pvdisplay
  "/dev/sdb1" is a new physical volume of "<10.00 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sdb1
  VG Name               
  PV Size               <10.00 GiB
  Allocatable           NO
  PE Size               0   
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               2Leo7s-XnBx-Qj7f-yLI1-FcUi-oMvu-P44FMY
   
[root@zhaikaiyun ~]#

[root@zhaikaiyun ~]# vgcreate vgdata /dev/sdb1  #用vgcreate命令在同一个设备上创建vg卷组
  Volume group "vgdata" successfully created
  
[root@zhaikaiyun ~]# vgs  #查看已有的逻辑卷组
  VG     #PV #LV #SN Attr   VSize   VFree 
  vgdata   1   1   0 wz--n- <10.00g <7.50g
[root@zhaikaiyun ~]#
  
[root@zhaikaiyun ~]# 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               <10.00 GiB
  PE Size               4.00 MiB
  Total PE              2559
  Alloc PE / Size       0 / 0   
  Free  PE / Size       2559 / <10.00 GiB
  VG UUID               fC6uiF-RkL1-dzMi-ucMe-pJXu-Ukat-WCihN5


[root@zhaikaiyun ~]# lvcreate -L 2559 -n datalv vgdata  #创建逻辑卷(格式:lvcreate -n 逻辑卷名 -L 逻辑卷大小 卷组名)
  Rounding up size to full physical extent 2.50 GiB
  Logical volume "datalv" created.
You have new mail in /var/spool/mail/root
[root@zhaikaiyun ~]# 

[root@zhaikaiyun ~]# lvdisplay
  --- Logical volume ---
  LV Path                /dev/vgdata/datalv
  LV Name                datalv
  VG Name                vgdata
  LV UUID                URETRc-e8kp-sPGV-1BqE-dnBi-02yH-QkcpH3
  LV Write Access        read/write
  LV Creation host, time zhaikaiyun, 2020-06-22 19:32:57 +0800
  LV Status              available
  # open                 0
  LV Size                2.50 GiB
  Current LE             640
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:2
   
[root@zhaikaiyun ~]#
[root@zhaikaiyun ~]# lvs
  LV     VG     Attr       LSize Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  datalv vgdata -wi-ao---- 2.50g                                                    
[root@zhaikaiyun ~]# 


[root@zhaikaiyun ~]# mkfs.ext4 /dev/vgdata/datalv #格式化
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
163840 inodes, 655360 blocks
32768 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=671088640
20 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks: 
    32768, 98304, 163840, 229376, 294912

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: done 

You have new mail in /var/spool/mail/root
[root@zhaikaiyun ~]#

[root@zhaikaiyun ~]# mount /dev/vgdata/datalv /zhaiky
[root@zhaikaiyun ~]# df -h
Filesystem                 Size  Used Avail Use% Mounted on
/dev/sda2                   18G   14G  4.6G  75% /
devtmpfs                   481M     0  481M   0% /dev
tmpfs                      492M     0  492M   0% /dev/shm
tmpfs                      492M  7.6M  484M   2% /run
tmpfs                      492M     0  492M   0% /sys/fs/cgroup
tmpfs                       99M     0   99M   0% /run/user/0
/dev/mapper/vgdata-datalv  2.4G  7.5M  2.3G   1% /zhaiky
[root@zhaikaiyun ~]# mount -a   ##自动挂载

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值