磁盘格式化

1.linux系统支持的格式:

[root@weix01 ~]# cat /etc/filesystems
xfs                         #centos7默认格式
ext4                      #centos6
ext3                      #centos5
ext2                      #再往前的版本
nodev proc
nodev devpts
iso9660
vfat
hfs
hfsplus
*

2.格式化磁盘mke2fs及常用选项:

(1)-t     #指定格式化后的格式        改名了暂时不支持xfs格式
(2)-b    #指定块大小
(3)-m   #指定预留空间
[root@weix01 ~]# mke2fs -m 1 /dev/sdb1
mke2fs 1.42.9 (28-Dec-2013)
文件系统标签=
OS type: Linux
块大小=4096 (log=2)
分块大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
196608 inodes, 786432 blocks
7864 blocks (1.00%) reserved for the super user

(4)-i     #指定多少字节对应一个inode
[root@weix01 ~]# mke2fs -i 8192 -t ext4 /dev/sdb1
mke2fs 1.42.9 (28-Dec-2013)
文件系统标签=
OS type: Linux
块大小=4096 (log=2)
分块大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
393216 inodes, 786432 blocks

3.mkfs.ext4 路径与mke2fs -t ext4 路径效果一样:

[root@weix01 ~]# mkfs.ext4 /dev/sdb1
mke2fs 1.42.9 (28-Dec-2013)
文件系统标签=
OS type: Linux
块大小=4096 (log=2)
分块大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
196608 inodes, 786432 blocks
39321 blocks (5.00%) reserved for the super user
第一个数据块=0
Maximum filesystem blocks=805306368
24 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks: 
	32768, 98304, 163840, 229376, 294912

Allocating group tables: 完成                            
正在写入inode表: 完成                            
Creating journal (16384 blocks): 完成
Writing superblocks and filesystem accounting information: 完成 

[root@weix01 ~]# mke2fs -t ext4 /dev/sdb1
mke2fs 1.42.9 (28-Dec-2013)
文件系统标签=
OS type: Linux
块大小=4096 (log=2)
分块大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
196608 inodes, 786432 blocks
39321 blocks (5.00%) reserved for the super user
第一个数据块=0
Maximum filesystem blocks=805306368
24 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks: 
	32768, 98304, 163840, 229376, 294912

Allocating group tables: 完成                            
正在写入inode表: 完成                            
Creating journal (16384 blocks): 完成
Writing superblocks and filesystem accounting information: 完成 

4.格式化xfs格式时使用mkfs.xfs

[root@weix01 ~]# mkfs.xfs /dev/sdb1
mkfs.xfs: /dev/sdb1 appears to contain an existing filesystem (ext4).
mkfs.xfs: Use the -f option to force overwrite.
[root@weix01 ~]# mkfs.xfs -f /dev/sdb1
meta-data=/dev/sdb1              isize=512    agcount=4, agsize=196608 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=786432, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
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

5.查看还没有挂载的磁盘:

[root@weix01 ~]# blkid /dev/sdb1
/dev/sdb1: UUID="1184ceda-0852-4f6f-89ae-92fe1093fb95" TYPE="xfs" 

6.更改块大小:当存储空间都是视频音乐等大文件,可以把块设置大一点,反之则小一点:使用-b选项 7.未指定磁盘格式情况下,默认是ext2格式:

[root@weix01 ~]# blkid /dev/sdb1
/dev/sdb1: UUID="5070d14a-dce9-4aa8-97d3-8210fcf66b73" TYPE="ext2" 

磁盘挂载

1.不管是否有分区,都可以直接格式化,磁盘要访问,必须要挂载 2.挂载命令mount

[root@weix01 ~]# mount /dev/sdb /mnt       #mount  磁盘   挂载点

[root@weix01 ~]# df -h
文件系统        容量  已用  可用 已用% 挂载点
/dev/sda3        28G  997M   27G    4% /
devtmpfs        479M     0  479M    0% /dev
tmpfs           489M     0  489M    0% /dev/shm
tmpfs           489M  6.7M  482M    2% /run
tmpfs           489M     0  489M    0% /sys/fs/cgroup
/dev/sda1       197M   97M  100M   50% /boot
tmpfs            98M     0   98M    0% /run/user/0
/dev/sdb         10G   33M   10G    1% /mnt

3.退出挂载:umount

[root@weix01 ~]# umount /dev/sdb                         #当前不在挂载点下面
[root@weix01 ~]# df -h
文件系统        容量  已用  可用 已用% 挂载点
/dev/sda3        28G  997M   27G    4% /
devtmpfs        479M     0  479M    0% /dev
tmpfs           489M     0  489M    0% /dev/shm
tmpfs           489M  6.7M  482M    2% /run
tmpfs           489M     0  489M    0% /sys/fs/cgroup
/dev/sda1       197M   97M  100M   50% /boot
tmpfs            98M     0   98M    0% /run/user/0

[root@weix01 mnt]# mount /dev/sdb /mnt              #当前在挂载点下面,用-l
[root@weix01 mnt]# umount -l /mnt

4.重新挂载:

 remount
              Attempt to remount an already-mounted filesystem.  This is
              commonly used to change the mount flags for a  filesystem,
              especially to make a readonly filesystem writable. It does
              not change device or mount point.

              The remount functionality follows the standard way how the
              mount  command works with options from fstab. It means the
              mount command doesn't read fstab (or  mtab)  only  when  a
              device and dir are fully specified.

              mount -o remount,rw /dev/foo /dir

              After  this  call  all  old mount options are replaced and
              arbitrary stuff from fstab is ignored,  except  the  loop=
              option which is internally generated and maintained by the
              mount command.

              mount -o remount,rw  /dir

5.系统启动挂载磁盘:查看配置文件fstab,第一列设备号,第二列挂载点,第三列格式,第四列默认,第五列是否备份,第六列优先级

# /etc/fstab
# Created by anaconda on Wed Nov 15 02:01:29 2017
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
UUID=d79705ad-6a9c-4cce-8394-c597cccdfed6 /                       xfs     defaults        0 0    
UUID=134f47b0-dcae-405a-8e42-f7aa49805be9 /boot                   xfs     defaults        0 0
UUID=5a440737-12d4-4f7c-b935-51b0afeffefc swap                    swap    defaults        0 0
~                                                     

6.UUID:设备号

手动增加 swap空间

1.dd命令:用来从操作磁盘,if指定从哪里去读,of指定将数据写到哪里,bs指定块大小,count,多少个块:

[root@weix01 ~]# dd if=/dev/zero of=/tmp/newdisk bs=1M count=100
记录了100+0 的读入
记录了100+0 的写出
104857600字节(105 MB)已复制,3.00048 秒,34.9 MB/秒
[root@weix01 ~]# du -sh /tmp/newdisk
100M	/tmp/newdisk

2.格式化:

[root@weix01 ~]# mkswap -f /tmp/newdisk
正在设置交换空间版本 1,大小 = 102396 KiB
无标签,UUID=366661a2-91bd-496c-8e87-11dc2b69bc21

3.增加到原来的上面去:swapon

[root@weix01 ~]# free -m
              total        used        free      shared  buff/cache   available
Mem:            976         115         610           6         249         683
Swap:          2047           0        2047
[root@weix01 ~]# swapon /tmp/newdisk
swapon: /tmp/newdisk:不安全的权限 0644,建议使用 0600。
[root@weix01 ~]# free -m
              total        used        free      shared  buff/cache   available
Mem:            976         115         610           6         249         683
Swap:          2147           0        2147

4.卸载下来:

[root@weix01 ~]# swapoff /tmp/newdisk
[root@weix01 ~]# free -m
              total        used        free      shared  buff/cache   available
Mem:            976         115         610           6         249         683
Swap:          2047           0        2047

[root@weix01 ~]# rm -f /tmp/newdisk