Creating swap partition in Linux

Time:2021-3-3

Create partition

[[email protected] lohr]# fdisk /dev/sdb
Welcome to fdisk (util Linux 2.23.2).

The changes stay in memory until you decide to write them to disk.
Think twice before using the write command.


Command (enter m for help): P

Disk / dev / SDB: 5368 MB, 5368709120 bytes, 10485760 sectors
Units = sector of 1 * 512 = 512 bytes
Sector size (logical / physical): 512 bytes / 512 bytes
I / O size (minimum / best): 512 bytes / 512 bytes
Disk label type: DOS
Disk identifier: 0x7daa5013

   Device boot start end blocks ID system
/dev/sdb1            2048     4196351     2097152   8e  Linux LVM
Command (enter m for help): M         
Command operation
   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 (enter 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)
Start sector (4196352-10485759, default is 4196352)
The default value of 4196352 will be used
Last sector, + sector or + size {K, m, G} (4196352-10485759, default is 10485759): + 500m
Partition 2 has been set to extended type with a size of 500 MIB

Command (enter m for help): P

Disk / dev / SDB: 5368 MB, 5368709120 bytes, 10485760 sectors
Units = sector of 1 * 512 = 512 bytes
Sector size (logical / physical): 512 bytes / 512 bytes
I / O size (minimum / best): 512 bytes / 512 bytes
Disk label type: DOS
Disk identifier: 0x7daa5013

   Device boot start end blocks ID system
/dev/sdb1            2048     4196351     2097152   8e  Linux LVM
/dev/sdb2         4196352     5220351      512000    5  Extended
Command (enter m for help): n
Partition type:
   p   primary (1 primary, 1 extended, 2 free)
   l   logical (numbered from 5)
Select (default p): l
Add logical partition 5
Starting sector (4198400-5220351, default is 4198400)
The default value of 4198400 will be used
Last sector, + sector or + size {K, m, G} (4198400-5220351, default is 5220351)
The default value of 5220351 will be used
Partition 5 has been set to Linux type with a size of 499 MIB
Command (enter m for help): l

 0 empty 24 NEC DOS 81 MINIX / old Linu BF Solaris        
 1 FAT12 27 hidden NTFS win 82 Linux exchange / so C1 DRDOS / sec (fat-
 2  XENIX root      39  Plan 9          83  Linux           c4  DRDOS/sec (FAT-
 3 XENIX usr 3C PartitionMagic 84 OS / 2 hidden C: C6 DRDOS / sec (fat)-
 FAT16 < 32m 40 venix 80286 85 Linux extension C7 syrinx         
 5 extend 41 PPC prep boot 86 NTFS volume set Da non file system data 
 6 FAT16 42 SFS 87 NTFS volume set DB CP / M / CTOs /
 7 HPFS / NTFS / exFAT 4D qnx4. X 88 Linux plain text de Dell tool      
 8 AIX 4E qnx4. X Part 2 8e Linux LVM DF bootit         
 9 AIX starts 4f qnx4. X Part 3 93 amoeba E1 DOS access       
 A OS / 2 boot manager 50 Ontrack DM 94 amoeba BBT E3 DOS R / O        
 b  W95 FAT32       51  OnTrack DM6 Aux 9f  BSD/OS          e4  SpeedStor      
 C w95 FAT32 (LBA) 52 CP / Ma0 IBM ThinkPad beos FS        
 e  W95 FAT16 (LBA) 53  OnTrack DM6 Aux a5  FreeBSD         ee  GPT            
 F w95 extension (LBA) 54 ontrackdm6 A6 OpenBSD EF EFI (fat-12 / 16)/
10  OPUS            55  EZ-Drive        a7  NeXTSTEP        f0  Linux/PA-RISC  
11 hidden FAT12 56 golden bow A8 Darwin UFS F1 speedstor      
12 Compaq diagnosis 5C Priam edit A9 NetBSD F4 speedstor      
14 hidden FAT16 < 3 61 speedstor AB Darwin starts DOS secondary       
16 hidden FAT16 63 GNU Hurd or sys AF HFS / HFS + FB VMware vmfs    
17 hidden HPFS / NTF 64 Novell Netware B7 bsdi FS FC VMware vmkcore 
18 ast intelligent sleep 65 Novell Netware B8 bsdi swap FD Linux raid automatic
1B hidden w95 fat3 70 disksecure multi boot BB wizard hidden lanstep        
1C hidden w95 fat3 75 PC / IX be Solaris boot FF BBT            
1E hidden w95 FAT1 80 old MINIX       
Command (enter m for help): t
Partition number (1,2,5, default 5)
Hex code (input L to list all codes): 82
Changed the type of partition 'Linux' to 'Linux Swap / Solaris'

Command (enter m for help): P

Disk / dev / SDB: 5368 MB, 5368709120 bytes, 10485760 sectors
Units = sector of 1 * 512 = 512 bytes
Sector size (logical / physical): 512 bytes / 512 bytes
I / O size (minimum / best): 512 bytes / 512 bytes
Disk label type: DOS
Disk identifier: 0x7daa5013

   Device boot start end blocks ID system
/dev/sdb1            2048     4196351     2097152   8e  Linux LVM
/dev/sdb2         4196352     5220351      512000    5  Extended
/dev/sdb5         4198400     5220351      510976   82  Linux swap / Solaris

Command (enter m for help): W
The partition table has been altered!

Calling ioctl() to re-read partition table.
Synchronizing disk.

Register partition with kernel

[[email protected] lohr]# partprobe /dev/sdb

format partition

[email protected]:~# mkswap /dev/sdb5
Setting up swapspace version 1, size = 510972 KiB
no label, UUID=9cdaac7c-7bdc-4309-9ad2-11b466a8429e

View virtual memory status

image

Using virtual memory

[email protected]:~# swapon /dev/sdc5

Check the virtual memory status again

image

mount

image

Recommended Today

Practice analysis of rust built-in trait: partialeq and EQ

Abstract:Rust uses traits in many places, from simple operator overloading to subtle features like send and sync. This article is shared from Huawei cloud community《Analysis of rust built-in trait: partialeq and EQ》Author: debugzhang Rust uses traits in many places, from simple operator overloading to subtle features like send and sync. Some traits can be automatically […]