DAY03-02 Amin linux-linux Disk Management
4.1 DF Command
[[email protected] ~]# df-h file system capacity used available% mount point/dev/sda3 26G 1008M 25G 4%/DEVTMPFS 902M 0 902M 0%/dev tmpfs 912M 0 912M 0%/DEV/SHM tmp FS 912M 8.6M 904M 1%/run tmpfs 912M 0 912M 0%/sys/fs/cgroup/dev/sda1 197M 113M 84M 58%/boot tmpfs 183M 0 183M 0%/run/user/0 byte byte KB MB GB TB with TMPFS temporary mount file system [[email protected] ~]# Df-lih file system Inode (i) available (i) used (i)% mount point/ Dev/sda3 13M 26K 13M 1%/DEVTMPFS 226K 379 226K 1%/dev Tmpfs 228K 1 228K 1%/dev/shm tmpfs 228K 459 228K 1%/run Tmpfs 228K 228K 1%/sys/fs/cgroup/dev/sda1 100K 328 100K 1%/boot Tmpfs 228K 1 228K 1%/run/user/0 file system still has storage space, but unable to write to the file, you can use the above command to view Inode remaining
4.2 du command
[[email protected] ~]# du -sh /root/ 52K /root/文件在小于4KB时,占用空间仍然是4KB,文件系统的block是4KB
4.3 Disk partitioning
虚拟机新加一块10GB硬盘 [[email protected] ~]# fdisk /dev/sdb 欢迎使用 fdisk (util-linux 2.23.2)。 m 查看帮助信息 n 创建新分区 p 显示分区 w 写入分区信息 d 删除分区 p 主分区 e 扩展分区MBR 最高支持2TB大小分区,四个主分区,或主分区+扩展分区不超过4个 创建过程:n,p,+2G n,e,+2G w 输入错误时,可以使用Ctrl+u 清空前面的内容 逻辑分区号从5开始
4.5 Disk formatting
[[email protected] ~]# cat/etc/filesystems xfs ext4 ext3 ext2 nodev proc Nodev devpts iso9660 vfat HFS hfsplus *mke2fs-t ext4-b 1024/DEV/SDB2MKFS.EXT4 = = = Mke2fs-t Ext4mkfs.xfs-b 2048/dev/sdb1mke2fs-i 8192-t ext4/dev/sdb1-b Specify block Size-m specify reserved space-I specify inode corresponding block size When you format a disk again using the MKFS format, you need to add the-f parameter [[email protected] ~]# blkid/dev/sdb1/dev/sdb1:uuid= "466344f1-3b42-47 A5-91F3-3D7BBF0875BD "type=" XFS "[[email protected] ~]# mkfs.xfs/dev/sdb1-f meta-data=/dev/sdb1 isize=512 agcount=4, agsize=655296 blks = sectsz=512 attr=2, Projid32bi T=1 = Crc=1 finobt=0, sparse=0 data = bsize= 4096 blocks=2621184, imaxpct=25 = sunit=0 swidth=0 blks naming =vers Ion 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
4.7 Disk Mount
[[email protected] ~]# mkfs.xfs -f /dev/sdb直接格式化一个新硬盘,需要加 -f 磁盘 [[email protected] ~]# mount /dev/sdb /mnt/ [[email protected] ~]# df -h /mnt 文件系统 容量 已用 可用 已用% 挂载点 /dev/sdb 10G 33M 10G 1% /mnt [[email protected] ~]# umount /mnt 或 [[email protected] ~]# umount /dev/sdb卸载时,提示目标忙,加 -l 参数 umount -l /mnt/ -o ro,rw,remountvi /etc/fstab 添加启动挂载
4.9 Adding swap space manually
New emulated disk [[email protected] ~]# dd if=/dev/zero of=/tmp/newdisk bs=1m [[email protected] ~]# mkswap-f/tmp /newdisk [[email protected] ~]# swapon/tmp/newdisk [[email protected] ~]# Swapoff/tmp/newdisk [[email protected] ~]# dd If=/dev/zero of=/tmp/newdisk bs=1m count=100 recorded 100+0 's read-write record 100+0 104857600 bytes (MB) Copied, 0.0819902 sec, 1.3 GB/s [[email protected] ~]# du-sh/tmp/newdisk 100m/tmp/n Ewdisk [[email protected] ~]# mkswap-f/tmp/newdisk is setting swap space version 1, size = 102396 KiB no label, Uuid=c4ee 6497-0175-4b15-a67b-a09900fef390 [[email protected] ~]# free-m Total used Free shared Buff/cache available mem:1839 91 1497 8 250 1582 swap:4095 0 4095 [[email protected] ~]# swapon/tmp/newdisk SW Apon:/tmp/newdisk: The right to be insecureLimited to 0644, 0600 is recommended. [[email protected] ~]# free-m total used free shared buff/cache available mem:1839 1497 8 1582 swap:4195 0 4195 [[email protected] ~]# swapoff/tmp/newdisk [[email protected] ~]# free-m Total used free shared Buff/cache available mem:1839 91 1498 8 1582 swap:4095 0 4095
4.10 LVM Tutorial
Create 3 partitions, change the partition type to 8e, use the command fdisk/dev/sdb to enter T, then select the disk number and then enter 8e Yum provides "/*/pvcreate" to create PV [[Email protect Ed] ~]# pvcreate/dev/sdb1 Physical Volume "/DEV/SDB1" successfully created. [[email protected] ~]# pvcreate/dev/sdb2 [[email protected] ~]# pvcreate/dev/sdb3 [[Email p Rotected] ~]# Pvdisplay can see the creation of a successful PV partition [[email protected] ~]# PVs PV VG Fmt Attr P Size pfree/dev/sdb1 lvm2---2.00g 2.00g/dev/sdb2 lvm2---2.00g 2.00g/ DEV/SDB3 lvm2---2.00g 2.00g create VG [[email protected] ~]# vgcreate vg1/dev/sdb1/dev/sdb2 V Olume Group "VG1" successfully created [[email protected] ~]# vgdisplay [[email protected] ~]# VGS VG #PV #LV #SN Attr vsize vfree vg1 2 0 0 wz--n-3.99g 3.99g creating LVM partitions [[Email&nbs P;protected] ~]# lvcreate-l 500m-n lv1 vg1 Logical volume "Lv1" created. formatting [[email protected] ~]# mkfs.ext4/dev/vg1/lv1 mount [[Email protecte] D] ~]# mount/dev/vg1/lv1/mnt/[[email protected] ~]# df-h file system capacity used% mount point available ...../dev/mapper/vg1-lv1 477M 2.3M 445M 1%/mnt Capacity extended to 1000M [[email p]-----...... Rotected] ~]# lvresize-l 1000m/dev/vg1/lv1 [[email protected] ~]# mount/dev/vg1/lv1/mnt/[[EMAIL&NB Sp;protected] ~]# LVS increased by 500M [[email protected] ~]# lvresize-l +500M/DEV/VG1/LV1 reduced capacity (XFS format not supported) first Umount E2FSCK-F/dev/vg1/lv1 Detect disk Error RESIZE2FS/DEV/VG1/LV1 Update Logical Volume Information lvresize-l 800m/dev/vg1/lv1 Reset Volume size Lvdisplay or LVS view size XFS partition (requires mount logical volume operation) to expand to 1000M [[email protected] ~]# lvresize-l 1000m/dev/vg1/lv1 [[email& Nbsp;protected] ~]# xfs_growfs-l 1000m/dev/vg1/lv1 above error ********
4.13 Disk Failure Small case
分区删除后,需要删除/etc/fstab里添加过的挂载信息
DAY03-02 Amin linux-linux Disk Management