R.A. Epigonos et al.

[GNU Parted] parted を使った HDD パーティション作成の自動化

パーティション分割を自動的に行うためには parted を引数を変えながら何度も呼び出す。parted は引数に parted コマンドを取る事ができるため自動化が可能。作成するパーティションテーブルのタイプは GPT、パーティションの reserved block count は 0、フォーマット は ext4。

あとから結果を比較するために、まずはいつもどおり手作業でパーティション作成。

# parted /dev/sdz
GNU Parted 2.3
Using /dev/sdz
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) mklabel gpt
Warning: The existing disk label on /dev/sdz will be destroyed and all data on this disk will be lost. Do you want to continue?
Yes/No? Yes
(parted) unit s
(parted) mkpart primary ext4 2048s -1s
Warning: You requested a partition from 2048s to 5860533167s.
The closest location we can manage is 2048s to 5860533134s.
Is this still acceptable to you?
Yes/No? Yes
(parted) align-check optimal 1
1 aligned
(parted) print
Model: ATA WDC WD30EZRX-00D (scsi)
Disk /dev/sdz: 5860533168s
Sector size (logical/physical): 512B/4096B
Partition Table: gpt

Number  Start  End          Size         File system  Name     Flags
 1      2048s  5860533134s  5860531087s               primary

(parted) quit
Information: You may need to update /etc/fstab.

できたパーティションを parted と fdisk で表示すると以下のようになる。

# parted /dev/sdz -- unit s print
Model: ATA WDC WD30EZRX-00D (scsi)
Disk /dev/sdz: 5860533168s
Sector size (logical/physical): 512B/4096B
Partition Table: gpt

Number  Start  End          Size         File system  Name     Flags
 1      2048s  5860533134s  5860531087s               primary

# fdisk -l /dev/sdz

WARNING: GPT (GUID Partition Table) detected on '/dev/sdz'! The util fdisk doesn't support GPT. Use GNU Parted.


Disk /dev/sdz: 3000.6 GB, 3000592982016 bytes
255 heads, 63 sectors/track, 364801 cylinders, total 5860533168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk identifier: 0x00000000

   Device Boot      Start         End      Blocks   Id  System
/dev/sdz1               1  4294967295  2147483647+  ee  GPT
Partition 1 does not start on physical sector boundary.

スクリプト化した場合は以下。基本的には引数 (parted コマンド) を変えながら何度も parted を呼んでいるだけ。Yes と答えることすらめんどくさければ yes Yes | を for の前につける。ちょっと表示がおかしくなる (ただし結果は一緒) 点が問題。

# for CMD in 'mklabel gpt' 'unit s mkpart primary ext4 2048s -1s' 'align-check optimal 1' 'unit s print' ; do parted --align optimal /dev/sdz -- ${CMD}; done
Warning: The existing disk label on /dev/sdz will be destroyed and all data on this disk will be lost. Do you want to continue?
Yes/No? Yes
Information: You may need to update /etc/fstab.

Warning: You requested a partition from 2048s to 5860533167s.
The closest location we can manage is 2048s to 5860533134s.
Is this still acceptable to you?
Yes/No? Yes
Information: You may need to update /etc/fstab.

1 aligned
Model: ATA WDC WD30EZRX-00D (scsi)
Disk /dev/sdz: 5860533168s
Sector size (logical/physical): 512B/4096B
Partition Table: gpt

Number  Start  End          Size         File system  Name     Flags
 1      2048s  5860533134s  5860531087s               primary

スクリプト化したことでできたパーティションを parted と fdisk で表示すると以下のようになる。手作業と同じ結果が得られている事がわかる。

# parted /dev/sdz -- unit s print
Model: ATA WDC WD30EZRX-00D (scsi)
Disk /dev/sdz: 5860533168s
Sector size (logical/physical): 512B/4096B
Partition Table: gpt

Number  Start  End          Size         File system  Name     Flags
 1      2048s  5860533134s  5860531087s               primary

# fdisk -l /dev/sdz

WARNING: GPT (GUID Partition Table) detected on '/dev/sdz'! The util fdisk doesn't support GPT. Use GNU Parted.


Disk /dev/sdz: 3000.6 GB, 3000592982016 bytes
255 heads, 63 sectors/track, 364801 cylinders, total 5860533168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk identifier: 0x00000000

   Device Boot      Start         End      Blocks   Id  System
/dev/sdz1               1  4294967295  2147483647+  ee  GPT
Partition 1 does not start on physical sector boundary.

あとはいつもどおり ext4 でフォーマットして作成したパーティションの詳細情報、速度計測など。事前に S.M.A.R.T. を使った HDD 温度監視は止めておきます。フォーマットにかかった時間は 4.7 日。

# time mkfs -t ext4 -m 0 -c -c /dev/sdz1
mke2fs 1.42.5 (29-Jul-2012)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
183148544 inodes, 732566385 blocks
0 blocks (0.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=0
22357 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

Testing with pattern 0xaa: done
Reading and comparing: done
Testing with pattern 0x55: done
Reading and comparing: done
Testing with pattern 0xff: done
Reading and comparing: done
Testing with pattern 0x00: done
Reading and comparing: done
Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done


real    6736m30.536s
user    810m28.583s
sys     325m28.504s
# tune2fs -l /dev/sdz1
tune2fs 1.42.5 (29-Jul-2012)
Filesystem volume name:   <none>
Last mounted on:          <not available>
Filesystem UUID:          ********-****-****-****-************
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:    user_xattr acl
Filesystem state:         clean
Errors behavior:          Continue
Filesystem OS type:       Linux
Inode count:              183148544
Block count:              732566385
Reserved block count:     0
Free blocks:              721019563
Free inodes:              183148533
First block:              0
Block size:               4096
Fragment size:            4096
Reserved GDT blocks:      849
Blocks per group:         32768
Fragments per group:      32768
Inodes per group:         8192
Inode blocks per group:   512
Flex block group size:    16
Filesystem created:       ************************
Last mount time:          n/a
Last write time:          ************************
Mount count:              0
Maximum mount count:      -1
Last checked:             ************************
Check interval:           0 (<none>)
Lifetime writes:          137 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:      ********-****-****-****-************
Journal backup:           inode blocks
# hdparm -I /dev/sdz

/dev/sdz:

ATA device, with non-removable media
        Model Number:       WDC WD30EZRX-00D8PB0
        Serial Number:      ***************
        Firmware Revision:  80.00A80
        Transport:          Serial, SATA 1.0a, SATA II Extensions, SATA Rev 2.5, SATA Rev 2.6, SATA Rev 3.0
Standards:
        Supported: 9 8 7 6 5
        Likely used: 9
Configuration:
        Logical         max     current
        cylinders       16383   16383
        heads           16      16
        sectors/track   63      63
        --
        CHS current addressable sectors:   16514064
        LBA    user addressable sectors:  268435455
        LBA48  user addressable sectors: 5860533168
        Logical  Sector size:                   512 bytes
        Physical Sector size:                  4096 bytes
        device size with M = 1024*1024:     2861588 MBytes
        device size with M = 1000*1000:     3000592 MBytes (3000 GB)
        cache/buffer size  = unknown
        Nominal Media Rotation Rate: 5400
Capabilities:
        LBA, IORDY(can be disabled)
        Queue depth: 32
        Standby timer values: spec'd by Standard, with device specific minimum
        R/W multiple sector transfer: Max = 16  Current = 16
        DMA: mdma0 mdma1 mdma2 udma0 udma1 udma2 udma3 udma4 *udma5 udma6
             Cycle time: min=120ns recommended=120ns
        PIO: pio0 pio1 pio2 pio3 pio4
             Cycle time: no flow control=120ns  IORDY flow control=120ns
Commands/features:
        Enabled Supported:
           *    SMART feature set
                Security Mode feature set
           *    Power Management feature set
           *    Write cache
           *    Look-ahead
           *    Host Protected Area feature set
           *    WRITE_BUFFER command
           *    READ_BUFFER command
           *    NOP cmd
           *    DOWNLOAD_MICROCODE
                Power-Up In Standby feature set
           *    SET_FEATURES required to spinup after power up
                SET_MAX security extension
           *    48-bit Address feature set
           *    Device Configuration Overlay feature set
           *    Mandatory FLUSH_CACHE
           *    FLUSH_CACHE_EXT
           *    SMART error logging
           *    SMART self-test
           *    General Purpose Logging feature set
           *    64-bit World wide name
           *    WRITE_UNCORRECTABLE_EXT command
           *    {READ,WRITE}_DMA_EXT_GPL commands
           *    Segmented DOWNLOAD_MICROCODE
           *    Gen1 signaling speed (1.5Gb/s)
           *    Gen2 signaling speed (3.0Gb/s)
           *    Gen3 signaling speed (6.0Gb/s)
           *    Native Command Queueing (NCQ)
           *    Host-initiated interface power management
           *    Phy event counters
           *    NCQ priority information
           *    unknown 76[15]
                DMA Setup Auto-Activate optimization
                Device-initiated interface power management
           *    Software settings preservation
           *    SMART Command Transport (SCT) feature set
           *    SCT LBA Segment Access (AC2)
           *    SCT Features Control (AC4)
           *    SCT Data Tables (AC5)
                unknown 206[12] (vendor specific)
                unknown 206[13] (vendor specific)
                unknown 206[14] (vendor specific)
Security:
        Master password revision code = 65534
                supported
        not     enabled
        not     locked
        not     frozen
        not     expired: security count
                supported: enhanced erase
        436min for SECURITY ERASE UNIT. 436min for ENHANCED SECURITY ERASE UNIT.
Logical Unit WWN Device Identifier: ****************
        NAA             : 5
        IEEE OUI        : ******
        Unique ID       : *********
Checksum: correct
# hdparm -Tt /dev/sdz

/dev/sdz:
 Timing cached reads:   378 MB in  2.00 seconds = 188.93 MB/sec
 Timing buffered disk reads: 230 MB in  3.01 seconds =  76.45 MB/sec
# hdparm -Tt /dev/sdz

/dev/sdz:
 Timing cached reads:   378 MB in  2.01 seconds = 188.23 MB/sec
 Timing buffered disk reads: 242 MB in  3.02 seconds =  80.13 MB/sec
# hdparm -Tt /dev/sdz

/dev/sdz:
 Timing cached reads:   378 MB in  2.00 seconds = 188.74 MB/sec
 Timing buffered disk reads: 242 MB in  3.01 seconds =  80.31 MB/sec
# hdparm -Tt /dev/sdz

/dev/sdz:
 Timing cached reads:   378 MB in  2.01 seconds = 188.44 MB/sec
 Timing buffered disk reads: 184 MB in  3.01 seconds =  61.20 MB/sec
# hdparm -Tt /dev/sdz

/dev/sdz:
 Timing cached reads:   378 MB in  2.01 seconds = 188.42 MB/sec
 Timing buffered disk reads: 242 MB in  3.01 seconds =  80.29 MB/sec

リファレンス

  1. Parted User’s Manual

ソーシャルブックマーク

  1. はてなブックマーク
  2. Google Bookmarks
  3. del.icio.us

ChangeLog

  1. Posted: 2008-06-12T23:58:37+09:00
  2. Modified: 2008-06-12T23:58:37+09:00
  3. Generated: 2023-08-27T23:09:14+09:00