首页 > 代码库 > linux系统--free,交换分区,mkswap,swapon,swapoff,dd,自动挂载,fuser
linux系统--free,交换分区,mkswap,swapon,swapoff,dd,自动挂载,fuser
swap分区:
free
-m
fdisk命令中,调整分区类型为82;
创建交换分区:
mkswap /dev/sda8
-L LABEL
swapon /dev/sda8
-a:启用所有的定义在/etc/fstab文件中的交换设备
swapoff /dev/sda8
[root@localhost ~]# free
total used free shared buffers cached
Mem: 1906492 346448 1560044 1256 33772 121320
-/+ buffers/cache: 191356 1715136
Swap: 2097148 0 2097148
[root@localhost ~]# free -m (单位为M) (元数据inode)(数据块block):加速磁盘访问速度
total used free shared buffers cached
Mem: 1861 337 1524 1 32 118
-/+ buffers/cache: 186 1675 (清除buffers/cache后)
Swap: 2047 0 2047 (交换分区使用情况)
[root@localhost ~]#
[root@localhost ~]# fdisk /dev/sdb (磁盘分区)
WARNING: DOS-compatible mode is deprecated. It‘s strongly recommended to
switch off the mode (command ‘c‘) and change display units to
sectors (command ‘u‘).
Command (m for help): p
Disk /dev/sdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x31e2db75
Device Boot Start End Blocks Id System
/dev/sdb1 1 262 2104483+ 83 Linux
/dev/sdb4 263 2610 18860310 5 Extended
/dev/sdb5 263 524 2104483+ 83 Linux
/dev/sdb6 525 1178 5253223+ 83 Linux
/dev/sdb7 1179 1310 1060258+ 83 Linux
Command (m for help): n
Command action
l logical (5 or over)
p primary partition (1-4)
;
Invalid partition number for type `;‘
Command action
l logical (5 or over)
p primary partition (1-4)
l
First cylinder (1311-2610, default 1311):
Using default value 1311
Last cylinder, +cylinders or +size{K,M,G} (1311-2610, default 2610): +1G (新增1G磁盘)
Command (m for help): p
Disk /dev/sdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x31e2db75
Device Boot Start End Blocks Id System
/dev/sdb1 1 262 2104483+ 83 Linux
/dev/sdb4 263 2610 18860310 5 Extended
/dev/sdb5 263 524 2104483+ 83 Linux
/dev/sdb6 525 1178 5253223+ 83 Linux
/dev/sdb7 1179 1310 1060258+ 83 Linux
/dev/sdb8 1311 1442 1060258+ 83 Linux
Command (m for help): 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
Command (m for help): t (调整文件系统类型)
Partition number (1-8): L
Partition number (1-8): 8
Hex code (type L to list codes): 82 (调整文件系统类型为 Linux swap / Solaris)
Changed system type of partition 8 to 82 (Linux swap / Solaris)
Command (m for help): p
Disk /dev/sdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x31e2db75
Device Boot Start End Blocks Id System
/dev/sdb1 1 262 2104483+ 83 Linux
/dev/sdb4 263 2610 18860310 5 Extended
/dev/sdb5 263 524 2104483+ 83 Linux
/dev/sdb6 525 1178 5253223+ 83 Linux
/dev/sdb7 1179 1310 1060258+ 83 Linux
/dev/sdb8 1311 1442 1060258+ 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@localhost ~]# 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.
[root@localhost ~]# partprobe /dev/sdb
[root@localhost ~]# 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.
[root@localhost ~]# cat /proc/partitions (查看分区表)
major minor #blocks name
8 0 20971520 sda
8 1 307200 sda1
8 2 18566144 sda2
8 3 2097152 sda3
8 16 20971520 sdb
8 17 2104483 sdb1
8 20 1 sdb4
8 21 2104483 sdb5
8 22 5253223 sdb6
8 23 1060258 sdb7
8 24 1060258 sdb8
[root@localhost ~]#
[root@localhost ~]# mkswap /dev/sdb8 (创建交换分区 文件系统)
Setting up swapspace version 1, size = 1060252 KiB
no label, UUID=f116f9b3-fe16-459a-98a3-68544f115987
[root@localhost ~]# free -m
total used free shared buffers cached
Mem: 1861 407 1454 1 57 125
-/+ buffers/cache: 223 1638
Swap: 2047 0 2047
[root@localhost ~]# swapon /dev/sdb8 (挂载交换分区)
[root@localhost ~]# free -m
total used free shared buffers cached
Mem: 1861 407 1453 1 57 125
-/+ buffers/cache: 224 1637
Swap: 3083 0 3083
[root@localhost ~]# swapoff /dev/sdb8 (取消交换分区)
[root@localhost ~]# free -m
total used free shared buffers cached
Mem: 1861 407 1454 1 57 125
-/+ buffers/cache: 223 1637
Swap: 2047 0 2047
[root@localhost ~]#
dd命令:
if=数据来源
of=数据存储目标
bs=1
count=2
seek=#: 创建数据文件时,跳过的空间大小;
与copy相比:copy以文件为单位,dd以磁盘块为单位,只复制文件的一部分,以字节为单位;
备份bootloader
dd if=/dev/sda of=/mnt/usb/mbr.backup bs=512 count=1
dd if=/mnt/usb/mbr.backup of=/dev/sda bs=512 count=1
备份设备文件
dd if=/dev/zero of=/var/swapfile bs=1M count=1024
/dev/zero 泡泡文件:生成0
[root@localhost ~]# dd if=/etc/inittab of=/root/inittab
1+1 records in
1+1 records out
884 bytes (884 B) copied, 0.000105692 s, 8.4 MB/s
[root@localhost ~]# ll
total 100
-rw-r--r--. 1 root root 989 Feb 18 17:09 adduser.sh
-rw-------. 1 root root 4080 Jun 21 2015 anaconda-ks.cfg
-rw-r--r--. 1 root root 95 Feb 17 20:23 case.sh
-rw-r--r--. 1 root root 884 Feb 22 17:38 inittab
-rw-r--r--. 1 root root 42001 Jun 21 2015 install.log
-rw-r--r--. 1 root root 9154 Jun 21 2015 install.log.syslog
crw-r--r--. 1 root root 66, 0 Feb 19 19:23 mydev
crw-r-----. 1 root root 66, 1 Feb 19 19:23 mydev2
-rw-r--r--. 1 root root 315 Feb 17 19:36 random.sh
-rwxr-xr-x. 1 root root 196 Nov 19 18:37 second.sh
-rw-r--r--. 1 root root 200 Nov 19 22:26 sum.sh
-rwxr-xr-x. 1 root root 118 Nov 19 18:53 third.sh
-rwxr-xr-x. 1 root root 425 Nov 19 18:48 user2.sh
-rwxr-xr-x. 1 root root 177 Nov 19 20:23 userexit.sh
[root@localhost ~]# cat inittab
# inittab is only used by upstart for the default runlevel.
#
# ADDING OTHER CONFIGURATION HERE WILL HAVE NO EFFECT ON YOUR SYSTEM.
#
# System initialization is started by /etc/init/rcS.conf
#
# Individual runlevels are started by /etc/init/rc.conf
#
通过dd文件创建文件,并作为swap分区
[root@localhost ~]# dd if=/dev/zero of=/var/swapfile bs=1M count=512
512+0 records in
512+0 records out
536870912 bytes (537 MB) copied, 3.61052 s, 149 MB/s
[root@localhost ~]# ll /var/swapfile
-rw-r--r--. 1 root root 536870912 Feb 22 18:02 /var/swapfile
[root@localhost ~]# ll -h /var/swapfile
-rw-r--r--. 1 root root 512M Feb 22 18:02 /var/swapfile
[root@localhost ~]# swapon /var/swapfile
swapon: /var/swapfile: read swap header failed: Invalid argument
[root@localhost ~]# mkswap /var/swapfile
mkswap: /var/swapfile: warning: don‘t erase bootbits sectors
on whole disk. Use -f to force.
Setting up swapspace version 1, size = 524284 KiB
no label, UUID=b7d8d095-31bc-4dae-9868-59c1726db417
[root@localhost ~]# swapon /var/swapfile
[root@localhost ~]# free -m
total used free shared buffers cached
Mem: 1861 921 940 1 57 639
-/+ buffers/cache: 223 1638
Swap: 2559 0 2559
[root@localhost ~]#
文件系统的配置文件/etc/fstab
OS在初始时,会自动挂载此文件中定义的每个文件系统
mount -a:挂载/etc/fstab文件中定义的所有文件系统
[root@localhost ~]# cat /etc/fstab
#
# /etc/fstab
# Created by anaconda on Sun Jun 21 02:15:00 2015
#
# 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
#
(要挂载的设备) (挂载点) 文件系统类型 挂载选项 转储频率(每多少天做一次完全备份) 文件系统检测次序(只有根可以为1)
UUID=57d85756-7680-4c7c-9125-6ad67dae2c45 / ext4 defaults 1 1
UUID=2622a4b4-ddc9-47a3-aa2b-f06bc9bec085 /boot ext4 defaults 1 2
UUID=33d94759-fa01-4c4f-b4ac-bf3a1fe5e84f swap swap defaults 0 0
tmpfs /dev/shm tmpfs defaults 0 0
devpts /dev/pts devpts gid=5,mode=620 0 0
sysfs /sys sysfs defaults 0 0
proc /proc proc defaults 0 0
[root@localhost ~]#
fuser: 验正进程正在使用的文件或套接字文件
-v: 查看某文件上正在运行的进程
-k:
-m
fuser -km MOUNT_POINT:终止正在访问此挂载点的所有进程
linux系统--free,交换分区,mkswap,swapon,swapoff,dd,自动挂载,fuser