White growth path 4

Marco education in linux now for a month, has been the basis of the modified file, find, search, delete, copy, replace and change file permissions. Now share with you a recent learning content: Mounting disk partitions, create a file system, device, increasing the swap, and create a logical volume, added, removed, canceled. It is considered an entry in the white of it!

1. Create a partition using:

• fdisk create an MBR partition
• gdisk create GPT partitions
• parted advanced partition operations
to reset the partition table in memory kernel version
• partprobe
listed block device
• lsblk

2. parted operations are with immediate effect, be careful with

Usage: parted [option] ... [equipment [command [argument] ...] ...]

  1. Creating a partition to gpt or msdos partitioning
    $ parted / dev / sdb mklabel gpt | msdos
    query partitioning
    $ prted / dev / sdb print
    set primary partition size
    $ parted / dev / sdb mkpart primary 1 200 ( default M)
    delete the partition, here is the partition number 1
    $ parted / dev / sdb rm 1
    lists partition information
    $ parted -l

3.fdisk mainly MBR partition used for GPT partitioning approach is experimental stage

fdisk -l to view the partition where the Disk label type: dos is the MBR partitioning there is the size of the
White growth path 4
fdisk / dev / sda will enter the interactive mode, m help command to view the sub-
White growth path 4
common sub-command:
the p-partition list
t to change the partition type
n to create a new partition
d delete partition
v verify the partition
w save and exit
q exit without saving
MBR format will set the primary or extended partition, and set the start position and end position to pay attention to
White growth path 4
gdisk and almost all fdisk partition interactive mode no longer introduced

4. Create a file system

  1. linux中现在常见的文件系统就xfs和etx系列
    其中mkfs命令对于两种文件系统创建都支持
    mkfs.xfs或者ext4 /dev/sdb1
    但是ext系列多用mke2fs
    因为mke2fs:ext系列文件系统专用管理工具支持更多选项
    -t {ext2|ext3|ext4} 指定文件系统类型
    -b {1024|2048|4096} 指定块大小
    -L ‘LABEL’ 设置卷标
    -j 相当于 -t ext3
    mkfs.ext3 = mkfs -t ext3 = mke2fs -j = mke2fs -t ext3
    -i # 为数据空间中每多少个字节创建一个inode;不应该小于block大小
    -N # 指定分区中创建多少个inode
    -I 一个inode记录占用的磁盘空间大小,128---4096
    -m # 默认5%,为管理人员预留空间占总空间的百分比
    -O FEATURE[,...] 启用指定特性
    -O ^FEATURE 关闭指定特性
  2. 常发生于死机或者非正常关机之后
    挂载为文件系统标记为“no clean”
    注意:一定不要在挂载状态下修复
    fsck: File System Check
    fsck.FS_TYPE
    fsck -t FS_TYPE
    -p 自动修复错误
    -r 交互式修复错误
    FS_TYPE 一定要与分区上已经文件类型相同
    e2fsck:ext系列文件专用的检测修复工具
    -y 自动回答为yes
    -f 强制修复

5. 创建完文件系统以后就可以挂载了

White growth path 4

注意:挂载点
事先存在,建议使用空目录
进程正在使用中的设备无法被卸载
查看挂载情况
findmnt 挂载点|设备名
查看正在访问指定文件系统的进程
lsof 挂载点
fuser -v 挂载点
终止所有在正访问指定的文件系统的进程
fuser -km 挂载点

6. 文件挂载配置文件

/etc/fstab每行定义一个要挂载的文件系统

  1. 要挂载的设备或伪文件系统
    ① 设备文件
    ②LABEL:LABEL=""
    ③UUID:UUID=""
    ④伪文件系统名称:proc, sysfs
  2. 挂载点
  3. 文件系统类型:ext4,xfs,iso9660,nfs,none
  4. 挂载选项:defaults ,acl,bind
  5. 转储频率:0:不做备份 1:每天转储 2:每隔一天转储
  6. fsck检查的文件系统的顺序:允许的数字是0 1 2
    0:不自检1:首先自检;一般只有rootfs才用2:非rootfs使用
    White growth path 4

7. df 文件系统空间占用等信息的查看工具

df [OPTION]... [FILE]...
-H 以10为单位 于-h相似
-T 文件系统类型
-h human-readable人类易读格式显示
-i inodes instead of blocks inode编号查询
-P 以Posix兼容的格式输出既显示对齐,不再换行显示

8. du 查看某目录总体空间占用状态

du [OPTION]... DIR
-h human-readable
-s summary
--max-depth=# 指定最大目录层级
White growth path 4

9. dd命令用法

White growth path 4

White growth path 4

10. 内存备份

White growth path 4

11. 迁移/home目录到新分区

  1. 先创建一个新分区
    $ fdisk /dev/sdc
  2. 分区创建一个文件系统
    $ mkfs.xfs /dev/sdc1
  3. 挂载在一个空目录
    $ mount /dev/sdc1 /mnt
  4. 复制家目录里所有文件到临时挂载点
    $ cp -a /home/. /mnt
  5. 删除/home文件夹中文件;再挂载到/home文件夹
    $ rm -rf /home/* ;mount /dev/sdc1 /home
  6. 写入配置文件
    $ vim /etc/fstab
  7. 重新扫描并检查挂载情况
    $ mount -a
    注:以上都是先进入维护模式init 1 ,再迁移

12. 增加一个swap分区或者文件

$ disk /dev/sdb 创建一个分区指定文件系统t 82
$ mkswap /dev/sdb1
给sdb1指定swap文件系统
$ vim /etc/fstab
写入配置文件保存
UUID=xxxx swap swap pri=10,defaults 0 0
pri是设定优先级0-32767人为设定 负数是系统默认生成的
$ swapon -a 启用swap重新扫描
$ swapon -s 查看swap使用情况

2.或者用文件生成一个swap设备

$ dd if=/dev/zero of=/swapfile bs=1M count=2048
生成一个大容量文件,或者在系统中找到一个无用的大容量文件
$ mkswap /swapfile
给这个文件指定swap文件系统
$ vim /etc/fstab写入配置文件
#swapfile swap swap defaults 0 0
注意:这里不能写入UUID 只能写路径名
$ swapon -a 启用swap重新扫描
$ swapon -s 查看swap使用情况

13. 实验:创建LV

$ fdisk /dev/sdc创建分区
指定系统id t gpt 31 mbr 8e
$ pvcreate /dev/sd{c1,d}
创建分区和磁盘的物理卷
$ vgcreate vg0 /dev/sd{c1,d}
把磁盘和分区的物理卷命名为vg0
$ lvcreate -n mysql -L 4G vg0
从vg0卷组分出逻辑卷,-n名字为mysql -L指定大小为4G
$ mkfs.xfs /dev/vg0/mysql 写入文件系统
创建相应的文件夹,挂载
$ vim /etc/fstab
写入配置文件
$ mount -a
检查挂载点

14. 实验:扩展LV

1.可以用剩余同卷组PE扩展

$ lvextend -r -L +100M /dev/vg0/binlog 扩展binlog逻辑卷 L是扩展大小 -r是文件系统同步
或者
$ lvextend -L +500M /dev/vg0/binlog 扩展大小
$ resize2fs /dev/vg0/binlog extN 同步ext 系列的文件系统
$ xfs_growfs /mnt/binlog xfs 同步xfs文件系统

2.如果没有剩余卷组的话加一块磁盘

可以直接用一块磁盘作为物理卷
$ pvcreate /dev/sdd
$ vgextend vg0 /dev/sdd 把物理卷/dev/sdd加入vg0 的卷组
$ lvextend -l +100%free /dev/vg0mysql
(-l指定大小PE块或者+100%free剩余)或者-L(直接指定大小 +3G)
再同步文件系统 可以lvextend -r
也可以xfs_growfs /data/mysql 此处跟的是挂载点

15. 逻辑卷磁盘的迁移

1.先检查逻辑卷的卷组是否和要迁入的服务器是否同名,如同名则改名
vgrename vg0 vg1 把vg0改名为vg1
禁用vg1卷组 并用vgdisplay 命令查看禁用情况
vgchange -an vg1 禁用vg1组状态为lv状态为notavailable
vgexport vg1 导出逻辑卷写入文件 生成后缀为vmdk的磁盘
复制磁盘文件到另外的虚拟机 使用现有磁盘找到文件
pvdisplay查看是否有新的物理卷
vgimport vg1
导入vg1卷组
vgchange -ay vg1 激活vg1 卷组
mount挂载新的逻辑卷并写入配置文件

16. 逻辑卷的缩减

$ Umount / data / binlog
unmounted
$ fsck -f / dev / vg0 / binlog file system check
$ resize2fs / dev / vg0 / binlog 10G down to 10G file system is not extended file system number plus
$ mount -a hanging Recovery load

17. Experimental: removal of the disk corresponding PV

First determine the removal device before removing the file system format volume group remaining cases, and removing volume groups
$ the pvmove / dev / sdd
$ the pvmove moved even a space not data
$ vgreduce vg0 / dev / sdd
This is the / dev / sdd from vg0 volume group removing
$ pvremove / dev / sdd sdd delete the physical volume becomes a free disk sdd

18. Experiment: delete logical volumes, volume groups, PV

$ Umount / mnt / vg1-mysql /
unmounted
$ lvremove / dev / vg1 / mysql delete the logical volume
$ vgremove vg1 delete vg1 volume group
$ pvremove / dev / sde sde delete physical volumes restored to the free disk

Guess you like

Origin blog.51cto.com/14322554/2403591