作业-第05周--课堂-Day22-磁盘管理 -Ⅲ

Day22 课堂笔记

2)parted 命令
案例1:需求:RAID5大小6T,已经装了系统了, 额外添加4块2T盘
现有一个做了RAID5的硬盘,要求分三个区,
硬盘总分区大小: 6.2T
/data0 4.8T
/data1 1T
4G (无需格式化,作DRBD+Hearbeat+MySQL高可用集群)

parted /dev/sdb mklabel gpt                     #<==修改分区格式为gpt。
parted /dev/sdb mkpart primary 0 4800000        #<==创建一个4.8T主分区
parted /dev/sdb mkpart primary 4800001 5800001  #<==创建一个1T主分区
parted /dev/sdb mkpart primary 5800002 5804098  #<==创建一个4G主分区
parted /dev/sdb p

实践如下:

[root@oldboyedu  ~]# parted /dev/sdb
GNU Parted 3.1
Using /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
============================================================
                ********查看的帮助********
============================================================
(parted) help                                                             
  align-check TYPE N                        check partition N for TYPE(min|opt) alignment
  help [COMMAND]                           print general help, or help on COMMAND
  mklabel,mktable LABEL-TYPE               create a new disklabel (partition table)
  mkpart PART-TYPE [FS-TYPE] START END     make a partition
  name NUMBER NAME                         name partition NUMBER as NAME
  print [devices|free|list,all|NUMBER]     display the partition table, available devices, free space, all found
        partitions, or a particular partition
  quit                                     exit program
  rescue START END                         rescue a lost partition near START and END
  
  resizepart NUMBER END                    resize partition NUMBER
  rm NUMBER                                delete partition NUMBER
  select DEVICE                            choose the device to edit
  disk_set FLAG STATE                      change the FLAG on selected device
  disk_toggle [FLAG]                       toggle the state of FLAG on selected device
  set NUMBER FLAG STATE                    change the FLAG on partition NUMBER
  toggle [NUMBER [FLAG]]                   toggle the state of FLAG on partition NUMBER
  unit UNIT                                set the default unit to UNIT
  version                                  display the version number and copyright information of GNU Parted
============================================================
                ********创建gpt格式的分区表********
============================================================
(parted) mklabel gpt
============================================================
                ********查看的结果********
============================================================
(parted) p                                                                
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 537MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 

Number  Start  End  Size  File system  Name  Flags
============================================================
                ********创建第1个主分区********
============================================================
(parted) mkpart primary 0 10                                              
Warning: The resulting partition is not properly aligned for best performance.
Ignore/Cancel? I                       <--> 忽略提示        
============================================================
                ********查看的结果********
============================================================               
(parted) p
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 537MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 

Number  Start   End     Size    File system  Name     Flags
 1      17.4kB  10.0MB  9983kB               primary
============================================================
                ********创建第2个主分区********
============================================================
(parted) mkpart primary 11 20                                           
Warning: The resulting partition is not properly aligned for best performance.
Ignore/Cancel? I      
============================================================
                ********查看的结果********
============================================================                                                    
(parted) p                                                                
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 537MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 

Number  Start   End     Size    File system  Name     Flags
 1      17.4kB  10.0MB  9983kB               primary
 2      11.0MB  20.0MB  9000kB               primary
============================================================
                ********创建第3个主分区********
============================================================
(parted) mkpart primary 21 30
============================================================
                ********查看的结果********
============================================================ 
(parted) p                                                                
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 537MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 

Number  Start   End     Size    File system  Name     Flags
 1      17.4kB  10.0MB  9983kB               primary
 2      11.0MB  20.0MB  9000kB               primary
 3      21.0MB  30.4MB  9437kB               primary
============================================================
                ********创建第4个逻辑分区********
============================================================
(parted) mkpart logic 31 40
============================================================
                ********查看的结果********
============================================================ 

(parted) p                                                                
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 537MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 

Number  Start   End     Size    File system  Name     Flags
 1      17.4kB  10.0MB  9983kB               primary
 2      11.0MB  20.0MB  9000kB               primary
 3      21.0MB  30.4MB  9437kB               primary
 4      31.5MB  39.8MB  8389kB               logic
============================================================
                ********删除第4个逻辑分区********
============================================================
(parted) rm 4                                                             
(parted) p                                                                
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 537MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 

Number  Start   End     Size    File system  Name     Flags
 1      17.4kB  10.0MB  9983kB               primary
 2      11.0MB  20.0MB  9000kB               primary
 3      21.0MB  30.4MB  9437kB               primary
============================================================
                ********保存并退出********
============================================================ 
(parted) q                                                                
Information: You may need to update /etc/fstab.
============================================================
                ********查看的结果********
============================================================ 
[root@oldboyedu  ~]# ll /dev/sdb*
brw-rw---- 1 root disk 8, 16 Mar 31 15:56 /dev/sdb
brw-rw---- 1 root disk 8, 17 Mar 31 15:56 /dev/sdb1
brw-rw---- 1 root disk 8, 18 Mar 31 15:56 /dev/sdb2
brw-rw---- 1 root disk 8, 19 Mar 31 15:56 /dev/sdb3

案例2:需求:刚买的服务器 4块2T 刚买,要做RAID5,装系统怎么搞定?

  • 方法1:Raid里可以支持RAID5后,6T,允许你把6T分成虚拟磁盘。
    200G分成第一个虚拟磁盘剩下不分留着装系统后(parted)。

  • 方法2:装系统过程中有这个功能,系统镜像支持GPT格式分区,很隐蔽。

  • 方法3:引导工具,进入然后用parted分区。

1. 文件系统

1.1、什么是文件系统?
计算机存储和组织数据的方法或者机制。落地是一个软件。

1.2、为什么需要文件系统?
磁盘、物理介质、磁粒子物理元素。 硬件需要软件驱动使用,磁盘需要文件系统驱动。
文件系统实现通过磁盘管理规划、存取数据。

1.3、文件系统有哪些种类?

  • Windows:NTFS、fat32、msdos
  • Linux:ext2、ext3(C5)、ext4(C6)、Xfs(C7)、btrfs

1.4、创建文件系统实践。

1)mkfs 命令

格式化ext4文件系统 mkfs.ext4

[root@oldboyedu ~]# mkfs -t ext4 /dev/sdb1  
==========================================================
      *****其实关键就是生成一定数量的Inode和Block*****
==========================================================
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
25688 inodes, 102400 blocks
5120 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=33685504
13 block groups
8192 blocks per group, 8192 fragments per group
1976 inodes per group
Superblock backups stored on blocks: 
    8193, 24577, 40961, 57345, 73729

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done 

查看mkfs参数(CentOS7man是查不到的,把参数写错即可)

[root@oldboyedu  ~]# mkfs --abc
mkfs.ext2: invalid option -- '-'         <-->显示无效的参数,然后就出来参数了
Usage: mkfs.ext2 [-c|-l filename] [-b block-size] [-C cluster-size]
    [-i bytes-per-inode] [-I inode-size] [-J journal-options]
    [-G flex-group-size] [-N number-of-inodes]
    [-m reserved-blocks-percentage] [-o creator-os]
    [-g blocks-per-group] [-L volume-label] [-M last-mounted-directory]
    [-O feature[,...]] [-r fs-revision] [-E extended-option[,...]]
    [-t fs-type] [-T usage-type ] [-U UUID] [-jnqvDFKSV] device [blocks-count]

指定块大小和inode大小格式

[root@oldboyedu ~]# mkfs -t ext4 -b 4096 -I 512 /dev/sdb3
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
38400 inodes, 38400 blocks
1920 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=39845888
2 block groups
32768 blocks per group, 32768 fragments per group
19200 inodes per group
Superblock backups stored on blocks: 
    32768

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done

[root@oldboyedu ~]# dumpe2fs /dev/sdb3|egrep -i "size"
dumpe2fs 1.42.9 (28-Dec-2013)
Filesystem features:      has_journal ext_attr resize_inode dir_index filetype extent 64bit flex_bg sparse_super large_file huge_file uninit_bg dir_nlink extra_isize
Block size:               4096
Fragment size:            4096
Group descriptor size:    64
Flex block group size:    16
Inode size:               512
Required extra isize:     28
Desired extra isize:      28
Journal size:             16M

2)mount 命令

[root@oldboyedu ~]# mount  /dev/sdb1 /mnt #临时挂载到/mnt
[root@oldboyedu ~]# df -h #查看挂载结果
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda3        19G  1.9G   18G  10% /
devtmpfs        980M  5.0M  975M   1% /dev
tmpfs           991M     0  991M   0% /dev/shm
tmpfs           991M   18M  973M   2% /run
tmpfs           991M     0  991M   0% /sys/fs/cgroup
/dev/sda1       253M  136M  118M  54% /boot
tmpfs           199M     0  199M   0% /run/user/0
tmpfs           199M     0  199M   0% /run/user/1000
/dev/sdb1        93M  1.6M   85M   2% /mnt #<====已挂载。

[root@oldboyedu ~]# cat /proc/mounts  #查看挂载结果
rootfs / rootfs rw 0 0
sysfs /sys sysfs rw,nosuid,nodev,noexec,relatime 0 0
proc /proc proc rw,nosuid,nodev,noexec,relatime 0 0
configfs /sys/kernel/config configfs rw,relatime 0 0
/dev/sda3 / xfs rw,relatime,attr2,inode64,noquota 0 0
systemd-1 /proc/sys/fs/binfmt_misc autofs rw,relatime,fd=32,pgrp=1,timeout=0,minproto=5,maxproto=5,direct,pipe_ino=19277 0 0
hugetlbfs /dev/hugepages hugetlbfs rw,relatime 0 0
debugfs /sys/kernel/debug debugfs rw,relatime 0 0
mqueue /dev/mqueue mqueue rw,relatime 0 0
/dev/sda1 /boot xfs rw,relatime,attr2,inode64,noquota 0 0
tmpfs /run/user/0 tmpfs rw,nosuid,nodev,relatime,size=202812k,mode=700 0 0
tmpfs /run/user/1000 tmpfs rw,nosuid,nodev,relatime,size=202812k,mode=700,uid=1000,gid=1000 0 0
/dev/sdb1 /mnt ext4 rw,relatime,data=ordered 0 0 #<==已挂载。
[root@oldboyedu ~]# touch /mnt/oldboy   #<==测试。
[root@oldboyedu ~]# ls /mnt
lost+found  oldboy

挂载的分区需格式化

[root@oldboyedu ~]# mount /dev/sdb2 /opt  #没有格式化没法挂载
mount: /dev/sdb2 is write-protected, mounting read-only
mount: unknown filesystem type '(null)'
[root@oldboyedu ~]# mkfs.xfs /dev/sdb2  #格式化xfs文件系统
meta-data=/dev/sdb2              isize=512    agcount=4, agsize=6400 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=25600, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal log           bsize=4096   blocks=855, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0

[root@oldboyedu ~]# mount -t xfs /dev/sdb2 /opt
[root@oldboyedu ~]# df -h|grep opt
/dev/sdb2        97M  5.3M   92M   6% /opt
[root@oldboyedu ~]# touch /opt/oldgirl
[root@oldboyedu ~]# ls /opt
oldgirl

如何开机自动挂载?编辑/etc/fstab ,实现开机自动挂载

[root@oldboyedu ~]# cat /etc/fstab 
UUID=3a3a295f-88f8-456d-94dc-1a3eeb517c02 /            xfs     defaults          0            0
UUID=fd2e0ca7-32be-425f-86a2-85c02b9ec5ea /boot        xfs     defaults          0            0
UUID=79a3924b-739e-48dc-ab0c-0444b9ac6591 swap         swap    defaults          0            0
设备                                      挂载点   文件系统类型  默认挂载选项  是否备份  是否开机磁盘检查
/dev/sdb2                                 /opt         xfs     defaults          0      0

2)umount 命令

[root@oldboyedu /mnt]# umount /mnt
umount: /mnt: target is busy.
        (In some cases useful info about processes that use
         the device is found by lsof(8) or fuser(1))
[root@oldboyedu /mnt]# pwd
/mnt
You have new mail in /var/spool/mail/root
[root@oldboyedu /mnt]# umount -lf /mnt     #<==强制卸载
[root@oldboyedu /mnt]# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda3        19G  1.9G   18G  10% /
devtmpfs        980M  5.0M  975M   1% /dev
tmpfs           991M     0  991M   0% /dev/shm
tmpfs           991M   18M  973M   2% /run
tmpfs           991M     0  991M   0% /sys/fs/cgroup
/dev/sda1       253M  136M  118M  54% /boot
tmpfs           199M     0  199M   0% /run/user/0
tmpfs           199M     0  199M   0% /run/user/1000

3)blkid 命令

[root@oldboyedu ~]# blkid
/dev/sdb1: UUID="a45b004f-2322-4dc4-a281-2a212dd2ab79" TYPE="ext4" 
/dev/sdb2: UUID="7daf8142-b641-4b60-a287-4e08dfa18611" TYPE="xfs" 
/dev/sda1: UUID="fd2e0ca7-32be-425f-86a2-85c02b9ec5ea" TYPE="xfs" 
/dev/sda2: UUID="79a3924b-739e-48dc-ab0c-0444b9ac6591" TYPE="swap" 
/dev/sda3: UUID="3a3a295f-88f8-456d-94dc-1a3eeb517c02" TYPE="xfs"

4)fsck命令

  • 正常的磁盘不能操作。
  • 卸载挂载点在操作
  • 只能修复ext文件系统
[root@oldboyedu ~]# fsck -a /dev/sdb1
fsck from util-linux 2.23.2
/dev/sdb1: clean, 12/25688 files, 8896/102400 blocks
[root@oldboyedu ~]# mount /dev/sdb1 /mnt
[root@oldboyedu ~]# fsck -a /dev/sdb1
fsck from util-linux 2.23.2
/dev/sdb1 is mounted.
e2fsck: Cannot continue, aborting.

[root@oldboyedu ~]# e2fsck /dev/sdb1
e2fsck 1.42.9 (28-Dec-2013)
/dev/sdb1: clean, 12/25688 files, 8896/102400 blocks
[root@oldboyedu ~]# fsck -a /dev/sdb1
fsck from util-linux 2.23.2
/dev/sdb1: clean, 12/25688 files, 8896/102400 blocks
[root@oldboyedu ~]# xfs_repair /dev/sdb2
xfs_repair: /dev/sdb2 contains a mounted filesystem
xfs_repair: /dev/sdb2 contains a mounted and writable filesystem

fatal error -- couldn't initialize XFS library
[root@oldboyedu ~]# umount /opt
[root@oldboyedu ~]# xfs_repair /dev/sdb2
Phase 1 - find and verify superblock...
Phase 2 - using internal log
        - zero log...
        - scan filesystem freespace and inode maps...
        - found root inode chunk
Phase 3 - for each AG...
        - scan and clear agi unlinked lists...
        - process known inodes and perform inode discovery...
        - agno = 0
        - agno = 1
        - agno = 2
        - agno = 3
        - process newly discovered inodes...
Phase 4 - check for duplicate blocks...
        - setting up duplicate extent list...
        - check for inodes claiming duplicate blocks...
        - agno = 0
        - agno = 1
        - agno = 2
        - agno = 3
Phase 5 - rebuild AG headers and trees...
        - reset superblock...
Phase 6 - check inode connectivity...
        - resetting contents of realtime bitmap and summary inodes
        - traversing filesystem ...
        - traversal finished ...
        - moving disconnected inodes to lost+found ...
Phase 7 - verify and correct link counts...
done

5)dd 命令

dd if=/dev/sda of=/dev/sdc    bs=512    count=10240
     来源      生成文件系统   block大小  块个数

swap作用,内存不够时候,用来充当内存,一般内存1.5倍。大于8G给8G
将来JAVA服务,内存泄漏
swap就会占用,操作系统性能下降

案例:增加swap分区 100M

============================================================
                    ******查看swap情况*****
============================================================
[root@oldboyedu  ~]# free -m
              total        used        free      shared  buff/cache   available
Mem:            972         135         699           7         137         682
Swap:           767           0         767
============================================================
                    ******创建100M虚拟磁盘*****
============================================================
[root@oldboyedu  ~]# dd if=/dev/zero of=/tmp/100M bs=1M count=100
100+0 records in
100+0 records out
104857600 bytes (105 MB) copied, 4.09005 s, 25.6 MB/s
============================================================
                    ******格式化100M虚拟磁盘*****
============================================================
[root@oldboyedu  ~]# mkswap /tmp/100M 
Setting up swapspace version 1, size = 102396 KiB
no label, UUID=ad35b6b9-dfbe-436f-9322-ac0a2019387e
============================================================
                    ******挂载100M虚拟磁盘*****
============================================================
[root@oldboyedu  ~]# swapon /tmp/100M
swapon: /tmp/100M: insecure permissions 0644, 0600 suggested.
[root@oldboyedu  ~]# free -m
              total        used        free      shared  buff/cache   available
Mem:            972         135         596           7         240         667
Swap:           867           0         867
============================================================
                    ******卸载100M虚拟磁盘*****
============================================================
[root@oldboyedu  ~]# swapoff /tmp/100M
[root@oldboyedu  ~]# free -m
              total        used        free      shared  buff/cache   available
Mem:            972         135         596           7         240         667

查看文件系统内部细节:
1)ext文件系统

[root@oldboyedu ~]# dumpe2fs /dev/sdb1|egrep -i "size"
dumpe2fs 1.42.9 (28-Dec-2013)
Filesystem features:      has_journal ext_attr resize_inode dir_index filetype extent 64bit flex_bg sparse_super huge_file uninit_bg dir_nlink extra_isize
Block size:               1024
Fragment size:            1024
Group descriptor size:    64
Flex block group size:    16
Inode size:           128
Journal size:             4096k

2)xfs文件系统

[root@oldboyedu ~]# xfs_info /dev/sda1
meta-data=/dev/sda1              isize=512    agcount=4, agsize=16384 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=65536, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal               bsize=4096   blocks=855, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 204,793评论 6 478
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 87,567评论 2 381
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 151,342评论 0 338
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,825评论 1 277
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,814评论 5 368
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,680评论 1 281
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 38,033评论 3 399
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,687评论 0 258
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 42,175评论 1 300
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,668评论 2 321
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,775评论 1 332
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,419评论 4 321
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 39,020评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,978评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,206评论 1 260
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 45,092评论 2 351
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,510评论 2 343

推荐阅读更多精彩内容