A situation that may occur is to realize that a laptop’s hard drive is too small for one’s needs.

Unfortunately, laptops don’t have space to hold a second hard drive, so usually people resort to cumbersome solutions such as an additional external USB flash disk.  This unfortunately comes with the burden of having to carry around another piece of equipment.

However, there is a solution: just replace your laptop’s main hard disk with a larger one.  We recently tinkered with a Fedora 23 laptop to increase the drive from 128 to 256 Gb, and added the new free space to the encrypted /home partition. Here’s how to do that.

Note: For some of these steps you’ll need another machine, a desktop computer running any distribution of Linux.

1. Buy a new hard disk of the desired size. Make sure it is compatible with your laptop and fits into it.

2. Remove the old hard disk from your laptop.

3. Attach the two hard disks via standard SATA cables to the desktop computer, and power it on.

4. Ensure that the hard disks are recognized by the OS:


The output of the command must show the two devices. For the sake of our example, let’s say that /dev/sda is the old hard disk and /dev/sdb is the new, larger hard disk.

5. Copy the content of the old hard disk into the new one:

cat /dev/sda > /dev/sdb

This might surprise you, as you probably learnt that the cat command must be used with text files, and byte-per-byte copies are done via the dd command (dd if=/dev/sda of=/dev/sdb bs=64K). However, in all recent versions of Linux cat is perfectly able to handle binary streams; you can try this for yourself by using it to copy a binary file, for instance an image (cat image.jpg > image2.jpg), and then by comparing the two files.

The advantage of cat is that it will automatically choose an optimized value for the blocksize while it’s cloning the hard disk, while dd requires that you specify in advance a static blocksize value (64K in our example). This will result in a faster copy. As a reference, we cloned a 128 Gb SSD drive in less than one hour.

6. Once the cloning is finished, detach the new hard disk from the desktop computer and install it on the laptop.

7. Boot the laptop and the OS. It should work as usual, except that the hard drive (identified now as /dev/sda as it’s the only disk in the laptop) will have about 104 Gb free at the end.

8. Use fdisk, gdisk, parted, or any other partitioning tool to create a partition on the free space available. Let’s assume this new partition is /dev/sda3.

9. Initialize the newly created partition for use with LVM:

pvcreate /dev/sda3

10. Add the new Physical Volume to the already existing Volume Group that contains the /home Logical Volume:

vgextend vg_main /dev/sda3

The steps that follow assume that the /home partition is encrypted. (If it’s not, the procedure is overly simple: just ignore the cryptsetup commands, and increase firstly the size of the /home Logical Volume and then the size of the underlying filesystem so that it takes up all free space.) This procedure is taken from this blog post.

11. Unmount the /home partition:

umount /home

12. Do a filesystem check of the encrypted /home partition:

fsck.ext4 /dev/mapper/luks-190b4a12-2c6f-4701-8c2f-0ebc89e7d72c

(the lsblk command will tell you which LUKS volume matches your encrypted /home partition)

13. Remove the device mapping for the LUKS volume:

cryptsetup luksClose luks-190b4a12-2c6f-4701-8c2f-0ebc89e7d72c

14. Extend the Logical Volume to take up all remaining free space:

lvextend -l +100%FREE /dev/vg_main/lv_home

15. Map the LUKS volume to a temporary name:

cryptsetup luksOpen /dev/vg_main/lv_home tmpluks

16. Resize the LUKS volume:

cryptsetup resize tmpluks

17. Resize the filesystem:

resize2fs /dev/mapper/tmpluks

18. Reboot the laptop.

Your new hard disk is now ready to use.

0 réponses

Laisser un commentaire

Participez-vous à la discussion?
N'hésitez pas à contribuer!

Laisser un commentaire

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *

Ce site utilise Akismet pour réduire les indésirables. En savoir plus sur comment les données de vos commentaires sont utilisées.