磁盘管理的顺序 硬盘-----分区-----格式化-----挂载-----正常访问 1 硬盘: 关闭虚拟机添加一块硬盘 2 分区: fdisk命令,这个命令不需要背诵,m键都有解释 3 格式化: mkfs -t 可以接文件系统的格式,如ext3 查看文件系统支持哪些格式,mkfs Tab Tab mke2fs -b block块的大小 -i 多少容量给一个inode -L 卷标名 -j 本来是ext2 ,加上-j之后变成ext3了 eg1 用mke2fs设置 卷标名为vbied_logical; block块大小为2048;每8192bytes分配一个inode;构建ext3系统;开始格式为/dev/hdc6
[root@localhost ~]# mke2fs -j -L "vbird_logical" -b 2048 -i 8192 /dev/hdc64 挂载 :mount 单一文件系统不应该被重复挂载到不同的挂载点上 单一目录不能挂载不同的文件系统 作为挂载点的目录理论上应该是空目录 -t 指定挂载的类型 -l 查看目前已经挂载的文件系统并显示卷标名称 附加扩展1: 挂载DVD或CD光盘(用centos原版光盘挂载)
[root@bogon ~]# mkdir /media/cdrom mkdir: cannot create directory ‘/media/cdrom’: File exists [root@bogon ~]# find d find: ‘d’: No such file or directory [root@bogon ~]# find -type d . [root@bogon ~]# find -type d -empty [root@bogon ~]# mount -t iso9660 /dev/cdrom /media/cdrom mount: /dev/sr0 is write-protected, mounting read-only [root@bogon ~]# df Filesystem 1K-blocks Used Available Use% Mounted on /dev/mapper/centos-root 18655232 949148 17706084 6% / devtmpfs 488792 0 488792 0% /dev tmpfs 499848 0 499848 0% /dev/shm tmpfs 499848 6912 492936 2% /run tmpfs 499848 0 499848 0% /sys/fs/cgroup /dev/sda1 201380 104920 96460 53% /boot tmpfs 99972 0 99972 0% /run/user/0 /dev/sr0 4414592 4414592 0 100% /media/cdrom可以指定系统格式也可以让系统自行监测 正确的文件名要看光驱是什么接口,因为光驱是IDE接口,所以是/dev/sr0。光驱一旦挂载之后就无法取出光盘,如果要退出,就要卸载
附加扩展2 : 用mount将一个目录挂载到另一个目录中去 eg :将/home这个目录挂载暂时挂载到/mnt/home
[root@bogon ~]# mount --bind /home /mnt/home [root@bogon ~]# ls -lid /home/ /mnt/home 33584979 drwxr-xr-x. 3 root root 17 Sep 15 09:23 /home/ 33584979 drwxr-xr-x. 3 root root 17 Sep 15 09:23 /mnt/home通过mount–blind 就可以实现, 从此进入/home就是进入/mnt/home目录中
设置开机自动挂载:在/etc/fstab中修改
[root@bogon ~]# cat /etc/fstab # # /etc/fstab # Created by anaconda on Sat Sep 15 09:18:31 2018 # # 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 # /dev/mapper/centos-root / xfs defaults 0 0 UUID=86251118-de2b-45b5-81bb-d75c82aa49a2 /boot xfs defaults 0 0 /dev/mapper/centos-swap swap swap defaults 0 0各个列的含义 第一列:文件名或label名 第二列:mount point 第三列:磁盘分区的文件系统,手动挂载时可以让系统自动检测,自动挂载时要自行填写 第四列:文件系统参数,如iocharset=cp950 创建swap分区 使用物理分区创建swap分区 用fdisk创建一个分区给文件系统作为swap分区
[root@bogon ~]# fdisk /dev/sda Welcome to fdisk (util-linux 2.23.2). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. Command (m for help): p Disk /dev/sda: 21.5 GB, 21474836480 bytes, 41943040 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk label type: dos Disk identifier: 0x000cd483 Device Boot Start End Blocks Id System /dev/sda1 * 2048 411647 204800 83 Linux /dev/sda2 411648 41943039 20765696 8e Linux LVM Command (m for help): t Partition number (1,2, default 2): 1 Hex code (type L to list all codes): 82 Changed type of partition 'Linux' to 'Linux swap / Solaris' Command (m for help): p Disk /dev/sda: 21.5 GB, 21474836480 bytes, 41943040 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk label type: dos Disk identifier: 0x000cd483 Device Boot Start End Blocks Id System /dev/sda1 * 2048 411647 204800 82 Linux swap / Solaris /dev/sda2 411648 41943039 20765696 8e Linux LVM Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. WARNING: Re-reading the partition table failed with error 16: Device or resource busy. The kernel still uses the old table. The new table will be used at the next reboot or after you run partprobe(8) or kpartx(8) Syncing disks. [root@bogon ~]# partprobe Warning: Unable to open /dev/sr0 read-write (Read-only file system). /dev/sr0 has been opened read-only. Warning: Unable to open /dev/sr1 read-write (Read-only file system). /dev/sr1 has been opened read-only. [root@bogon ~]# mkswap /dev/sda1 mkswap: error: /dev/sda1 is mounted; will not make swapspace [root@bogon ~]# umount /dev/sda1 [root@bogon ~]# mkswap /dev/sda1 mkswap: /dev/sda1: warning: wiping old xfs signature. Setting up swapspace version 1, size = 204796 KiB no label, UUID=67deef71-dacb-4bd4-9eb1-9b589b233d78 [root@bogon ~]# free total used free shared buff/cache available Mem: 999696 133608 713200 6912 152888 697412 Swap: 2097148 0 2097148 [root@bogon ~]# swapon /dev/sda1 [root@bogon ~]# free total used free shared buff/cache available Mem: 999696 133568 713216 6912 152912 697440 Swap: 2301944 0 2301944使用文件创建swap分区 创建一个128mb的内存交换空间
[root@bogon ~]# dd -if=/dev/zero of=/tmp/swap bs=1m count=128 dd: invalid option -- 'i' Try 'dd --help' for more information. [root@bogon ~]# dd if=/dev/zero of=/tmp/swap bs=1m count=128 dd: invalid number ‘1m’ [root@bogon ~]# dd if=/dev/zero of=/tmp/swap bs=1M count=128 128+0 records in 128+0 records out 134217728 bytes (134 MB) copied, 2.06883 s, 64.9 MB/s [root@bogon ~]# mksawp /tmp/s swap systemd-private-5e1730845efd426d9a194ea865174114-vgauthd.service-Rdk94N/ systemd-private-5e1730845efd426d9a194ea865174114-vmtoolsd.service-j1jvJW/ systemd-private-7062b3f07c054e0cb208df1584bfab3c-vgauthd.service-I4DvZd/ systemd-private-7062b3f07c054e0cb208df1584bfab3c-vmtoolsd.service-pE9nms/ systemd-private-e4e9aa3c8e984781b94f3679126d4c78-vgauthd.service-vPILVE/ systemd-private-e4e9aa3c8e984781b94f3679126d4c78-vmtoolsd.service-L32swM/ [root@bogon ~]# mksawp /tmp/swap -bash: mksawp: command not found [root@bogon ~]# mkswap /tmp/swap Setting up swapspace version 1, size = 131068 KiB no label, UUID=990ce39e-5d1d-4d9e-9d51-70b4ce54b5c2 [root@bogon ~]# free total used free shared buff/cache available Mem: 999696 133924 577992 6912 287780 685036 Swap: 2301944 0 2301944 [root@bogon ~]# swapon /tmp/swap swapon: /tmp/swap: insecure permissions 0644, 0600 suggested. [root@bogon ~]# free total used free shared buff/cache available Mem: 999696 133784 578100 6912 287812 685160 Swap: 2433012 0 2433012 [root@bogon ~]#