[root@localhost ~]# fdisk -l
##fidisk是一个创建和维护分区表的程序,(列出所有分区表)
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: 0x000c8ce2
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 41943039 19921920 8e Linux LVM
Disk /dev/mapper/rhel-root: 18.2 GB, 18249416704 bytes, 35643392 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/rhel-swap: 2147 MB, 2147483648 bytes, 4194304 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
##可以看到我们只有一块磁盘,但是有两个分区分别为rhel-root和rhel-swap两个分区
##现在我们使用虚拟机手动增加一块磁盘
##点击玩下一步,然后继续点击—>SCSI—>创建新的虚拟磁盘—>20G—>将磁盘拆分成多个文件—>确定
[root@localhost ~]# fdisk -l
Disk /dev/sdb: 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 /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: 0x000c8ce2
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 41943039 19921920 8e Linux LVM
Disk /dev/mapper/rhel-root: 18.2 GB, 18249416704 bytes, 35643392 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/rhel-swap: 2147 MB, 2147483648 bytes, 4194304 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
##这下我们可以看到已经有两个分区和两个磁盘了
##分区完成后我们进行格式化,格式化完成后进行挂载(linux里面的分区可以挂载到任何指定的目录里面,目录就是磁盘设备的访问入口,多个挂载相当于多个入口)
[root@localhost ~]# fdisk /dev/sdb
##我先先分一下新建的分区
`##我们这里先使用传统的fdisk分区的方式(在硬盘容量大于2Tb的 时候无法使用fdisk进行分区的管理),这个分区最多只能分四个区,我们再分区的话,需要先划拓展分区,然后再在拓展分区上花逻辑分区,
##现在很多的都是用GPT分区方案,这个方案适合特别大的硬盘,比如几百个TB的也可以分。
##parted命令可以划分单个分区大于2T的GPT格式的分区,也可以划分普通的MBR分区,fdisk命令对于大于2T的分区无法划分(大于2.2TB的存储空间用fdisk不支持,需要采用parted来分区),所以用fdisk无法看到parted划分的GPT格式的分区。Parted 具有丰富的功能,它除了能够进行分区的添加、删除等常见操作外,还可以进行移动分区、创建文件系统、调整文件系统大小、复制文件系统等操作
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 0x091f3e18.
Command (m for help): m
##查看帮助
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
g create a new empty GPT partition table
G create an IRIX (SGI) partition table
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition's system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)
Command (m for help): n
##新建分区,其中d是删除分区
Partition type:
p primary (0 primary, 0 extended, 3 free)
e extended
##询问的是分的是主分区还是拓展分区
Select (default p): p
##p分主分区
Partition number (1-4, default 1): 1
##从第一个分区开始
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): +10G
##按回车代表直接将整块硬盘分区了,但是我们分区的意义就是将磁盘分为多个区域,然后干不同的事情,我们这里尝试分10G(前面已经提示+size{k,m,g}就是分多大空间出来)
Partition 2 of type Linux and of size 10 GiB is set
##已经分出来了
Select (default p): p
Partition number (2-4, default 2): 2
First sector (2099200-41943039, default 2099200):
Using default value 2099200
Last sector, +sectors or +size{K,M,G} (2099200-41943039, default 41943039): +10G
Partition 2 of type Linux and of size 10 GiB is set
Command (m for help): p
##p是打印分区表,也就是查看分区情况
Disk /dev/sdb: 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: 0x091f3e18
Device Boot Start End Blocks Id System
/dev/sdb1 2048 20973567 10485760 83 Linux
##可以在里面随便按按键,只要不按w (将表写入磁盘并退出)就行
Command (m for help): q
[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.
Command (m for help): p
[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 0xbe917a1f.
##没有写入磁盘退出的话,我们可以看到硬盘又恢复到分区之前了,所以我们重新按照刚才的分区方案进行分区后按"w"写入分区后:
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@localhost ~]# cat /proc/partitions
##proc我们前面有了解,是反应内存的信息的目录,而proc下的partitions就是反应内存真正识别的设备
major minor #blocks name
8 16 20971520 sdb
8 17 10485760 sdb1
8 0 20971520 sda
8 1 1048576 sda1
8 2 19921920 sda2
11 0 4391936 sr0
253 0 17821696 dm-0
253 1 2097152 dm-1
##我们可以看到sdb1说明刚刚的写入成功
[root@localhost ~]# mkfs.xfs /dev/sdb1
##这是第二步,我们将sdb1格式化,企业版7下我们使用xfs命令
meta-data=/dev/sdb1 isize=512 agcount=4, agsize=655360 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=2621440, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal log bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
[root@localhost ~]# mkdir /data1/
##创建根下的data1目录,为挂载做准备
[root@localhost ~]# mount /dev/sdb1/ /data1/
##将sdb1挂载到data1上
[root@localhost ~]# cp apache-tomcat-7.0.103.tar.gz /data1/
##将跟下的tomcat复制到data1下 也就相当于复制到磁盘sdb1上
[root@localhost ~]# ls
anaconda-ks.cfg apache-tomcat-7.0.103.tar.gz initial-setup-ks.cfg nginx-1.18.0 nginx-1.18.0.tar.gz westos
[root@localhost ~]# cd /data1
[root@localhost data1]# ls
apache-tomcat-7.0.103.tar.gz
[root@localhost data1]# pwd
/data1
[root@localhost data1]# df
##可以看到/dev/sdb1挂载到data1上了
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/rhel-root 17811456 3881904 13929552 22% /
devtmpfs 996932 0 996932 0% /dev
tmpfs 1014056 0 1014056 0% /dev/shm
tmpfs 1014056 10672 1003384 2% /run
tmpfs 1014056 0 1014056 0% /sys/fs/cgroup
/dev/sda1 1038336 168076 870260 17% /boot
tmpfs 202812 36 202776 1% /run/user/1000
/dev/sr0 4391278 4391278 0 100% /run/media/cxg/RHEL-7.6 Server.x86_64
/dev/sdb1 10475520 42372 10433148 1% /data1
tmpfs 202812 0 202812 0% /run/user/0
##我们使用mount属于手工挂载,每次重启后又得重新挂载,这时候我们就解决前面上一章软件管理留下的设置自动挂载到问题
[root@localhost data1]# vim /etc/fstab
##########################出现错误 这里第一项应该是/dev/sdb1/
##红框里面是加入的内容,他的意思:/dev/sdb1/是设备命,/data1挂载点,xfs文件系统类型(企业版7我们类型是sfs),defaults默认的挂载选项, 0 0 是不检测挂载的校验
[root@localhost ~]# umount /data1/
##先对卸载掉sdb1的挂载
[root@localhost ~]# df
##再用df查看这个设备已经不在了
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/rhel-root 17811456 3721976 14089480 21% /
devtmpfs 996932 0 996932 0% /dev
tmpfs 1014056 0 1014056 0% /dev/shm
tmpfs 1014056 10728 1003328 2% /run
tmpfs 1014056 0 1014056 0% /sys/fs/cgroup
/dev/sda1 1038336 168076 870260 17% /boot
tmpfs 202812 4 202808 1% /run/user/42
tmpfs 202812 24 202788 1% /run/user/1000
tmpfs 202812 0 202812 0% /run/user/0
/dev/sr0 4391278 4391278 0 100% /run/media/cxg/RHEL-7.6 Server.x86_64
[root@localhost ~]# mount -a
##挂载所有磁盘(他的运行原理是去/etc/fstab下查看里面的内容,然后对其进行加载,我们上面设置的/etc/fstab下增加了/dev/sdb1/的挂载,系统会帮我们挂载上,所以data1又被挂载上了)
[root@localhost ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/rhel-root 17811456 3721956 14089500 21% /
devtmpfs 996932 0 996932 0% /dev
tmpfs 1014056 0 1014056 0% /dev/shm
tmpfs 1014056 10728 1003328 2% /run
tmpfs 1014056 0 1014056 0% /sys/fs/cgroup
/dev/sda1 1038336 168076 870260 17% /boot
tmpfs 202812 4 202808 1% /run/user/42
tmpfs 202812 24 202788 1% /run/user/1000
tmpfs 202812 0 202812 0% /run/user/0
/dev/sr0 4391278 4391278 0 100% /run/media/cxg/RHEL-7.6 Server.x86_64
/dev/sdb1 10475520 42372 10433148 1% /data1
##我们尝试再给sdb分一个分区
[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.
Command (m for help): n
Partition type:
p primary (1 primary, 0 extended, 3 free)
e extended
Select (default p):
Using default response p
Partition number (2-4, default 2):
First sector (20973568-41943039, default 20973568):
Using default value 20973568
Last sector, +sectors or +size{K,M,G} (20973568-41943039, default 41943039):
##这块不设置大小的话,默认将剩余的内存都分给新建的sdb2
Using default value 41943039
Partition 2 of type Linux and of size 10 GiB is set
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
[root@localhost ~]# cat /proc/partitions
##我们从上面的代码可以看到error 16: Device or resource busy,设备繁忙,再分区的话,需要重启才会生效,但是我们有时候不想重启,怎么办
major minor #blocks name
8 0 20971520 sda
8 1 1048576 sda1
8 2 19921920 sda2
8 16 20971520 sdb
8 17 10485760 sdb1
11 0 4391936 sr0
253 0 17821696 dm-0
253 1 2097152 dm-1
[root@localhost ~]# fdisk -l /dev/sdb
##fdisk里面可以看到分好的sdb2,但是这个只是假的,表象,我们不重启的话就需要刷新下磁盘
Disk /dev/sdb: 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: 0x2643a621
Device Boot Start End Blocks Id System
/dev/sdb1 2048 20973567 10485760 83 Linux
/dev/sdb2 20973568 41943039 10484736 83 Linux
[root@localhost ~]# partprobe
##这个命令相当于刷新磁盘
Warning: Unable to open /dev/sr0 read-write (Read-only file system). /dev/sr0 has been opened read-only.
[root@localhost ~]# cat /proc/partitions
##可以看到刷新后这个sdb2已经出来了(这个叫刷新内核分区表)
major minor #blocks name
8 0 20971520 sda
8 1 1048576 sda1
8 2 19921920 sda2
8 16 20971520 sdb
8 17 10485760 sdb1
8 18 10484736 sdb2
11 0 4391936 sr0
253 0 17821696 dm-0
253 1 2097152 dm-1
[root@localhost ~]# vim /etc/fstab
##这个图片是将我们内存的挂载也设置成为自动挂载,不用每次重启后再次mount
[root@localhost ~]# mount -a
##挂载/etc/fstab下的所有挂载设置
mount: /dev/sr0 is write-protected, mounting read-only
[root@localhost ~]# cd
[root@localhost ~]# df
##可以看到都已经挂载上了
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/rhel-root 17811456 3721996 14089460 21% /
devtmpfs 996932 0 996932 0% /dev
tmpfs 1014056 0 1014056 0% /dev/shm
tmpfs 1014056 10732 1003324 2% /run
tmpfs 1014056 0 1014056 0% /sys/fs/cgroup
/dev/sda1 1038336 168076 870260 17% /boot
tmpfs 202812 4 202808 1% /run/user/42
tmpfs 202812 24 202788 1% /run/user/1000
tmpfs 202812 0 202812 0% /run/user/0
/dev/sr0 4391278 4391278 0 100% /media
/dev/sdb1 10475520 42372 10433148 1% /data1
[root@localhost ~]# umount /media
##我们卸载media
[root@localhost ~]# df
##发现已经卸载
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/rhel-root 17811456 3721996 14089460 21% /
devtmpfs 996932 0 996932 0% /dev
tmpfs 1014056 0 1014056 0% /dev/shm
tmpfs 1014056 10732 1003324 2% /run
tmpfs 1014056 0 1014056 0% /sys/fs/cgroup
/dev/sda1 1038336 168076 870260 17% /boot
tmpfs 202812 4 202808 1% /run/user/42
tmpfs 202812 24 202788 1% /run/user/1000
tmpfs 202812 0 202812 0% /run/user/0
/dev/sr0 4391278 4391278 0 100% /run/media/cxg/RHEL-7.6 Server.x86_64
/dev/sdb1 10475520 42372 10433148 1% /data1
[root@localhost ~]# mount -a
##在重新挂在下
mount: /dev/sr0 is write-protected, mounting read-only
[root@localhost ~]# df
##光盘已经挂载了
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/rhel-root 17811456 3721996 14089460 21% /
devtmpfs 996932 0 996932 0% /dev
tmpfs 1014056 0 1014056 0% /dev/shm
tmpfs 1014056 10732 1003324 2% /run
tmpfs 1014056 0 1014056 0% /sys/fs/cgroup
/dev/sda1 1038336 168076 870260 17% /boot
tmpfs 202812 4 202808 1% /run/user/42
tmpfs 202812 24 202788 1% /run/user/1000
tmpfs 202812 0 202812 0% /run/user/0
/dev/sr0 4391278 4391278 0 100% /media
/dev/sdb1 10475520 42372 10433148 1% /data1
##下次重启的时候看一下是不是自动挂载上了,同时针对虚拟机我们还有注意事项,就是已经开机自动连接要打开
[root@localhost ~]# mkfs.ext4 /dev/sdb2/
##linux系统用的都是cfs和ext格式文件,将sdb2格式化
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@localhost ~]# cat /proc/partitions
##可以看到sdb2的分区情况
major minor #blocks name
8 0 20971520 sda
8 1 1048576 sda1
8 2 19921920 sda2
8 16 20971520 sdb
8 17 10485760 sdb1
8 18 10484736 sdb2
11 0 4391936 sr0
253 0 17821696 dm-0
253 1 2097152 dm-1
[root@localhost ~]# mkdir /data2
[root@localhost ~]# mount /dev/sdb2 /data2
##挂载到data2
[root@localhost ~]# cd /data2
[root@localhost data2]# ll
total 16
drwx------. 2 root root 16384 May 6 00:55 lost+found
[root@localhost data2]# ls
lost+found
[root@localhost data2]# cd
[root@localhost ~]# ls
anaconda-ks.cfg yum-3.4.3-167.el7.centos.noarch.rpm
apache-tomcat-7.0.103.tar.gz yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
initial-setup-ks.cfg yum-plugin-fastestmirror-1.1.31-53.el7.noarch.rpm
[root@localhost ~]# cd
[root@localhost ~]# cp apache-tomcat-7.0.103.tar.gz /data2/
##将tomcat拷贝到data2下
[root@localhost ~]# cd /data2
[root@localhost data2]# ls
apache-tomcat-7.0.103.tar.gz lost+found
[root@localhost data2]# df
##可以看到挂载
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/rhel-root 17811456 3722300 14089156 21% /
devtmpfs 996932 0 996932 0% /dev
tmpfs 1014056 0 1014056 0% /dev/shm
tmpfs 1014056 10784 1003272 2% /run
tmpfs 1014056 0 1014056 0% /sys/fs/cgroup
/dev/sda1 1038336 168076 870260 17% /boot
tmpfs 202812 4 202808 1% /run/user/42
tmpfs 202812 20 202792 1% /run/user/1000
tmpfs 202812 0 202812 0% /run/user/0
/dev/sr0 4391278 4391278 0 100% /media
/dev/sdb1 10475520 42372 10433148 1% /data1
/dev/sdb2 10189076 46268 9602188 1% /data2
[root@localhost data2]# vim etc/fstab
##将sdb2也设置成自动挂载
[root@localhost data2]# mount -a
##挂载所有磁盘
[root@localhost data2]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/rhel-root 17811456 3722300 14089156 21% /
devtmpfs 996932 0 996932 0% /dev
tmpfs 1014056 0 1014056 0% /dev/shm
tmpfs 1014056 10784 1003272 2% /run
tmpfs 1014056 0 1014056 0% /sys/fs/cgroup
/dev/sda1 1038336 168076 870260 17% /boot
tmpfs 202812 4 202808 1% /run/user/42
tmpfs 202812 20 202792 1% /run/user/1000
tmpfs 202812 0 202812 0% /run/user/0
/dev/sr0 4391278 4391278 0 100% /media
/dev/sdb1 10475520 42372 10433148 1% /data1
/dev/sdb2 10189076 46268 9602188 1% /data2
[root@localhost data2]# umount /data2/
##发现已经卸载了
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/rhel-root 17811456 3721948 14089508 21% /
devtmpfs 996932 0 996932 0% /dev
tmpfs 1014056 0 1014056 0% /dev/shm
tmpfs 1014056 10784 1003272 2% /run
tmpfs 1014056 0 1014056 0% /sys/fs/cgroup
/dev/sdb1 10475520 42372 10433148 1% /data1
/dev/sr0 4391278 4391278 0 100% /media
/dev/sda1 1038336 168076 870260 17% /boot
tmpfs 202812 4 202808 1% /run/user/42
tmpfs 202812 28 202784 1% /run/user/1000
tmpfs 202812 0 202812 0% /run/user/0
##现在我们要删除sdb2这个分区,我们首先要卸载,然后再删除自动挂载,前面我们已经卸载了
[root@localhost ~]# vim /etc/fstab
##删除掉dev/sdb2那一行
[root@localhost ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/rhel-root 17811456 3722500 14088956 21% /
devtmpfs 996932 0 996932 0% /dev
tmpfs 1014056 0 1014056 0% /dev/shm
tmpfs 1014056 10860 1003196 2% /run
tmpfs 1014056 0 1014056 0% /sys/fs/cgroup
/dev/sdb1 10475520 42372 10433148 1% /data1
/dev/sr0 4391278 4391278 0 100% /media
/dev/sda1 1038336 168076 870260 17% /boot
tmpfs 202812 4 202808 1% /run/user/42
tmpfs 202812 24 202788 1% /run/user/1000
tmpfs 202812 0 202812 0% /run/user/0
[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.
Command (m for help): m
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
g create a new empty GPT partition table
G create an IRIX (SGI) partition table
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition's system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)
Command (m for help): d
Partition number (1,2, default 2): 2
Partition 2 is deleted
[root@localhost ~]# partprobe
##刷新一下
Warning: Unable to open /dev/sr0 read-write (Read-only file system). /dev/sr0 has been opened read-only.
[root@localhost ~]# cat /proc/partitions
##可以看到sdb2分区已经被删掉
major minor #blocks name
8 0 20971520 sda
8 1 1048576 sda1
8 2 19921920 sda2
8 16 20971520 sdb
8 17 10485760 sdb1
11 0 4391936 sr0
253 0 17821696 dm-0
253 1 2097152 dm-1
##接下来我们可能遇到磁盘空间不够的情况,我们需要对它的空间进行拉伸,怎么拉伸呢?
[root@localhost ~]# df -h /data1/
##看data1下的磁盘容量的使用情况
Filesystem Size Used Avail Use% Mounted on
/dev/sdb1 10G 42M 10G 1% /data1
##对于这种标准分区的硬盘,我们可以直接拉伸吗? 显然是不可以的。
[root@localhost ~]# df -h
##看磁盘容量的使用情况
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/rhel-root 17G 3.6G 14G 21% /
devtmpfs 974M 0 974M 0% /dev
tmpfs 991M 0 991M 0% /dev/shm
tmpfs 991M 11M 980M 2% /run
tmpfs 991M 0 991M 0% /sys/fs/cgroup
/dev/sdb1 10G 42M 10G 1% /data1
/dev/sr0 4.2G 4.2G 0 100% /media
/dev/sda1 1014M 165M 850M 17% /boot
tmpfs 199M 4.0K 199M 1% /run/user/42
tmpfs 199M 28K 199M 1% /run/user/1000
tmpfs 199M 0 199M 0% /run/user/0
##但是我们可以对/dev/mapper/rhel-root根目录下的磁盘进行热拉伸
[root@localhost ~]# vim /etc/fstab
##我们先删除掉sdb1的自动挂载
[root@localhost ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/rhel-root 17811456 3722148 14089308 21% /
devtmpfs 996932 0 996932 0% /dev
tmpfs 1014056 0 1014056 0% /dev/shm
tmpfs 1014056 10852 1003204 2% /run
tmpfs 1014056 0 1014056 0% /sys/fs/cgroup
/dev/sdb1 10475520 42372 10433148 1% /data1
/dev/sr0 4391278 4391278 0 100% /media
/dev/sda1 1038336 168076 870260 17% /boot
tmpfs 202812 4 202808 1% /run/user/42
tmpfs 202812 28 202784 1% /run/user/1000
tmpfs 202812 0 202812 0% /run/user/0
[root@localhost ~]# umount /data1/
##再卸载
[root@localhost ~]# df
##已经完全卸载了
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/rhel-root 17811456 3722148 14089308 21% /
devtmpfs 996932 0 996932 0% /dev
tmpfs 1014056 0 1014056 0% /dev/shm
tmpfs 1014056 10852 1003204 2% /run
tmpfs 1014056 0 1014056 0% /sys/fs/cgroup
/dev/sr0 4391278 4391278 0 100% /media
/dev/sda1 1038336 168076 870260 17% /boot
tmpfs 202812 4 202808 1% /run/user/42
tmpfs 202812 28 202784 1% /run/user/1000
tmpfs 202812 0 202812 0% /run/user/0
[root@localhost ~]# fdisk /dev/sdb
##我们在删除掉sdb1这个分区
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): d
Selected partition 1
Partition 1 is deleted
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@localhost ~]# cat /proc/partitions
##可以看到sdb1分区已经被删除了
major minor #blocks name
8 0 20971520 sda
8 1 1048576 sda1
8 2 19921920 sda2
8 16 20971520 sdb
11 0 4391936 sr0
253 0 17821696 dm-0
253 1 2097152 dm-1
[root@localhost ~]# lvs
##这个是逻辑卷,存在的底层硬盘都是啥
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
root rhel -wi-ao---- <17.00g
swap rhel -wi-ao---- 2.00g
[root@localhost ~]# pvcreate /dev/sdb
##这个是创建sdb磁盘为pvs(物理卷)
WARNING: dos signature detected on /dev/sdb at offset 510. Wipe it? [y/n]: y##以前使用过,有信息,询问是否清空,回应y
Wiping dos signature on /dev/sdb.
Physical volume "/dev/sdb" successfully created.
[root@localhost ~]# pvs
##属于物理卷,可以看到sdb的20个G已经过来了,我们先给sdb打印出物理卷
PV VG Fmt Attr PSize PFree
/dev/sda2 rhel lvm2 a-- <19.00g 0
/dev/sdb lvm2 --- 20.00g 20.00g
[root@localhost ~]# lvs
##逻辑卷,一般是底层的硬盘,可以拉伸的磁盘
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
root rhel -wi-ao---- <17.00g
swap rhel -wi-ao---- 2.00g
[root@localhost ~]# vgs
##这个是卷组,它是将逻辑卷加起来 就是17+2=19g
VG #PV #LV #SN Attr VSize VFree
rhel 1 2 0 wz--n- <19.00g 0
##我们可以利用卷组来将一个root下的磁盘和一个sdb磁盘加起来,然后合并到一个组里面,来达到对根磁盘的扩容,下面是步骤
[root@localhost ~]# vgextend rhel /dev/sdb
##这个命令是将20G的sdb扩展到卷组里完成扩容
[root@localhost ~]# vgs
##可以看到扩展后,我们的卷组已经有了20G的free
VG #PV #LV #SN Attr VSize VFree
rhel 2 2 0 wz--n- <19.00g 20.00g
[root@localhost ~]# lvextend -L +20G /dev/rhel/root
##第一个lvextend是拉伸, -L是扩展多大 后面是扩展到的磁盘
Insufficient free space: 5120 extents needed, but only 5119 available
[root@localhost ~]# lvextend -l 5119 /dev/rhel/root
##上面提示我们只有5119的PE,但是20G是5120的PE,因此我们改用加PE的方式 小l加上5119PE
[root@localhost ~]# lvs
##可以看到我们的rhel已经扩展了
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
root rhel -wi-ao---- 36.99g
swap rhel -wi-ao---- 2.00g
[root@localhost ~]# df -h
##但是在查看挂载信息的容量时候发现没有扩容
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/rhel-root 17G 3.6G 14G 21% /
devtmpfs 974M 0 974M 0% /dev
tmpfs 991M 0 991M 0% /dev/shm
tmpfs 991M 11M 980M 2% /run
tmpfs 991M 0 991M 0% /sys/fs/cgroup
/dev/sdb1 10G 42M 10G 1% /data1
/dev/sr0 4.2G 4.2G 0 100% /media
/dev/sda1 1014M 165M 850M 17% /boot
tmpfs 199M 4.0K 199M 1% /run/user/42
tmpfs 199M 28K 199M 1% /run/user/1000
tmpfs 199M 0 199M 0% /run/user/0
[root@localhost ~]# xfs_growfs /dev/rhel/root
##因此我们将root拉伸到和逻辑卷里面相等的容量,就是这个命令
meta-data=/dev/mapper/rhel-root isize=512 agcount=5, agsize=1113856 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=5241856, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 5241856 to 9697280
[root@localhost ~]# df -h
##可以看到
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/rhel-root 37G 3.6G 34G 10% /
devtmpfs 974M 0 974M 0% /dev
tmpfs 991M 0 991M 0% /dev/shm
tmpfs 991M 11M 980M 2% /run
tmpfs 991M 0 991M 0% /sys/fs/cgroup
/dev/sr0 4.2G 4.2G 0 100% /media
/dev/sda1 1014M 165M 850M 17% /boot
tmpfs 199M 4.0K 199M 1% /run/user/42
tmpfs 199M 24K 199M 1% /run/user/1000
tmpfs 199M 0 199M 0% /run/user/0