New additions and additions to Linux swap partitions are extended from the network

Source: Internet
Author: User
Tags hex code

Source Network Evil One eyebrow copyright attribution

After installing the Linux system, the swap partition is too small to do, how can I expand the swap partition? There are two ways, one is to create a new swap partition, and one to increase the swap partition. These two methods are described below:

First you must have root authority, the process must be very careful, accidentally destroyed the entire hard disk data, perform the following process before you need to think twice, the consequences of the wrong operation by the performer himself.

Remember!!! Remember!!! Remember!!! Device name letter to the actual input such as/DEV/SDA Sda1/dev/sdb sdb1 sdb2 and so on, or the loss of the data itself is responsible AH "

New Swap partition
1. Enter the console as root and enter

# swapoff-a #停止交换分区

2. Use the FDISK command to add the swap partition's drive letter, (example: # fdisk/dev/sdb) Remove the swap partition, enter D to delete the swap partition, and then n Add the partition (the hard disk must have free space when added, then use T to change the newly added partition ID to Swap type), and finally the operation is actually written to the hard disk with W (the operation is not valid until W is useless).

3. # mkswap/dev/sdb2 #格式化swap分区, the sdb2 here depends on the actual partition device name displayed after you add the P command

4.# SWAPON/DEV/SDB2 #启动新的swap分区

5. In order for the system to start automatically enable the swap partition, you can edit/etc/fstab, add the following line
/DEV/SDB2 swap swap defaults 0 0

6. Complete

Add Swap partition

1. Create a file for the swap partition: increase <?xml:namespace prefix = st1 ns = "Urn:schemas-microsoft-com:office:smarttags"/><?xml: namespace prefix = st1/>1g the size of the swap partition, the command is written as follows, where count equals the desired block size.
# dd If=/dev/zero of=/home/swapfile bs=1m count=1024

2. Set the swap partition file:
# Mkswap/home/swapfile #建立swap的文件系统

3. Enable swap partition files now:
# Swapon/home/swapfile #启用swap文件

4. Make the system self-enabled when booting, add a line in file/etc/fstab:
/home/swapfile swap swap defaults 0 0

5. Complete

***********************************************************************************************************

First method: How to add a swap partition
The implementation is as follows:
1: Check the size of my original swap partition:
Use the Swapon command:
[Email protected]/]# swapon-s
Filename Type Size used priority
/dev/sda3 Partition 522104 0-1

I have an existing swap partition size of 512m*************

2: Add a Swap partition
Using the FDISK command
[Email protected]/]# Fdisk/dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF Disklabel
Building a new DOS disklabel. Changes'll remain in memory only,
Until decide to write them. After that, of course, the previous
Content won ' t be recoverable.

Warning:invalid flag 0x0000 of partition Table 4 would be a corrected by W (rite)

Command (M for help):N
Command Action
E Extended
P primary partition (1-4)
P
Partition number (1-4):1
First cylinder (1-261, default 1):
Using Default value 1
Last cylinder or +size or +sizem or +sizek (1-261, default 261):
Using Default Value 261

Command (M for help):P

disk/dev/sdb:2147 MB, 2147483648 bytes
255 heads, Sectors/track, 261 cylinders
Units = Cylinders of 16065 * 8225280 bytes

Device Boot Start End Blocks Id System
/DEV/SDB1 1 261 2096451 Linux
Command (M for help):T
Selected partition 1
Hex code (type L to list codes):L

0 Empty 1e Hidden W95 FAT1, Minix be Solaris boot
1 FAT12 NEC DOS bayi minix/old Lin BF Solaris
2 Xenix root Plan 9 swap/so C1 drdos/sec (fat-
3 Xenix usr 3c partitionmagic Linux c4 drdos/sec (fat-
4 FAT16 32M Venix 80286 os/2 hidden c:c6 drdos/sec (fat-
5 Extended PPC PReP Boot Linux Extended C7 Syrinx
6 FAT16 SFS, NTFS volume set da non-fs data
7 Hpfs/ntfs 4d qnx4.x NTFS Volume set db cp/m/CTOS/.
8 AIX 4e qnx4.x 2nd part Linux plaintext de Dell Utility
9 AIX Bootable 4f qnx4.x 3rd part 8e Linux LVM DF bootit
A os/2 Boot manag ontrack DM Amoeba E1 DOS Access
b W95 FAT32 Wuyi Ontrack DM6 Aux 94 Amoeba BBT E3 DOS r/o
C W95 FAT32 (LBA) cp/m 9f bsd/os e4 speedstor
E W95 FAT16 (LBA) Ontrack DM6 Aux A0 IBM Thinkpad hi EB BeOS FS
F W95 Ext ' d (LBA) OnTrackDM6 a5 FreeBSD ee EFI GPT
Ten OPUS ez-drive a6 OpenBSD ef EFI (fat-12/16/
One Hidden FAT12 Bow A7 NeXTSTEP f0 linux/pa-risc b
Compaq Diagnost 5c Priam edisk A8 Darwin UFS F1 SpeedStor
Hidden FAT16 speedstor A9 NetBSD f4 SpeedStor
Hidden FAT16, GNU HURD or Sys ab Darwin boot F2 DOS Secondary
Hidden hpfs/ntf Novell Netware b7 BSDI FS FD Linux RAID Auto
AST smartsleep Novell Netware b8 BSDI swap fe lanstep
1b Hidden W95 FAT3 disksecure Mult bb Boot Wizard hid FF BBT
1c Hidden W95 FAT3 Pc/ix
Hex code (type L to list codes):82
Changed system type of partition 1 to (Linux swap)
Command (M for help):P

disk/dev/sdb:2147 MB, 2147483648 bytes
255 heads, Sectors/track, 261 cylinders
Units = Cylinders of 16065 * 8225280 bytes

Device Boot Start End Blocks Id System
/DEV/SDB1 1 261 2096451 for Linux swap#交换分区格式

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

Calling IOCTL () to re-read partition table.
Syncing disks.

The swap partition has been successfully added to completion. ********

3: Format swap swap partition, set up swap file system
Use command: Mkswap
[Email protected]/]# MKSWAP/DEV/SDB1
Setting up Swapspace version 1, size = 2146758 KB
4: Enable swap partition:
Use command: Swapon
[Email protected]/]# SWAPON/DEV/SDB1
5: See if the newly added swap partition exists:
Execute command: Swapon–s
[Email protected]/]# swapon-s
Filename Type Size used priority
/dev/sda3 Partition 522104 0-1
/DEV/SDB1 Partition 2096440 0-2

The red part is the original swap partition size.
The blue section is now the newly added swap partition size.
6: Edit the/etc/fstab file so that the swap partition is enabled at boot time
/DEB/SDB1 swap swap defaults 0 0

New additions and additions to Linux swap partitions are extended from the network

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.