Linux磁盘分区

  • 查看磁盘
[root@localhost ~]# fdisk -l

Disk /dev/vda: 32.2 GB, 32212254720 bytes, 62914560 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: 0x0009680e

   Device Boot      Start         End      Blocks   Id  System
/dev/vda1            2048     4194303     2096128   82  Linux swap / Solaris
/dev/vda2   *     4194304    56623103    26214400   83  Linux
  • 初始化磁盘
[root@localhost ~]# fdisk /dev/vda
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): n
Partition type:
   p   primary (1 primary, 0 extended, 3 free)
   e   extended
Select (default p): p
Partition number (1-4, default 1): 1
...
Command (m for help): t
Selected partition 1
Hex code (type L to list all codes): 8e
...
Command (m for help): w
...
  • 创建物理卷
[root@localhost ~]# pvcreate /dev/vda1
  • 创建卷组
[root@localhost ~]# vgcreate mygroup /dev/vda1           //mygroup是卷组名,自己起
  • 创建逻辑卷
[root@localhost ~]# vgdisplay mygroup | grep "Total PE"      //查看该卷组的逻辑数
  • 激活卷组
[root@localhost ~]# vgchange -ay mygroup     //还记得mygroup是你自己起的卷组名么,激活卷组是懒得重启VPS
  1 logical volume(s) in volume group "mygroup" now active
  • 扩展卷组
[root@localhost ~]# vgextend mygroup /dev/vda1
  • 创建逻辑卷
[root@localhost ~]# vgdisplay mygroup | grep "Total PE" 
  Total PE              127999   
[root@localhost ~]# lvcreate -l 127999 mygroup  -n  ccc 
  • 格式化逻辑卷
[root@localhost ~]# mkfs.ext4 /dev/mygroup/ccc     //格式化mygroup卷组的ccc卷组盘
  • 创建要挂载盘的目录
[root@localhost ~]# mkdir /data      //根据要挂载盘的文件而定,所创建的文件目录。
  • 加入启动项
[root@localhost ~]# echo /dev/mygroup/ccc /data ext4 defaults 0 0 >> /etc/fstab      //根据要挂载盘的文件而定,所创建的文件目录。
[root@localhost ~]# vim /etc/fstab    // 查看写入状况
---
# /etc/fstab
# Created by anaconda on Mon Jan  2 22:58:53 2017
#
# 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=381f5199-12a4-4d44-91af-be015a752145 /                       ext4    defaults        1 1
UUID=4b0d629d-79d8-43e3-82bd-8a7b98fcfb75 swap                    swap    defaults        0 0
/dev/mygroup/ccc /data ext4 defaults 0 0
  • 挂载
[root@localhost ~]# mount -a 
[root@localhost ~]# df -h     //磁盘就挂载上去了。
Filesystem                Size  Used Avail Use% Mounted on
/dev/vda2                  25G  4.6G   19G  20% /
devtmpfs                  7.8G     0  7.8G   0% /dev
tmpfs                     7.8G     0  7.8G   0% /dev/shm
tmpfs                     7.8G  777M  7.0G  10% /run
tmpfs                     7.8G     0  7.8G   0% /sys/fs/cgroup
/dev/mapper/mygroup-ccc   493G   81G  387G  18% /data
/dev/mapper/zfrgroup-zfr   99G  1.4G   92G   2% /home
tmpfs                     1.6G     0  1.6G   0% /run/user/0
  • 新增磁盘空间
[root@localhost ~]# partprobe
[root@localhost ~]# pvcreate /dev/vda2
[root@localhost ~]# pvdisplay
[root@localhost ~]# vgdisplay
[root@localhost ~]# vgextend mygroup /dev/vda2 
[root@localhost ~]# lvextend -L +5G  /dev/mygroup/ccc
[root@localhost ~]# resize2fs /dev/mygroup/ccc 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值