fedora6にUSB接続でHDDを繋げ新しくLVMでパーティションをきる

はじめに

windows で使ってた HDD を色々な諸事情のため linux で使うことになりました。
備忘録も兼ねて構築したのをメモっときます。

興味ない人すみません。

HDD 接続

USB 接続すると /var/log/message に情報が出力されます。

kernel: USB Mass Storage support registered.
kernel:   Vendor: IC35L120  Model: AVV207-1          Rev: V24O
kernel:   Type:   Direct-Access                      ANSI SCSI revision: 02
kernel: SCSI device sdb: 241254720 512-byte hdwr sectors (123522 MB)
kernel: <font color="red">sdb</font>: Write Protect is off
kernel: <font color="red">sdb</font>: assuming drive cache: write through

こんな感じ。重要なのは赤い文字で囲ったとこ。
家の環境だと /dev/sdb に今繋いだ HDD があるってこと。

パーティション構築

次にパーティションを切りなおそうと fdisk をうつと何故かエラーがでて動かない。

1
$ fdisk /dev/sdb

ファイルシステムは作り直せるのかなと思って作り直した。
そーするとパーティションを切り直せた。解決。
どーやら NTFS のせいで悪さをしてたみたい。

1
2
$ mkfs.ext3 /dev/sdb
$ fdisk /dev/sdb

fdisk の使うコマンド

1
2
3
4
n : 新しくパーティションを切る
t : タイプの変更(LVMにする時はこれを使う)
d : パーティションの削除
p : 既存のパーティションの確認

ざっくりいうとこんな感じ。
詳細はここを見て下さい。

$fdisk /dev/sdb
 
The number of cylinders for this disk is set to 15017.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
   (e.g., DOS FDISK, OS/2 FDISK)
 
Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p  
Partition number (1-4): 1
First cylinder (1-15017, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-15017, default 15017):
Using default value 15017
 
Command (m for help): p
 
Disk /dev/sdb: 123.5 GB, 123522416640 bytes
255 heads, 63 sectors/track, 15017 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
 
   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1       15017   120624021   83  Linux
 
Command (m for help): t
Selected partition 1
Hex code (type L to list codes): 8e
Changed system type of partition 1 to 8e (Linux LVM)
 
Command (m for help): p
 
Disk /dev/sdb: 123.5 GB, 123522416640 bytes
255 heads, 63 sectors/track, 15017 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
 
   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1       15017   120624021   8e  Linux LVM

LVM構築

用語説明 詳細はここ

PV : 物理ボリューム
VG : ボリュームグループ
LV : 論理ボリューム
PE : 物理エクステント

まず PV を作成。

1
2
3
4
5
6
7
8
9
10
11
12
13
$pvcreate /dev/sdb
$pvdisplay /dev/sdb
 
  --- NEW Physical volume ---
  PV Name               /dev/sdb
  VG Name
  PV Size               115.04 GB
  Allocatable           NO
  PE Size (KByte)       0
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               PE1e1K-u67E-JcdK-DjLR-twDV-mqpr-gBzpyW

次に VG を作成。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
$vgcreate [VG名前] /dev/sdb
     -e サイズ(default 4m) : 物理エクステントの大きさを変更
$vgdisplay /dev/sdb
 
  --- Volume group ---
  VG Name               [VG名]
  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               115.04 GB
  PE Size               4.00 MB
  Total PE              29449
  Alloc PE / Size       0 / 0   
  Free  PE / Size       29449 / 115.04 GB
  VG UUID               9gzpCP-O3bX-doFn-gJYR-I0h7-tZ9g-adQ2bd

そして最後に LV を作る。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
$lvcreate -L [サイズ(30G)] -n [LV名] [VG名]
$lvdisplay
 
  --- Logical volume ---
  LV Name                /dev/[VG名]/[LV名]
  VG Name                [VG名]
  LV UUID                PFZ1M8-4zda-veNg-hJVW-7CW9-1Ohz-xjxYVL
  LV Write Access        read/write
  LV Status              available
  # open                 0
  LV Size                80.00 GB
  Current LE             20480
  Segments               1
  Allocation             inherit
  Read ahead sectors     0
  Block device           253:2

LVの名前を変えたい。

1
$lvrename [VG名] [old LV名] [new LV名]

VGの名前を変えたい。

1
2
3
$vgchange -an [old LV名]            #LVを無効にしている
$vgrename [old VG名] [new VG名]
$vgchange -an [new LV名]            #LVを有効にしている

最後にファイルシステムを作成

1
$mkfs.ext3 /dev/[VG名]/[LV名]

あとは mount して使用する。
/etc/fstab に書いとけば再起動しても大丈夫。
ふむ。地味にながくなった。

参考資料

http://pantora.net/pages/linux/lvm/1/
http://pantora.net/pages/linux/lvm/2/
http://pantora.net/pages/linux/lvm/3/

One Response to “fedora6にUSB接続でHDDを繋げ新しくLVMでパーティションをきる”

  1. Supernova » Blog Archive » fstabを書く時は要注意 Says:

    [...] ことの発端は USB の HDD を追加したことです。 前の LVM [...]

Leave a Reply

Trackback URL

Recent Entries