FastNetMon

Monday 6 September 2010

Как удалить все до единого разделы с диска в Linux?

Итак, имеем сглючивший софт, который сотворил нечто вот такое:
fdisk -l /dev/sda

Disk /dev/sda: 1500.3 GB, 1500301910016 bytes
255 heads, 63 sectors/track, 182401 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x000a44f0

Device Boot Start End Blocks Id System
/dev/sda1 1 523 4199044+ fd Linux raid autodetect
/dev/sda2 524 785 2104515 fd Linux raid autodetect
/dev/sda3 786 1177 3148740 fd Linux raid autodetect
/dev/sda4 1178 182401 1455681780 85 Linux extended
/dev/sda5 1178 1569 3148739+ fd Linux raid autodetect
/dev/sda6 1570 1961 3148739+ fd Linux raid autodetect
/dev/sda7 1962 2353 3148739+ fd Linux raid autodetect
/dev/sda8 2354 2745 3148739+ fd Linux raid autodetect
/dev/sda9 2746 3137 3148739+ fd Linux raid autodetect
/dev/sda10 3138 3529 3148739+ fd Linux raid autodetect
/dev/sda11 3530 3921 3148739+ fd Linux raid autodetect
/dev/sda12 3922 4313 3148739+ fd Linux raid autodetect
/dev/sda13 4314 4705 3148739+ fd Linux raid autodetect
/dev/sda14 4706 5097 3148739+ fd Linux raid autodetect
/dev/sda15 5098 5489 3148739+ fd Linux raid autodetect
/dev/sda16 5490 5881 3148739+ fd Linux raid autodetect
/dev/sda17 5882 6273 3148739+ fd Linux raid autodetect
/dev/sda18 6274 6665 3148739+ fd Linux raid autodetect
/dev/sda19 6666 7057 3148739+ fd Linux raid autodetect
/dev/sda20 7058 7449 3148739+ fd Linux raid autodetect
/dev/sda21 7450 7841 3148739+ fd Linux raid autodetect
/dev/sda22 7842 8233 3148739+ fd Linux raid autodetect
/dev/sda23 8234 8625 3148739+ fd Linux raid autodetect
/dev/sda24 8626 9017 3148739+ fd Linux raid autodetect
/dev/sda25 9018 9409 3148739+ fd Linux raid autodetect
/dev/sda26 9410 9801 3148739+ fd Linux raid autodetect
/dev/sda27 9802 10193 3148739+ fd Linux raid autodetect
/dev/sda28 10194 10585 3148739+ fd Linux raid autodetect
/dev/sda29 10586 10977 3148739+ fd Linux raid autodetect
/dev/sda30 10978 11369 3148739+ fd Linux raid autodetect
/dev/sda31 11370 11761 3148739+ fd Linux raid autodetect
/dev/sda32 11762 12153 3148739+ fd Linux raid autodetect
/dev/sda33 12154 12545 3148739+ fd Linux raid autodetect
/dev/sda34 12546 12937 3148739+ fd Linux raid autodetect
/dev/sda35 12938 13329 3148739+ fd Linux raid autodetect
/dev/sda36 13330 13721 3148739+ fd Linux raid autodetect
/dev/sda37 13722 14113 3148739+ fd Linux raid autodetect
/dev/sda38 14114 14505 3148739+ fd Linux raid autodetect
/dev/sda39 14506 14897 3148739+ fd Linux raid autodetect
/dev/sda40 14898 15289 3148739+ fd Linux raid autodetect
/dev/sda41 15290 15681 3148739+ fd Linux raid autodetect
/dev/sda42 15682 16073 3148739+ fd Linux raid autodetect
/dev/sda43 16074 16465 3148739+ fd Linux raid autodetect
/dev/sda44 16466 16857 3148739+ fd Linux raid autodetect
/dev/sda45 16858 17249 3148739+ fd Linux raid autodetect
/dev/sda46 17250 17641 3148739+ fd Linux raid autodetect
/dev/sda47 17642 18033 3148739+ fd Linux raid autodetect
/dev/sda48 18034 18425 3148739+ fd Linux raid autodetect
/dev/sda49 18426 18817 3148739+ fd Linux raid autodetect
/dev/sda50 18818 19209 3148739+ fd Linux raid autodetect
/dev/sda51 19210 19601 3148739+ fd Linux raid autodetect
/dev/sda52 19602 19993 3148739+ fd Linux raid autodetect
/dev/sda53 19994 20385 3148739+ fd Linux raid autodetect
/dev/sda54 20386 182401 1301393519+ fd Linux raid autodetect

Удалять все это руками - самоубийство. Поэтому требуется автоматизация :) Здесь нам поможет parted:

parted /dev/sda
GNU Parted 1.8.8
Using /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) mklabel
Warning: The existing disk label on /dev/sda will be destroyed and all data on this disk will be lost. Do you want to continue?
Yes/No? Yes
New disk label type? [msdos]?
(parted) quit
Information: You may need to update /etc/fstab.

Вот и все, диск идеально чист:
fdisk -l /dev/sda

Disk /dev/sda: 1500.3 GB, 1500301910016 bytes
255 heads, 63 sectors/track, 182401 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x000a44f0

Device Boot Start End Blocks Id System

По материалам: http://www.virtualvcp.com/linux-technical-guides/125-clearing-a-guid-partition-table-gpt-in-linux

8 comments :

  1. В одну строку это выглядит так:

    parted -s disk.img mklabel msdos

    ReplyDelete
  2. О, еще круче, спасибо :)

    ReplyDelete
  3. fdisk's "o create a new empty DOS partition table"?

    ReplyDelete
  4. Вполне возможно, я лично понятия не имею, как тоже самое сделать в fdisk :)

    ReplyDelete
  5. Command (m for help): m
    Command action
    a toggle a bootable flag
    b edit bsd disklabel
    c toggle the dos compatibility flag
    d delete a partition
    l list known partition types
    m print this menu
    n add a new partition
    o create a new empty DOS partition table

    ReplyDelete
  6. КОгда разделов штук 50 это может утомить :)

    ReplyDelete
  7. Что может утомить? Грохнуть их все одной командой "o", или что?

    ReplyDelete
  8. А, прошу прощения за невнимательность, вижу, ага, вариант :)

    ReplyDelete

Note: only a member of this blog may post a comment.