swapパーティション作成

swapパーティション作成

hda3を分割してhda4を作り,swapとする。

元々入っているfdisk_2.11yはバグがあるので,fdisk_2.11g-5z_arm.ipkをインストール hdd3のバックアップを取る

# cd /hdd3 
# tar cvf - Documents | gzip -c > docs.tar.gz

hdd3をumountする

# umount /hdd3 

まだアプリが起動している場合は以下のエラーが出る。

umount: /hdd3: Device or resource busy 

その場合はプロセスを探して終了する。

# ps -ef 
UID PID PPID C STIME TTY TIME CMD 
root 1 0 0 13:13 ? 00:00:04 init 
……

自動起動するサーバなどを止めることを忘れずに。

パーティションを切る

# /usr/sbin/fdisk /dev/hda

(フルパスでないと2.11yが起動してしまうので注意)

The number of cylinders for this disk is set to 1949. 
There is nothing wrong with that, but this is larger than 1024, 
and could in certain setups cause problems with: 
1) software that runs at boot time (e.g., old versions of LILO) 
2) booting and partitioning software from other OSs 
(e.g., DOS FDISK, OS/2 FDISK) 

現在のパーティションを確認する。

Command (m for help): p

Disk /dev/hda: 255 heads, 63 sectors, 1949 cylinders 
Units = cylinders of 16065 * 512 bytes 

Device Boot Start End Blocks Id System 
/dev/hda1 1 13 104391 83 Linux 
/dev/hda2 14 263 2008125 83 Linux 
/dev/hda3 264 1949 13542795 c Win95 FAT32 (LBA) 

hdd3のパーティションを削除する。

Command (m for help): d
Partition number (1-4): 3 

hdd3のパーティションが削除されているのが分かる。

Command (m for help): p 

Disk /dev/hda: 255 heads, 63 sectors, 1949 cylinders 
Units = cylinders of 16065 * 512 bytes 

Device Boot Start End Blocks Id System 
/dev/hda1 1 13 104391 83 Linux 
/dev/hda2 14 263 2008125 83 Linux 

hdd3を切り直す。

Command (m for help): n
Command action 
e extended 
p primary partition (1-4) 
p 
Partition number (1-4): 3 
First cylinder (264-1949, default 264): 
Using default value 264 
Last cylinder or +size or +sizeM or +sizeK (264-1949, default 1949): 1924 

新しいhdd3ができているのが分かる。

Command (m for help): p 

Disk /dev/hda: 255 heads, 63 sectors, 1949 cylinders 
Units = cylinders of 16065 * 512 bytes 

Device Boot Start End Blocks Id System 
/dev/hda1 1 13 104391 83 Linux 
/dev/hda2 14 263 2008125 83 Linux 
/dev/hda3 264 1924 13341982+ 83 Linux 

hdd4を作る。容量は適当に192MBにしてみた。

Command (m for help): n
Command action 
e extended 
p primary partition (1-4) 
p 
Partition number (1-4): 4 
First cylinder (1925-1949, default 1925): 
Using default value 1925 
Last cylinder or +size or +sizeM or +sizeK (1925-1949, default 1949): 
Using default value 1949 

新しいhdd4ができているのが分かる。

Command (m for help): p 

Disk /dev/hda: 255 heads, 63 sectors, 1949 cylinders 
Units = cylinders of 16065 * 512 bytes 

Device Boot Start End Blocks Id System 
/dev/hda1 1 13 104391 83 Linux 
/dev/hda2 14 263 2008125 83 Linux 
/dev/hda3 264 1924 13341982+ 83 Linux 
/dev/hda4 1925 1949 200812+ 83 Linux 

hdd4をswapにする。

Command (m for help): t  
Partition number (1-4): 4
Hex code (type L to list codes):82 
Changed system type of partition 4 to 82 (Linux swap) 

hdd4がswapになっているのが分かる。

Command (m for help): p 

Disk /dev/hda: 255 heads, 63 sectors, 1949 cylinders 
Units = cylinders of 16065 * 512 bytes 

Device Boot Start End Blocks Id System 
/dev/hda1 1 13 104391 83 Linux 
/dev/hda2 14 263 2008125 83 Linux 
/dev/hda3 264 1924 13341982+ 83 Linux 
/dev/hda4 1925 1949 200812+ 82 Linux swap 

hdd3はFAT32にする。

Command (m for help): t 
Partition number (1-4): 3 
Hex code (type L to list codes): c 
Changed system type of partition 3 to c (Win95 FAT32 (LBA)) 

hdd3がFAT32になっているのが分かる。

Command (m for help): p 

Disk /dev/hda: 255 heads, 63 sectors, 1949 cylinders 
Units = cylinders of 16065 * 512 bytes 

Device Boot Start End Blocks Id System 
/dev/hda1 1 13 104391 83 Linux 
/dev/hda2 14 263 2008125 83 Linux 
/dev/hda3 264 1924 13341982+ c Win95 FAT32 (LBA) 
/dev/hda4 1925 1949 200812+ 82 Linux swap 

書き込んで終了。

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

Calling ioctl() to re-read partition table. 
Re-read table failed with error 16: Device or resource busy. 
Reboot your system to ensure the partition table is updated. 

WARNING: If you have created or modified any DOS 6.x 
partitions, please see the fdisk manual page for additional 
information. 
Syncing disks. 

というわけでできたか確認。

# /usr/sbin/fdisk -l /dev/hda 

Disk /dev/hda: 255 heads, 63 sectors, 1949 cylinders 
Units = cylinders of 16065 * 512 bytes 

Device Boot Start End Blocks Id System 
/dev/hda1 1 13 104391 83 Linux 
/dev/hda2 14 263 2008125 83 Linux 
/dev/hda3 264 1924 13341982+ c Win95 FAT32 (LBA) 
/dev/hda4 1925 1949 200812+ 82 Linux swap 


hda3とhda4をそれぞれフォーマットする。

# mkdosfs -F32 /dev/hda3
# mkswap /dev/hda4 

エラーが出たら再起動してから再度フォーマットしてみる。

swapを有効にする。

# swapon /dev/hda4 

swapが有効になったかを確認する。

# free 
total used free shared buffers 
Mem: 62044 54004 8040 0 1868 
Swap: 200804 0 200804 
Total: 262848 54004 208844 

/etc/fstabを編集しておく。
最終行に以下を追加。

/dev/hda4 swap swap defaults 0 0 

これでswapon -a,swapoff -aでswapのon/offができる。

swaponを自動化する。
/etc/rc.d/init.d/swapを作成。

# vi /etc/rc.d/init.d/swap 
#!/bin/sh 
swapon -a 

シンボリックリンクを作成。

# ln -s /etc/rc.d/init.d/swap /etc/rc.d/rc5.d/S50swap 

モードを変更しておく。

# cd /etc/rc.d/init.d 
# chmod 775 swap 

再起動してみてswapの自動起動を確認。

$ free 

hdd3のデータを復元する。

# mount -t vfat -o iocharset=utf8,codepage=932 /dev/hdc3 /mnt/cf
# mount -t vfat -o iocharset=utf8,codepage=932 /dev/hda3 /mnt/hda 
# cd /mnt/hda 
# cp -a /mnt/cf/Documents/ . 
# umount /mnt/cf
# umount /mnt/hda

ref

MakiWikiさん
月夜さん( ゚д゚ ) さん
キジモナカズバさん

最終更新:2009年03月29日 01:52