Redhat Linux 7中硬盘操作的示例分析
Redhat Linux 7中硬盘操作的示例分析
在这个例子中,我们将使用Redhat Linux 7的硬盘操作功能来完成一些简单的任务。首先,我们需要使用fdisk命令来检查硬盘的分区表:
[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 / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk label type: dos
Disk identifier: 0x000f8f6b
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 41943039 19948820 8e Linux LVM
接下来,我们使用parted命令来查看硬盘的分区类型:
[root@localhost ~]# parted
GNU Parted 2.3
Using /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) print
Model: VMware Virtual disk (scsi)
Disk /dev/sda: 21.5GB
Sector size (logical/physical): 512B/4096B
Partition Table: msdos
Number Start End Size Type File system Flags
1 1049kB 1075MB 1074MB primary ext4 boot
2 1075MB 21.5GB 20.5GB extended
5 1075MB 21.5GB 20.5GB logical lvm
(parted) quit
Information: You may need to update /etc/fstab.
接下来,我们使用pvcreate命令来创建物理卷:
[root@localhost ~]# pvcreate /dev/sda5
Physical volume "/dev/sda5" successfully created.
接下来,我们使用vgcreate命令来创建卷组:
[root@localhost ~]# vgcreate vg_data /dev/sda5
Volume group "vg_data" successfully created
接下来,我们使用lvcreate命令来创建逻辑卷:
[root@localhost ~]# lvcreate -L 2G -n lv_data vg_data
Logical volume "lv_data" created.
接下来,我们使用mkfs.ext4命令来格式化逻辑卷:
[root@localhost ~]# mkfs.ext4 /dev/vg_data/lv_data
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, 2621440 blocks
131072 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=268 435456
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, 2654208
Allocating group tables: done
Writing inode tables: done
Writing superblocks and filesystem accounting information: done
接下来,我们使用mount命令来挂载逻辑卷:
[root@localhost ~]# mount /dev/vg_data/lv_data /mnt/
接下来,我们使用df命令来检查挂载点:
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/rhel-root 50G 1.4G 47G 3% /
devtmpfs 3.9G 0 3.9G 0% /dev
tmpfs 3.9G 9.3M 3.9G 1% /dev/shm
tmpfs 3.9G 18M 3.9G 1% /run
tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup
/dev/sda1 1014M 134M 881M 14% /boot
tmpfs 783M 0 783M 0% /run/user/0
/dev/mapper/vg_data-lv_data 2.0G 33M 1.9G 2% /mnt
接下来,我们使用umount命令来卸载逻辑卷:
[root@localhost ~]# umount /mnt/
接下来,我们使用lvremove命令来删除逻辑卷:
[root@localhost ~]# lvremove /dev/vg_data/lv_data
Do you really want to remove active logical volume lv_data? [y/n]: y
Logical volume "lv_data" successfully removed
接下来,我们使用vgremove命令来删除卷组:
[root@localhost ~]# vgremove vg_data
Volume group "vg_data" successfully removed
接下来,我们使用pvremove命令来删除物理卷:
[root@localhost ~]# pvremove /dev/sda5
Labels on physical volume "/dev/sda5" successfully wiped.
相关文章