Just another IT site ※IT系の記事は当方環境での実施内容となるため実施する場合は自己責任でお願いいたします。At Your Own Risk!! TURN BACK WHILE YOU CAN
PR

新人Linux研修用⑧ Hyper-V上のLinuxにディスクを追加

※IT系の記事は当方環境での実施内容となるため実施する場合は自己責任でお願いいたします。スクリプトはAI生成のものも多いのでコピー&ペーストの際は文字コードに注意ください!

Hype-Vマネージャーで対象のホストを右クリック⇒設定

SCSIコントローラ⇒ハードドライブ⇒追加

仮想ハードディスク⇒新規⇒次へ

VHDX⇒次へ

容量可変⇒次へ

適当な名前⇒次へ

新しい空の仮想ハードディスクの内容を作成する⇒サイズは練習なので1G⇒次へ

完了

OK

Hyper-VのLinuxを起動

[root@localhost ~]# fdisk -l

Disk /dev/sdb: 1073 MB, 1073741824 bytes, 2097152 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O サイズ (最小 / 推奨): 4096 バイト / 4096 バイト


Disk /dev/sda: 53.7 GB, 53687091200 bytes, 104857600 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O サイズ (最小 / 推奨): 4096 バイト / 4096 バイト
Disk label type: dos
ディスク識別子: 0x00069725

デバイス ブート      始点        終点     ブロック   Id  システム
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200   104857599    51379200   8e  Linux LVM

Disk /dev/mapper/centos-root: 50.5 GB, 50457477120 bytes, 98549760 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O サイズ (最小 / 推奨): 4096 バイト / 4096 バイト


Disk /dev/mapper/centos-swap: 2147 MB, 2147483648 bytes, 4194304 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O サイズ (最小 / 推奨): 4096 バイト / 4096 バイト

[root@localhost ~]# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0xbb370612.

The device presents a logical sector size that is smaller than
the physical sector size. Aligning to a physical sector (or optimal
I/O) size boundary is recommended, or performance may be impacted.

コマンド (m でヘルプ): p

Disk /dev/sdb: 1073 MB, 1073741824 bytes, 2097152 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O サイズ (最小 / 推奨): 4096 バイト / 4096 バイト
Disk label type: dos
ディスク識別子: 0xbb370612

デバイス ブート      始点        終点     ブロック   Id  システム

コマンド (m でヘルプ): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
パーティション番号 (1-4, default 1):
最初 sector (2048-2097151, 初期値 2048):
初期値 2048 を使います
Last sector, +sectors or +size{K,M,G} (2048-2097151, 初期値 2097151):
初期値 2097151 を使います
Partition 1 of type Linux and of size 1023 MiB is set

コマンド (m でヘルプ): t
Selected partition 1
Hex code (type L to list all codes): l

 0  空              24  NEC DOS         81  Minix / 古い Li bf  Solaris
 1  FAT12           27  Hidden NTFS Win 82  Linux スワップ  c1  DRDOS/sec (FAT-
 2  XENIX root      39  Plan 9          83  Linux           c4  DRDOS/sec (FAT-
 3  XENIX usr       3c  PartitionMagic  84  OS/2 隠し C: ド c6  DRDOS/sec (FAT-
 4  FAT16 <32M      40  Venix 80286     85  Linux 拡張領域  c7  Syrinx
 5  拡張領域        41  PPC PReP Boot   86  NTFS ボリューム da  非 FS データ
 6  FAT16           42  SFS             87  NTFS ボリューム db  CP/M / CTOS / .
 7  HPFS/NTFS/exFAT 4d  QNX4.x          88  Linux プレーン  de  Dell ユーティリ
 8  AIX             4e  QNX4.x 2nd part 8e  Linux LVM       df  BootIt
 9  AIX ブート可能  4f  QNX4.x 3rd part 93  Amoeba          e1  DOS access
 a  OS/2 ブートマネ 50  OnTrack DM      94  Amoeba BBT      e3  DOS R/O
 b  W95 FAT32       51  OnTrack DM6 Aux 9f  BSD/OS          e4  SpeedStor
 c  W95 FAT32 (LBA) 52  CP/M            a0  IBM Thinkpad ハ eb  BeOS fs
 e  W95 FAT16 (LBA) 53  OnTrack DM6 Aux a5  FreeBSD         ee  GPT
 f  W95 拡張領域 (L 54  OnTrackDM6      a6  OpenBSD         ef  EFI (FAT-12/16/
10  OPUS            55  EZ-Drive        a7  NeXTSTEP        f0  Linux/PA-RISC
11  隠し FAT12      56  Golden Bow      a8  Darwin UFS      f1  SpeedStor
12  Compaq 診断     5c  Priam Edisk     a9  NetBSD          f4  SpeedStor
14  隠し FAT16 <32M 61  SpeedStor       ab  Darwin ブート   f2  DOS セカンダリ
16  隠し FAT16      63  GNU HURD または af  HFS / HFS+      fb  VMware VMFS
17  隠し HPFS/NTFS  64  Novell Netware  b7  BSDI fs         fc  VMware VMKCORE
18  AST SmartSleep  65  Novell Netware  b8  BSDI スワップ   fd  Linux raid 自動
1b  隠し W95 FAT32  70  DiskSecure Mult bb  隠し Boot Wizar fe  LANstep
1c  隠し W95 FAT32  75  PC/IX           be  Solaris ブート  ff  BBT
1e  隠し W95 FAT16  80  古い Minix
Hex code (type L to list all codes): 83
Changed type of partition 'Linux' to 'Linux'

コマンド (m でヘルプ): w
パーティションテーブルは変更されました!

ioctl() を呼び出してパーティションテーブルを再読込みします。
ディスクを同期しています。
[root@localhost ~]# fdisk /dev/sdb

The device presents a logical sector size that is smaller than
the physical sector size. Aligning to a physical sector (or optimal
I/O) size boundary is recommended, or performance may be impacted.
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


コマンド (m でヘルプ): p

Disk /dev/sdb: 1073 MB, 1073741824 bytes, 2097152 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O サイズ (最小 / 推奨): 4096 バイト / 4096 バイト
Disk label type: dos
ディスク識別子: 0xbb370612

デバイス ブート      始点        終点     ブロック   Id  システム
/dev/sdb1            2048     2097151     1047552   83  Linux

コマンド (m でヘルプ): q

[root@localhost ~]# mkfs.ext3 /dev/sdb1
mke2fs 1.42.9 (28-Dec-2013)
Discarding device blocks: done
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
65536 inodes, 261888 blocks
13094 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=268435456
8 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376

Allocating group tables: done
Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done

[root@localhost ~]# cd /mnt
[root@localhost mnt]# mkdir sdb1
[root@localhost mnt]# mount /dev/sdb1 /mnt/sdb1
[root@localhost mnt]# df -h
ファイルシス            サイズ  使用  残り 使用% マウント位置
devtmpfs                  453M     0  453M    0% /dev
tmpfs                     464M     0  464M    0% /dev/shm
tmpfs                     464M  6.8M  457M    2% /run
tmpfs                     464M     0  464M    0% /sys/fs/cgroup
/dev/mapper/centos-root    47G  1.6G   46G    4% /
/dev/sda1                1014M  228M  787M   23% /boot
tmpfs                      93M     0   93M    0% /run/user/0
/dev/sdb1                 991M  1.3M  939M    1% /mnt/sdb1
[root@localhost mnt]# cd /mnt/sdb1
[root@localhost sdb1]# touch a
[root@localhost sdb1]# ll
合計 16
-rw-r--r--. 1 root root     0  8月  1 22:08 a
drwx------. 2 root root 16384  8月  1 22:08 lost+found
[root@localhost sdb1]# cd
[root@localhost ~]# umount /mnt/sdb1/
[root@localhost ~]# df -h
ファイルシス サイズ 使用 残り 使用% マウント位置
devtmpfs 453M 0 453M 0% /dev
tmpfs 464M 0 464M 0% /dev/shm
tmpfs 464M 6.8M 457M 2% /run
tmpfs 464M 0 464M 0% /sys/fs/cgroup
/dev/mapper/centos-root 47G 1.6G 46G 4% /
/dev/sda1 1014M 228M 787M 23% /boot
tmpfs 93M 0 93M 0% /run/user/0

OS起動時の自動マウント設定

vi /etc/fstab
/dev/sdb1                    /mnt/sdb1   ext3 defaults        0 0 

 

 

タイトルとURLをコピーしました