做这个之前得把之前的分区先删掉
[root@localhost ~]# vim /bin/fdisk.sh
[root@localhost ~]# cat /bin/fdisk.sh
#!/bin/bash
fdisk $1<<end
n
$2
$3
wq
end
[root@localhost ~]# chmod +x /bin/fdisk.sh
[root@localhost ~]# fdisk.sh /dev/vdb p +100M
Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide towrite them.
Be careful before using the write command.
Command (m for help): Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): Partition number (1-4, default1): First sector (2048-20971519, default2048): Usingdefault value 2048
Last sector, +sectors or +size{K,M,G} (2048-20971519, default20971519): Partition 1oftype Linux andof size 100 MiB isset
Command (m for help): The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@localhost ~]# fdisk -l
Disk /dev/vda: 10.7 GB, 10737418240 bytes, 20971520 sectors
Units = sectors of1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x00013f3e
Device Boot Start End Blocks Id System
/dev/vda1 * 20482097033210484142+ 83 Linux
Disk /dev/vdb: 10.7 GB, 10737418240 bytes, 20971520 sectors
Units = sectors of1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x9d727787
Device Boot Start End Blocks Id System
/dev/vdb1 204820684710240083 Linux
建立swap分区
做这个之前得把之前的分区先删掉
[root@localhost ~]# vim /bin/swap.sh
[root@localhost ~]# cat /bin/swap.sh
#!/bin/bash
fdisk $1<<end
n
p
$2
t
$3
wq
end
[root@localhost ~]# chmod +x /bin/swap.sh
[root@localhost ~]# swap.sh /dev/vdb +1G 82
Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide towrite them.
Be careful before using the write command.
Command (m for help): Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): Partition number (1-4, default1): First sector (2048-20971519, default2048): Usingdefault value 2048
Last sector, +sectors or +size{K,M,G} (2048-20971519, default20971519): Partition 1oftype Linux andof size 1 GiB isset
Command (m for help): Selected partition 1
Hex code (type L to list all codes): Changed typeof partition 'Linux'to'Linux swap / Solaris'
Command (m for help): The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@localhost ~]# fdisk -l
Disk /dev/vda: 10.7 GB, 10737418240 bytes, 20971520 sectors
Units = sectors of1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x00013f3e
Device Boot Start End Blocks Id System
/dev/vda1 * 20482097033210484142+ 83 Linux
Disk /dev/vdb: 10.7 GB, 10737418240 bytes, 20971520 sectors
Units = sectors of1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x9d727787
Device Boot Start End Blocks Id System
/dev/vdb1 20482099199104857682 Linux swap / Solaris
[root@localhost ~]#