2

I want to switch from Linux Mint to Musix. I want to backup my files and copy them after installation, but I was unable to do this because my only external medium for storage is an 8 Gb USB stick. Even when compressed to tar.gz, my files are approximately 12 Gb. That being said, I thought I have only two possibilities left (apart from buying an external hard disk) : 1) To store my files on a cloud drive and 2) To keep the files in a separate partition and copy them after the installation.

Is it possible to access the files this way? If so, is it safe?

  • creating a "data" partition is a good idea, do you have 12G or so of unformated space ? or you know how to shrink a partition without loosing data ? – Archemar Dec 5 '15 at 17:40
  • That's the problem @Archemar,if I shrink the partition I could cause a data loss.Do you know how to prevent this from happening? – VIPaul Dec 5 '15 at 20:47
0

Most installers will wipe the partition on which they install the operating system, but you can store data in a different partition. This means that before you install Musix, you need to split your existing partition in two. Shrink the existing filesystem and the partition that contains it, and create a new partition covering the feed space.

Assuming that you're using the ext4 filesystem (that's the default on Mint, like most Linux distributions) on a PC partition, you can shrink the filesystem, but not while it's mounted. So you need to reboot from some rescue media to do it. You can use SystemRescueCd or GParted Live. You can use the GUI program GParted to simultaneously shrink the partition and the filesystem it contains, or you can use resize2fs to shrink the filesystem followed by fdisk or parted to shrink the partition on the command line. Here are the steps to do it on the command line, in more detail; I assume that your internal disk is /dev/sdz and that it currently contains a single partition /dev/sdz1 containing an ext4 filesystem.

  1. Check the current disk layout. Make sure you're working on the intended disk.

    fdisk -l /dev/sdz
    file -s /dev/sdz1
    

    This should show a disk of the expected size and should tell you that /dev/sdz1 is an ext4 filesystem.

  2. Shrink the filesystem. Let's say you want to shrink it to 50 GB.

    resize2fs /dev/sdz1 50G
    
  3. Shrink the partition.

    # parted /dev/sdz
    (parted) print
    …
    (parted) resizepart 1 ???
    

    Be careful with resizepart: the second argument is the end of the partition, not its size. So you need to add 50GB to the start position shown by the print command. Be careful with units and rounding; it may be better to run unit KiB first to avoid any rounding.

  4. Reboot into the installer and tell it to use the free space.

You'll now have two partitions, one with the operating system and one with your old data. If you want to stay this way, a good way to split your files over two partitions is to have one for the operating system (perforce mounted on /) and one for user data mounted on /home. If you choose to do this, reorganize your files on the existing partition accordingly (put everything in a directory called /vipaul); you can do that before or after the OS installation.

If you want to end up with a single partition, you'll need to do something a bit more sophisticated, because there's no way to merge two filesystems, and you won't be able to grow the new partition since it won't be at the beginning of the disk. If your old data plus the new operating system together cover less than half the disk, then once you've shrunk the partition, create a new partition of the same size at the end of the disk, and copy your data there. Then remove the partition at the beginning of the disk, install the operating system there, move your data from the kept partition to the new OS partition, remove the now-empty partition at the end of the disk and enlarge the OS partition.

Linux has a more flexible partition scheme: LVM. LVM partitions don't have to be contiguous and it's a lot easier and less error-prone to manipulate them; for example, resizing a partition is just lvresize /dev/VOLUME_GROUP/VOLUME_NAME NEW_SIZE. However, you can't convert PC partitions to LVM, and not all Linux distributions have an installer that supports LVM.

  • But when I tried to shrink the partition Gparted warned me that I could lose data.This warning is shown automatically every time a partition is edited,thus it's safe to shrink the partition? Or the warning is genuine and it really is dangerous? – VIPaul Dec 6 '15 at 6:10
  • @VIPaul With parted you need to shrink the filesystem first. GParted does both, so in principle you shouldn't lose data. (I don't know why the command line and the GUI have diverged so much.) I think GParted always shows this warning. Of course you should have backups all the same, but it should be ok. Run fsck -n /dev/sda1 immediately after shrinking the partition, it'll tell you if there are any errors. – Gilles 'SO- stop being evil' Dec 6 '15 at 14:31
1

Both methods will work.

Keeping important files somewhere else is a good idea in general. Either in the cloud or anywhere else (backups!).

But a separate partition will also work and most people I know have separate partitions for /home and for /usr/local/. As long as you do not format these you can simple remount those after installing your new distribution.

1

You can definitely create a new partition and save your files there. Just make sure that you don't install to that partition when you're reinstalling the OS, otherwise it will overwrite what you saved.

I would create a partition before I sent it to cloud storage. That's 12GB of data that you have to upload and then download again once you're done.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.