OCI の Oracle Linux 9 でスワップメモリ追加やディスク拡張を試してみた

最近は Ubuntu を使う機会が多いのですが、久しぶりに RedHat 系の OS を触りたくなり、OCI 無料インスタンスの Oracle Linux でスワップメモリ追加やディスク拡張を試してみました。

SSH 接続して日本時間に設定

$ ssh [email protected]

$ sudo timedatectl set-timezone Asia/Tokyo

$ date

スワップメモリを増やす

$ free
               total        used        free      shared  buff/cache   available
Mem:          970796      509692      323788        4668      293924      461104
Swap:         970748           0      970748

$ sudo swapoff -a

$ sudo dd if=/dev/zero of=/.swapfile bs=128M count=16 # 2GB

$ sudo mkswap /.swapfile

$ sudo swapon /.swapfile

$ sudo swapon -s

$ free
               total        used        free      shared  buff/cache   available
Mem:          970796      573488       64008         856      493008      397308
Swap:        2097148           0     2097148

ディスク拡張(ルートボリューム拡張)

$ df -h
Filesystem                  Size  Used Avail Use% Mounted on
devtmpfs                    4.0M     0  4.0M   0% /dev
tmpfs                       475M     0  475M   0% /dev/shm
tmpfs                       190M  4.6M  186M   3% /run
/dev/mapper/ocivolume-root   30G   11G   19G  37% /
/dev/mapper/ocivolume-oled   15G  189M   15G   2% /var/oled
/dev/sda2                   2.0G  344M  1.7G  18% /boot
/dev/sda1                   100M  6.3M   94M   7% /boot/efi

$ lsblk
NAME               MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS
sda                  8:0    0  100G  0 disk 
├─sda1               8:1    0  100M  0 part /boot/efi
├─sda2               8:2    0    2G  0 part /boot
└─sda3               8:3    0 44.5G  0 part 
  ├─ocivolume-root 252:0    0 29.5G  0 lvm  /
  └─ocivolume-oled 252:1    0   15G  0 lvm  /var/oled

$ sudo /usr/libexec/oci-growfs

Volume Group: ocivolume
Volume Path: /dev/ocivolume/root
Mountpoint Data     
---------------
          mountpoint: /
              source: /dev/mapper/ocivolume-root
     filesystem type: xfs
         source size: 29.4G
                type: lvm
                size: 29.5G
    physical devices: ['/dev/sda3']
    physical volumes: ['/dev/sda', '/dev/sda']
    partition number: ['3']
   volume group name: ocivolume
   volume group path: /dev/ocivolume/root

Partition dry run expansion "/dev/sda3" succeeded.
CHANGE: partition=3 start=4401152 old: size=93325312 end=97726463 new: size=205314015 end=209715166

Expanding partition /dev/sda3: Confirm?   [y/N] y

Partition expand expansion "/dev/sda3" succeeded.
update-partition set to true
FLOCK: try exec open fd 9, on failure exec exits this program
FLOCK: /dev/sda: obtained exclusive lock
resizing 3 on /dev/sda using resize_sfdisk_gpt
209715200 sectors of 512. total size=107374182400 bytes
## sfdisk --unit=S --dump /dev/sda
label: gpt
label-id: 03BB97DA-6F69-460E-A76C-82C8377A90CF
device: /dev/sda
unit: sectors
first-lba: 34
last-lba: 97727250
sector-size: 512

/dev/sda1 : start=        2048, size=      204800, type=C12A7328-F81F-11D2-BA4B-00A0C93EC93B, uuid=3AF7074E-C0BB-400D-8FC7-E9EC738AA53F, name="EFI System Partition"
/dev/sda2 : start=      206848, size=     4194304, type=0FC63DAF-8483-4772-8E79-3D69D8477DE4, uuid=14BE7023-6C02-4573-8891-9F639B9D936A
/dev/sda3 : start=     4401152, size=    93325312, type=E6D6D379-F507-44C2-A23C-238F2A3DF928, uuid=E700F071-90A5-40BB-8132-52AF688193B7
padding 33 sectors for gpt secondary header
max_end=209715166 tot=209715200 pt_end=97726463 pt_start=4401152 pt_size=93325312
resize of /dev/sda returned 0.
FLOCK: /dev/sda: releasing exclusive lock

CHANGED: partition=3 start=4401152 old: size=93325312 end=97726463 new: size=205314015 end=209715166

Extending /dev/sda3 succeeded.
Device /dev/sda3 extended successfully.
Logical volume /dev/ocivolume/root extended successfully.

$ lsblk
NAME               MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS
sda                  8:0    0  100G  0 disk 
├─sda1               8:1    0  100M  0 part /boot/efi
├─sda2               8:2    0    2G  0 part /boot
└─sda3               8:3    0 97.9G  0 part 
  ├─ocivolume-root 252:0    0 82.9G  0 lvm  /
  └─ocivolume-oled 252:1    0   15G  0 lvm  /var/oled

$ df -h
Filesystem                  Size  Used Avail Use% Mounted on
devtmpfs                    4.0M     0  4.0M   0% /dev
tmpfs                       475M     0  475M   0% /dev/shm
tmpfs                       190M  4.6M  186M   3% /run
/dev/mapper/ocivolume-root   83G   12G   72G  14% /
/dev/mapper/ocivolume-oled   15G  191M   15G   2% /var/oled
/dev/sda2                   2.0G  344M  1.7G  18% /boot
/dev/sda1                   100M  6.3M   94M   7% /boot/efi

SELinux 無効化

$ sudo setenforce 0

$ sudo getenforce

$ sudo sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config

SSH ポート変更

$ sudo sed -i 's/#Port 22/Port 8080/' /etc/ssh/sshd_config

$ sudo firewall-cmd --permanent --zone=public --add-port=8080/tcp

$ sudo firewall-cmd --reload

$ sudo systemctl restart sshd

$ ss -antl

$ sudo reboot

$ ssh -p 8080 [email protected]

タグ: ,