fdisk: with script
2008年10月18日 (shellscript)
fdiskコマンドをスクリプトでできたらいいなと・・
まずは普通にfdisk.
command
# fdisk /dev/sdb The number of cylinders for this disk is set to 3732. 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): d Selected partition 1 Command (m for help): n Command action e extended p primary partition (1-4) p Partition number (1-4): 1 First cylinder (1-3732, default 1): 1 Last cylinder or +size or +sizeM or +sizeK (1-3732, default 3732): +1024M Command (m for help): t Selected partition 1 Hex code (type L to list codes): 83 Command (m for help): a Partition number (1-4): 1 Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. # mkfs.ext3 /dev/sdb1 mke2fs 1.39 (29-May-2006) Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) 125184 inodes, 250032 blocks 12501 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=260046848 8 block groups 32768 blocks per group, 32768 fragments per group 15648 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376 Writing inode tables: done Creating journal (4096 blocks): done Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every 38 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override. # mount -t ext3 /dev/sdb1 /mnt #
流れとしては
fdisk:既存のパーティションを削除→1024Mのパーティションを作成→ファイルシステムはLinux→ブート可にする→テーブルを書き込んでfdisk終了↓
mkfs.ext3:ext3でフォーマット↓
mount:ファイルシステムext3でマウント
という感じ.これをスクリプトで実行したいなと.少々分かりにくいので入力だけ抜き出す.
# fdisk /dev/sdb > d > n > p > 1 > 1 > +1024M > t > 83 > a > 1 > w # mkfs.ext3 /dev/sdb1 # mount -t ext3 /dev/sdb1 /mnt
ぐぐると案外出てきた.上記のことをスクリプトでやろうとすると・・
source
#!/bin/sh #fdisk with shell script USB_FLASHMEMORY=/dev/sdb fdisk $USB_FLASHMEMORY <<\__EOF__ d n p 1 1 +1024M t 83 a 1 w __EOF__ mkfs.ext3 ${USB_FLASHMEMORY}1 mount -t ext3 ${USB_FLASHMEMORY}1 /mnt
っとまぁこんな感じになる.
PR
Comment