Skip to main content
Home
The Baheyeldin Dynasty
The journey for wisdom starts with knowledge
  • Home
  • About
  • Site Map
  • Contact

How to upgrade a Linux laptop to a new hard disk

  1. Home

By Khalid on 2015/07/28 - 15:00, last updated 2022/11/16 - 15:16

Recently my laptop hard disk died suddenly, and I had an unused 2.5" laptop disk lying around, so I just put that in, and installed Ubuntu Linux LTS 14.04, then added the packages I needed.

However, using smartmontools, I found out that the not so new disk has unhealthy statistics, and did not want to risk down time on my main computer.

So I decided to be proactive and put a new disk in it. Because I have spend the better part of a day to install what I need, and added to it over the weeks, I did not want to do a fresh install. Rather, I wanted to copy what I have to a new disk. This is a fairly doable process for someone who is familiar with the Linux command line.

I had an older 256GB OCZ Vertex 4 SSD as well, and wanted to use it for faster I/O.

The main tutorial I used was: Migrate Disk in Ubuntu. However, because I am using Grub2, not plain Grub, I found that a few steps need to change.

The article below is how I did all this.

Hardware You Will Need

Because this is a laptop, and there is no room to have another disk in it, get yourself a USB or eSATA disk drive dock or a disk drive enclosure. Those can be helpful for backup in the future, so they are good to have around.

Insert the new disk in the dock/enclosure, and connect it to the host computer. Using dmesg, you will find out the drive letter (e.g. sdb).

Partition The New Hard Disk

First you need to partition the disk the way you want it. There are different schools of thought here, with some wanting /boot on its own partition, /var in another, and /home in a yet another. Others want it simple with everything in one partition. With smaller disks, the latter is more appropriate.

For my purposes, this is a small disk (256GB), so no need for separate partitions. Also, it does not need GPT, nor my laptop support EFI BIOS. So again, keeping things simple with just MS-DOS style partitions, and an MBR.

You can use fdisk, parted, cfdisk, or gdisk, depending on what features you want.

I used fdisk.

fdisk /dev/sdb

Disk /dev/sda: 256.1 GB, 256060514304 bytes
255 heads, 63 sectors/track, 31130 cylinders, total 500118192 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
Disk identifier: 0x00069eac

Device Boot Start End Blocks Id System
/dev/sda1 63 16000739 8000338+ 82 Linux swap / Solaris
/dev/sda2 * 16000740 500118191 242058726 83 Linux

Do not forget to add a swap partition that is at least as large as your RAM size, otherwise hibernate will not work.

Create The File System, and Mount The New Disk

Now, create a new file system on the partition that want the root file system to reside on.

mkfs -t ext4 /dev/sdb2

And then create a directory for the the new disk:

mkdir /mnt/disk2

Mount the new disk's root partition on the new directory:

mount /dev/sdb2 /mnt/disk2

Copy The Old Disk To The New Disk

Now, we need to copy the existing disk to the new disk. It is best if you log out from any desktop GUI that you are in, and do this from a terminal (Alt-F1).

cd /
time find . -xdev -print0 | cpio -pa0V /mnt/disk2

Note that -xdev is required, otherwise special files are copied. For example /proc/kcore is 128TB in size!

Mount Virtual File Systems

In preparation for chroot, we need to map the existing virtual file systems to the new disk.

mount --bind /dev /mnt/disk2/dev
mount --bind /sys /mnt/disk2/sys
mount --bind /proc /mnt/disk2/proc

Change Root

Now we chroot, so the new disk's UUID is used for Grub2.

chroot /mnt/disk2

Grub2

Now, create the new Grub2 configuration:

grub-mkconfig -o /boot/grub/grub.cfg

And then let Grub2 install a new MBR:

grub-install /dev/sdb

Change fstab

Then you need to find out the UUID for the root partition on the new disk. You can use blkid, tune2fs, or simply ls, like so:

ls -l /dev/disk/by-uuid/

lrwxrwxrwx 1 root root 10 Jul 27 22:08 2aca8caa-4ee9-477a-ae1a-7cc0d1f8a6a9 -> ../../sda1
lrwxrwxrwx 1 root root 10 Jul 27 22:34 9f491cf9-5e8d-467f-a1ec-244dead0af49 -> ../../sdb2
lrwxrwxrwx 1 root root 10 Jul 27 22:08 cb79050e-0bd9-49a6-8c4f-a9984dafb1e7 -> ../../sda5

Note the line for sdb2, which is our root partition on the new disk.

You then have to edit the /etc/fstab, and change the UUID for the root device to the above.

Enable Swap

Turn off all swap:

swapoff -a

Initialize swap on the new disk's swap partition:

mkswap /dev/sdb1

Setting up swapspace version 1, size = 8000332 KiB
no label, UUID=b4b6931b-e002-4e93-ab3e-14225b676754

Again, Edit /etc/fstab and change (or add) the above UUID

swapon -a

Reboot With the New Disk

Shutdown the computer, replace the old disk with the new disk, then start the computer.

Everything should be as they are.

Change Swap Partition UUID for Hibernate

For Hibernate functionality to work again, you have to configure the UUID of the Swap partition in a few places, as per this article.

If You Are Booted Into Grub Rescue

If you get booted into Grub2 rescue, then Grub2 did not write a proper MBR.

You can boot using the following Grub Rescue commands:

grub rescue> set prefix=(hd0,1)/boot/grub
grub rescue> set root=(hd0,1)
grub rescue> insmod normal
grub rescue> normal

Login, and use the command:

grub-install /dev/sda

Further Reading

  • Migrate Disk in Ubuntu
  • How to Rescue a non-booting Grub2 on Linux
  • Grub2 Tutorial
  • Ubuntu Swap FAQ
Contents: 
Linux
Tags: 
Grub2
fdisk
gdisk
cfdisk
parted
swap
  • Add comment

Current

Pandemic

  • COVID-19
  • Coronavirus

Search

Site map

Contents

  • Family
    • Khalid
    • Ancestry
    • Extended
  • Friends
  • Nokat نكت
  • Writings
    • Cooking
    • Culture
    • Science
    • History
    • Linguistics
    • Media
    • Literature
    • Politics
    • Humor
    • Terrorism
    • Business
    • Philosophy
    • Religion
    • Children
  • Technology
    • Linux
    • Arabization
    • Drupal
      • Association
    • Software
    • Internet
    • Technology in Society
    • Digital Archeology
    • NCR History
    • MidEast Internet
    • Programming
    • Saudi ISPs
    • Miscellaneous
  • Places
    • Canada
      • Weather
    • Egypt
      • Cuisine
      • Alexandria
      • E.G.C.
    • USA
    • Saudi Arabia
  • Interests
    • Astronomy
    • Fishing
    • Photography
    • Snorkeling
    • Nature
    • Photomicroscopy
  • Miscellany

In Depth

  • al-Hakim bi Amr Allah: Fatimid Caliph of Egypt الحاكم بأمر الله
  • Alexandria, Egypt
  • Arabic on the Internet
  • Articles on the history of Muslims and Arabs in the Iberian Peninsula تاريخ المسلمين و العرب في الأند
  • DIY GOTO Telescope Controller With Autoguiding and Periodic Error Correction
  • E.G.C. English Girls College in Alexandria, Egypt
  • Egyptian Cuisine, Food and Recipes مأكولات مصرية
  • George Saliba: Seeking the Origins of Modern Science?
  • Internet Scams and Fraud
  • Mistaken for an Arab or Muslim: Absurdities of being a victim in the War on Terror
  • Mistaken Identity: How some people confuse my site for others
  • One People's Terrorist Is Another People's Freedom Fighter
  • Overview of Google's Technologies
  • Photomicroscopy
  • Pseudoscience: Lots of it around ...
  • Resources for using Google Adsense with Drupal
  • Rockwood Conservation Area, Southern Ontario
  • Selected Symbolic Novels And Movies
  • Snorkeling the Red Sea near Jeddah
  • Updates and Thoughts on the Egyptian Revolution of 2011

Recent Content

Most recent articles on the site.

  • Origin Of COVID-19: Natural Spillover, Lab Leak Or Biological Weapon?
  • Kamal Salibi and the "Israel from Yemen" theory
  • How To Upgrade HomeAssistant Core In A Python Venv Using uv
  • Ancestry - Paternal Side
  • Review of Wait Water Saver For Whole House Humidifiers
more

Most Comments

Most commented on articles ...

  • Another scam via Craigslist: offering more than asking price
  • Warning to female tourists thinking of marrying Egyptians
  • Craigslist classified for used car: Cheque fraud scam
  • Winning the lottery scam email: World Cup South African lottery
  • Email Scam: BMW 5 Series car and lottery winning
more

About Khalid

Various little bits of information ...

  • Khalid Baheyeldin: brief biography
  • Presentations and Talks
  • Youtube Videos
  • GitHub Projects
  • Drupal.org Profile
  • Astrophotography @ Flickr

Sponsored Links

Your Link Ad Here

Tags

Android Mobile Ubuntu Sony OnStep OpenWRT Router Ericsson COVID-19 Rogers Coronavirus Arabic Kubuntu Home Assistant GSM Telescope tablet Spectrum Scam Python 419 Laptop Firefox DIY CPU Conspiracy Comet Balkanization backup App
More

© Copyright 1999-2025 The Baheyeldin Dynasty. All rights reserved.
You can use our content under the Terms of Use.
Please read our privacy policy before you post any information on this site.
All posted articles and comments are copyright by their owner, and reflect their own views and opinions, which may not necessarily be consistent with the views and opinions of the owners of The Baheyeldin Dynasty.

Web site developed by 2bits.com Inc.