linux 基础 管理系统存储

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了linux 基础 管理系统存储相关的知识,希望对你有一定的参考价值。

######管理系统存储######

 

####1.分区划分####

 

 

 

Command action

   a   toggle a bootable flag

   b   edit bsd disklabel

   c   toggle the dos compatibility flag

   d   delete a partition                                ####删除分区

   g   create a new empty GPT partition table

   G   create an IRIX (SGI) partition table

   l   list known partition types

   m   print this menu

   n   add a new partition                                ####增加一个新的分区

   o   create a new empty DOS partition table

   p   print the partition table

   q   quit without saving changes                        ####退出不保存

   s   create a new empty Sun disklabel

   t   change a partition‘s system id                    ####修改分区功能id

   u   change display/entry units

   v   verify the partition table

   w   write table to disk and exit                      ####保存更改到分区列表

   x   extra functionality (experts only)

 

 

[[email protected] ~]# fdisk -l                            ###显示系统中所有可以使用的设备

 

Disk /dev/vda: 10.7 GB, 10737418240 bytes, 20971520 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: 0x00013f3e

 

   Device Boot      Start         End      Blocks   Id  System

/dev/vda1   *        2048    20970332    10484142+  83  Linux

 

Disk /dev/vdb: 10.7 GB, 10737418240 bytes, 20971520 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

 

 

[[email protected] ~]# fdisk /dev/vdb                                ######分区

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.

 

Device does not contain a recognized partition table

Building a new DOS disklabel with disk identifier 0x0374426c.

 

Command (m for help): n                                            ####增加一个新的分区

Partition type:

   p   primary (0 primary, 0 extended, 4 free)

   e   extended

Select (default p):

Using default response p                                            ###p为主分区

Partition number (1-4, default 1):                                  ####默认主分区id

First sector (2048-20971519, default 2048):                         ####此分区的起始位置

Using default value 2048

Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519): +100M  ####分区大小

Partition 1 of type Linux and of size 100 MiB is set

 

Command (m for help): n

Partition type:

   p   primary (1 primary, 0 extended, 3 free)

   e   extended

Select (default p):

Using default response p

Partition number (2-4, default 2):

First sector (206848-20971519, default 206848):

Using default value 206848

Last sector, +sectors or +size{K,M,G} (206848-20971519, default 20971519): +100M

Partition 2 of type Linux and of size 100 MiB is set

 

Command (m for help): n

Partition type:

   p   primary (2 primary, 0 extended, 2 free)

   e   extended

Select (default p):

Using default response p

Partition number (3,4, default 3):

First sector (411648-20971519, default 411648):

Using default value 411648

Last sector, +sectors or +size{K,M,G} (411648-20971519, default 20971519): +100M

Partition 3 of type Linux and of size 100 MiB is set

 

Command (m for help): n

Partition type:

   p   primary (3 primary, 0 extended, 1 free)

   e   extended

Select (default e):

Using default response e                                        ###e为拓展分区(最多分四个分区第四个为拓展分区,要给他剩下的全部空间,拓展分区里面可以继续分,为逻辑分区)

Selected partition 4

First sector (616448-20971519, default 616448):

Using default value 616448

Last sector, +sectors or +size{K,M,G} (616448-20971519, default 20971519):

Using default value 20971519

Partition 4 of type Extended and of size 9.7 GiB is set

 

Command (m for help): n

All primary partitions are in use

Adding logical partition 5

First sector (618496-20971519, default 618496):

Using default value 618496

Last sector, +sectors or +size{K,M,G} (618496-20971519, default 20971519): +100M

Partition 5 of type Linux and of size 100 MiB is set

 

Command (m for help): p                                ###显示分区情况

 

Disk /dev/vdb: 10.7 GB, 10737418240 bytes, 20971520 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: 0x0374426c

 

   Device Boot      Start         End      Blocks   Id  System

/dev/vdb1            2048      206847      102400   83  Linux

/dev/vdb2          206848      411647      102400   83  Linux

/dev/vdb3          411648      616447      102400   83  Linux

/dev/vdb4          616448    20971519    10177536    5  Extended

/dev/vdb5          618496      823295      102400   83  Linux

 

Command (m for help): wq                                             ####保存退出

The partition table has been altered!

 

Calling ioctl() to re-read partition table.

Syncing disks.

[ro[email protected] ~]# partprobe                                     ####同步分区列表

Warning: Unable to open /dev/sr0 read-write (Read-only file system).  /dev/sr0 has been opened read-only.

Warning: Unable to open /dev/sr0 read-write (Read-only file system).  /dev/sr0 has been opened read-only.

Warning: Unable to open /dev/sr0 read-write (Read-only file system).  /dev/sr0 has been opened read-only.

 

[[email protected] ~]# cat /proc/partitions                         ####查看磁盘分区

major minor  #blocks  name

 

 253        0   10485760 vda

 253        1   10484142 vda1

 253       16   10485760 vdb

 253       17     102400 vdb1

 253       18     102400 vdb2

 253       19     102400 vdb3

 253       20          1 vdb4

 253       21     101376 vdb5

  11        0    3799040 sr0

 

######挂载#####

[[email protected] ~]# mount /dev/vdb5 /mnt/

mount: /dev/vdb5 is write-protected, mounting read-only

mount: unknown filesystem type ‘(null)‘

[[email protected] ~]# mkfs.xfs /dev/vdb5                ####格式化(安装.xfs文件)

meta-data=/dev/vdb5              isize=256    agcount=4, agsize=6336 blks

         =                       sectsz=512   attr=2, projid32bit=1

         =                       crc=0

data     =                       bsize=4096   blocks=25344, imaxpct=25

         =                       sunit=0      swidth=0 blks

naming   =version 2              bsize=4096   ascii-ci=0 ftype=0

log      =internal log           bsize=4096   blocks=853, version=2

         =                       sectsz=512   sunit=0 blks, lazy-count=1

realtime =none                   extsz=4096   blocks=0, rtextents=0

[[email protected] ~]# mount /dev/vdb5 /mnt/            ###临时挂载

[[email protected] ~]# df

Filesystem     1K-blocks    Used Available Use% Mounted on

/dev/vda1       10473900 3813008   6660892  37% /

devtmpfs          927072       0    927072   0% /dev

tmpfs             942660      80    942580   1% /dev/shm

tmpfs             942660   17024    925636   2% /run

tmpfs             942660       0    942660   0% /sys/fs/cgroup

/dev/vdb5          97964    5228     92736   6% /mnt

[[email protected] ~]# mount

proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)

sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime,seclabel)

devtmpfs on /dev type devtmpfs (rw,nosuid,seclabel,size=927072k,nr_inodes=231768,mode=755)

securityfs on /sys/kernel/security type securityfs (rw,nosuid,nodev,noexec,relatime)

tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev,seclabel)

devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,seclabel,gid=5,mode=620,ptmxmode=000)

tmpfs on /run type tmpfs (rw,nosuid,nodev,seclabel,mode=755)

tmpfs on /sys/fs/cgroup type tmpfs (rw,nosuid,nodev,noexec,seclabel,mode=755)

cgroup on /sys/fs/cgroup/systemd type cgroup (rw,nosuid,nodev,noexec,relatime,xattr,release_agent=/usr/lib/systemd/systemd-cgroups-agent,name=systemd)

pstore on /sys/fs/pstore type pstore (rw,nosuid,nodev,noexec,relatime)

cgroup on /sys/fs/cgroup/cpuset type cgroup (rw,nosuid,nodev,noexec,relatime,cpuset)

cgroup on /sys/fs/cgroup/cpu,cpuacct type cgroup (rw,nosuid,nodev,noexec,relatime,cpuacct,cpu)

cgroup on /sys/fs/cgroup/memory type cgroup (rw,nosuid,nodev,noexec,relatime,memory)

cgroup on /sys/fs/cgroup/devices type cgroup (rw,nosuid,nodev,noexec,relatime,devices)

cgroup on /sys/fs/cgroup/freezer type cgroup (rw,nosuid,nodev,noexec,relatime,freezer)

cgroup on /sys/fs/cgroup/net_cls type cgroup (rw,nosuid,nodev,noexec,relatime,net_cls)

cgroup on /sys/fs/cgroup/blkio type cgroup (rw,nosuid,nodev,noexec,relatime,blkio)

cgroup on /sys/fs/cgroup/perf_event type cgroup (rw,nosuid,nodev,noexec,relatime,perf_event)

cgroup on /sys/fs/cgroup/hugetlb type cgroup (rw,nosuid,nodev,noexec,relatime,hugetlb)

configfs on /sys/kernel/config type configfs (rw,relatime)

/dev/vda1 on / type xfs (rw,relatime,seclabel,attr2,inode64,noquota)

rpc_pipefs on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw,relatime)

selinuxfs on /sys/fs/selinux type selinuxfs (rw,relatime)

systemd-1 on /proc/sys/fs/binfmt_misc type autofs (rw,relatime,fd=29,pgrp=1,timeout=300,minproto=5,maxproto=5,direct)

mqueue on /dev/mqueue type mqueue (rw,relatime,seclabel)

hugetlbfs on /dev/hugepages type hugetlbfs (rw,relatime,seclabel)

debugfs on /sys/kernel/debug type debugfs (rw,relatime)

sunrpc on /proc/fs/nfsd type nfsd (rw,relatime)

/dev/vdb5 on /mnt type xfs (rw,relatime,seclabel,attr2,inode64,noquota)

[[email protected] ~]# vim /etc/fstab                ##永久挂载(0 0 :不备份不检测)

 

/dev/vdb5  /mnt/  xfs defaults  0  0

 

[[email protected] ~]# df

Filesystem     1K-blocks    Used Available Use% Mounted on

/dev/vda1       10473900 3812972   6660928  37% /

devtmpfs          927072       0    927072   0% /dev

tmpfs             942660      80    942580   1% /dev/shm

tmpfs             942660   17024    925636   2% /run

tmpfs             942660       0    942660   0% /sys/fs/cgroup

/dev/vdb5          97964    5228     92736   6% /mnt

[[email protected] ~]# umount /mnt/

[[email protected] ~]# df

Filesystem     1K-blocks    Used Available Use% Mounted on

/dev/vda1       10473900 3812952   6660948  37% /

devtmpfs          927072       0    927072   0% /dev

tmpfs             942660      80    942580   1% /dev/shm

tmpfs             942660   17024    925636   2% /run

tmpfs             942660       0    942660   0% /sys/fs/cgroup

[[email protected] ~]# mount -a                         #####读取/etc/fstab

[[email protected] ~]# df

Filesystem     1K-blocks    Used Available Use% Mounted on

/dev/vda1       10473900 3812952   6660948  37% /

devtmpfs          927072       0    927072   0% /dev

tmpfs             942660      80    942580   1% /dev/shm

tmpfs             942660   17024    925636   2% /run

tmpfs             942660       0    942660   0% /sys/fs/cgroup

/dev/vdb5          97964    5228     92736   6% /mnt

[[email protected] ~]# blkid                            ###显示系统正在使用设备id

/dev/vda1: UUID="9bf6b9f7-92ad-441b-848e-0257cbb883d1" TYPE="xfs"

/dev/vdb5: UUID="f8173528-d977-436b-b08c-cc66cdb8d60f" TYPE="xfs"

/dev/sr0: UUID="2015-02-19-11-11-02-00" LABEL="RHEL-7.1 Server.x86_64" TYPE="iso9660" PTTYPE="dos"

 

 

 

###########2.swap######

 

[[email protected] ~]# fdisk /dev/vdb                    ####设备分区

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

All primary partitions are in use

Adding logical partition 6

First sector (825344-20971519, default 825344):

Using default value 825344

Last sector, +sectors or +size{K,M,G} (825344-20971519, default 20971519): +1000M

Partition 6 of type Linux and of size 1000 MiB is set

 

Command (m for help): p

 

Disk /dev/vdb: 10.7 GB, 10737418240 bytes, 20971520 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: 0x0374426c

 

   Device Boot      Start         End      Blocks   Id  System

/dev/vdb1            2048      206847      102400   83  Linux

/dev/vdb2          206848      411647      102400   83  Linux

/dev/vdb3          411648      616447      102400   83  Linux

/dev/vdb4          616448    20971519    10177536    5  Extended

/dev/vdb5          618496      823295      102400   83  Linux

/dev/vdb6          825344     2873343     1024000   83  Linux

 

Command (m for help): t                        ####修改分区功能id

Partition number (1-6, default 6): 6

Hex code (type L to list all codes): l

 

 0  Empty           24  NEC DOS         81  Minix / old Lin bf  Solaris        

 1  FAT12           27  Hidden NTFS Win 82  Linux swap / So c1  DRDOS/sec (FAT-

 2  XENIX root      39  Plan 9          83  Linux           c4  DRDOS/sec (FAT-

 3  XENIX usr       3c  PartitionMagic  84  OS/2 hidden C:  c6  DRDOS/sec (FAT-

 4  FAT16 <32M      40  Venix 80286     85  Linux extended  c7  Syrinx         

 5  Extended        41  PPC PReP Boot   86  NTFS volume set da  Non-FS data    

 6  FAT16           42  SFS             87  NTFS volume set db  CP/M / CTOS / .

 7  HPFS/NTFS/exFAT 4d  QNX4.x          88  Linux plaintext de  Dell Utility   

 8  AIX             4e  QNX4.x 2nd part 8e  Linux LVM       df  BootIt         

 9  AIX bootable    4f  QNX4.x 3rd part 93  Amoeba          e1  DOS access     

 a  OS/2 Boot Manag 50  OnTrack DM      94  Amoeba BBT      e3  DOS R/O        

 b  W95 FAT32       51  OnTrack DM6 Aux 9f  BSD/OS          e4  SpeedStor      

 c  W95 FAT32 (LBA) 52  CP/M            a0  IBM Thinkpad hi eb  BeOS fs        

 e  W95 FAT16 (LBA) 53  OnTrack DM6 Aux a5  FreeBSD         ee  GPT            

 f  W95 Ext‘d (LBA) 54  OnTrackDM6      a6  OpenBSD         ef  EFI (FAT-12/16/

10  OPUS            55  EZ-Drive        a7  NeXTSTEP        f0  Linux/PA-RISC b

11  Hidden FAT12    56  Golden Bow      a8  Darwin UFS      f1  SpeedStor      

12  Compaq diagnost 5c  Priam Edisk     a9  NetBSD          f4  SpeedStor      

14  Hidden FAT16 <3 61  SpeedStor       ab  Darwin boot     f2  DOS secondary  

16  Hidden FAT16    63  GNU HURD or Sys af  HFS / HFS+      fb  VMware VMFS    

17  Hidden HPFS/NTF 64  Novell Netware  b7  BSDI fs         fc  VMware VMKCORE

18  AST SmartSleep  65  Novell Netware  b8  BSDI swap       fd  Linux raid auto

1b  Hidden W95 FAT3 70  DiskSecure Mult bb  Boot Wizard hid fe  LANstep        

1c  Hidden W95 FAT3 75  PC/IX           be  Solaris boot    ff  BBT            

1e  Hidden W95 FAT1 80  Old Minix      

Hex code (type L to list all codes): 82

Changed type of partition ‘Linux‘ to ‘Linux swap / Solaris‘

 

Command (m for help): p

 

Disk /dev/vdb: 10.7 GB, 10737418240 bytes, 20971520 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: 0x0374426c

 

   Device Boot      Start         End      Blocks   Id  System

/dev/vdb1            2048      206847      102400   83  Linux

/dev/vdb2          206848      411647      102400   83  Linux

/dev/vdb3          411648      616447      102400   83  Linux

/dev/vdb4          616448    20971519    10177536    5  Extended

/dev/vdb5          618496      823295      102400   83  Linux

/dev/vdb6          825344     2873343     1024000   82  Linux swap / Solaris

 

Command (m for help): wq

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.

[[email protected] ~]# partprobe

Warning: Unable to open /dev/sr0 read-write (Read-only file system).  /dev/sr0 has been opened read-only.

Warning: Unable to open /dev/sr0 read-write (Read-only file system).  /dev/sr0 has been opened read-only.

Warning: Unable to open /dev/sr0 read-write (Read-only file system).  /dev/sr0 has been opened read-only.

 

[[email protected] ~]# mkswap /dev/vdb6                    #####命令格式化分区为swap格式

Setting up swapspace version 1, size = 1023996 KiB

no label, UUID=b62379d4-c43f-432b-be9f-d335c57b0434

[[email protected] ~]# swapon -s                           ####

[[email protected] ~]# swapon -a /dev/vdb6                ####enable all swaps from /etc/fstab

 

[[email protected] ~]# swapon -s

FilenameTypeSizeUsedPriority

/dev/vdb6                              partition10239960-1

[[email protected] ~]# vim /etc/fstab

[[email protected] ~]# swapoff /dev/vdb6                    ##disable all swaps from /dev/vdb6

设备

/dev/vdb6  swap swap defaults  0    0

 

[[email protected] ~]# swapon -s

[[email protected] ~]# swapon -a

[[email protected] ~]# swapon -s

FilenameTypeSizeUsedPriority

/dev/vdb6                              partition10239960-1

 

 

 

 

 

 

 #########3.磁盘加密#########

 1.磁盘加密

 

[[email protected] mapper]# cryptsetup luksFormat /dev/vdb5           ####对/dev/vdb5进行加密

    

WARNING!

========

This will overwrite data on /dev/vdb5 irrevocably.

 

Are you sure? (Type uppercase yes): YES                            ####(要用大写)

Enter passphrase:

Verify passphrase:

[[email protected] mapper]# mount /dev/vdb5 /mnt/                    ####挂载/dev/vdb5 到/mnt/

mount: unknown filesystem type ‘crypto_LUKS‘                     ###显示磁盘已经加密

[[email protected] mapper]# cryptsetup open /dev/vdb5 westos        ####开锁(westos:给定一个文件名称,这个文件会出现在/dev/mapper/下面,)

Enter passphrase for /dev/vdb5: ####输入密码

[[email protected] mapper]# ll /dev/mapper/

total 0

crw-------. 1 root root 10, 236 Nov 18 20:03 control

lrwxrwxrwx. 1 root root       7 Nov 18 21:37 westos -> ../dm-0

[[email protected] mapper]# mount /dev/mapper/westos  /mnt/        ####挂载

mount: /dev/mapper/westos is write-protected, mounting read-only

mount: unknown filesystem type ‘(null)‘

[[email protected] mapper]# mkfs.xfs /dev/mapper/westos             ####格式化(注意:挂载前要对其进行格式化处理)

meta-data=/dev/mapper/westos     isize=256    agcount=4, agsize=6272 blks

         =                       sectsz=512   attr=2, projid32bit=1

         =                       crc=0

data     =                       bsize=4096   blocks=25088, imaxpct=25

         =                       sunit=0      swidth=0 blks

naming   =version 2              bsize=4096   ascii-ci=0 ftype=0

log      =internal log           bsize=4096   blocks=853, version=2

         =                       sectsz=512   sunit=0 blks, lazy-count=1

realtime =none                   extsz=4096   blocks=0, rtextents=0

[[email protected] mapper]# mount /dev/mapper/westos  /mnt/

[[email protected] mapper]# cd /mnt

[[email protected] mnt]# ls

[[email protected] mnt]# touch file{1..5}

[[email protected] mnt]# ls

file1  file2  file3  file4  file5

[[email protected] mnt]# cd

[[email protected] ~]# umount /mnt/

[[email protected] mnt]# ls

[[email protected] mnt]# cryptsetup close westos                            ####关闭westos

[[email protected] mnt]# ll /dev/mapper/

total 0

crw-------. 1 root root 10, 236 Nov 18 20:03 control

[[email protected] mnt]# mount /dev/mapper/westos /mnt/

mount: special device /dev/mapper/westos does not exist

 

 

 

 

2.加密磁盘的永久挂载

 

[[email protected] mapper]# vim /etc/crypttab

 

解密后设备管理文件    设备    加密字符存放文件

westos             /dev/vdb5  /root/lukspsfile

 

[[email protected] mapper]# vim /root/lukspsfile

 

输入设定密码

 

[[email protected] mapper]# chmod 600 /root/lukspsfile

 

[[email protected] mapper]# vim /etc/fstab                 #####关机重启后自动执行

 

/dev/mapper/westos /mnt/ xfs   defaults  0  0

 

[[email protected] mapper]# cryptsetup luksAddKey /dev/vdb2 /root/luksfile

Enter any passphrase:                                   ####输入设定好的密码

 

 

[[email protected] mnt]# reboot                            ###关机重启,开机后自动挂载

 

 

[[email protected] ~]# df

Filesystem         1K-blocks    Used Available Use% Mounted on

/dev/vda1           10473900 3219328   7254572  31% /

devtmpfs              927072       0    927072   0% /dev

tmpfs                 942660      84    942576   1% /dev/shm

tmpfs                 942660   17080    925580   2% /run

tmpfs                 942660       0    942660   0% /sys/fs/cgroup

/dev/mapper/westos     96940    5176     91764   6% /mnt

/dev/sr0             3798292 3798292         0 100% /run/media/root/RHEL-7.1 Server.x86_64

 

 

3.加密清楚

 

[[email protected] ~]# vim /etc/fstab

 

删除/dev/mapper/westos /mnt/ xfs   defaults  0  0

 

[[email protected] ~]# vim /etc/crypttab

删除解密后设备管理文件    设备    加密字符存放文件

     westos             /dev/vdb5  /root/lukspsfile

 

[[email protected] ~]# rm -fr /root/lukspsfile                ####删除加密字符存放文件

[[email protected] ~]# umount /mnt/

[[email protected] ~]# cryptsetup close westos

[[email protected] ~]# mkfs.xfs /dev/vdb5                    ###格式化/dev/vdb5

mkfs.xfs: /dev/vdb5 appears to contain an existing filesystem (crypto_LUKS).

mkfs.xfs: Use the -f option to force overwrite.

[[email protected] ~]# mkfs.xfs /dev/vdb5 -f                ###强制格式化

meta-data=/dev/vdb5              isize=256    agcount=4, agsize=6400 blks

         =                       sectsz=512   attr=2, projid32bit=1

         =                       crc=0

data     =                       bsize=4096   blocks=25600, imaxpct=25

         =                       sunit=0      swidth=0 blks

naming   =version 2              bsize=4096   ascii-ci=0 ftype=0

log      =internal log           bsize=4096   blocks=853, version=2

         =                       sectsz=512   sunit=0 blks, lazy-count=1

realtime =none                   extsz=4096   blocks=0, rtextents=0

[[email protected] ~]# mount /dev/vdb5 /mnt/

 

 

 

#####磁盘阵列######

 

[[email protected] ~]# fdisk /dev/vdb

磁盘分区,分三个一样大的分区,分区功能id为fd。

 

Command (m for help): p

 

Disk /dev/vdb: 10.7 GB, 10737418240 bytes, 20971520 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: 0x0374426c

 

   Device Boot      Start         End      Blocks   Id  System

/dev/vdb1            2048     2099199     1048576   fd  Linux raid autodetect

/dev/vdb2         2099200     4196351     1048576   fd  Linux raid autodetect

/dev/vdb3         4196352     6293503     1048576   fd  Linux raid autodetect

 

监控命令:watch -n 1 cat /proc/mdstat

 

[[email protected] ~]# mdadm -C /dev/md0 -a yes -l 1 -n 2 -x 1 /dev/vdb{1..3}        ###建一个新的阵列(-C /dev/md0建一个新的阵列;-a yes 有一个/proc/mdstat;-l 1 级别为1;-n 2 使用两个;-x 1 一个备用)

mdadm: /dev/vdb1 appears to be part of a raid array:

    level=raid1 devices=2 ctime=Sat Nov 19 02:39:55 2016

mdadm: Note: this array has metadata at the start and

    may not be suitable as a boot device.  If you plan to

    store ‘/boot‘ on this device please ensure that

    your boot-loader understands md/v1.x metadata, or use

    --metadata=0.90

mdadm: /dev/vdb2 appears to be part of a raid array:

    level=raid1 devices=2 ctime=Sat Nov 19 02:39:55 2016

mdadm: /dev/vdb3 appears to be part of a raid array:

    level=raid1 devices=2 ctime=Sat Nov 19 02:39:55 2016

Continue creating array? yes

mdadm: Defaulting to version 1.2 metadata

mdadm: array /dev/md0 started.

[[email protected] ~]# mount /dev/md0 /mnt/

[[email protected] ~]# mdadm -D /dev/md0                ###显示磁盘阵列情况

/dev/md0:

        Version : 1.2

  Creation Time : Sat Nov 19 02:45:58 2016

     Raid Level : raid1

     Array Size : 1048000 (1023.61 MiB 1073.15 MB)

  Used Dev Size : 1048000 (1023.61 MiB 1073.15 MB)

   Raid Devices : 2

  Total Devices : 3

    Persistence : Superblock is persistent

 

    Update Time : Sat Nov 19 02:47:10 2016

          State : clean

 Active Devices : 2

Working Devices : 3

 Failed Devices : 0

  Spare Devices : 1

 

           Name : localhost:0  (local to host localhost)

           UUID : e2215abd:a63d553a:30f55154:42231172

         Events : 17

 

    Number   Major   Minor   RaidDevice State

       0     253       17        0      active sync   /dev/vdb1

       1     253       18        1      active sync   /dev/vdb2

 

       2     253       19        -      spare   /dev/vdb3

[[email protected] ~]# mdadm -f /dev/md0 /dev/vdb1                    ####破坏/dev/vdb1

mdadm: set /dev/vdb1 faulty in /dev/md0

[[email protected] ~]# mdadm -D /dev/md0

/dev/md0:

        Version : 1.2

  Creation Time : Sat Nov 19 02:45:58 2016

     Raid Level : raid1

     Array Size : 1048000 (1023.61 MiB 1073.15 MB)

  Used Dev Size : 1048000 (1023.61 MiB 1073.15 MB)

   Raid Devices : 2

  Total Devices : 3

    Persistence : Superblock is persistent

 

    Update Time : Sat Nov 19 02:48:33 2016

          State : clean, degraded, recovering

 Active Devices : 1

Working Devices : 2

 Failed Devices : 1

  Spare Devices : 1

 

 Rebuild Status : 62% complete

 

           Name : localhost:0  (local to host localhost)

           UUID : e2215abd:a63d553a:30f55154:42231172

         Events : 29

 

    Number   Major   Minor   RaidDevice State

       2     253       19        0      spare rebuilding   /dev/vdb3

       1     253       18        1      active sync   /dev/vdb2

 

       0     253       17        -      faulty   /dev/vdb1

[[email protected] ~]# mdadm -r /dev/md0 /dev/vdb1                    ####移除/dev/vdb1

mdadm: hot removed /dev/vdb1 from /dev/md0

[[email protected] ~]# mdadm -D /dev/md0

/dev/md0:

        Version : 1.2

  Creation Time : Sat Nov 19 02:45:58 2016

     Raid Level : raid1

     Array Size : 1048000 (1023.61 MiB 1073.15 MB)

  Used Dev Size : 1048000 (1023.61 MiB 1073.15 MB)

   Raid Devices : 2

  Total Devices : 2

    Persistence : Superblock is persistent

 

    Update Time : Sat Nov 19 02:49:02 2016

          State : clean

 Active Devices : 2

Working Devices : 2

 Failed Devices : 0

  Spare Devices : 0

 

           Name : localhost:0  (local to host localhost)

           UUID : e2215abd:a63d553a:30f55154:42231172

         Events : 39

 

    Number   Major   Minor   RaidDevice State

       2     253       19        0      active sync   /dev/vdb3

       1     253       18        1      active sync   /dev/vdb2

[[email protected] ~]# mdadm -a /dev/md0 /dev/vdb1                    ###添加/dev/vdb1

mdadm: added /dev/vdb1

[[email protected] ~]# mdadm -D /dev/md0

/dev/md0:

        Version : 1.2

  Creation Time : Sat Nov 19 02:45:58 2016

     Raid Level : raid1

     Array Size : 1048000 (1023.61 MiB 1073.15 MB)

  Used Dev Size : 1048000 (1023.61 MiB 1073.15 MB)

   Raid Devices : 2

  Total Devices : 3

    Persistence : Superblock is persistent

 

    Update Time : Sat Nov 19 02:49:43 2016

          State : clean

 Active Devices : 2

Working Devices : 3

 Failed Devices : 0

  Spare Devices : 1

 

           Name : localhost:0  (local to host localhost)

           UUID : e2215abd:a63d553a:30f55154:42231172

         Events : 40

 

    Number   Major   Minor   RaidDevice State

       2     253       19        0      active sync   /dev/vdb3

       1     253       18        1      active sync   /dev/vdb2

 

       3     253       17        -      spare   /dev/vdb1

[[email protected] ~]# umount /mnt

[[email protected] ~]# mdadm -S /dev/md0                        ####停止磁盘阵列

mdadm: stopped /dev/md0

[[email protected] ~]# mdadm -D /dev/md0

mdadm: cannot open /dev/md0: No such file or directory

 

 

#####配额#####

 

分一个磁盘/dev/vdb1,大小为5G.

 

[[email protected] ~]# mkfs.xfs /dev/vdb1                            ####格式化

mkfs.xfs: /dev/vdb1 appears to contain an existing filesystem (xfs).

mkfs.xfs: Use the -f option to force overwrite.

[[email protected] ~]# mkfs.xfs /dev/vdb1 -f

meta-data=/dev/vdb1              isize=256    agcount=4, agsize=327680 blks

         =                       sectsz=512   attr=2, projid32bit=1

         =                       crc=0

data     =                       bsize=4096   blocks=1310720, imaxpct=25

         =                       sunit=0      swidth=0 blks

naming   =version 2              bsize=4096   ascii-ci=0 ftype=0

log      =internal log           bsize=4096   blocks=2560, version=2

         =                       sectsz=512   sunit=0 blks, lazy-count=1

realtime =none                   extsz=4096   blocks=0, rtextents=0

[[email protected] ~]# mkdir /pub                                                   ###建立一个/pub目录

[[email protected] ~]# mount /dev/vdb1 /pub                                        ##挂载/dev/vdb1到/pub

[[email protected] ~]# chmod 1777 /pub                                            ####给权限(文件只能所有人删除)

[[email protected] ~]# su - westos

Last login: Sat Nov 19 00:56:26 EST 2016 on pts/0

[[email protected] ~]$ dd if=/dev/zero of=/pub/file bs=1M count=3000            ###截取3G的文件到/pub/file

3000+0 records in

3000+0 records out

3145728000 bytes (3.1 GB) copied, 47.9492 s, 65.6 MB/s

[[email protected] ~]$ du -sh /pub/file                                        ###查看文件大小

3.0G/pub/file

[[email protected] ~]$ df -h

Filesystem      Size  Used Avail Use% Mounted on

/dev/vda1        10G  3.7G  6.4G  37% /

devtmpfs        906M     0  906M   0% /dev

tmpfs           921M   80K  921M   1% /dev/shm

tmpfs           921M   17M  904M   2% /run

tmpfs           921M     0  921M   0% /sys/fs/cgroup

/dev/vdb1       5.0G  3.0G  2.1G  60% /pub

[[email protected] ~]$ logout

[[email protected] ~]# df

Filesystem     1K-blocks    Used Available Use% Mounted on

/dev/vda1       10473900 3809528   6664372  37% /

devtmpfs          927072       0    927072   0% /dev

tmpfs             942660      80    942580   1% /dev/shm

tmpfs             942660   17016    925644   2% /run

tmpfs             942660       0    942660   0% /sys/fs/cgroup

/dev/vdb1        5232640 3104928   2127712  60% /pub

[[email protected] ~]# umount /pub/

 

开始配额:

 

[[email protected] ~]# mount -o usrquota /dev/vdb1 /pub                ###挂载

[[email protected] ~]# mount

proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)

sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime,seclabel)

devtmpfs on /dev type devtmpfs (rw,nosuid,seclabel,size=927072k,nr_inodes=231768,mode=755)

securityfs on /sys/kernel/security type securityfs (rw,nosuid,nodev,noexec,relatime)

tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev,seclabel)

devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,seclabel,gid=5,mode=620,ptmxmode=000)

tmpfs on /run type tmpfs (rw,nosuid,nodev,seclabel,mode=755)

tmpfs on /sys/fs/cgroup type tmpfs (rw,nosuid,nodev,noexec,seclabel,mode=755)

cgroup on /sys/fs/cgroup/systemd type cgroup (rw,nosuid,nodev,noexec,relatime,xattr,release_agent=/usr/lib/systemd/systemd-cgroups-agent,name=systemd)

pstore on /sys/fs/pstore type pstore (rw,nosuid,nodev,noexec,relatime)

cgroup on /sys/fs/cgroup/cpuset type cgroup (rw,nosuid,nodev,noexec,relatime,cpuset)

cgroup on /sys/fs/cgroup/cpu,cpuacct type cgroup (rw,nosuid,nodev,noexec,relatime,cpuacct,cpu)

cgroup on /sys/fs/cgroup/memory type cgroup (rw,nosuid,nodev,noexec,relatime,memory)

cgroup on /sys/fs/cgroup/devices type cgroup (rw,nosuid,nodev,noexec,relatime,devices)

cgroup on /sys/fs/cgroup/freezer type cgroup (rw,nosuid,nodev,noexec,relatime,freezer)

cgroup on /sys/fs/cgroup/net_cls type cgroup (rw,nosuid,nodev,noexec,relatime,net_cls)

cgroup on /sys/fs/cgroup/blkio type cgroup (rw,nosuid,nodev,noexec,relatime,blkio)

cgroup on /sys/fs/cgroup/perf_event type cgroup (rw,nosuid,nodev,noexec,relatime,perf_event)

cgroup on /sys/fs/cgroup/hugetlb type cgroup (rw,nosuid,nodev,noexec,relatime,hugetlb)

configfs on /sys/kernel/config type configfs (rw,relatime)

/dev/vda1 on / type xfs (rw,relatime,seclabel,attr2,inode64,noquota)

rpc_pipefs on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw,relatime)

selinuxfs on /sys/fs/selinux type selinuxfs (rw,relatime)

systemd-1 on /proc/sys/fs/binfmt_misc type autofs (rw,relatime,fd=30,pgrp=1,timeout=300,minproto=5,maxproto=5,direct)

debugfs on /sys/kernel/debug type debugfs (rw,relatime)

hugetlbfs on /dev/hugepages type hugetlbfs (rw,relatime,seclabel)

mqueue on /dev/mqueue type mqueue (rw,relatime,seclabel)

sunrpc on /proc/fs/nfsd type nfsd (rw,relatime)

/dev/vdb1 on /pub type xfs (rw,relatime,seclabel,attr2,inode64,usrquota)

[[email protected] ~]# quotaon -uv /dev/vdb1                                    ###

quotaon: Enforcing user quota already on /dev/vdb1

[[email protected] ~]# edquota  -u westos                                       ###

[[email protected] ~]# rm -fr /pub/*                                            ###删除

[[email protected] ~]# edquota  -u westos

###配额1000M

Disk quotas for user westos (uid 1001):

  Filesystem                   blocks       soft       hard     inodes     soft     hard

  /dev/vdb1                         0          0    1024000          0        0        

 

[[email protected] ~]# su - westos

[[email protected] ~]$ dd if=/dev/zero of=/pub/file bs=1M count=100

100+0 records in

100+0 records out

104857600 bytes (105 MB) copied, 0.113085 s, 927 MB/s

[[email protected] ~]$ dd if=/dev/zero of=/pub/file bs=1M count=1000

1000+0 records in

1000+0 records out

1048576000 bytes (1.0 GB) copied, 8.05441 s, 130 MB/s

[[email protected] ~]$ dd if=/dev/zero of=/pub/file bs=1M count=1010        ###截取内容大于设定配额报错

dd: error writing ‘/pub/file’: Disk quota exceeded

1001+0 records in

1000+0 records out

1048576000 bytes (1.0 GB) copied, 10.2889 s, 102 MB/s

[[email protected] ~]$ du -sh /pub/file

1000M/pub/file

[[email protected] ~]$ touch /pub/file1

touch: cannot touch ‘/pub/file1’: Disk quota exceeded                ###也不能新建文件

 

 

[[email protected] ~]# vim /etc/fstab                                    ###重启后自动配额

 

/dev/vdb1   /pub   xfs    defaults,usrquota  0  0

 

[[email protected] ~]# quotaoff -uv /dev/vdb1                            ####关闭配额

Disabling user quota enforcement on /dev/vdb1

/dev/vdb1: user quotas turned off

[[email protected] ~]# su - westos

Last login: Sat Nov 19 01:08:49 EST 2016 on pts/0

[[email protected] ~]$ dd if=/dev/zero of=/pub/file bs=1M count=1010

1010+0 records in

1010+0 records out

1059061760 bytes (1.1 GB) copied, 10.5216 s, 101 MB/s

 


本文出自 “12112684” 博客,请务必保留此出处http://12122684.blog.51cto.com/12112684/1875192

以上是关于linux 基础 管理系统存储的主要内容,如果未能解决你的问题,请参考以下文章

Linux基础补充——存储结构与管理硬盘

Linux(RadHat)基础学习—系统存储设备与系统分区

Linux基础2-1 根文件系统分析

Linux基础2-1 根文件系统分析

Linux系统基础入门知识磁盘存储管理-基本分区

学习linux-基础一(计算机基础)