0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

定時帰る術-Linuxディスク管理とSWAP領域作成(mkfs.xfs、swapコマンド)

Posted at

新しいディスクを追加し、SWAP領域にしようかと思います。
ここで、HDD全部SWAP領域にした例ですが、partedを使ってHDDを分けても同じ考えたです。
また、↓がLVMを使えない方法ですが、LVMバージョンも投稿しようかと思います。

ディスク構成確認

(階層まで表示できるので、見やすい)

[root@mgmt ~]# lsblk
NAME               MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda                  8:0    0   30G  0 disk
  sda1               8:1    0  600M  0 part /boot/efi
  sda2               8:2    0    1G  0 part /boot
  sda3               8:3    0 28.4G  0 part
   rhel_mgmt-root 253:0    0 25.4G  0 lvm  /
   rhel_mgmt-swap 253:1    0    3G  0 lvm  [SWAP]
sr0                 11:0    1 11.3G  0 rom

UUIDやラベル確認などの確認

[root@mgmt tmp]# blkid
/dev/sda1: UUID="470D-267D" BLOCK_SIZE="512" TYPE="vfat" PARTLABEL="EFI System Partition" PARTUUID="9286b5b1-8419-4702-85a7-f2162506e30c"
/dev/sda2: UUID="97a85300-b5d4-4b85-b882-23f2caa3b490" BLOCK_SIZE="512" TYPE="xfs" PARTUUID="46e6ed81-718e-4297-a5cc-ffb20d774a3a"
/dev/sda3: UUID="jqGLGm-PCU5-4x5x-Y3AB-5Vxm-X3QH-G7UyGE" TYPE="LVM2_member" PARTUUID="f05bb69c-a763-4e7a-8aa0-2075291399d6"
/dev/sr0: BLOCK_SIZE="2048" UUID="2022-10-13-06-03-04-00" LABEL="RHEL-8-7-0-BaseOS-x86_64" TYPE="iso9660" PTUUID="2fedb33c" PTTYPE="dos"
/dev/mapper/rhel_mgmt-root: UUID="a1c50de0-70f7-40fa-b392-73c89bc362b9" BLOCK_SIZE="512" TYPE="xfs"
/dev/mapper/rhel_mgmt-swap: UUID="591d8057-6967-493c-9cb1-0a25a4af4ed5" TYPE="swap"

ディスクフォマード

[root@mgmt ~]# mkfs.xfs /dev/sdb
meta-data=/dev/sdb               isize=512    agcount=4, agsize=655360 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=1, sparse=1, rmapbt=0
         =                       reflink=1    bigtime=0 inobtcount=0
data     =                       bsize=4096   blocks=2621440, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0, ftype=1
log      =internal log           bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
Discarding blocks...Done.

ラベルを付ける

[root@mgmt ~]# xfs_admin -L snow-swap /dev/sdb
writing all SBs
new label = "snow-swap"

ディスクラベル確認

[root@mgmt ~]# xfs_admin -l /dev/sdb
label = "snow-swap"

swap容量確認(容量が表示されるなら、有効されると見受け)

[root@mgmt ~]# free -h
              total        used        free      shared  buff/cache   available
Mem:          3.8Gi       712Mi       1.8Gi       8.0Mi       1.4Gi       2.9Gi
Swap:         3.0Gi          0B       3.0Gi

↓でも確認できる(cat /proc/swapsと同じ結果)

[root@mgmt ~]# swapon -s
ファイル名                              タイプ          サイズ  使用済み        優先順位
/dev/dm-1                               partition       3145724 0       -2

ラベル指定し、SWAP領域を作成する

[root@mgmt ~]# mkswap -L snow-swap /dev/sdb
mkswap: /dev/sdb: 警告: 古い swap 署名を消去しています。
スワップ空間バージョン 1 を設定します。サイズ = 10 GiB (10737414144 バイト)
LABEL=snow-swap, UUID=149c8dd8-8872-4bca-9632-dcbbb4e7b1e6

SWAP領域「snow-swap」を有効にする

[root@mgmt ~]# swapon LABEL=snow-swap

SWAP領域確認

[root@mgmt ~]# swapon -s
ファイル名                              タイプ          サイズ  使用済み        優先順位
/dev/dm-1                               partition       3145724 0       -2
/dev/sdb                                partition       10485756        0       -3

SWAP容量確認

[root@mgmt ~]# free -h
              total        used        free      shared  buff/cache   available
Mem:          3.8Gi       721Mi       1.8Gi       8.0Mi       1.4Gi       2.9Gi
Swap:          12Gi          0B        12Gi

/etc/fstab編集

[root@mgmt ~]# cat /etc/fstab
/dev/mapper/rhel_mgmt-root /                       xfs     defaults        0 0
UUID=97a85300-b5d4-4b85-b882-23f2caa3b490 /boot                   xfs     defaults        0 0
UUID=470D-267D          /boot/efi               vfat    umask=0077,shortname=winnt 0 2
/dev/mapper/rhel_mgmt-swap none                    swap    defaults        0 0
LABEL=snow-swap swap swap defaults 0 0

OSを再起動し、SWAP容量確認

[root@mgmt ~]# reboot
[root@mgmt ~]#
[root@mgmt ~]# free -h
total used free shared buff/cache available
Mem: 3.8Gi 425Mi 2.9Gi 8.0Mi 498Mi 3.2Gi
Swap: 12Gi 0B 12Gi

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?