机房的一台新装cento,top发现没有swap分区,看来机房初装系统有问题。
[[email protected] ~]# top top - 18:26:53 up 3:41, 2 users, load average: 0.00, 0.01, 0.05 Tasks: 213 total, 1 running, 212 sleeping, 0 stopped, 0 zombie Cpu(s): 0.0%us, 0.0%sy, 0.0%ni, 99.9%id, 0.1%wa, 0.0%hi, 0.0%si, 0.0%st Mem: 16324896k total, 259328k used, 16065568k free, 5984k buffers Swap: 0k total, 0k used, 0k free, 26932k cached
可以看到,Swap 为 0k
查看该服务器系统盘分区情况:
[[email protected] ~]# parted /dev/sda GNU Parted 2.1 Using /dev/sda Welcome to GNU Parted! Type ‘help‘ to view a list of commands. (parted) p Model: ATA ST33000650NS (scsi) Disk /dev/sda: 3001GB Sector size (logical/physical): 512B/512B Partition Table: gpt Number Start End Size File system Name Flags 1 1049kB 316MB 315MB ext4 2 316MB 4510MB 4194MB raid 3 4510MB 3001GB 2996GB ext4
换一台也是刚安装的服务器对比一下:
[[email protected] ~]# parted /dev/sda GNU Parted 2.1 Using /dev/sda Welcome to GNU Parted! Type ‘help‘ to view a list of commands. (parted) p Model: ATA ST33000650NS (scsi) Disk /dev/sda: 3001GB Sector size (logical/physical): 512B/512B Partition Table: gpt Number Start End Size File system Name Flags 1 1049kB 106MB 105MB ext4 2 106MB 8495MB 8389MB linux-swap(v1) 3 8495MB 3001GB 2992GB ext
看来是第二分区没分区,分区挂载试试
[[email protected] ~]# mkswap /dev/sda2 Setting up swapspace version 1, size = 4095996 KiB no label, UUID=d713cc10-10dc-42d0-b152-c6eecbcd6579 #UUID=d713cc10-10dc-42d0-b152-c6eecbcd6579 [[email protected] ~]# swapon /dev/sda2 [[email protected] ~]# top top - 18:35:24 up 3:49, 2 users, load average: 0.00, 0.01, 0.05 Tasks: 212 total, 1 running, 211 sleeping, 0 stopped, 0 zombie Cpu(s): 0.0%us, 0.1%sy, 0.0%ni, 98.5%id, 1.3%wa, 0.0%hi, 0.0%si, 0.0%st Mem: 16324896k total, 262768k used, 16062128k free, 6100k buffers Swap: 4095996k total, 0k used, 4095996k free, 27000k cached
成功了,Swap: 4095996k total
最后放到/etc/fstab中,确保重启后可正常使用
[[email protected] ~]# cat /etc/fstab UUID=356d4065-9613-490e-a22f-f7c1a7b85d84 / ext4 defaults 1 1 UUID=cb053b9d-9ef8-48e3-8227-683c62d937f6 /boot ext4 defaults 1 2 UUID=d713cc10-10dc-42d0-b152-c6eecbcd6579 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 LABEL=/data2 /data2 ext4 defaults 0 0
时间: 2024-10-11 17:24:04