如何使用 parted 创建交换分区?

如何使用 parted 创建交换分区?

如何使用命令行创建交换分区gparted(parted)

我已成功创建分区,但似乎无法将分区设置为Linux swap / Solaris。我试过

mkpart extended linux-swap -512MB -1s
// -> Error: Invalid number.
&

mkpart extended linux-swap(v1) -512MB -1s
// -> Error: Invalid number.
&

mkpart
type:   extended
Start:  -512MB
End:    -1s
// this works, but I can't set the FS-TYPE

// 帮助页面

(parted) help mkpart                                                      
  mkpart PART-TYPE [FS-TYPE] START END     make a partition

    PART-TYPE is one of: primary, logical, extended
        FS-TYPE is one of: zfs, btrfs, nilfs2, ext4, ext3, ext2, fat32, fat16, hfsx, hfs+, hfs, jfs, swsusp, linux-swap(v1), linux-swap(v0), ntfs,
        reiserfs, freebsd-ufs, hp-ufs, sun-ufs, xfs, apfs2, apfs1, asfs, amufs5, amufs4, amufs3, amufs2, amufs1, amufs0, amufs, affs7, affs6, affs5,
        affs4, affs3, affs2, affs1, affs0, linux-swap, linux-swap(new), linux-swap(old)
        START and END are disk locations, such as 4GB or 10%.  Negative values count from the end of the disk.  For example, -1s specifies exactly the
        last sector.

        'mkpart' makes a partition without creating a new file system on the partition.  FS-TYPE may be specified to set an appropriate partition ID.

答案1

假设您parted/dev/sda磁盘设备上使用,并且已经在上创建了主 ext4 分区/dev/sda2

$ sudo parted /dev/sda
(parted) mkpart
Partition type? primary/extended? primary
File system type? [ext2]? linux-swap
Start? 0%
End? 100%

然后你需要格式化交换文件系统并打开它

$ sudo mkswap /dev/vdb2
$ sudo swapon --all --verbose
swapon on /dev/sda2
swapon: /dev/sda2: found swap signature: version 1, page-size 4, same byte order
swapon: /dev/sda2: pagesize=4096, swapsize=2147483648, devsize=2147483648

将其添加/etc/fstab以便每次重启时都会安装它。

$ sudo vi /etc/fstab
/dev/sda2 none swap sw 0 0

Ubuntu 的 Swap 指南非常全面

答案2

如果您已经创建了分区,我认为您可以使用“mkswap”而不是“mkpart”。

相关内容