磁盘格式化
常用的磁盘格式
xfs:常用于centos7系统
ext4:常用与centos6系统
ext3:用于centos5系统
mount
查看当前磁盘使用格式
[root@shu001 ~]# mount | grep "/dev/sd"
/dev/sda3 on / type xfs (rw,relatime,seclabel,attr2,inode64,noquota)
/dev/sda1 on /boot type xfs (rw,relatime,seclabel,attr2,inode64,noquota)
[root@shu001 ~]#
mke2fs命令
不支持xfs格式化
mke2fs [参数][设备]
参数:
- -c:格式化前先检测磁盘;
- -L:预设该分区的标签也就是名称;
- -t:指定文件系统类型,可以试ext2、ext3、ext4;
实验1:指定/dev/sdb2的文件类型为ext4[root@shu001 ~]# mke2fs -t ext4 /dev/sdb2 mke2fs 1.42.9 (28-Dec-2013) 文件系统标签= OS type: Linux 块大小=4096 (log=2) 分块大小=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 131072 inodes, 524288 blocks 26214 blocks (5.00%) reserved for the super user 第一个数据块=0 Maximum filesystem blocks=536870912 16 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@shu001 ~]# blkid /dev/sdb2 /dev/sdb2: UUID="30bd1de6-894f-48b6-9d8f-54afd99d6853" TYPE="ext4" [root@shu001 ~]#
实验2:指定/dev/sdb2的名称或标签为test02
[root@shu001 ~]# mke2fs -L test02 /dev/sdb2
mke2fs 1.42.9 (28-Dec-2013)
文件系统标签=test02
OS type: Linux
块大小=4096 (log=2)
分块大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
131072 inodes, 524288 blocks
26214 blocks (5.00%) reserved for the super user
第一个数据块=0
Maximum filesystem blocks=536870912
16 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表: 完成
Writing superblocks and filesystem accounting information: 完成
[root@shu001 ~]# blkid /dev/sdb2
/dev/sdb2: LABEL="test02" UUID="faf6d819-408b-45ed-a1d2-6f1d4d85803e" TYPE="ext2"
[root@shu001 ~]#
mkfs命令
格式:
mkfs.[文件格式][参数][设备]
mkfs.xfs -f /dev/sdb3
[root@shu001 ~]# mkfs.xfs -L test-xfs /dev/sdb3
mkfs.xfs: /dev/sdb3 appears to contain a partition table (dos).
mkfs.xfs: Use the -f option to force overwrite.
[root@shu001 ~]# mkfs.xfs -L testxfs /dev/sdb3
mkfs.xfs: /dev/sdb3 appears to contain a partition table (dos).
mkfs.xfs: Use the -f option to force overwrite.
[root@shu001 ~]# mkfs.xfs /dev/sdb3
mkfs.xfs: /dev/sdb3 appears to contain a partition table (dos).
mkfs.xfs: Use the -f option to force overwrite.
[root@shu001 ~]# mkfs.xfs -f /dev/sdb3
meta-data=/dev/sdb3 isize=512 agcount=4, agsize=131072 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=524288, 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
[root@shu001 ~]# blkid /dev/sdb3
/dev/sdb3: UUID="c890c488-0732-4a58-930c-391a9de5bce9" TYPE="xfs"
[root@shu001 ~]#
参数:
- -f:强制执行
- -b:指定块文件的大小,比如-b 2048 代表指定块大小为2048B也就是2KB
blkid命令
查看硬盘分区的格式与UUID
格式:
blkid [设备]
blkid /dev/sdb3
[root@shu001 ~]# blkid /dev/sdb3
/dev/sdb3: UUID="c890c488-0732-4a58-930c-391a9de5bce9" TYPE="xfs"
[root@shu001 ~]#
磁盘挂载
挂载磁盘
mount命令
格式:
mount [设备][挂载点]
mount /dev/sdb2
实验1:将sdb2挂载到/mnt/目录下
[root@shu001 ~]# mount /dev/sdb2 /mnt/
[root@shu001 ~]# df -h | grep -v tmpfs
文件系统 容量 已用 可用 已用% 挂载点
/dev/sda3 28G 1.3G 27G 5% /
/dev/sda1 197M 97M 100M 50% /boot
/dev/sdb2 2.0G 33M 2.0G 2% /mnt
[root@shu001 ~]#
/etc/fstab配置文件
开机自动挂载设备文件
先查看/etc/fstab文件
[root@shu001 ~]# cat /etc/fstab
#
# /etc/fstab
# Created by anaconda on Thu Nov 9 03:29:01 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=74ffca85-fbd2-4e59-954a-883c0e1b296a / xfs defaults 0 0
UUID=28f1791a-029f-404e-8c1b-9dc89527f51b /boot xfs defaults 0 0
UUID=c2011d84-3c06-4e9d-9fd6-01a9e0fb44d0 swap swap defaults 0 0
[root@shu001 ~]#
从中我们发现可以在此文件中修改添加可以添加自动挂载
按格式在文档中添加
[root@shu001 ~]# tail /etc/fstab
# /etc/fstab
# Created by anaconda on Thu Nov 9 03:29:01 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=74ffca85-fbd2-4e59-954a-883c0e1b296a / xfs defaults 0 0
UUID=28f1791a-029f-404e-8c1b-9dc89527f51b /boot xfs defaults 0 0
UUID=c2011d84-3c06-4e9d-9fd6-01a9e0fb44d0 swap swap defaults 0 0
/dev/sdb2 /mnt xfs defaults 0 0
[root@shu001 ~]#
使用mount -a自动挂载[root@shu001 ~]# mount -a
卸载磁盘:
umount [设备]
实验:将sdb2卸载
[root@shu001 ~]# df -h | grep -v tmpfs
文件系统 容量 已用 可用 已用% 挂载点
/dev/sda3 28G 1.3G 27G 5% /
/dev/sda1 197M 97M 100M 50% /boot
/dev/sdb2 2.0G 33M 2.0G 2% /mnt
[root@shu001 ~]# umount /dev/sdb2
[root@shu001 ~]# df -h | grep -v tmpfs
文件系统 容量 已用 可用 已用% 挂载点
/dev/sda3 28G 1.3G 27G 5% /
/dev/sda1 197M 97M 100M 50% /boot
[root@shu001 ~]#
手动增加swap空间
swap类似于Windows的虚拟内存,分区时一般指定虚拟内存的大小是实际内存的2倍;
增加虚拟磁盘的思路为:建立swapfile——》格式化为swap格式——》启用虚拟磁盘
建立swapfile
建立虚拟磁盘/tmp/newdisk,块文件为1M每个,共100个,也就是100M;
[root@shu001 ~]# dd if=/dev/zero of=/tmp/newdisk bs=1M count=100
记录了100+0 的读入
记录了100+0 的写出
104857600字节(105 MB)已复制,0.606041 秒,173 MB/秒
[root@shu001 ~]# du -sh /tmp/newdisk
100M /tmp/newdisk
[root@shu001 ~]#
格式化swapfile新磁盘
swapfile -f [虚拟磁盘路径]
[root@shu001 ~]# mkswap -f /tmp/newdisk
正在设置交换空间版本 1,大小 = 102396 KiB
无标签,UUID=d4a33f8d-8e8a-47d4-a9d6-bbcd764fecfd
[root@shu001 ~]#
加载启用虚拟磁盘
swapon [虚拟磁盘路径]
swapon /tmp/newdisk
[root@shu001 ~]# free -m
total used free shared buff/cache available
Mem: 984 112 637 6 234 701
Swap: 2047 0 2047
[root@shu001 ~]# swapon /tmp/newdisk
swapon: /tmp/newdisk:不安全的权限 0644,建议使用 0600。
[root@shu001 ~]# free -m
total used free shared buff/cache available
Mem: 984 112 637 6 234 701
Swap: 2147 0 2147
[root@shu001 ~]#
卸载虚拟磁盘
swapoff [虚拟磁盘路径]
swapoff /tmp/newdisk
[root@shu001 ~]# free -m
total used free shared buff/cache available
Mem: 984 112 637 6 234 701
Swap: 2147 0 2147
[root@shu001 ~]# swapoff /tmp/newdisk
[root@shu001 ~]# free -m
total used free shared buff/cache available
Mem: 984 112 637 6 234 701
Swap: 2047 0 2047
[root@shu001 ~]#
转载于:https://blog.51cto.com/shuzonglu/2055971