centos 7 扩容,(没有卷组、没有磁盘分区) 新建卷组 扩容
作记录学习
环境 vmware workstations centos 7.2
背景 预先安装时,分配磁盘较小, 系统安装时,没有创建卷组
1、将虚拟机关机后,手动扩充磁盘空间
2、机器磁盘分配后,还不能用,还需要格式化系统
查看当前磁盘分布
[root@localhost ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/sda3 18G 4.7G 14G 27% / devtmpfs 475M 0 475M 0% /dev tmpfs 489M 144K 489M 1% /dev/shm tmpfs 489M 7.1M 482M 2% /run tmpfs 489M 0 489M 0% /sys/fs/cgroup /dev/sda1 297M 144M 154M 49% /boot tmpfs 98M 12K 98M 1% /run/user/0 [root@localhost ~]# fdisk -l Disk /dev/sda: 21.5 GB, 21474836480 bytes, 41943040 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: 0x0008a4e1 Device Boot Start End Blocks Id System /dev/sda1 * 2048 616447 307200 83 Linux /dev/sda2 616448 4810751 2097152 82 Linux swap / Solaris /dev/sda3 4810752 41943039 18566144 83 Linux [root@localhost ~]#
[root@localhost ~]# pvdisplay # 查看物理分区 [root@localhost ~]# vgdisplay # 查看卷组信息 [root@localhost ~]# lvdisplay # 查看逻辑分区
没有 物理分区 卷组信息 逻辑分区
3、对新增加的硬盘进行分区
执行步骤:
- 执行“fdisk /dev/sda”,进入到fdisk
- 输入p指令,查看已分区数量(有3个 /dev/sda1 /dev/sda2 /dev/sda3)
- 输入 n {new partition}指令,新增加一个分区
- 输入p {primary partition},分区类型选择为主分区
- 输入分区号 4 {partition number} ,分区号选4(上面显示我已经有3个分区了)
- 回车 默认(起始扇区)
- 回车 默认(结束扇区)
- 输入t {change partition id}指令,修改分区类型
- 按提示输入刚才的分区号4
- 输入分区类型 8e {Linux LVM partition}
- 输入w指令,将以上改动写入分区表
- 最后完成,退出fdisk命令
以下图片仅供参考
[root@localhost ~]#reboot # 重启系统
[root@localhost ~]# fdisk -l #再次查看 ,发现多了个 sda4 Disk /dev/sda: 68.7 GB, 68719476736 bytes, 134217728 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: 0x0008a4e1 Device Boot Start End Blocks Id System /dev/sda1 * 2048 616447 307200 83 Linux /dev/sda2 616448 4810751 2097152 82 Linux swap / Solaris /dev/sda3 4810752 41943039 18566144 83 Linux /dev/sda4 41943040 134217727 46137344 8e Linux LVM
[root@vnode1 ~]# mkfs.ext3 /dev/sda4 # 此步几乎可以省略,后续,有待验证
注意点:做完上面的操作,已经有物理卷,可以不创建卷组,逻辑卷,直接 mount
下面是创建卷组、逻辑卷,再挂载
4、创建卷组
[root@localhost ~]# vgcreate centos /dev/sda4 Physical volume "/dev/sda4" successfully created Volume group "centos" successfully created [root@localhost ~]# vgdisplay --- Volume group --- VG Name centos 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 44.00 GiB PE Size 4.00 MiB Total PE 11263 Alloc PE / Size 0 / 0 Free PE / Size 11263 / 44.00 GiB VG UUID 3r3gTx-mrY2-6RAA-mrPt-RBnn-8BaV-3DlO1l
5、创建逻辑卷
[root@localhost ~]# lvcreate -L 43G -n root centos # 创建 Logical volume "root" created. [root@localhost ~]# lvdisplay --- Logical volume --- LV Path /dev/centos/root LV Name root VG Name centos LV UUID XNJ9Ut-0fmU-RQqq-AY2f-xC2j-9zhL-qLFuwY LV Write Access read/write LV Creation host, time localhost.localdomain, 2019-08-13 11:31:18 +0800 LV Status available # open 0 LV Size 43.00 GiB Current LE 11008 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 8192 Block device 253:0 [root@localhost /]# mkfs.ext3 /dev/centos/root #格式化逻辑分区 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 2818048 inodes, 11272192 blocks 563609 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=4294967296 344 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, 4096000, 7962624, 11239424 Allocating group tables: done Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done
6、挂载点,这里把新增逻辑分区,挂在到了 /data 目录
[root@localhost /]# mount /dev/centos/root /data [root@localhost /]# df -h Filesystem Size Used Avail Use% Mounted on /dev/sda3 18G 8.2G 9.6G 46% / devtmpfs 475M 0 475M 0% /dev tmpfs 489M 84K 489M 1% /dev/shm tmpfs 489M 7.1M 482M 2% /run tmpfs 489M 0 489M 0% /sys/fs/cgroup /dev/sda1 297M 144M 154M 49% /boot tmpfs 98M 20K 98M 1% /run/user/42 tmpfs 98M 0 98M 0% /run/user/0 /dev/mapper/centos-root 43G 52M 40G 1% /data
# 这里从逻辑分区 /dev/centos/root 变成了 /dev/mapper/centos-root,是个很奇怪的点,后续要弄清楚
7、永久挂载
普通mount ,重启机器后,就会失效,如果想永久挂载,还需要修改配置文件
[root@localhost bin]# vim /etc/fstab # 修改配置文件
# # /etc/fstab # Created by anaconda on Mon Jul 1 01:07:33 2019 # # 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=f66e8bc7-ef82-473e-b565-df8ef7cfcda7 / xfs defaults 0 0 UUID=c6e2743d-3e47-40a6-a74f-e429e1b3efc4 /boot xfs defaults 0 0 UUID=681ef8e7-767e-47d4-84c4-7d705ac9dea4 swap swap defaults 0 0 #/dev/cetnos/root /data xfs auto 0 0 #逻辑分区 挂载点 文件格式(与前面格式化文件格式保持一致) defaults(默认是读写) 0 0 /dev/mapper/centos-root /date ext3 defaults 0 0
[root@localhost bin]# umount /dev/centos/root #卸载挂载点 [root@localhost bin]# mount -a #读取配置文件挂载 [root@localhost bin]# root #重启,查看挂载点,是否失效
备注
df -T -h # 查看挂载的分区信息
parted -l #查看所有的分区信息
blkid
parted -l #查看所有的分区信息
blkid
[root@]# mkfs -t ext3 /dev/sda4 mke2fs 1.39 (29-May-2006) /dev/sda4 isapparently in use by the system; will not make a filesystem here! 提示/dev/sda4 正在被使用。 /dev/sda4 正在被DM管理,所以我们创建文件系统时提示报错,我们手工的移除,就可以正常的创建文件系统,操作如下: [root@ ]# dmsetup status [root@]# dmsetup remove_all
fuser -km /data # 强制终止 data进程