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?

ubuntuを低メモリマシンに突っ込む手順 ~SSHにcloud-imageを添えてdd~

0
Last updated at Posted at 2026-06-30

はじめに

稀に必要になるので、さくらのVPSを契約している。ただしメモリ1GBのプラン。

Ubuntu Server をISOでインストールする場合のシステム要件は、最低1.5GBのメモリ。
24.04は頑張ればインストールできたが、稀にインストーラーがメモリ不足でクラッシュする。
これが26.04だとかなり高確率でクラッシュしてつらい。

Ubuntu 26.04 amd64において512MB, 1GBプランでは、メモリ容量不足により正常にインストールできない事象を確認しております。(2GBプラン以上が推奨となります)
ディストリビューション公式のシステム要件をご確認うえ、ご利用いただきますようお願いいたします。

スケールアップもあんまりしたくないので、最低要件が1GBであるらしい cloud image を突っ込むことにした。

手順

記事中のデバイス名とかIPアドレスとか固有値はダミーに置き換えているので、環境にあわせて適宜書き換え

イメージファイルの準備

ダウンロード

cloudimgファイルを取得する。今回は ubuntu-26.04-server-cloudimg-amd64.img

残念ながら、さくらのVPSではamd64v3には対応していない模様

変換

取得したイメージはqcow2イメージであるため、これをrawイメージへ変換する。

$ file ubuntu-26.04-server-cloudimg-amd64.img
ubuntu-26.04-server-cloudimg-amd64.img: QEMU QCOW Image (v3), 3758096384 bytes (v3), 3758096384 bytes

$ qemu-img convert -f qcow2 -O raw ubuntu-26.04-server-cloudimg-amd64.img ubuntu-26.04-server-cloudimg-amd64-raw.img

$ file ubuntu-26.04-server-cloudimg-amd64-raw.img
ubuntu-26.04-server-cloudimg-amd64-raw.img: DOS/MBR boot sector, extended partition table (last)

圧縮

イメージファイルをローカルから転送するので、転送時間削減のため気休めにZIP圧縮する。
面倒ならば圧縮を省略してもよいし、別の圧縮形式でもよい。
zipでもgzipでも好きなもので、ddコマンドに流し込むので標準出力で出せる形式とする。

リモートホストの準備

Live OSで起動と設定

使い勝手のよさそうなものを適当に選ぶ。
今回は以下の理由により vyos-2026.03-generic-amd64.iso を用いる。

  • たぶん軽量
  • 個人的にネットワークの設定が楽
  • SSHサービスの起動も楽

SSH接続できて圧縮ファイルの展開ができてddが使えてパーティション操作ができればいい。
systemrescuecdとかでもいいし、さくらが準備しているLinuxのインストールイメージを一覧から選んでもいい。

ネットワーク設定してSSH接続できるところまで準備する。ついでにパケットフィルタを仕掛けておくとか。

書き込み先のディスク(今回は /dev/vda )が空の状態と想定して記述する。

# lsblk /dev/vda
NAME MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS
vda  252:0    0  100G  0 disk

イメージ展開

SSH経由でイメージの書き込み

このコマンドはローカル側で実行する

今回はzip圧縮なので、展開は unzip -p となる。
gz圧縮ならば、 gzip -dc で。

$ cat ubuntu-26.04-server-cloudimg-amd64-raw.img.zip | ssh -t vyos@[RemoteAddress] "sudo unzip -p - | sudo dd of=/dev/vda bs=4M status=progress && sudo sync"
Pseudo-terminal will not be allocated because stdin is not a terminal.
vyos@[RemoteAddress]'s password:
3691347968 bytes (3.7 GB, 3.4 GiB) copied, 40 s, 92.3 MB/s
0+112539 records in
0+112539 records out
3758096384 bytes (3.8 GB, 3.5 GiB) copied, 41.0876 s, 91.5 MB/s

書き込み後のディスク状態確認とパーティションの調整

以降はリモートホストにSSHでログインした状態にてすすめる。

書き込みが正しく完了すれば、4つのパーティションができあがる。

# lsblk /dev/vda
NAME    MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS
vda     252:0    0  100G  0 disk
├─vda1  252:1    0  2.4G  0 part
├─vda13 252:13   0 1023M  0 part
├─vda14 252:14   0    4M  0 part
└─vda15 252:15   0  106M  0 part

# fdisk -l /dev/vda
GPT PMBR size mismatch (7340031 != 209715199) will be corrected by write.
The backup GPT table is not on the end of the device.
Disk /dev/vda: 100 GiB, 107374182400 bytes, 209715200 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 438A498E-DEB2-4F75-8D7A-EB71729FD067

Device       Start     End Sectors  Size Type
/dev/vda1  2324480 7339998 5015519  2.4G Linux root (x86-64)
/dev/vda13    2048 2097152 2095105 1023M Linux extended boot
/dev/vda14 2099200 2107391    8192    4M BIOS boot
/dev/vda15 2107392 2324479  217088  106M EFI System

Partition table entries are not in disk order.

ルートパーティションのサイズが小さいので、これを最大まで拡大しつつ、微妙にパーティションテーブルの不整合が起きているのを修正する。

# parted /dev/vda print
Warning: Not all of the space available to /dev/vda appears to be used, you can fix the GPT to use all of the space (an extra 202375168 blocks) or continue with
the current setting?
Fix/Ignore? Fix

Fix と入れてエンター

Model: Virtio Block Device (virtblk)
Disk /dev/vda: 107GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:

Number  Start   End     Size    File system  Name             Flags
13      1049kB  1074MB  1073MB  ext4                          bls_boot
14      1075MB  1079MB  4194kB                                bios_grub
15      1079MB  1190MB  111MB   fat32                         boot, esp
 1      1190MB  3758MB  2568MB  ext4         cloudimg-rootfs

しかし、VyOSには growpart がなかった。危なっかしいやり方でパーティション1を切りなおす。

# fdisk /dev/vda

Welcome to fdisk (util-linux 2.38.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): d
Partition number (1,13-15, default 15): 1

Partition 1 has been deleted.

Command (m for help): n
Partition number (1-12,16-128, default 1): 1
First sector (34-209715166, default 2324480):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2324480-209715166, default 209713151):

Created a new partition 1 of type 'Linux filesystem' and of size 98.9 GiB.
Partition #1 contains a ext4 signature.

Do you want to remove the signature? [Y]es/[N]o: N

Command (m for help): w

The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

同期・反映・確認

# partprobe /dev/vda

# e2fsck -f /dev/vda1
e2fsck 1.47.0 (5-Feb-2023)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
cloudimg-rootfs: 101925/313600 files (0.0% non-contiguous), 528275/626939 blocks

# resize2fs /dev/vda1
resize2fs 1.47.0 (5-Feb-2023)
Resizing the filesystem on /dev/vda1 to 25923584 (4k) blocks.
The filesystem on /dev/vda1 is now 25923584 (4k) blocks long.

# lsblk /dev/vda
NAME    MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS
vda     252:0    0  100G  0 disk
├─vda1  252:1    0 98.9G  0 part
├─vda13 252:13   0 1023M  0 part
├─vda14 252:14   0    4M  0 part
└─vda15 252:15   0  106M  0 part

システム設定

マウントとchroot

cloudinitのファイル作成のみであればchrootは不要かもしれない。
マウントしてファイルだけ配置してやればいけそうな気がする。
ただ、cloud-init cleanをしなかった場合、初回処理がスキップされてSSHホスト鍵が作成されず、sshdの起動にコケたりする謎。

# mount /dev/vda1 /mnt
# for i in /dev /dev/pts /proc /sys /run; do sudo mount -B $i /mnt$i; done
# chroot /mnt /bin/bash

# cat /etc/os-release
PRETTY_NAME="Ubuntu 26.04 LTS"
NAME="Ubuntu"
VERSION_ID="26.04"
VERSION="26.04 LTS (Resolute Raccoon)"
VERSION_CODENAME=resolute
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=resolute
LOGO=ubuntu-logo

cloud-initによるシステム設定

システム内にファイルを配置する。
cloud-initのファイルは別記事を参考に。
キーボードレイアウトの設定を追加。

ディレクトリと meta-data の作成

# mkdir -p /var/lib/cloud/seed/nocloud-net

# cat << 'EOF' > /var/lib/cloud/seed/nocloud-net/meta-data
instance-id: sakura-vps
local-hostname: sakura
EOF

user-data の作成

# cat << 'EOF' > /var/lib/cloud/seed/nocloud-net/user-data
#cloud-config
timezone: Asia/Tokyo
locale: en_US.utf8
keyboard:
  layout: jp
  model: jp106

apt:
  primary:
    - arches: default
      uri: https://jp.archive.ubuntu.com/ubuntu
  security:
    - arches: default
      uri: https://security.ubuntu.com/ubuntu

package_update: false
package_upgrade: false
package_reboot_if_required: false

users:
- name: sakura-user
  gecos: SAKURA-User
  groups: users, admin
  sudo: ALL=(ALL) ALL
  shell: /bin/bash
  lock_passwd: false
  passwd: $6$THISISSALT$prmsbx3r15NGXhHY7wshZksSVtVjhnk0YcxkSCYo2gzuj.4TC/bZxxMf3dpKwxuFTI1eXJqc7ZKDShsy/Da1S1
  ssh_authorized_keys:
    - ecdsa-sha2-nistp521 AAAA(以下省略)
EOF

network-config の作成

# cat << 'EOF' > /var/lib/cloud/seed/nocloud-net/network-config
network:
    ethernets:
        ens3:
            addresses:
            - 203.0.113.2/24
            - 2001:db8:beef:pork:seed:cafe::2/64
            nameservers:
                addresses:
                - 2001:4860:4860::8888
                - 2001:4860:4860::8844
                - 8.8.8.8
                - 8.8.4.4
                search: []
            routes:
            - to: default
                via: 203.0.113.1
            - to: default
              via: fe80::1 
    version: 2
EOF

パーミッション変更

chmod 600 /var/lib/cloud/seed/nocloud-net/*

状態初期化

cloud-init clean --logs

chrootを終了しシャットダウン

# exit

# for i in /run /sys /proc /dev/pts /dev; do sudo umount /mnt$i; done
# umount /mnt

# poweroff
Are you sure you want to poweroff this system (vyos)? [y/N] y

システム起動と微調整

きっとこれで起動はしてくるはず。
cloud-init で作成したユーザーでログインできるはず。

SSHでログインするときは、LiveCDの鍵が記憶されているので known_hosts から消しておく

状態確認

コンソールとSSHでログインできることと、昇格できることを確認しておく。
パーティションサイズもきちんと拡張されていることを確認しておく。何度か resize2fs を打ち忘れていたため、パーティションサイズの認識が元に戻っていて右往左往した。

立ち上がってさえくれれば、メモリ1GBで動作はまあ問題ない。

# free -h
               total        used        free      shared  buff/cache   available
Mem:           956Mi       170Mi       354Mi       1.9Mi       453Mi       785Mi
Swap:             0B          0B          0B

あとがき

たぶん割とすぐに標準OSへUbuntu 26.04を追加してくれるに違いない。debian 13も追加してくれるに違いない。

追記

されてました。09/14に。

さくらのVPS 標準OS「Ubuntu 26.04」提供開始のお知らせ

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?