[Tips] Manage Harddisk Partitions

Dedicated for Linux & related opensource software

[Tips] Manage Harddisk Partitions

文章 #1  未閱讀文章PoP » 2012-03-09 06:18

Get partiton info

All harddisks

    fdisk -l
        or
    sfdisk -d

One harddisk

    fdisk -l /dev/sda
        or
    sfdisk -d /dev/sda


Backup partiton table

All harddisks

    sfdisk -d > harddisks_partition_table

One harddisk

    sfdisk -d /dev/sda > sda_partition_table


Restore partiton table

One harddisk

    sfdisk /dev/sda < sda_partition_table


Clone partiton table

Identical harddisks

    sfdisk -d /dev/sda | sfdisk /dev/sdb
當流赤足蹋澗石,水聲激激風吹衣。
人生如此自可樂,豈必局束為人鞿?
頭像
PoP
 
文章: 13620
註冊時間: 2006-12-06 03:42

Re: [Tips] Manage Harddisk Partitions

文章 #2  未閱讀文章PoP » 2012-03-09 06:21

Create identical partition on different brand/model

useful for software raid setup

    1. sfdisk -d /dev/sda > sda_partition_table
    
# partition table of /dev/sda
unit: sectors

/dev/sda1 : start= 63, size= 273042, Id=fd, bootable
/dev/sda2 : start= 273105, size= 15647310, Id=fd

    2. Create new partition with `fdisk /dev/sdb` first, any size will do the trick!

    3. sfdisk -d /dev/sdb > sdb_partition_table
    
# partition table of /dev/sdb
unit: sectors

/dev/sdb1 : start= 63, size= 273042, Id=83

    4. edit sdb_partition_table, delete last partition line for just created partition.

    5. edit sda_partition_table, delete all lines except interested partition line.
    
/dev/sda2 : start= 273105, size= 15647310, Id=fd

    6. Update partition number and the `start=` value as newly created partition on /dev/sdb to reflect actual layout for the to-be created partition, also prevents overwriting existing partition.
    
/dev/sdb1 : start= 63, size= 15647310, Id=fd

    7. append sda_partition_table to sdb_partition_table with `cat sda_partition_table >> sdb_partition_table`
    
# partition table of /dev/sdb
unit: sectors

/dev/sdb1 : start= 63, size= 15647310, Id=fd

    8. sfdisk /dev/sdb < sdb_partition_table
當流赤足蹋澗石,水聲激激風吹衣。
人生如此自可樂,豈必局束為人鞿?
頭像
PoP
 
文章: 13620
註冊時間: 2006-12-06 03:42


回到 Linux

誰在線上

正在瀏覽這個版面的使用者:沒有註冊會員 和 1 位訪客

cron