9月26日任务
4.5/4.6 磁盘格式化
4.7/4.8 磁盘挂载
4.9 手动增加swap空间
4.5/4.6 磁盘格式化
#查看Linux所支持的文件格式
[root@zgxlinux-01 ~]# cat /etc/filesystems xfs ext4 ext3 ext2 nodev proc nodev devpts iso9660 vfat hfs hfsplus *
#格式化命令:mke2fs (不能指定为xfs格式) mkfs (格式没有限制)
选项 mke2fs -t #指定密钥格式化成什么文件系统 例如:ext4 /ext3 /ext2
mke2fs -b #指定块大小
mke2fs -m #指定预留空间大小
mke2fs -i #指定inode
[root@zgxlinux-01 ~]# ls -l 总用量 8 -rw-r--r--. 1 root root 0 9月 5 14:24 1.txt -rwx------. 1 root root 2557 9月 4 13:07 anaconda-ks.cfg -rw-r--r--. 1 root root 32 9月 13 14:27 nhy -rw-r--r--. 1 root root 0 9月 13 14:43 user1 [root@zgxlinux-01 ~]# echo 1 >1.txt [root@zgxlinux-01 ~]# ls -l 1.txt -rw-r--r--. 1 root root 2 9月 17 14:59 1.txt [root@zgxlinux-01 ~]# du -sb 1.txt #按大小显示 2 1.txt [root@zgxlinux-01 ~]# du -sh 1.txt #按块显示,不足4字节按1个块4字节显示 4.0K 1.txt
#格式化dev/sdb1指定为ext4格式,同时指定块大小为4096
[root@zgxlinux-01 ~]# mke2fs -t ext4 -b 4096 /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 262144 inodes, 1048576 blocks 52428 blocks (5.00%) reserved for the super user 第一个数据块=0 Maximum filesystem blocks=1073741824 32 block groups 32768 blocks per group, 32768 fragments per group 8192 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736 Allocating group tables: 完成 正在写入inode表: 完成 Creating journal (32768 blocks): 完成 Writing superblocks and filesystem accounting information: 完成 #还可以用另一个命令方式格式化 [root@zgxlinux-01 ~]# 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 262144 inodes, 1048576 blocks 52428 blocks (5.00%) reserved for the super user #表示给root用户的预留空间 第一个数据块=0 Maximum filesystem blocks=1073741824 32 block groups 32768 blocks per group, 32768 fragments per group 8192 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736 Allocating group tables: 完成 正在写入inode表: 完成 Creating journal (32768 blocks): 完成 Writing superblocks and filesystem accounting information: 完成
#格式化sdb2同时指定格式为xfs格式
[root@zgxlinux-01 ~]# mkfs.xfs /dev/sdb2 meta-data=/dev/sdb2 isize=512 agcount=4, agsize=262144 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=0, sparse=0 data = bsize=4096 blocks=1048576, 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
#blkid命令查看还未挂载的磁盘命令
[root@zgxlinux-01 ~]# blkid /dev/sdb1 /dev/sdb1: UUID="821b4504-7879-48b9-a62c-0af55a27d25e" TYPE="ext4" [root@zgxlinux-01 ~]# blkid /dev/sdb2 /dev/sdb2: UUID="053fc287-462d-4f6c-acbf-2e95ee8c25b2" TYPE="xfs"
#格式化/dev/sdb3 ,同时指定格式为ext4 ,块大小2048 ,预留空间为0.1%
[root@zgxlinux-01 ~]# mke2fs -t ext4 -b 2048 -m 0.1 /dev/sdb3 mke2fs 1.42.9 (28-Dec-2013) 文件系统标签= OS type: Linux 块大小=2048 (log=1) 分块大小=2048 (log=1) Stride=0 blocks, Stripe width=0 blocks 262144 inodes, 2097152 blocks 2097 blocks (0.10%) reserved for the super user 第一个数据块=0 Maximum filesystem blocks=270532608 128 block groups 16384 blocks per group, 16384 fragments per group 2048 inodes per group Superblock backups stored on blocks: 16384, 49152, 81920, 114688, 147456, 409600, 442368, 802816, 1327104, 2048000 Allocating group tables: 完成 正在写入inode表: 完成 Creating journal (32768 blocks): 完成 Writing superblocks and filesystem accounting information: 完成
#选项 :mount -o rw 可读可写 ro 只读 renount 重新挂载
[user2@zgxlinux-01 ~]$ vi /etc/fstab #系统启动默认挂载磁盘和分区的配置文件 UUID=7d46e9e9-a01b-4bca-9904-11fbf733c8a8 / xfs defaults 0 0 #根分区要检测设置1 ,其他分区要检测设2,不检测设 UUID=5f65c820-256d-4270-802a-c4ada528e6a0 /boot xfs defaults 0 0 UUID=0d7c481c-18db-4799-853d-86a6f0ae6fdc swap swap defaults 0 0
4.9 手动增加swap空间
#命令dd 用来操作磁盘,可以读,可以写。 if指定从哪里读,of指定将0写入到哪里,bs指定块的大小,count=1M*100 (/dev/zero 是linux 中永远输出0的设备文件, 使用它作输入可以得到全为空的文件)。
[root@zgxlinux-01 ~]# dd if=/dev/zero of=/tmp/newdisk bs=1M count=100 记录了100+0 的读入 记录了100+0 的写出 104857600字节(105 MB)已复制,2.73983 秒,38.3 MB/秒 [root@zgxlinux-01 ~]# du -sh /tmp/newdisk 100M /tmp/newdisk [root@zgxlinux-01 ~]# mkswap -f /tmp/newdisk #格式化 正在设置交换空间版本 1,大小 = 102396 KiB 无标签,UUID=27c139e5-b946-4e68-957c-04ec5139eb26 [root@zgxlinux-01 ~]# free -m total used free shared buff/cache available Mem: 983 126 595 7 261 679 Swap: 2047 0 2047 [root@zgxlinux-01 ~]# swapon /tmp/newdisk #加载到现有swap分区 swapon: /tmp/newdisk:不安全的权限 0644,建议使用 0600。 [root@zgxlinux-01 ~]# free -m total used free shared buff/cache available Mem: 983 126 595 7 261 679 Swap: 2147 0 2147 [root@zgxlinux-01 ~]# chmod 600 /tmp/newdisk [root@zgxlinux-01 ~]# swapoff /tmp/newdisk #从swap分区卸载 [root@zgxlinux-01 ~]# free -m total used free shared buff/cache available Mem: 983 126 595 7 261 679 Swap: 2047 0 2047 [root@zgxlinux-01 ~]# rm -rf /tmp/newdisk #删除