読者です 読者をやめる 読者になる 読者になる

manatee-itの備忘ログ

プログラム初心者のブログ。ruby on railsでWebサービスを作成中。(仕事が忙しくなかななか進まず) つまずいた所をなんでも記録。 環境:Ruby2.1 + Rails4.1.1 + Passenger + CentOS6.4(Apache + sqlite/MySQL)

Partedによるパーティション作成+LVM作成+ファイルシステム作成+マウント処理

インストール時に使い切っていなかったディスク領域にpartedコマンドでパーティション+LVMを作成し、ext4でフォーマットを実施。

環境:CentOS 6.5

パーティション作成 LVM作成 ファイルシステム作成 マウント処理

パーティション作成

[root@CentOS ~]# parted /dev/sda
GNU Parted 2.1
/dev/sda を使用
GNU Parted へようこそ! コマンド一覧を見るには 'help' と入力してください。
(parted) print
モデル: ATA WDC WD5000AAKX-0 (scsi)
ディスク /dev/sda: 500GB
セクタサイズ (論理/物理): 512B/512B
パーティションテーブル: gpt

番号  開始    終了   サイズ  ファイルシステム  名前  フラグ
 1    1049kB  211MB  210MB   ext4                    boot
 2    211MB   108GB  107GB                           lvm

(parted) unit MB
(parted) print
モデル: ATA WDC WD5000AAKX-0 (scsi)
ディスク /dev/sda: 500108MB
セクタサイズ (論理/物理): 512B/512B
パーティションテーブル: gpt

番号  開始    終了      サイズ    ファイルシステム  名前  フラグ
 1    1.05MB  211MB     210MB     ext4                    boot
 2    211MB   107585MB  107374MB                          lvm

(parted) mkpart
パーティションの名前?  []?
ファイルシステムの種類?  [ext2]?
開始? 107585
終了? 500108
警告: WARNING: the kernel failed to re-read the partition table on /dev/sda (デバイスもしくはリソースがビジー状態です).  As a result, it may not reflect all
of your changes until after reboot.
(parted) print
モデル: ATA WDC WD5000AAKX-0 (scsi)
ディスク /dev/sda: 500108MB
セクタサイズ (論理/物理): 512B/512B
パーティションテーブル: gpt

番号  開始      終了      サイズ    ファイルシステム  名前  フラグ
 1    1.05MB    211MB     210MB     ext4                    boot
 2    211MB     107585MB  107374MB                          lvm
 3    107585MB  500108MB  392523MB

(parted) set
パーティション番号? 3
反転するフラグ? lvm
新しい状態?  [on]/off? on
警告: WARNING: the kernel failed to re-read the partition table on /dev/sda (デバイスもしくはリソースがビジー状態です).  As a result, it may not reflect all
of your changes until after reboot.
(parted) print
モデル: ATA WDC WD5000AAKX-0 (scsi)
ディスク /dev/sda: 500108MB
セクタサイズ (論理/物理): 512B/512B
パーティションテーブル: gpt

番号  開始      終了      サイズ    ファイルシステム  名前  フラグ
 1    1.05MB    211MB     210MB     ext4                    boot
 2    211MB     107585MB  107374MB                          lvm
 3    107585MB  500108MB  392523MB                          lvm

(parted) quit

■LVM作成

【PVの作成】

[root@CentOS ~]# pvdisplay
  --- Physical volume ---
  PV Name               /dev/sda2
  VG Name               vg_centos
  PV Size               100.00 GiB / not usable 4.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              25599
  Free PE               0
  Allocated PE          25599
  PV UUID               djfDDx-6Rpo-4X5d-5MeC-YWn0-yONI-Jy8QlI

  "/dev/sda3" is a new physical volume of "365.57 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sda3
  VG Name
  PV Size               365.57 GiB
  Allocatable           NO
  PE Size               0
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               AjNZRX-mMEs-QXkR-2VH8-kRFA-4caI-b1cky6



[root@CentOS ~]# pvcreate /dev/sda3
  Physical volume "/dev/sda3" successfully created
[root@CentOS ~]# pvdisplay
  --- Physical volume ---
  PV Name               /dev/sda2
  VG Name               vg_centos
  PV Size               100.00 GiB / not usable 4.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              25599
  Free PE               0
  Allocated PE          25599
  PV UUID               djfDDx-6Rpo-4X5d-5MeC-YWn0-yONI-Jy8QlI

  "/dev/sda3" is a new physical volume of "365.57 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sda3
  VG Name
  PV Size               365.57 GiB
  Allocatable           NO
  PE Size               0
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               3u11TK-uRB6-j8oe-i77M-JsKj-Jvas-kzJKpN

【VGの作成】

[root@CentOS ~]# vgdisplay
  --- Volume group ---
  VG Name               vg_centos
  System ID
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  3
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               100.00 GiB
  PE Size               4.00 MiB
  Total PE              25599
  Alloc PE / Size       25599 / 100.00 GiB
  Free  PE / Size       0 / 0
  VG UUID               jS4d8e-1Tax-ulu0-41qT-DrlL-hONN-XcpoMh

[root@CentOS ~]# vgcreate vg_virtualbox /dev/sda3
  Volume group "vg_virtualbox" successfully created
[root@CentOS ~]# vgdisplay
  --- Volume group ---
  VG Name               vg_virtualbox
  System ID
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  1
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                0
  Open LV               0
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               365.56 GiB
  PE Size               4.00 MiB
  Total PE              93584
  Alloc PE / Size       0 / 0
  Free  PE / Size       93584 / 365.56 GiB
  VG UUID               A0o3SZ-ziMe-targ-Re2J-F6Ax-jkpb-xnVBqQ

  --- Volume group ---
  VG Name               vg_centos
  System ID
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  3
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               100.00 GiB
  PE Size               4.00 MiB
  Total PE              25599
  Alloc PE / Size       25599 / 100.00 GiB
  Free  PE / Size       0 / 0
  VG UUID               jS4d8e-1Tax-ulu0-41qT-DrlL-hONN-XcpoMh

【LVの作成】  現状で必要な容量のみ作成することにし、他のLVを追加するかそのまま拡張するか後で決めることにした。

[root@CentOS ~]# lvdisplay
  --- Logical volume ---
  LV Path                /dev/vg_centos/LogVol01
  LV Name                LogVol01
  VG Name                vg_centos
  LV UUID                afUoDQ-z5FZ-IvQG-19sy-RgAc-TMH1-DZBnOR
  LV Write Access        read/write
  LV Creation host, time CentOS, 2015-07-05 14:21:10 +0900
  LV Status              available
  # open                 1
  LV Size                96.00 GiB
  Current LE             24575
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0

  --- Logical volume ---
  LV Path                /dev/vg_centos/LogVol00
  LV Name                LogVol00
  VG Name                vg_centos
  LV UUID                opf5WS-n2mV-3X4o-KHN2-v5rP-sbC7-3YWSQj
  LV Write Access        read/write
  LV Creation host, time CentOS, 2015-07-05 14:21:28 +0900
  LV Status              available
  # open                 1
  LV Size                4.00 GiB
  Current LE             1024
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1



[root@CentOS ~]# lvcreate -n /dev/vg_virtualbox/LogVol00 -L 144GB vg_virtualbox
  Logical volume "LogVol00" created
[root@CentOS ~]# lvdisplay
  --- Logical volume ---
  LV Path                /dev/vg_virtualbox/LogVol00
  LV Name                LogVol00
  VG Name                vg_virtualbox
  LV UUID                n5Grvt-rvhF-XY10-SdZL-Hq0M-JVMn-iJ66kV
  LV Write Access        read/write
  LV Creation host, time CentOS, 2015-07-25 23:21:33 +0900
  LV Status              available
  # open                 0
  LV Size                144.00 GiB
  Current LE             36864
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:2

  --- Logical volume ---
  LV Path                /dev/vg_centos/LogVol01
  LV Name                LogVol01
  VG Name                vg_centos
  LV UUID                afUoDQ-z5FZ-IvQG-19sy-RgAc-TMH1-DZBnOR
  LV Write Access        read/write
  LV Creation host, time CentOS, 2015-07-05 14:21:10 +0900
  LV Status              available
  # open                 1
  LV Size                96.00 GiB
  Current LE             24575
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0

  --- Logical volume ---
  LV Path                /dev/vg_centos/LogVol00
  LV Name                LogVol00
  VG Name                vg_centos
  LV UUID                opf5WS-n2mV-3X4o-KHN2-v5rP-sbC7-3YWSQj
  LV Write Access        read/write
  LV Creation host, time CentOS, 2015-07-05 14:21:28 +0900
  LV Status              available
  # open                 1
  LV Size                4.00 GiB
  Current LE             1024
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1

ext4ファイルシステム作成

[root@CentOS ~]# mkfs -t ext4 /dev/vg_virtualbox/LogVol00
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
9437184 inodes, 37748736 blocks
1887436 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
1152 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
        4096000, 7962624, 11239424, 20480000, 23887872

Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 26 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

[root@CentOS ~]# tune2fs -l /dev/vg_virtualbox/LogVol00
tune2fs 1.41.12 (17-May-2010)
Filesystem volume name:   <none>
Last mounted on:          <not available>
Filesystem UUID:          55f40716-75dc-411f-a8ae-ab1ee90720b4
Filesystem magic number:  0xEF53
Filesystem revision #:    1 (dynamic)
Filesystem features:      has_journal ext_attr resize_inode dir_index filetype extent flex_bg sparse_super large_file huge_file uninit_bg dir_nlink extra_isize
Filesystem flags:         signed_directory_hash
Default mount options:    (none)
Filesystem state:         clean
Errors behavior:          Continue
Filesystem OS type:       Linux
Inode count:              9437184
Block count:              37748736
Reserved block count:     1887436
Free blocks:              37108459
Free inodes:              9437173
First block:              0
Block size:               4096
Fragment size:            4096
Reserved GDT blocks:      1015
Blocks per group:         32768
Fragments per group:      32768
Inodes per group:         8192
Inode blocks per group:   512
Flex block group size:    16
Filesystem created:       Sat Jul 25 23:23:53 2015
Last mount time:          n/a
Last write time:          Sat Jul 25 23:24:19 2015
Mount count:              0
Maximum mount count:      26
Last checked:             Sat Jul 25 23:23:53 2015
Check interval:           15552000 (6 months)
Next check after:         Thu Jan 21 23:23:53 2016
Lifetime writes:          2437 MB
Reserved blocks uid:      0 (user root)
Reserved blocks gid:      0 (group root)
First inode:              11
Inode size:               256
Required extra isize:     28
Desired extra isize:      28
Journal inode:            8
Default directory hash:   half_md4
Directory Hash Seed:      041343e4-690e-4af6-945e-5e731ac0076d
Journal backup:           inode blocks


[root@CentOS ~]# tune2fs -c 0 -i 0 /dev/vg_virtualbox/LogVol00
tune2fs 1.41.12 (17-May-2010)
Setting maximal mount count to -1
Setting interval between checks to 0 seconds

[root@CentOS ~]#[root@CentOS ~]# tune2fs -l /dev/vg_virtualbox/LogVol00 |grep -e 'Check interval' -e 'Maximum mount count'
Maximum mount count:      -1
Check interval:           0 (<none>)

■マウント処理

[root@CentOS ~]# mkdir /virtualbox
[root@CentOS ~]# vim /etc/fstab
[root@CentOS ~]# cat /etc/fstab

#
# /etc/fstab
# Created by anaconda on Sun Jul  5 14:24:36 2015
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/vg_centos-LogVol01 /                       ext4    defaults        1 1
UUID=fb09d98f-b893-42ad-a001-f5d1cc343ec4 /boot                   ext4    defaults        1 2
/dev/mapper/vg_virtualbox-LogVol00 /virtualbox                       ext4    defaults        1 3
/dev/mapper/vg_centos-LogVol00 swap                    swap    defaults        0 0
tmpfs                   /dev/shm                tmpfs   defaults        0 0
devpts                  /dev/pts                devpts  gid=5,mode=620  0 0
sysfs                   /sys                    sysfs   defaults        0 0
proc                    /proc                   proc    defaults        0 0
[root@CentOS ~]# mount -a
[root@CentOS ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_centos-LogVol01
                       95G   50G   41G  56% /
tmpfs                 3.8G     0  3.8G   0% /dev/shm
/dev/sda1             190M   64M  117M  36% /boot
/dev/mapper/vg_virtualbox-LogVol00
                      142G   60M  135G   1% /virtualbox
[root@CentOS ~]# ls /virtualbox/
lost+found
[root@CentOS ~]# chown manatee. /virtualbox/
[root@CentOS ~]# ls -ld /virtualbox/
drwxr-xr-x. 5 manatee manatee 4096  7月 25 23:45 2015 /virtualbox/