1、lsblk命令学习
1、lsblk介绍
用于列出所有可用块设备的信息,而且还能显示他们之间的依赖关系,但是它不会列出RAM盘的信息。块设备有硬盘,闪存盘,cd-ROM等等。lsblk命令包含在util-linux-ng包中,现在该包改名为util-linux。这个包带了几个其它工具,如dmesg。要安装lsblk,请在此处下载util-linux包。Fedora用户可以通过命令sudo yum install -y util-linux-ng来安装该包。
2、选项介绍
-a, --all 显示所有设备。
-b, --bytes 以bytes方式显示设备大小。
-d, --nodeps 不显示 slaves 或 holders。
-D, --discard print discard capabilities。
-e, --exclude <list> 排除设备 (default: RAM disks)。
-f, --fs 显示文件系统信息。
-h, --help 显示帮助信息。
-i, --ascii use ascii characters only。
-m, --perms 显示权限信息。
-l, --list 使用列表格式显示。
-n, --noheadings 不显示标题。
-o, --output <list> 输出列。
-P, --pairs 使用key="value"格式显示。
-r, --raw 使用原始格式显示。
-t, --topology 显示拓扑结构信息。
3、用法
lsblk 选项
4、七个栏目名称解释
NAME :这是块设备名。
MAJ:MIN :本栏显示主要和次要设备号。
RM :本栏显示设备是否可移动设备。注意,在本例中设备sdb和sr0的RM值等于1,这说明他们是可移动设备。
SIZE :本栏列出设备的容量大小信息。例如298.1G表明该设备大小为298.1GB,而1K表明该设备大小为1KB。
RO :该项表明设备是否为只读。在本案例中,所有设备的RO值为0,表明他们不是只读的。
TYPE :本栏显示块设备是否是磁盘或磁盘上的一个分区。在本例中,sda和sdb是磁盘,而sr0是只读存储(rom)。
MOUNTPOINT :本栏指出设备挂载的挂载点。
2、pvcreate命令学习
1、pvcreate介绍
pvcreate 命令用于将物理硬盘分区初始化为物理卷,以便LVM使用。
软件包 lvm2
2、参数介绍
-f #强制创建物理卷,不需要用户确认
-u #指定设备的UUID
-y #所有的问题都回答“yes”
-Z #是否利用前4个扇区
3、对象
物理卷:指定要创建的物理卷对应的设备文件名。
4、用法
pvcreate [参数] 对象
3、mkfs命令学习
1、mkfs介绍
Linux mkfs(英文全拼:make file system)命令用于在特定的分区上建立 linux 文件系统。
2、参数介绍
device : 预备检查的硬盘分区,例如:/dev/sda1
-V : 详细显示模式
-t : 给定档案系统的型式,Linux 的预设值为 ext2
-c : 在制做档案系统前,检查该partition 是否有坏轨
-l bad_blocks_file : 将有坏轨的block资料加到 bad_blocks_file 里面
block : 给定 block 的大小
3、使用方式
mkfs [-V] [-t fstype] [fs-options] filesys [blocks]
4、案例
#在 /dev/hda5 上建一个 msdos 的档案系统,同时检查是否有坏轨存在,并且将过程详细列出来 :
mkfs -V -t msdos -c /dev/hda5
#将sda6分区格式化为ext3格式
mfks -t ext3 /dev/sda6
#这里的文件系统是要指定的,比如 ext3 ;reiserfs ;ext2 ;fat32 ;msdos 等。
4、fdisk命令学习
1、fdisk介绍
Linux fdisk是一个创建和维护分区表的程序,它兼容DOS类型的分区表、BSD或者SUN类型的磁盘列表。
2、必要参数
-l 列出素所有分区表
-u 与"-l"搭配使用,显示分区数目
3、选择参数
-s<分区编号> 指定分区
-v 版本信息
4、菜单操作说明
m :显示菜单和帮助信息
a :活动分区标记/引导分区
d :删除分区
l :显示分区类型
n :新建分区
p :显示分区信息
q :退出不保存
t :设置分区号
v :进行分区检查
w :保存修改
x :扩展应用,高级功能
5、语法
fdisk [必要参数][选择参数]
5、数据迁移方案
1、添加硬盘
[root@centos08 ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 80G 0 disk
├─sda1 8:1 0 200M 0 part /boot
└─sda2 8:2 0 79.8G 0 part
├─centos_centos-root 253:0 0 75.8G 0 lvm /
└─centos_centos-swap 253:1 0 4G 0 lvm [SWAP]
sdb 8:16 0 80G 0 disk
sr0 11:0 1 4.2G 0 rom
#系统默认的硬盘是sba开始
#我们自己添加后就是 sdb sd(b..z) 每个单元代表一个硬盘
2、创建分区
[root@centos08 ~]# fdisk /dev/sdb
欢迎使用 fdisk (util-linux 2.23.2)。
更改将停留在内存中,直到您决定将更改写入磁盘。
使用写入命令前请三思。
Device does not contain a recognized partition table
使用磁盘标识符 0x8ab262d1 创建新的 DOS 磁盘标签。
命令(输入 m 获取帮助):m
命令操作
命令(输入 m 获取帮助):n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p):
Using default response p
分区号 (1-4,默认 1):1
起始 扇区 (2048-167772159,默认为 2048):
将使用默认值 2048
Last 扇区, +扇区 or +size{K,M,G} (2048-167772159,默认为 167772159):+30G
分区 1 已设置为 Linux 类型,大小设为 30 GiB
命令(输入 m 获取帮助):W
The partition table has been altered!
Calling ioctl() to re-read partition table.
正在同步磁盘
3、创建物理卷
[root@centos08 ~]# pvcreate /dev/sdb1
Physical volume "/dev/sdb" successfully created.
4、创建卷组
[root@centos08 ~]# vgcreate vgtest01 /dev/sdb1
Volume group "vgtest01" successfully created
#vgtest01 创建卷组的名称
#/dev/sdb 所使用的物理卷
5、创建逻辑卷
[root@centos08 ~]# lvcreate -L 20G -n lvtest01 vgtest01
Logical volume "lvtest01" created.
#选项解释
#-L 指定逻辑卷的大小 不可超出物理卷的大小
# -n 指定逻辑卷的名字
# vgtest01 指定卷组
6、查看逻辑卷的路径
[root@centos08 ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 80G 0 disk
├─sda1 8:1 0 200M 0 part /boot
└─sda2 8:2 0 79.8G 0 part
├─centos_centos-root 253:0 0 75.8G 0 lvm /
└─centos_centos-swap 253:1 0 4G 0 lvm [SWAP]
sdb 8:16 0 80G 0 disk
└─vgtest01-lvtest01 253:2 0 20G 0 lvm
sr0 11:0 1 4.2G 0 rom
7、制作类型为ext4的文件类型系统(格式化)
root@centos08 ~]# mkfs.ext4 /dev/vgtest01/lvtest01
mke2fs 1.42.9 (28-Dec-2013)
文件系统标签=
OS type: Linux
块大小=4096 (log=2)
分块大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
1310720 inodes, 5242880 blocks
262144 blocks (5.00%) reserved for the super user
第一个数据块=0
Maximum filesystem blocks=2153775104
160 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
Allocating group tables: 完成
正在写入inode表: 完成
Creating journal (32768 blocks): 完成
Writing superblocks and filesystem accounting information: 完成
8、将逻辑卷挂载到系统中
[root@centos08 ~]# vim /etc/fstab
/dev/vgtest01/lvtest01 /mnt ext4 defaults 0 0
#选项解释
#/dev/vgtest01/lvtest01 逻辑卷位置
#/mnt 挂载的位置 挂载点
#ext4 文件系统的类型
#defaults 挂载方式默认 默认挂载
#0 0 不检测不备份
9、测试挂载是否成功
[root@centos08 ~]# mount -a
[root@centos08 ~]# df -Th
文件系统 类型 容量 已用 可用 已用% 挂载点
/dev/mapper/centos_centos-root xfs 76G 3.6G 73G 5% /
devtmpfs devtmpfs 473M 0 473M 0% /dev
tmpfs tmpfs 489M 0 489M 0% /dev/shm
tmpfs tmpfs 489M 7.0M 482M 2% /run
tmpfs tmpfs 489M 0 489M 0% /sys/fs/cgroup
/dev/sda1 xfs 197M 139M 59M 71% /boot
tmpfs tmpfs 98M 0 98M 0% /run/user/0
/dev/mapper/vgtest01-lvtest01 ext4 20G 45M 19G 1% /mnt
#mount -a 就不需要重启服务器 就可以直接看到挂载是否可以
10、创建文件测试
[root@centos08 ~]# touch /mnt/filc001
[root@centos08 ~]# ll /mnt/filc001
-rw-r--r-- 1 root root 0 5月 28 00:05 /mnt/filc001
[root@centos08 ~]# umount /mnt/
[root@centos08 ~]# ll /mnt/filc001
ls: 无法访问/mnt/filc001: 没有那个文件或目录
[root@centos08 ~]# ll /mnt/
总用量 0
[root@centos08 ~]# mount -a
[root@centos08 ~]# ll /mnt/
总用量 16
-rw-r--r-- 1 root root 0 5月 28 00:05 filc001
drwx------ 2 root root 16384 5月 27 23:48 lost+found
11、把/etc/*下的全部文件拷贝到lvtest01中
[root@centos08 ~]# cp -rf /etc/* /mnt/
[root@centos08 ~]# ll /mnt/
[root@centos08 ~]# umount /mnt
总用量 1916
12、修改卷组名称
[root@centos08 ~]# vgrename vgtest01 newvgtest02
Volume group "vgtest01" successfully renamed to "newtest02"
13、修改逻辑卷名称
[root@centos08 ~]# lvrename /dev/newtest02/lvtest01 newlvtest02
Renamed "lvtest01" to "newlvtest02" in volume group "newtest02"
14、设置逻辑卷为非活动状态,及逻辑现在不可用
[root@centos08 ~]# vgchange -a n newvgtest02
0 logical volume(s) in volume group "newvgtest02" now active
[root@centos08 ~]# lvdisplay
#查看状态
LV Status NOT available
15、导出卷组
[root@centos08 ~]# vgexport newvgtest02
Volume group "newvgtest02" successfully exported
16、扫描物理卷
[root@centos08 ~]# pvscan
PV /dev/sda2 VG centos_centos lvm2 [79.80 GiB / 0 free]
PV /dev/sdb is in exported VG newvgtest02 [<80.00 GiB / <60.00 GiB free]
Total: 2 [<159.80 GiB] / in use: 2 [<159.80 GiB] / in no VG: 0 [0 ]
17、关闭服务器(虚拟机)
支持热插拔就可以直接将硬盘放入到另一台服务器上了
1、虚拟机
1、找到所有虚拟磁盘文件
-rw-r--r-- 1 Mis王 197121 264 5月 27 14:47 'CentOS 08.vmxf'
-rw-r--r-- 1 Mis王 197121 11993088 5月 27 16:56 'CentOS 08-s001.vmdk'
-rw-r--r-- 1 Mis王 197121 10551296 5月 27 16:56 'CentOS 08-s002.vmdk'
-rw-r--r-- 1 Mis王 197121 8323072 5月 27 16:56 'CentOS 08-s003.vmdk'
-rw-r--r-- 1 Mis王 197121 2949120 5月 27 16:56 'CentOS 08-s004.vmdk'
-rw-r--r-- 1 Mis王 197121 23396352 5月 27 16:56 'CentOS 08-s005.vmdk'
-rw-r--r-- 1 Mis王 197121 524288 5月 27 15:13 'CentOS 08-s006.vmdk'
-rw-r--r-- 1 Mis王 197121 524288 5月 27 15:13 'CentOS 08-s007.vmdk'
-rw-r--r-- 1 Mis王 197121 524288 5月 27 15:13 'CentOS 08-s008.vmdk'
-rw-r--r-- 1 Mis王 197121 524288 5月 27 15:13 'CentOS 08-s009.vmdk'
-rw-r--r-- 1 Mis王 197121 524288 5月 27 15:13 'CentOS 08-s010.vmdk'
-rw-r--r-- 1 Mis王 197121 524288 5月 27 15:13 'CentOS 08-s011.vmdk'
-rw-r--r-- 1 Mis王 197121 524288 5月 27 15:13 'CentOS 08-s012.vmdk'
-rw-r--r-- 1 Mis王 197121 524288 5月 27 15:13 'CentOS 08-s013.vmdk'
-rw-r--r-- 1 Mis王 197121 524288 5月 27 15:13 'CentOS 08-s014.vmdk'
-rw-r--r-- 1 Mis王 197121 524288 5月 27 15:13 'CentOS 08-s015.vmdk'
-rw-r--r-- 1 Mis王 197121 524288 5月 27 15:13 'CentOS 08-s016.vmdk'
-rw-r--r-- 1 Mis王 197121 524288 5月 27 15:13 'CentOS 08-s017.vmdk'
-rw-r--r-- 1 Mis王 197121 524288 5月 27 15:13 'CentOS 08-s018.vmdk'
-rw-r--r-- 1 Mis王 197121 524288 5月 27 15:13 'CentOS 08-s019.vmdk'
-rw-r--r-- 1 Mis王 197121 524288 5月 27 15:13 'CentOS 08-s020.vmdk'
-rw-r--r-- 1 Mis王 197121 131072 5月 27 15:13 'CentOS 08-s021.vmdk'
2、将这些文件复制到另一个虚拟的目录里
Mis王@DESKTOP-8GP8K20 MINGW64 /e/yun/Ubuntu虚拟机3/Centos7.4/Centos08
$ cp *.vmdk /e/yun/Ubuntu虚拟机3/Centos7.4/Centos07/CentOS 08的虚拟磁盘文件
#在07的虚拟机操作
编辑虚拟机设置-添加-硬盘-SCSI-使用现有的虚拟磁盘-浏览
选择CentOS 08.vmdk 即可
18、验证是否插入成功
[root@centos07 ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 80G 0 disk
├─sda1 8:1 0 200M 0 part /boot
└─sda2 8:2 0 79.8G 0 part
├─centos_centos-root 253:0 0 75.8G 0 lvm /
└─centos_centos-swap 253:1 0 4G 0 lvm [SWAP]
sdb 8:16 0 80G 0 disk
sr0 11:0 1 4.2G 0 rom
6、目标设备操作
1、扫描发现磁盘
[root@centos07 ~]# echo "- - -" > /sys/class/scsi_host//host2/scan
[root@centos07 ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 80G 0 disk
├─sda1 8:1 0 200M 0 part /boot
└─sda2 8:2 0 79.8G 0 part
├─centos_centos-root 253:0 0 75.8G 0 lvm /
└─centos_centos-swap 253:1 0 4G 0 lvm [SWAP]
sdb 8:16 0 80G 0 disk
└─sdb1 8:17 0 30G 0 part
sr0 11:0 1 4.2G 0 rom
2、扫描物理卷,然后导入卷组
[root@centos07 ~]# pvscan
PV /dev/sda2 VG centos_centos lvm2 [79.80 GiB / 0 free]
PV /dev/sdb1 is in exported VG newvgtest02 [<30.00 GiB / <10.00 GiB free]
Total: 2 [<109.80 GiB] / in use: 2 [<109.80 GiB] / in no VG: 0 [0 ]
[root@centos07 ~]# vgimport newvgtest02
Volume group "newvgtest02" successfully imported
[root@centos07 ~]# vgdisplay newvgtest02
--- Volume group ---
VG Name newvgtest02
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 5
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 1
Open LV 0
Max PV 0
Cur PV 1
Act PV 1
VG Size <30.00 GiB
PE Size 4.00 MiB
Total PE 7679
Alloc PE / Size 5120 / 20.00 GiB
Free PE / Size 2559 / <10.00 GiB
VG UUID BsRxub-3NXc-t52x-KHzu-XNp0-x7G1-2mscbL
3、激活逻辑卷
[root@centos07 ~]# vgchange -a y newvgtest02
1 logical volume(s) in volume group "newvgtest02" now active
[root@centos07 ~]# lvdisplay
--- Logical volume ---
LV Path /dev/newvgtest02/lvtest01
LV Name lvtest01
VG Name newvgtest02
LV UUID YN3NBv-slsA-wZdK-j9a9-UNyI-Lcu9-L2KTMH
LV Write Access read/write
LV Creation host, time centos08, 2021-05-28 02:04:04 +0800
LV Status available
# open 0
LV Size 20.00 GiB
Current LE 5120
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:2
4、将逻辑挂载到系统中
[root@centos07 ~]# vim /etc/fstab
/dev/newvgtest02/lvtest01 /mnt ext4 defaults 0 0
[root@centos07 ~]# mount -a
[root@centos07 ~]# df -Th
文件系统 类型 容量 已用 可用 已用% 挂载点
/dev/mapper/centos_centos-root xfs 76G 3.6G 73G 5% /
devtmpfs devtmpfs 473M 0 473M 0% /dev
tmpfs tmpfs 489M 0 489M 0% /dev/shm
tmpfs tmpfs 489M 7.0M 482M 2% /run
tmpfs tmpfs 489M 0 489M 0% /sys/fs/cgroup
/dev/sda1 xfs 197M 139M 59M 71% /boot
tmpfs tmpfs 98M 0 98M 0% /run/user/0
/dev/mapper/newvgtest02-lvtest01 ext4 20G 84M 19G 1% /mnt
Linux磁盘管理与数据迁移:lsblk、pvcreate、mkfs、fdisk实战
8697

被折叠的 条评论
为什么被折叠?



