##硬盘挂载 mount 设备 目录:挂载 umount 设备或者umount 目录:卸载操作 备注:同一个目录下挂载两个设备,后面挂载的会把前面的覆盖;同意设备挂载两次,会提示设备繁忙。 挂载后编辑/etc/fstab,才可以生效,启动也不会丢失。 vim /etc/fstab 设备 目录 格式 权限 自检 备份 0 0 第一个0表示不自检,第二个0表示不备份
#####主分区创建及其挂载实验:##### [root@localhost Desktop]# ls /dev/sd* /dev/sda /dev/sda1 /dev/sda2 /dev/sdb [root@localhost Desktop]# fdisk /dev/sdb #分区操作 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. Device does not contain a recognized partition table Building a new DOS disklabel with disk identifier 0x44ad761f. Command (m for help): Command (m for help): m #查看总的可用参数 Command action a toggle a bootable flag b edit bsd disklabel c toggle the dos compatibility flag d delete a partition #删除分区 g create a new empty GPT partition table G create an IRIX (SGI) partition table l list known partition types #显示分区类型 m print this menu #显示帮助信息 n add a new partition #新建一个分区 o create a new empty DOS partition table p print the partition table #显示分区表 q quit without saving changes #退出不保存 s create a new empty Sun disklabel t change a partition's system id u change display/entry units v verify the partition table w write table to disk and exit #保存并退出 x extra functionality (experts only) Command (m for help): p Disk /dev/sdb: 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: 0x44ad761f Device Boot Start End Blocks Id System #与74行对应 Command (m for help): n Partition type: p primary (0 primary, 0 extended, 4 free) #主分区 e extended #扩展分区 Select (default p): p #选择主分区 Partition number (1-4, default 1): 1 #分区编号为1 First sector (2048-41943039, default 2048): #起始扇区 Using default value 2048 Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): +5G #需要的大小 Partition 1 of type Linux and of size 5 GiB is set Command (m for help): p Disk /dev/sdb: 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: 0x44ad761f Device Boot Start End Blocks Id System #与52行对应 /dev/sdb1 2048 10487807 5242880 83 Linux Command (m for help): w #保存并退出 The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. [root@localhost Desktop]# mkfs. #格式化操作,下面显示的是可以格式化的类型 mkfs.btrfs mkfs.ext2 mkfs.ext4 mkfs.minix mkfs.vfat mkfs.cramfs mkfs.ext3 mkfs.fat mkfs.msdos mkfs.xfs [root@localhost Desktop]# mkfs.ext4 /dev/sdb1 mke2fs 1.42.9 (28-Dec-2013) Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 327680 inodes, 1310720 blocks 65536 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=1342177280 40 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: done Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done [root@localhost Desktop]# mkdir /haha [root@localhost Desktop]# mount /dev/sdb1 /haha [root@localhost Desktop]# [root@localhost Desktop]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/rhel-root 18G 2.9G 15G 17% / devtmpfs 2.0G 0 2.0G 0% /dev tmpfs 2.0G 140K 2.0G 1% /dev/shm tmpfs 2.0G 8.8M 2.0G 1% /run tmpfs 2.0G 0 2.0G 0% /sys/fs/cgroup /dev/sda1 497M 119M 379M 24% /boot /dev/sr0 3.5G 3.5G 0 100% /run/media/root/RHEL-7.0 Server.x86_64 /dev/sdb1 4.8G 20M 4.6G 1% /haha [root@localhost Desktop]# vim /etc/fstab /dev/sdb1 /haha ext4 defaults 0 0 重启检查 [root@localhost Desktop]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/rhel-root 18G 2.9G 15G 17% / devtmpfs 2.0G 0 2.0G 0% /dev tmpfs 2.0G 84K 2.0G 1% /dev/shm tmpfs 2.0G 8.8M 2.0G 1% /run tmpfs 2.0G 0 2.0G 0% /sys/fs/cgroup /dev/sdb1 4.8G 20M 4.6G 1% /haha #挂载正常 /dev/sda1 497M 119M 379M 24% /boot /dev/sr0 3.5G 3.5G 0 100% /run/media/root/RHEL-7.0 Server.x86_64 ###完成主分区创建及其挂载###SWAP分区(交换分区): 在系统中取出一部分空间临时充当内存去使用。即将冷数据放到硬盘中,降低内存压力
##### 扩大SWAP分区实验 ##### [root@localhost Desktop]# free -m #查看内存使用情况 total used free shared buffers cached Mem: 3939 963 2975 9 0 298 -/+ buffers/cache: 664 3274 Swap: 2047 0 2047 [root@localhost Desktop]# [root@localhost Desktop]# fdisk /dev/sdb 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): n #新建分区 Partition type: p primary (1 primary, 0 extended, 3 free) e extended Select (default p): e #扩展分区(扩展分区无法直接保存数据,必须要有逻辑分区来保存数据) Partition number (2-4, default 2): 2 First sector (10487808-41943039, default 10487808): #起始扇区 Using default value 10487808 Last sector, +sectors or +size{K,M,G} (10487808-41943039, default 41943039): #结束扇区 Using default value 41943039 Partition 2 of type Extended and of size 15 GiB is set Command (m for help): Command (m for help): n #新建分区 Partition type: p primary (1 primary, 1 extended, 2 free) l logical (numbered from 5) Select (default p): l #新建逻辑分区 Adding logical partition 5 First sector (10489856-41943039, default 10489856): Using default value 10489856 Last sector, +sectors or +size{K,M,G} (10489856-41943039, default 41943039): +3G Partition 5 of type Linux and of size 3 GiB is set Command (m for help): Command (m for help): p #查看分区信息 Disk /dev/sdb: 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: 0x3947f2c3 Device Boot Start End Blocks Id System /dev/sdb1 2048 10487807 5242880 83 Linux /dev/sdb2 10487808 41943039 15727616 5 Extended /dev/sdb5 10489856 16781311 3145728 83 Linux Command (m for help): 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@localhost Desktop]# 提示:不同步的话查不到扩展逻辑分区 [root@localhost Desktop]# ls -l /dev/sd* brw-rw----. 1 root disk 8, 0 Sep 4 10:22 /dev/sda brw-rw----. 1 root disk 8, 1 Sep 4 10:22 /dev/sda1 brw-rw----. 1 root disk 8, 2 Sep 4 10:22 /dev/sda2 brw-rw----. 1 root disk 8, 16 Sep 4 10:48 /dev/sdb brw-rw----. 1 root disk 8, 17 Sep 4 10:22 /dev/sdb1 [root@localhost Desktop]# 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/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. [root@localhost Desktop]# ls -l /dev/sd* brw-rw----. 1 root disk 8, 0 Sep 4 10:51 /dev/sda brw-rw----. 1 root disk 8, 1 Sep 4 10:22 /dev/sda1 brw-rw----. 1 root disk 8, 2 Sep 4 10:22 /dev/sda2 brw-rw----. 1 root disk 8, 16 Sep 4 10:51 /dev/sdb brw-rw----. 1 root disk 8, 17 Sep 4 10:22 /dev/sdb1 brw-rw----. 1 root disk 8, 18 Sep 4 10:51 /dev/sdb2 brw-rw----. 1 root disk 8, 21 Sep 4 10:51 /dev/sdb5 [root@localhost Desktop]# mkswap /dev/sdb5 #新建交换分区 Setting up swapspace version 1, size = 3145724 KiB no label, UUID=4e1fd20d-5a08-4fe2-a7c0-bc87ebea43fc [root@localhost Desktop]# swapon /dev/sdb5 #交换分区生效 [root@localhost Desktop]# free -m total used free shared buffers cached Mem: 3939 973 2965 9 1 298 -/+ buffers/cache: 672 3266 Swap: 5119 0 5119 编辑配置文件 [root@localhost Desktop]# vim /etc/fstab /dev/sdb5 swap swap defaults 0 0 ##### 扩大SWAP分区实验结束 #####