开机挂载/etc/fstab及/etc/mtab
共分了六列:
第一列:磁盘设备文件名或该设备的Lable
第二列:挂载点(mount point)
第三列:磁盘分区的文件系统
第四列:文件系统参数
第五列:能否被dump备份命令作用
第六列:是否已fsck检验扇区
在/etc/fstab新增一行:
特殊设备loop挂载(镜像文件不刻录就挂载使用)
[root@CentOS Desktop]# ll -h ubuntu-14.04.5-server-i386.iso -rw-r--r--. 1 kevin kevin 595M Feb 26 03:26 ubuntu-14.04.5-server-i386.iso [root@CentOS Desktop]# mkdir /mnt/centos_dvd [root@CentOS Desktop]# mount -o loop ubuntu-14.04.5-server-i386.iso /mnt/centos_dvd/ [root@CentOS Desktop]# df Filesystem 1K-blocks Used Available Use% Mounted on /dev/sda2 10321208 7488116 2308804 77% / tmpfs 515264 228 515036 1% /dev/shm /dev/sda3 10321208 1025616 8771304 11% /home /dev/sr0 3757116 3757116 0 100% /root /home/kevin/Desktop/ubuntu-14.04.5-server-i386.iso 609280 609280 0 100% /mnt/centos_dvd [root@CentOS Desktop]# ll /mnt/centos_dvd/ total 173 dr-xr-xr-x. 1 root root 2048 Aug 3 2016 boot dr-xr-xr-x. 1 root root 2048 Aug 3 2016 dists dr-xr-xr-x. 1 root root 2048 Aug 3 2016 doc dr-xr-xr-x. 1 root root 2048 Aug 3 2016 install dr-xr-xr-x. 1 root root 18432 Aug 3 2016 isolinux -r--r--r--. 1 root root 143592 Aug 3 2016 md5sum.txt dr-xr-xr-x. 1 root root 2048 Aug 3 2016 pics dr-xr-xr-x. 1 root root 2048 Aug 3 2016 pool dr-xr-xr-x. 1 root root 2048 Aug 3 2016 preseed -r--r--r--. 1 root root 235 Aug 3 2016 README.diskdefines lr-xr-xr-x. 1 root root 1 Aug 3 2016 ubuntu -> . [root@CentOS Desktop]# umount /mnt/centos_dvd
新建大文件以制作loop设备文件
1 . 准备
2 . 创建大型文件
# 创建一个空的文件在/home/loopdefv: [root@CentOS Desktop]# dd if=/dev/zero of=/home/loopdev bs=1M count=512 512+0 records in 512+0 records out 536870912 bytes (537 MB) copied, 0.859372 s, 625 MB/s # if是input file ,输入文件,那个/dev/zero是会一直输出0的设备 # of是output file,将一堆零写入到后面的文件中 # bs是每个block大小,就像文件系统那样的block # count 则是总共几个bs的意思 [root@CentOS Desktop]# ll -h /home/loopdev -rw-r--r--. 1 root root 512M Mar 7 03:53 /home/loopdev
3 . 格式化# 很简单就创建一个512MB的文件,接下来当然是格式化了 [root@CentOS Desktop]# mkfs -t ext3 /home/loopdev mke2fs 1.41.12 (17-May-2010) /home/loopdev is not a block special device. Proceed anyway? (y,n) y Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 32768 inodes, 131072 blocks 6553 blocks (5.00%) reserved for the super user ............... ...............
4 . 挂载
# 利用-o loop参数 [root@CentOS Desktop]# mount -o loop /home/loopdev /media/cdrom [root@CentOS Desktop]# df Filesystem 1K-blocks Used Available Use% Mounted on /dev/sda2 10321208 7488124 2308796 77% / tmpfs 515264 228 515036 1% /dev/shm /dev/sda3 10321208 1549908 8247012 16% /home /dev/sr0 3757116 3757116 0 100% /root /home/loopdev 516040 16800 473028 4% /media/cdrom
内存交换空间的创建
1 . 使用物理分区构架swap
# 先进行分区: [root@CentOS kevin]# fdisk /dev/sdc # 新建分区: Command (m for help): n Command action e extended p primary partition (1-4) # 选择主分区: Partition number (1-4): 1 First cylinder (1-10443, default 1): Using default value 1 Last cylinder, +cylinders or +size{K,M,G} (1-10443, default 10443): +256M # 显示分区: Command (m for help): p ................ ................ Device Boot Start End Blocks Id System /dev/sdc1 1 34 273073+ 83 Linux # 更改分区系统ID(参数为t) Command (m for help): t Selected partition 1 # 按l会显示ID表: Hex code (type L to list codes): l 0 Empty 24 NEC DOS 81 Minix / old Lin bf Solaris 1 FAT12 39 Plan 9 82 Linux swap / So c1 DRDOS/sec (FAT- 2 XENIX root 3c PartitionMagic 83 Linux c4 DRDOS/sec (FAT- 3 XENIX usr 40 Venix 80286 84 OS/2 hidden C: c6 DRDOS/sec (FAT- 4 FAT16 <32M 41 PPC PReP Boot 85 Linux extended c7 Syrinx 5 Extended 42 SFS 86 NTFS volume set da Non-FS data 6 FAT16 4d QNX4.x 87 NTFS volume set db CP/M / CTOS / . 7 HPFS/NTFS 4e QNX4.x 2nd part 88 Linux plaintext de Dell Utility 8 AIX 4f QNX4.x 3rd part 8e Linux LVM df BootIt 9 AIX bootable 50 OnTrack DM 93 Amoeba e1 DOS access a OS/2 Boot Manag 51 OnTrack DM6 Aux 94 Amoeba BBT e3 DOS R/O b W95 FAT32 52 CP/M 9f BSD/OS e4 SpeedStor c W95 FAT32 (LBA) 53 OnTrack DM6 Aux a0 IBM Thinkpad hi eb BeOS fs e W95 FAT16 (LBA) 54 OnTrackDM6 a5 FreeBSD ee GPT f W95 Ext'd (LBA) 55 EZ-Drive a6 OpenBSD ef EFI (FAT-12/16/ 10 OPUS 56 Golden Bow a7 NeXTSTEP f0 Linux/PA-RISC b 11 Hidden FAT12 5c Priam Edisk a8 Darwin UFS f1 SpeedStor 12 Compaq diagnost 61 SpeedStor a9 NetBSD f4 SpeedStor 14 Hidden FAT16 <3 63 GNU HURD or Sys ab Darwin boot f2 DOS secondary 16 Hidden FAT16 64 Novell Netware af HFS / HFS+ fb VMware VMFS 17 Hidden HPFS/NTF 65 Novell Netware b7 BSDI fs fc VMware VMKCORE 18 AST SmartSleep 70 DiskSecure Mult b8 BSDI swap fd Linux raid auto 1b Hidden W95 FAT3 75 PC/IX bb Boot Wizard hid fe LANstep 1c Hidden W95 FAT3 80 Old Minix be Solaris boot ff BBT 1e Hidden W95 FAT1 # swap分区为82号: Hex code (type L to list codes): 82 # 显示分区情况: Command (m for help): p Device Boot Start End Blocks Id System /dev/sdc1 1 34 273073+ 82 Linux swap / Solaris # 保存修改: Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. # 这个很重要,让内更新分区表: [root@CentOS kevin]# partprobe Warning: WARNING: the kernel failed to re-read the partition table on /dev/sda (Device or resource busy). As a result, it may not reflect all of your changes until after reboot. 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. Error: Invalid partition table - recursive partition on /dev/sr0. [root@CentOS kevin]#
文件系统格式ID对照表:
# 开始构建swap分区: [root@CentOS kevin]# mkswap /dev/sdc1 Setting up swapspace version 1, size = 273068 KiB no label, UUID=1ff052d0-25bb-4b2d-abf7-3014ad003afd # 非常快速 # 开始查看与加载: [root@CentOS kevin]# free total used free shared buffers cached Mem: 1030528 268428 762100 0 33188 120352 -/+ buffers/cache: 114888 915640 Swap: 1048568 0 1048568 # 查看物理内存,总共-已用-剩余-共享-缓冲-快取 [root@CentOS kevin]# swapon /dev/sdc1 [root@CentOS kevin]# free total used free shared buffers cached Mem: 1030528 268520 762008 0 33208 120364 -/+ buffers/cache: 114948 915580 Swap: 1321632 0 1321632 # 有增加了 [root@CentOS kevin]# swapon -s Filename Type Size Used Priority /dev/sda5 partition 1048568 0 -1 /dev/sdc1 partition 273064 0 -2 # 上面列出了使用的swap设备有哪些的意思
使用文件构建swap
# 使用dd命令新增一个128M的文件在/tmp下面: [root@CentOS kevin]# dd if=/dev/zero of=/tmp/swap bs=1M count=128 128+0 records in 128+0 records out 134217728 bytes (134 MB) copied, 1.01558 s, 132 MB/s [root@CentOS kevin]# ll -h /tmp/swap -rw-r--r--. 1 root root 128M Mar 7 04:37 /tmp/swap # 使用mkswap将/tmp/swap这个文件格式化为swap的文件格式: [root@CentOS kevin]# mkswap /tmp/swap Setting up swapspace version 1, size = 131068 KiB no label, UUID=a3af4d82-bd1c-490f-a02e-125806aa82e8 # 这个命令使用时要特别注意,因为弄错字节会使系统挂掉 # 使用swapon来将/tmp/swap启动: [root@CentOS kevin]# free total used free shared buffers cached Mem: 1030528 402576 627952 0 33744 251648 -/+ buffers/cache: 117184 913344 Swap: 1321632 0 1321632 [root@CentOS kevin]# swapon /tmp/swap [root@CentOS kevin]# swapon -s Filename Type Size Used Priority /dev/sda5 partition 1048568 0 -1 /dev/sdc1 partition 273064 0 -2 /tmp/swap file 131064 0 -3 # 使用swapoff关掉swap file: [root@CentOS kevin]# swapoff /tmp/swap [root@CentOS kevin]# swapoff /dev/sdc1 [root@CentOS kevin]# free total used free shared buffers cached Mem: 1030528 402396 628132 0 33764 251648 -/+ buffers/cache: 116984 913544 Swap: 1048568 0 1048568
swap使用上的限制
文件系统的特殊查看与操作
磁盘空间的浪费问题
- 利用GNU的parted进行分区行为
- 重点回顾
- 本章习题