Jump to content

User:Slashme/TIFU

From Wikipedia, the free encyclopedia

My screwup:

   root@davelaptop:/home/david# fdisk -l
   
   Disk /dev/sda: 298.1 GiB, 320072933376 bytes, 625142448 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
   Disklabel type: dos
   Disk identifier: 0xae09ff0b
   
   Device     Boot Start       End   Sectors   Size Id Type
   /dev/sda1  *     2048 625139711 625137664 298.1G  7 HPFS/NTFS/exFAT
   
   Disk /dev/sdb: 7.5 GiB, 8019509248 bytes, 15663104 sectors
   Units: sectors of 1 * 512 = 512 bytes
   Sector size (logical/physical): 512 bytes / 512 bytes
   I/O size (minimum/optimal): 512 bytes / 512 bytes
   Disklabel type: dos
   Disk identifier: 0x0006f36d
   
   Device     Boot   Start      End  Sectors  Size Id Type
   /dev/sdb1  *       2048  2287615  2285568  1.1G 83 Linux
   /dev/sdb2       2287616 15663103 13375488  6.4G 83 Linux
   
   Disk /dev/sdc: 931.5 GiB, 1000204886016 bytes, 1953525168 sectors
   Units: sectors of 1 * 512 = 512 bytes
   Sector size (logical/physical): 512 bytes / 512 bytes
   I/O size (minimum/optimal): 512 bytes / 512 bytes
   Disklabel type: dos
   Disk identifier: 0x7c46eeab
   
   Device     Boot      Start        End    Sectors   Size Id Type
   /dev/sdc1        208982016 1933043711 1724061696 822.1G  7 HPFS/NTFS/exFAT
   /dev/sdc2  *          2048    3905535    3903488   1.9G 83 Linux
   /dev/sdc3       1933043712 1953523711   20480000   9.8G 82 Linux swap / Solaris
   /dev/sdc4          3907582  208982015  205074434  97.8G  5 Extended
   /dev/sdc5          3907584  208982015  205074432  97.8G 83 Linux
   
   Partition table entries are not in disk order.
   root@davelaptop:/home/david# dd if=/mnt/big/debian-live-8.2.0-amd64-cinnamon-desktop.iso of=/dev/sdc  bs=4M; sync
   ^C54+0 records in
   53+0 records out
   222298112 bytes (222 MB) copied, 2.93226 s, 75.8 MB/s
   

The fix:

First, zero the start of the disk, or nothing will work right:

   dd if=/dev/zero of=/dev/sdc ibs=1MiB count=1
   1+0 records in
   2048+0 records out
   1048576 bytes (1.0 MB) copied, 0.0544217 s, 19.3 MB/s
   

Next, recreate the partition table:

   root@davelaptop:/media/david/7d9d33d0-3269-49ae-8bca-a67701d8f019/backup# parted /dev/sdc
   GNU Parted 3.2
   Using /dev/sdc
   Welcome to GNU Parted! Type 'help' to view a list of commands.
   (parted) print                                                            
   Error: /dev/sdc: unrecognised disk label
   Model: TOSHIBA External USB 3.0 (scsi)                                    
   Disk /dev/sdc: 1000GB
   Sector size (logical/physical): 512B/512B
   Partition Table: unknown
   Disk Flags: 
   (parted) mklabel msdos                                                    
   Error: Partition(s) 1, 3, 5 on /dev/sdc have been written, but we have been unable to inform the kernel of the change, probably because
   it/they are in use.  As a result, the old partition(s) will remain in use.  You should reboot now before making further changes.
   Ignore/Cancel? ignore                                                     
   (parted) mkpart primary 208982016s 1933043711s                            
   Error: Partition(s) 3, 5 on /dev/sdc have been written, but we have been unable to inform the kernel of the change, probably because
   it/they are in use.  As a result, the old partition(s) will remain in use.  You should reboot now before making further changes.
   Ignore/Cancel? ignore                                                     
   (parted) mkpart primary 2048s 3905535s
   Error: Partition(s) 3, 5 on /dev/sdc have been written, but we have been unable to inform the kernel of the change, probably because
   it/they are in use.  As a result, the old partition(s) will remain in use.  You should reboot now before making further changes.
   Ignore/Cancel? ignore                                                     
   (parted) mkpart primary 1933043712s 1953523711s                           
   Error: Partition(s) 5 on /dev/sdc have been written, but we have been unable to inform the kernel of the change, probably because
   it/they are in use.  As a result, the old partition(s) will remain in use.  You should reboot now before making further changes.
   Ignore/Cancel? ignore                                                     
   (parted) print                                                            
   Model: TOSHIBA External USB 3.0 (scsi)
   Disk /dev/sdc: 1000GB
   Sector size (logical/physical): 512B/512B
   Partition Table: msdos
   Disk Flags: 
   
   Number  Start   End     Size    Type     File system  Flags
    2      1049kB  2000MB  1999MB  primary               lba
    1      107GB   990GB   883GB   primary               lba
    3      990GB   1000GB  10.5GB  primary               lba
   
   (parted) quit                                                             
   Information: You may need to update /etc/fstab.
   
   root@davelaptop:/media/david/7d9d33d0-3269-49ae-8bca-a67701d8f019/backup# fdisk /dev/sdc
   
   Welcome to fdisk (util-linux 2.25.2).
   Changes will remain in memory only, until you decide to write them.
   Be careful before using the write command.
   
   
   Command (m for help): p
   Disk /dev/sdc: 931.5 GiB, 1000204886016 bytes, 1953525168 sectors
   Units: sectors of 1 * 512 = 512 bytes
   Sector size (logical/physical): 512 bytes / 512 bytes
   I/O size (minimum/optimal): 512 bytes / 512 bytes
   Disklabel type: dos
   Disk identifier: 0xb657c75b
   
   Device     Boot      Start        End    Sectors   Size Id Type
   /dev/sdc1        208982016 1933043711 1724061696 822.1G 83 Linux
   /dev/sdc2             2048    3905535    3903488   1.9G 83 Linux
   /dev/sdc3       1933043712 1953523711   20480000   9.8G 83 Linux
   
   Partition table entries are not in disk order.
   
   Command (m for help): d
   Partition number (1-3, default 3): 1
   
   Partition 1 has been deleted.
   
   Command (m for help): d
   Partition number (2,3, default 3): 
   
   Partition 3 has been deleted.
   
   Command (m for help): d
   Selected partition 2
   Partition 2 has been deleted.
   
   Command (m for help): p
   Disk /dev/sdc: 931.5 GiB, 1000204886016 bytes, 1953525168 sectors
   Units: sectors of 1 * 512 = 512 bytes
   Sector size (logical/physical): 512 bytes / 512 bytes
   I/O size (minimum/optimal): 512 bytes / 512 bytes
   Disklabel type: dos
   Disk identifier: 0xb657c75b
   
   
   
   Command (m for help): n
   Partition type
      p   primary (0 primary, 0 extended, 4 free)
      e   extended (container for logical partitions)
   Select (default p):  
   
   Using default response p.
   Partition number (1-4, default 1): 
   First sector (2048-1953525167, default 2048): 
   Last sector, +sectors or +size{K,M,G,T,P} (2048-1953525167, default 1953525167): 
   
   Created a new partition 1 of type 'Linux' and of size 931.5 GiB.
   
   Command (m for help): q
   
   root@davelaptop:/media/david/7d9d33d0-3269-49ae-8bca-a67701d8f019/backup# parted /dev/sdc
   GNU Parted 3.2
   Using /dev/sdc
   Welcome to GNU Parted! Type 'help' to view a list of commands.
   (parted) print                                                            
   Model: TOSHIBA External USB 3.0 (scsi)
   Disk /dev/sdc: 1000GB
   Sector size (logical/physical): 512B/512B
   Partition Table: msdos
   Disk Flags: 
   
   Number  Start   End     Size    Type     File system     Flags
    2      1049kB  2000MB  1999MB  primary  ext4
    1      107GB   990GB   883GB   primary  ntfs
    3      990GB   1000GB  10.5GB  primary  linux-swap(v1)
   
   (parted) mkpart extended 3907582s 208982015s                              
   Warning: The resulting partition is not properly aligned for best performance.
   Ignore/Cancel? ignore                                                     
   Error: Partition(s) 5 on /dev/sdc have been written, but we have been unable to inform the kernel of the change, probably because
   it/they are in use.  As a result, the old partition(s) will remain in use.  You should reboot now before making further changes.
   Ignore/Cancel? ignore                                                     
   (parted) print                                                            
   Model: TOSHIBA External USB 3.0 (scsi)
   Disk /dev/sdc: 1000GB
   Sector size (logical/physical): 512B/512B
   Partition Table: msdos
   Disk Flags: 
   
   Number  Start   End     Size    Type      File system     Flags
    2      1049kB  2000MB  1999MB  primary   ext4
    4      2001MB  107GB   105GB   extended                  lba
    1      107GB   990GB   883GB   primary   ntfs
    3      990GB   1000GB  10.5GB  primary   linux-swap(v1)
   
   (parted) mkpart logical 3907584s 208982015s                               
   (parted) print                                                            
   Model: TOSHIBA External USB 3.0 (scsi)
   Disk /dev/sdc: 1000GB
   Sector size (logical/physical): 512B/512B
   Partition Table: msdos
   Disk Flags: 
   
   Number  Start   End     Size    Type      File system     Flags
    2      1049kB  2000MB  1999MB  primary   ext4
    4      2001MB  107GB   105GB   extended                  lba
    5      2001MB  107GB   105GB   logical                   lba
    1      107GB   990GB   883GB   primary   ntfs
    3      990GB   1000GB  10.5GB  primary   linux-swap(v1)
   
   (parted) quit                                                             
   Information: You may need to update /etc/fstab.
   
   root@davelaptop:/media/david/7d9d33d0-3269-49ae-8bca-a67701d8f019/backup# fdisk /dev/sdc
   
   Welcome to fdisk (util-linux 2.25.2).
   Changes will remain in memory only, until you decide to write them.
   Be careful before using the write command.
   
   
   Command (m for help): p
   Disk /dev/sdc: 931.5 GiB, 1000204886016 bytes, 1953525168 sectors
   Units: sectors of 1 * 512 = 512 bytes
   Sector size (logical/physical): 512 bytes / 512 bytes
   I/O size (minimum/optimal): 512 bytes / 512 bytes
   Disklabel type: dos
   Disk identifier: 0xb657c75b
   
   Device     Boot      Start        End    Sectors   Size Id Type
   /dev/sdc1        208982016 1933043711 1724061696 822.1G 83 Linux
   /dev/sdc2             2048    3905535    3903488   1.9G 83 Linux
   /dev/sdc3       1933043712 1953523711   20480000   9.8G 83 Linux
   /dev/sdc4          3907582  208982015  205074434  97.8G  f W95 Ext'd (LBA)
   /dev/sdc5          3907584  208982015  205074432  97.8G 83 Linux
   
   Partition table entries are not in disk order.
   
   Command (m for help): a
   Partition number (1-5, default 5): 2
   
   The bootable flag on partition 2 is enabled now.
   
   Command (m for help): t
   Partition number (1-5, default 5): 1
   Hex code (type L to list all codes): 7
   
   Changed type of partition 'Linux' to 'HPFS/NTFS/exFAT'.
   
   Command (m for help): p
   Disk /dev/sdc: 931.5 GiB, 1000204886016 bytes, 1953525168 sectors
   Units: sectors of 1 * 512 = 512 bytes
   Sector size (logical/physical): 512 bytes / 512 bytes
   I/O size (minimum/optimal): 512 bytes / 512 bytes
   Disklabel type: dos
   Disk identifier: 0xb657c75b
   
   Device     Boot      Start        End    Sectors   Size Id Type
   /dev/sdc1        208982016 1933043711 1724061696 822.1G  7 HPFS/NTFS/exFAT
   /dev/sdc2  *          2048    3905535    3903488   1.9G 83 Linux
   /dev/sdc3       1933043712 1953523711   20480000   9.8G 83 Linux
   /dev/sdc4          3907582  208982015  205074434  97.8G  f W95 Ext'd (LBA)
   /dev/sdc5          3907584  208982015  205074432  97.8G 83 Linux
   
   Partition table entries are not in disk order.
   
   Command (m for help): t
   Partition number (1-5, default 5): 3
   Hex code (type L to list all codes): 82
   
   Changed type of partition 'Linux' to 'Linux swap / Solaris'.
   
   Command (m for help): t
   Partition number (1-5, default 5): 4
   Hex code (type L to list all codes): 5
   You cannot change a partition into an extended one or vice versa. Delete it first.
   
   Type of partition 4 is unchanged: W95 Ext'd (LBA).
   
   Command (m for help): d
   Partition number (1-5, default 5): 4
   
   Partition 4 has been deleted.
   
   Command (m for help): p
   Disk /dev/sdc: 931.5 GiB, 1000204886016 bytes, 1953525168 sectors
   Units: sectors of 1 * 512 = 512 bytes
   Sector size (logical/physical): 512 bytes / 512 bytes
   I/O size (minimum/optimal): 512 bytes / 512 bytes
   Disklabel type: dos
   Disk identifier: 0xb657c75b
   
   Device     Boot      Start        End    Sectors   Size Id Type
   /dev/sdc1        208982016 1933043711 1724061696 822.1G  7 HPFS/NTFS/exFAT
   /dev/sdc2  *          2048    3905535    3903488   1.9G 83 Linux
   /dev/sdc3       1933043712 1953523711   20480000   9.8G 82 Linux swap / Solaris
   
   Partition table entries are not in disk order.
   
   Command (m for help): n
   Partition type
      p   primary (3 primary, 0 extended, 1 free)
      e   extended (container for logical partitions)
   Select (default e): e
   
   Selected partition 4
   First sector (3905536-1953525167, default 3905536): 3907582
   Last sector, +sectors or +size{K,M,G,T,P} (3907582-208982015, default 208982015): 
   
   Created a new partition 4 of type 'Extended' and of size 97.8 GiB.
   Command (m for help): p
   Disk /dev/sdc: 931.5 GiB, 1000204886016 bytes, 1953525168 sectors
   Units: sectors of 1 * 512 = 512 bytes
   Sector size (logical/physical): 512 bytes / 512 bytes
   I/O size (minimum/optimal): 512 bytes / 512 bytes
   Disklabel type: dos
   Disk identifier: 0xb657c75b
   
   Device     Boot      Start        End    Sectors   Size Id Type
   /dev/sdc1        208982016 1933043711 1724061696 822.1G  7 HPFS/NTFS/exFAT
   /dev/sdc2  *          2048    3905535    3903488   1.9G 83 Linux
   /dev/sdc3       1933043712 1953523711   20480000   9.8G 82 Linux swap / Solaris
   /dev/sdc4          3907582  208982015  205074434  97.8G  5 Extended
   
   Partition table entries are not in disk order.
   
   Command (m for help): w
   The partition table has been altered.
   
   root@davelaptop:/media/david/7d9d33d0-3269-49ae-8bca-a67701d8f019/backup# 
   root@davelaptop:/media/david/7d9d33d0-3269-49ae-8bca-a67701d8f019/backup# fdisk -l /dev/sdc
   
   Disk /dev/sdc: 931.5 GiB, 1000204886016 bytes, 1953525168 sectors
   Units: sectors of 1 * 512 = 512 bytes
   Sector size (logical/physical): 512 bytes / 512 bytes
   I/O size (minimum/optimal): 512 bytes / 512 bytes
   Disklabel type: dos
   Disk identifier: 0xb657c75b
   
   Device     Boot      Start        End    Sectors   Size Id Type
   /dev/sdc1        208982016 1933043711 1724061696 822.1G  7 HPFS/NTFS/exFAT
   /dev/sdc2  *          2048    3905535    3903488   1.9G 83 Linux
   /dev/sdc3       1933043712 1953523711   20480000   9.8G 82 Linux swap / Solaris
   /dev/sdc4          3907582  208982015  205074434  97.8G  5 Extended
   
   Partition table entries are not in disk order.
   root@davelaptop:/media/david/7d9d33d0-3269-49ae-8bca-a67701d8f019/backup# parted /dev/sdc
   GNU Parted 3.2
   Using /dev/sdc
   Welcome to GNU Parted! Type 'help' to view a list of commands.
   (parted) print                                                            
   Model: TOSHIBA External USB 3.0 (scsi)
   Disk /dev/sdc: 1000GB
   Sector size (logical/physical): 512B/512B
   Partition Table: msdos
   Disk Flags: 
   
   Number  Start   End     Size    Type      File system     Flags
    2      1049kB  2000MB  1999MB  primary   ext4            boot
    4      2001MB  107GB   105GB   extended
    1      107GB   990GB   883GB   primary   ntfs
    3      990GB   1000GB  10.5GB  primary   linux-swap(v1)
   
   (parted) mkpart logical 3907584s 208982015s                               
   (parted) print                                                            
   Model: TOSHIBA External USB 3.0 (scsi)
   Disk /dev/sdc: 1000GB
   Sector size (logical/physical): 512B/512B
   Partition Table: msdos
   Disk Flags: 
   
   Number  Start   End     Size    Type      File system     Flags
    2      1049kB  2000MB  1999MB  primary   ext4            boot
    4      2001MB  107GB   105GB   extended
    5      2001MB  107GB   105GB   logical                   lba
    1      107GB   990GB   883GB   primary   ntfs
    3      990GB   1000GB  10.5GB  primary   linux-swap(v1)
   
   (parted) quit                                                             
   Information: You may need to update /etc/fstab.
   
   root@davelaptop:/media/david/7d9d33d0-3269-49ae-8bca-a67701d8f019/backup# fdisk -l /dev/sdc
   
   Disk /dev/sdc: 931.5 GiB, 1000204886016 bytes, 1953525168 sectors
   Units: sectors of 1 * 512 = 512 bytes
   Sector size (logical/physical): 512 bytes / 512 bytes
   I/O size (minimum/optimal): 512 bytes / 512 bytes
   Disklabel type: dos
   Disk identifier: 0xb657c75b
   
   Device     Boot      Start        End    Sectors   Size Id Type
   /dev/sdc1        208982016 1933043711 1724061696 822.1G  7 HPFS/NTFS/exFAT
   /dev/sdc2  *          2048    3905535    3903488   1.9G 83 Linux
   /dev/sdc3       1933043712 1953523711   20480000   9.8G 82 Linux swap / Solaris
   /dev/sdc4          3907582  208982015  205074434  97.8G  5 Extended
   /dev/sdc5          3907584  208982015  205074432  97.8G 83 Linux
   
   Partition table entries are not in disk order.
   

Now re-install GRUB:

   root@davelaptop:/media/david/7d9d33d0-3269-49ae-8bca-a67701d8f019/backup# mount /boot
   root@davelaptop:/media/david/7d9d33d0-3269-49ae-8bca-a67701d8f019/backup# ls /boot/
   grub  lost+found
   root@davelaptop:/media/david/7d9d33d0-3269-49ae-8bca-a67701d8f019/backup# grub-install ^C
   root@davelaptop:/media/david/7d9d33d0-3269-49ae-8bca-a67701d8f019/backup# grub-install --boot-directory=/boot /dev/sdc
   Installing for i386-pc platform.
   Installation finished. No error reported.

Also ran blkid and used the output to correct /etc/fstab

reinstall kernel:

   root@davelaptop:~# apt-get install --reinstall linux-image-3.16.0-4-amd64
   Reading package lists... Done
   Building dependency tree       
   Reading state information... Done
   0 upgraded, 0 newly installed, 1 reinstalled, 0 to remove and 0 not upgraded.
   Need to get 0 B/33.8 MB of archives.
   After this operation, 0 B of additional disk space will be used.
   Preconfiguring packages ...
   (Reading database ... 204683 files and directories currently installed.)
   Preparing to unpack .../linux-image-3.16.0-4-amd64_3.16.7-ckt20-1+deb8u4_amd64.deb ...
   Unpacking linux-image-3.16.0-4-amd64 (3.16.7-ckt20-1+deb8u4) over (3.16.7-ckt20-1+deb8u4) ...
   Setting up linux-image-3.16.0-4-amd64 (3.16.7-ckt20-1+deb8u4) ...
   /etc/kernel/postinst.d/initramfs-tools:
   update-initramfs: Generating /boot/initrd.img-3.16.0-4-amd64

But still my system didn't boot: it got me to the grub> prompt. I could still boot by typing

   grub> linux (hd0,msdos2)/vmlinuz<tab> root=/dev/sdc5"
   grub> initrd (hd0,msdos2)/initrd<tab>
   grub> boot

<tab> is where I pressed the tab key: grub2 is clever enough to do tab completion!

Even after trying another grub-install, the system still wouldn't boot, but I then did the following:

   #apt-get purge grub-common

to remove all traces of grub2 from my computer, and then

   #apt-get install grub-pc

to do a fresh install of grub2.

Woot! System working!