暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

磁盘分区实战(parted)

蜜蜂点滴 2020-03-04
1608

一、先删除fdisk模拟分区的四个盘

[root@qiqi~]#fdisk /dev/sdb

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to

         switch off the mode (command 'c') and change display units to

         sectors (command 'u').

Command (m for help): d #<--删除分区

Partition number (1-5): #<--删除编号为1的分区

Command (m for help): d

Partition number (1-5): 2

Command (m for help): p

Disk /dev/sdb: 1073 MB, 1073741824 bytes

255 heads, 63 sectors/track, 130 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0x3f0ec866

   Device Boot      Start         End      Blocks   Id  System

/dev/sdb3              61          80      160650    5  Extended

/dev/sdb4               1          20      160618+  83  Linux

Partition table entries are not in disk order

Command (m for help): d

Partition number (1-5): 3

Command (m for help): d

Selected partition 4 #<--3为扩展分区已删除,4也随之删除。

Command (m for help): 4

4: unknown command

Command (m for help): w #<--保存修改

The partition table has been altered!

Calling ioctl() to re-read partition table.

Syncing disks.

二、知识简介

1、磁盘大于2T使用parted 创建分区,当一个分区大小超过2T时, 不能再使用MBR引导记录, 使用GPT来识别大容量磁盘,命令行输入:

#parted /dev/sdd   #<--交互式开始分区

2、分区方法:

mklabel(创建分区表 MRB-msdos/gpt)#<--修改分区格式gpt             create a new disklabel (partition table)    mklabel gpt

②mkpart (创建新的分区) make a partition                            

  mkpart primary 0 20M #<--创建第一个主分区

print(显示分区表信息)

   display the partition table

rm(删除指定分区信息)

         delete partition NUMBER

    quit(退出分区界面)

    exit program

3、

①(parted) mklabel gpt   #<--修改分区引导记录信息                                       Warning: Partition(s) on /dev/sdd are being used.

 Ignore/Cancel? Ignore 

②(parted) mkpart primary 0 200M #<--输入分区大小 创建分区信息

删除分区方法(parted)rm  分区号码

③在格式化前需要执行以下命令

 #partprobe  /dev/sdb (你分区的全路径名称)    #<--- 告知内核系统已经对磁盘进行了分区

文件系统有什么: 采用相应机制存储和管理数据

centos5: ext2 ext3 

        centos6: ext4

centos7: xfs    

特点: 在数据库服务器中可以更高效存储数据信息

  在格式化磁盘时, 效率更高(大的磁盘)

  nfs 网络文件系统  分布式文件系统

  

做格式化处理:

#mkfs.ext4 /dev/sdb1#<--格式化ext4文件系统 mkfs.ext4其实关键就是生成一定数量的Inode和Block。

mkfs.xfs  /dev/sdb1     --- 无法识别小分区信息(10M以下)

#mkfs -t xfs /dev/sdb1 


④进行磁盘挂载

    #mount /dev/sdb1 /mnt  临时挂载重启失效


如何实现自动挂载分区(/dev/sdc1  /mnt_100M)

    mount /dev/sdc1 /mnt_100M

方法一: 将挂载命令放入到/etc/rc.local文件中

#vim /etc/rc.local

输入:mount /dev/sdc1 /mnt_100M

说明:没有格式化没法挂载

cat /proc/mounts  #查看挂载结果

umount -lf /mnt     #<==强制卸载

df -h #查看挂载结果

说明: 需要确保rc.local目录具有执行权限

# ll -d /etc/rc.local 

    lrwxrwxrwx. 1 root root 13 Dec 29 16:33 /etc/rc.local -> rc.d/rc.local

# ll -d /etc/rc.d/rc.local 

    -rwxr-xr-x. 1 root root 499 Jan 29 11:33 /etc/rc.d/rc.local

方法二: 利用fstab文件实现分区自动挂载

vim /etc/fstab

设备文件    挂载点目录  文件系统类型   挂载的参数信息    是否进行备份    是否检查磁盘

/dev/sdc1   /mnt_100M   xfs            defaults           0              0


三、企业案例: 

tomcat(网站服务)--java语言编写的程序, 运行过程中比较消耗内存

临时需要添加内存 --- 将硬盘空间临时充当内存使用  -- swap分区

如何调正swap分区大小

从磁盘中取出一定空间重当内存使用

命令行输入:

#dd if=/dev/zero of=/tmp/1G  bs=100M  count=10  

    10+0 records in

    10+0 records out

    1048576000 bytes (1.0 GB) copied, 25.9294 s, 40.4 MB/s

root@qiqi~]# 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"


mount -a 可以将fstab里的信息挂载。


放入/etc/rc.local 实现自动挂载 但不推荐。

/sbin/mount -t xfs /dev/sdb2 /opt


查看文件系统内部细节:

[root@qiqi~]# dumpe2fs /dev/sdb1 #查看ext文件系统内部细节

[root@qiqi~]# 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




指定块大小和inode大小格式:

[root@qiqi~]# 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@qiqi~]# 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


文件删除原理:

no space left on device. 磁盘容量不足

swap作用,内存不够时候,用来充当内存,一般内存1.5倍。大于8G给8G

将来JAVA服务,内存泄漏。。。

swap就会占用。。。操作系统性能下降


[root@qiqi~]# free -m

              total        used        free      shared  buff/cache   available

Mem:           1980         143        1689           9         146        1671

Swap:           767           0         767


增加swap分区 100M

[root@qiqi~]# 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 (3 primary, 0 extended, 1 free)

   e   extended

Select (default e): p

Selected partition 4

First sector (718848-2097151, default 718848): 

Using default value 718848

Last sector, +sectors or +size{K,M,G} (718848-2097151, default 2097151): +150M

Partition 4 of type Linux and of size 150 MiB is set


Command (m for help): p


Disk /dev/sdb: 1073 MB, 1073741824 bytes, 2097152 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: 0x000006b6


   Device Boot      Start         End      Blocks   Id  System

/dev/sdb1            2048      206847      102400   83  Linux

/dev/sdb2          206848      411647      102400   83  Linux

/dev/sdb3          411648      718847      153600   83  Linux

/dev/sdb4          718848     1026047      153600   83  Linux


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@qiqi~]# partprobe /dev/sdb

[root@qiqi~]# mkswap /dev/sdb4

Setting up swapspace version 1, size = 153596 KiB

no label, UUID=2d1ac352-4cc0-4727-8318-5526a3c309c2

[root@qiqi~]# swapon -a /dev/sdb4

You have new mail in /var/spool/mail/root

[root@qiqi~]# free -m

              total        used        free      shared  buff/cache   available

Mem:           1980         144        1673          19         162        1658

Swap:           917           0         917

四、fsck 磁盘检查和修复

1、正常的磁盘不能操作。

2、卸载挂载点在操作

[root@qiqi~]# fsck

fsck         fsck.btrfs   fsck.cramfs  fsck.ext2    fsck.ext3    fsck.ext4    fsck.minix   fsck.xfs     


[root@qiqi~]# fsck -a /dev/sdb1

fsck from util-linux 2.23.2

/dev/sdb1: clean, 12/25688 files, 8896/102400 blocks

[root@qiqi~]# mount /dev/sdb1 /mnt

[root@qiqi~]# fsck -a /dev/sdb1

fsck from util-linux 2.23.2

/dev/sdb1 is mounted.

e2fsck: Cannot continue, aborting.

[root@qiqi~]# e2fsck /dev/sdb1

e2fsck 1.42.9 (28-Dec-2013)

/dev/sdb1: clean, 12/25688 files, 8896/102400 blocks

[root@qiqi~]# fsck -a /dev/sdb1

fsck from util-linux 2.23.2

/dev/sdb1: clean, 12/25688 files, 8896/102400 blocks


[root@qiqi~]# 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@qiqi~]# umount /opt

[root@qiqi~]# 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



文章转载自蜜蜂点滴,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论