2019年8月22日 星期四

在老舊機器上使用大容量硬碟

2008 年買的 HP 伺服器,好像 BIOS 只能用 MBR,沒辦法用 GPT。可以建立 GPT,但是執行 mkfs.ext4 時,就會出現 I/O error。原來是懷疑 Seagate 的 8TB 硬碟有問題,換成 WD 的 4TB 的 NAS 碟,還是一樣死掉。

後來想到可能是 GPT 的問題,改用 MBR,卻無法建立超過 2TB 的磁區。好吧,那就用 LVM,可是卻只能建2個磁區,第3個就會一直抱怨 overlap。8TB 的硬碟只能用一半的空間,這怎能接受。後來看到 LVM 可以使用整個硬碟,不用建分割區,問題就完全解決。用 dmesg 看系統訊息,也完全不再有 error 的訊息,我本該懺悔,錯怪硬碟了。

但是,隔一晚之後,它還是死了。看看在硬碟上的註記,就能知道對這硬碟已經完全放棄了,而且非常生氣。


使用整顆硬碟來建立 LVM
建立 PV 及 VG

# [root@localhost ~]# pvcreate /dev/sdb
WARNING: dos signature detected on /dev/sdb at offset 510. Wipe it? [y/n]: y
  Wiping dos signature on /dev/sdb.
  Physical volume "/dev/sdb" successfully created.

[root@localhost ~]# vgcreate vg_dspace /dev/sdb
  Volume group "vg_dspace" successfully created
檢視建立的 VG

# vgdisplay vg_dspace
  --- Volume group ---
  VG Name               vg_dspace
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  8
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                1
  Open LV               0
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               <7.28 TiB
  PE Size               4.00 MiB
  Total PE              1907721
  Alloc PE / Size       1887437 / 7.20 TiB
  Free  PE / Size       20284 / 79.23 GiB
  VG UUID               MWcmt5-QcYs-TmOK-yEWD-O5O4-uH4L-vyYuhL
   


G

[root@localhost ~]# lvcreate -L 7.2TB vg_dspace  -n vc_dspace
  Rounding up size to full physical extent 7.20 TiB
  Logical volume "vc_dspace" created.

[root@localhost ~]# mkfs.ext4 /dev/vg_dspace/vc_dspace 
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
241594368 inodes, 1932735488 blocks
96636774 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4081057792
58983 block groups
32768 blocks per group, 32768 fragments per group
4096 inodes per group
Superblock backups stored on blocks: 
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
        4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968, 
        102400000, 214990848, 512000000, 550731776, 644972544

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


G

[root@localhost ~]# lsblk
NAME                  MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda                     8:0    0  1.8T  0 disk 
├─sda1                  8:1    0    1G  0 part /boot
└─sda2                  8:2    0  1.8T  0 part 
  ├─centos-root       253:0    0   50G  0 lvm  /
  ├─centos-swap       253:1    0  6.9G  0 lvm  [SWAP]
  └─centos-home       253:2    0  1.8T  0 lvm  /home
sdb                     8:16   0  7.3T  0 disk 
└─vg_dspace-vc_dspace 253:3    0  7.2T  0 lvm  
sr0                    11:0    1 1024M  0 rom  

   


[root@localhost ~]# lvremove /dev/vg_dspace/vc_dspace
Do you really want to remove active logical volume vg_dspace/vc_dspace? [y/n]: y
  Logical volume "vc_dspace" successfully removed



                           cfdisk (util-linux 2.23.2)

                              Disk Drive: /dev/sdb
                      Size: 4000787030016 bytes, 4000.7 GB
            Heads: 25   Sectors per Track: 3   Cylinders: 104187162

    Name        Flags    Part Type  FS Type          [Label]        Size (MB)
 ------------------------------------------------------------------------------
    sdb1                    Primary   Linux                          2000300.01 
    sdb2                    Primary   Linux                          2000487.03*



partprobe


[[root@localhost ~]# vgdisplay vg_dspace
  --- Volume group ---
  VG Name               vg_dspace
  System ID             
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  3
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                0
  Open LV               0
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               <3.64 TiB
  PE Size               4.00 MiB
  Total PE              953861
  Alloc PE / Size       0 / 0   
  Free  PE / Size       953861 / <3.64 TiB
  VG UUID               aLTwuw-I8Cc-JAhn-2wtB-9UQr-42Td-XuZHLk



[root@localhost ~]# pvcreate /dev/sdb1 /dev/sdb2
  Physical volume "/dev/sdb1" successfully created.
  Physical volume "/dev/sdb2" successfully created.
[root@localhost ~]# vgcreate vg_dspace /dev/sdb1 /dev/sdb2
  Volume group "vg_dspace" successfully created



巨巨
[[root@localhost ~]# lvcreate -L 3.64TB  -n vc_dspace  vg_dspace
  Rounding up size to full physical extent 3.64 TiB
  Volume group "vg_dspace" has insufficient free space (953861 extents): 954205 required.

[root@localhost ~]# lvcreate -L 3.635TB  -n vc_dspace  vg_dspace
  Rounding up size to full physical extent <3.64 TiB
  Logical volume "vc_dspace" created.


[root@localhost ~]# mkfs.ext4 /dev/vg_dspace/vc_dspace 
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
243941376 inodes, 975763456 blocks
48788172 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=3124756480
29778 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, 71663616, 78675968, 
 102400000, 214990848, 512000000, 550731776, 644972544

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information:            
Warning, had trouble writing out superblocks.



[root@localhost ~]# mkfs.ext4 /dev/vg_dspace/vc_dspace 
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
243941376 inodes, 975763456 blocks
48788172 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=3124756480
29778 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, 71663616, 78675968, 
 102400000, 214990848, 512000000, 550731776, 644972544

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information:            
Warning, had trouble writing out superblocks.




[ 1761.247023] sd 4:0:0:0: [sdb] tag#0 CDB: Write(16) 8a 00 00 00 00 00 e8 f1 a9 f0 00 00 02 98 00 00
[ 1761.247030] blk_update_request: I/O error, dev sdb, sector 3908151792
[ 1761.256705] sd 4:0:0:0: [sdb] Read Capacity(16) failed: Result: hostbyte=DID_BAD_TARGET driverbyte=DRIVER_OK
[ 1761.256717] sd 4:0:0:0: [sdb] Sense not available.
[ 1761.257615] sd 4:0:0:0: [sdb] Read Capacity(10) failed: Result: hostbyte=DID_BAD_TARGET driverbyte=DRIVER_OK
[ 1761.257621] sd 4:0:0:0: [sdb] Sense not available.
[ 1761.257790] sdb: detected capacity change from 4000787030016 to 0
[ 1761.545493] VFS: Dirty inode writeback failed for block device dm-3 (err=-5).
[ 1827.839344] scsi_io_completion: 58 callbacks suppressed
[ 1827.839358] sd 4:0:0:0: [sdb] tag#0 FAILED Result: hostbyte=DID_BAD_TARGET driverbyte=DRIVER_OK
[ 1827.839365] sd 4:0:0:0: [sdb] tag#0 CDB: ATA command pass through(16) 85 06 20 00 00 00 00 00 00 00 00 00 00 00 e5 00
[ 1846.090413] sd 4:0:0:0: [sdb] tag#0 FAILED Result: hostbyte=DID_BAD_TARGET driverbyte=DRIVER_OK
[ 1846.090430] sd 4:0:0:0: [sdb] tag#0 CDB: ATA command pass through(16) 85 06 2c 00 00 00 00 00 00 00 00 00 00 00 e5 00
.

後來,先在 3TB 的硬碟上裝好 CentOS 7,然後再用 LVM 擴充硬碟。在舊機器,最多只能支援 3TB 的硬碟。

# vgextend centos /dev/sdb1
umount /home
userdel agee

不支援 xfs
mkfs.ext4 /dev/centos/home
# lvreduce --resize --size 100G /dev/centos/home
# lvcreate -L 3.64TB  -n dspace  centos

修改 /etc/fstab,改用 ext4

useradd -g users -G lp,wheel,audio,cdrom -m john
passwd john

沒有留言:

張貼留言

網誌存檔